Class: Core::Io::Json::Grammar::Root

Inherits:
Object
  • Object
show all
Includes:
Intermediate
Defined in:
app/api/core/io/json/grammar.rb

Instance Attribute Summary

Attributes included from Intermediate

#children

Instance Method Summary collapse

Methods included from Intermediate

#[], #leaf, #merge, #merge_children_with

Constructor Details

#initialize(owner, children = nil) ⇒ Root

Returns a new instance of Root


58
59
60
61
# File 'app/api/core/io/json/grammar.rb', line 58

def initialize(owner, children = nil)
  super(children)
  @owner = owner
end

Instance Method Details

#call(object, options, stream) ⇒ Object


88
89
90
91
92
93
94
# File 'app/api/core/io/json/grammar.rb', line 88

def call(object, options, stream)
  rooted_json(stream, options[:nested]) do |stream|
    stream.attribute('created_at', object.created_at)
    stream.attribute('updated_at', object.updated_at)
    super(object, options, stream)
  end
end

#encode(object, options) ⇒ Object


69
70
71
# File 'app/api/core/io/json/grammar.rb', line 69

def encode(object, options)
  object_encoder(object, options).call(object, options, options[:stream])
end

#for(owner) ⇒ Object


63
64
65
# File 'app/api/core/io/json/grammar.rb', line 63

def for(owner)
  duplicate { |children| self.class.new(owner, children) }
end

#inspectObject


103
104
105
# File 'app/api/core/io/json/grammar.rb', line 103

def inspect
  "Root<#{super}>"
end