class CachedSerializer::AttrSerializerCollection

Attributes

collection[RW]

Public Class Methods

new(collection = []) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 5
def initialize(collection = [])
  self.collection = collection
end

Public Instance Methods

<<(item) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 24
def <<(item)
  add(item)
end
add(*attr_serializers) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 9
def add(*attr_serializers)
  attr_serializers.each do |attr_serializer|
    existing = collection.find { |serializer| serializer.attr_name == attr_serializer.attr_name }
    if existing
      existing.recompute_ifs.concat(attr_serializer.recompute_ifs)
      existing.recompute = attr_serializer.recompute # shadowed attrs override the blocks of previously-declared ones
      existing.expires_in = attr_serializer.expires_in # shadowed attrs override the expires_in of previously-declared ones
    else
      collection << attr_serializer
    end
  end
end
Also aliased as: push
concat(items) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 28
def concat(items)
  add(*items)
end
method_missing(method, *args, &block) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 32
def method_missing(method, *args, &block)
  collection.send(method, *args, &block)
end
push(*attr_serializers)
Alias for: add
respond_to?(method, *args) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 36
def respond_to?(method, *args)
  collection.respond_to?(method, *args)
end
serialize_for(subject) click to toggle source
# File lib/cached_serializer/attr_serializer_collection.rb, line 40
def serialize_for(subject)
  collection.reduce({}) do |memo, attr_serializer|
    memo.merge(attr_serializer.serialize_for(subject))
  end
end