Module: Core::Io::Json::Grammar::Intermediate

Included in:
Endpoint::BasicHandler::Associations::BelongsTo::Handler::Association, Actions, Node, Root
Defined in:
app/api/core/io/json/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children


3
4
5
# File 'app/api/core/io/json/grammar.rb', line 3

def children
  @children
end

Instance Method Details

#[](name) ⇒ Object


13
14
15
# File 'app/api/core/io/json/grammar.rb', line 13

def [](name)
  @children[name] ||= Node.new(name)
end

#call(object, options, stream) ⇒ Object


17
18
19
# File 'app/api/core/io/json/grammar.rb', line 17

def call(object, options, stream)
  process_children(object, options, stream)
end

#initialize(children) ⇒ Object


5
6
7
# File 'app/api/core/io/json/grammar.rb', line 5

def initialize(children)
  @children = children || {}
end

#inspectObject


45
46
47
# File 'app/api/core/io/json/grammar.rb', line 45

def inspect
  @children.values.inspect
end

#leaf(name, attribute) ⇒ Object


9
10
11
# File 'app/api/core/io/json/grammar.rb', line 9

def leaf(name, attribute)
  @children[name] ||= Leaf.new(name, attribute)
end

#merge(node) {|node.merge_children_with(self)| ... } ⇒ Object

Yields:


28
29
30
# File 'app/api/core/io/json/grammar.rb', line 28

def merge(node)
  yield(node.merge_children_with(self))
end

#merge_children_with(node) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/api/core/io/json/grammar.rb', line 32

def merge_children_with(node)
  (node.children.keys + @children.keys).uniq.each_with_object({}) do |k, store|
    cloned = case
             when @children.key?(k) && node.children.key?(k) then node.children[k].merge(@children[k])
             when @children.key?(k)                          then @children[k]
             when node.children.key?(k)                      then node.children[k]
             else raise 'Odd, how did that happen?'
             end

    store[k] = cloned
  end
end