Skip to content

Customize attributes by any callable object #105

@ZurgInq

Description

@ZurgInq

example:

class ToISO8601
  def self.call(obj)
    obj.iso8601
  end
end

# or ToISO8601 = ->(obj) { obj.iso8601 }

class PostSerializer
  include JSONAPI::Serializer

  attribute :created_at, ToISO8601
  attribute :updated_at, ToISO8601
  # or by lambda
  # attribute :updated_at, ->(obj) { obj.iso8601 }
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions