Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration documents from ASM #143

Merged
merged 1 commit into from
Aug 21, 2021

Conversation

tashirosota
Copy link
Contributor

#98

@tashirosota tashirosota force-pushed the issues/98 branch 3 times, most recently from e932206 to 7ffbf3a Compare July 2, 2021 13:35
@tashirosota
Copy link
Contributor Author

@okuramasafumi
Hi. I made a template for the time being.
Let me check some,

 - Is the location correct?
 - How pattern do you want migration case?
 - Is there anything you would like to mention in particular?

@okuramasafumi
Copy link
Owner

Is the location correct?

doc directory is fine, but this directory is also used by yard (that's why it's ignored).
We could use docs directory so that we can separate handwritten documents with autogenerated documents.

Also I want to mention that file name should be something like "migrate_from_jbuilder", not just "jbuilder".

How pattern do you want migration case?

I think we need migration document for real-world, complex cases. For example, with jbuilder we use partials a lot so I'd like to mention how to write partial-like serializer with Alba.

Is there anything you would like to mention in particular?

It's important to mention that Alba doesn't have all the features AMS or jbuilder have. For example, Alba doesn't support cache. I think it's fair to mention some feature Alba doesn't have.

@tashirosota
Copy link
Contributor Author

@okuramasafumi
Thanks for review!I'll fix in this week.

@tashirosota
Copy link
Contributor Author

@okuramasafumi
I'm sorry it will take longer than expected!
If I'm in a hurry, I'd like to divide the PR for each serializer, but what about?
I will start with the ActiveModelSerializers that we use all the time.

@okuramasafumi
Copy link
Owner

@tashirosota Yeah just adding a document for AMS is fine.

@tashirosota tashirosota changed the title [WIP] Add migration documents Add migration documents Jul 13, 2021
@tashirosota tashirosota marked this pull request as ready for review July 13, 2021 12:07
@tashirosota
Copy link
Contributor Author

tashirosota commented Jul 13, 2021

@okuramasafumi
Hi okura.Please review for this!
I usually use ASM, couldn't find unsupported ASM's features, if you know then, teach me.
And please review for pr.

@tashirosota tashirosota changed the title Add migration documents Add migration documents from ASM Jul 13, 2021
@tashirosota tashirosota force-pushed the issues/98 branch 4 times, most recently from b3bb901 to 81dc546 Compare July 13, 2021 12:33

This guide is aimed at helping ActiveModelSerializers users transition to Alba, and it consists of three parts:

1. Basically serialization
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Basically serialization
1. Basic serialization

This guide is aimed at helping ActiveModelSerializers users transition to Alba, and it consists of three parts:

1. Basically serialization
2. Complexity serialization
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Complexity serialization
2. Complex serialization

end

class Article
attr_accessor :id, :title, :body
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
attr_accessor :id, :title, :body
attr_accessor :user_id, :title, :body

end
```

## 1. Basically serialization
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 1. Basically serialization
## 1. Basic serialization

Comment on lines 67 to 73
=> {
user: {
id: id,
created_at: created_at,
updated_at: updated_at
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=> {
user: {
id: id,
created_at: created_at,
updated_at: updated_at
}
}
# => {
# user: {
# id: id,
# created_at: created_at,
# updated_at: updated_at
# }
# }

When we print output, it should be commented out to make it clear that it's no actually code

}
```

#### When Alba
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### When Alba
#### Alba

Comment on lines 284 to 286
=> {
email: email
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=> {
email: email
}
# => {
# email: email
# }

}
```

#### When Alba
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### When Alba
#### Alba

Comment on lines 309 to 318
=> {
:id=>1,
:created_at=>created_at,
:updated_at=>updated_at,
:custom_params=>{
:given_params=>{
:a=>:b
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=> {
:id=>1,
:created_at=>created_at,
:updated_at=>updated_at,
:custom_params=>{
:given_params=>{
:a=>:b
}
}
}
# => {
# :id=>1,
# :created_at=>created_at,
# :updated_at=>updated_at,
# :custom_params=>{
# :given_params=>{
# :a=>:b
# }
# }
# }

Comment on lines 340 to 347
=> {
:id=>1,
:created_at=>created_at,
:updated_at=>updated_at,
:custom_params=>{
:a=>:b
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=> {
:id=>1,
:created_at=>created_at,
:updated_at=>updated_at,
:custom_params=>{
:a=>:b
}
}
# => {
# :id=>1,
# :created_at=>created_at,
# :updated_at=>updated_at,
# :custom_params=>{
# :a=>:b
# }
# }

@okuramasafumi
Copy link
Owner

@tashirosota I suggested multiple changes including fixing typos and commenting out outputs.

https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/howto/serialize_poro.md
This document shows that serializing PORO with AMS is pretty hard. Should we use ActiveModel objects for examples instead?

@tashirosota tashirosota force-pushed the issues/98 branch 2 times, most recently from 0b1369a to 0eeb5d2 Compare July 29, 2021 13:58
Example clsss is included `ActiveModel::Model`, because [serializing PORO with AMS is pretty hard](https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/howto/serialize_poro.md).This example also works with ActiveRecord.

```rb
class User
Copy link
Contributor Author

@tashirosota tashirosota Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@okuramasafumi
Thanks for review!
I can't find how to serialize with object included ActiveModel::Model.
https://github.com/rails-api/active_model_serializers/tree/0-10-stable#high-level-behavior
SomeResource < ActiveModelSerializers::Model is a bad example of both compatibility, so I'd like to use SomeResource < ActiveRecord::Base, but is that okay?
Like this.

class User < ActiveRecord::Base
  # columns: id, created_at, updated_at
  has_one :profile
  has_many :articles
end

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply.
Yes, using AR::Base is fine.

@tashirosota tashirosota force-pushed the issues/98 branch 4 times, most recently from c291bf9 to 8625ebc Compare August 3, 2021 13:01
@codecov
Copy link

codecov bot commented Aug 21, 2021

Codecov Report

Merging #143 (1aec442) into main (755a9c6) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #143      +/-   ##
==========================================
+ Coverage   99.37%   99.40%   +0.02%     
==========================================
  Files           9        9              
  Lines         322      336      +14     
==========================================
+ Hits          320      334      +14     
  Misses          2        2              
Impacted Files Coverage Δ
lib/alba.rb 100.00% <0.00%> (ø)
lib/alba/resource.rb 99.39% <0.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 755a9c6...1aec442. Read the comment docs.

Copy link
Owner

@okuramasafumi okuramasafumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@okuramasafumi okuramasafumi merged commit f91b492 into okuramasafumi:main Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants