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.



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

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

Instance Method Details

#call(object, options, stream) ⇒ Object



95
96
97
98
99
100
101
# File 'app/api/core/io/json/grammar.rb', line 95

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



78
79
80
# File 'app/api/core/io/json/grammar.rb', line 78

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

#for(owner) ⇒ Object



72
73
74
# File 'app/api/core/io/json/grammar.rb', line 72

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

#inspectObject



110
111
112
# File 'app/api/core/io/json/grammar.rb', line 110

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