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.



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

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

Instance Method Details

#call(object, options, stream) ⇒ Object



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

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



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

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

#for(owner) ⇒ Object



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

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

#inspectObject



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

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