Class: Graphiti::Util::RemoteSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/util/remote_serializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ RemoteSerializer

Returns a new instance of RemoteSerializer.



8
9
10
11
# File 'lib/graphiti/util/remote_serializer.rb', line 8

def initialize(base)
  @serializer = ::Class.new(base)
  @serializer.type { @object._type }
end

Class Method Details

.for(base, models) ⇒ Object



4
5
6
# File 'lib/graphiti/util/remote_serializer.rb', line 4

def self.for(base, models)
  new(base).generate(models)
end

Instance Method Details

#generate(models) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphiti/util/remote_serializer.rb', line 13

def generate(models)
  models.each do |model|
    model.to_h.each_pair do |key, value|
      if key == :_relationships
        add_relationships(value)
      elsif add_attribute?(model, key)
        @serializer.attribute(key)
      end
    end
  end
  post_process(@serializer, models)
  @serializer
end