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 PORO serializable base class: ActiveModelSerializers::Model #1272

Merged
merged 1 commit into from
Oct 20, 2015

Conversation

bf4
Copy link
Member

@bf4 bf4 commented Oct 15, 2015

Extracted from #1260

end

def read_attribute_for_serialization(key)
if key == :id || key == 'id'
Copy link
Contributor

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.

Copy link
Member Author

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 notifications@github.com 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 key == :id || key == 'id'
    
    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.


Reply to this email directly or view it on GitHub.

Copy link
Member Author

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...

@bf4
Copy link
Member Author

bf4 commented Oct 20, 2015

bf4 added a commit that referenced this pull request Oct 20, 2015
Add PORO serializable base class: ActiveModelSerializers::Model
@bf4 bf4 merged commit 737784c into rails-api:master Oct 20, 2015
@bf4 bf4 deleted the add_public_poro_base branch October 20, 2015 17:50
@aldreth aldreth mentioned this pull request Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants