Module: Conglomerate::Serializer

Defined in:
lib/conglomerate/serializer.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(descendant) ⇒ Object



3
4
5
# File 'lib/conglomerate/serializer.rb', line 3

def self.included(descendant)
  descendant.extend(ClassMethods)
end

Instance Method Details

#initialize(objects, options = {}) ⇒ Object



7
8
9
10
# File 'lib/conglomerate/serializer.rb', line 7

def initialize(objects, options = {})
  self.objects = [*objects].compact
  self.context = options.fetch(:context, nil)
end

#serializeObject



12
13
14
15
16
17
18
# File 'lib/conglomerate/serializer.rb', line 12

def serialize
  {
    "collection" => actions.inject({}) do |collection, action|
      send("apply_#{action}", collection)
    end
  }
end