class Nagare::Collection
Attributes
collection[R]
serializer[R]
Public Class Methods
_key()
click to toggle source
# File lib/nagare.rb, line 76 def self._key @key || "items" end
attributes(*attributes)
click to toggle source
# File lib/nagare.rb, line 84 def self.attributes(*attributes) @attributes = _attributes.concat(attributes) end
key(key)
click to toggle source
# File lib/nagare.rb, line 80 def self.key(key) @key = key end
new(collection, context, serializer:)
click to toggle source
# File lib/nagare.rb, line 88 def initialize(collection, context, serializer:) @collection = collection @context = context @serializer = serializer end
Public Instance Methods
as_json(options = nil)
click to toggle source
# File lib/nagare.rb, line 100 def as_json(options = nil) items = map do |item| item.as_json end attributes.merge({ self.class._key => items, }) end
each() { |serializer| ... }
click to toggle source
# File lib/nagare.rb, line 94 def each collection.map do |item| yield serializer.new(item, context) end end