-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 PORO serializable base class: ActiveModelSerializers::Model #1272
Conversation
end | ||
|
||
def read_attribute_for_serialization(key) | ||
if key == :id || key == 'id' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we make attributes a hash with indifferent access, we wouldn't need this ||
check.
I just think it's a little weird to only have indifferent access for the id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to explain it but now I'm not sure
B mobile phone
On Oct 15, 2015, at 6:22 AM, L. Preston Sego III [email protected] wrote:
In lib/active_model_serializers/model.rb:
- def id
attributes.fetch(:id) { self.class.name.downcase }
- end
Defaults to the downcased model name and updated_at
- def cache_key
attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime("%Y%m%d%H%M%S%9N")}" }
- end
Defaults to the time the serializer file was modified.
- def updated_at
attributes.fetch(:updated_at) { File.mtime(**FILE**) }
- end
- def read_attribute_for_serialization(key)
if we make attributes a hash with indifferent access, we wouldn't need this || check.if key == :id || key == 'id'
I just think it's a little weird to only have indifferent access for the id.—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reasons I don't recall there might be an id
method but not and :id
attribute but it still hits method_missing...
I'm going to merge this so people can being using it, even though there's some followup |
Add PORO serializable base class: ActiveModelSerializers::Model
Extracted from #1260