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

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.


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

def children
  @children
end

Instance Method Details

#[](name) ⇒ Object


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

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

#call(object, options, stream) ⇒ Object


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

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

#initialize(children) ⇒ Object


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

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

#inspectObject

rubocop:enable Metrics/MethodLength


54
55
56
# File 'app/api/core/io/json/grammar.rb', line 54

def inspect
  @children.values.inspect
end

#leaf(name, attribute) ⇒ Object


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

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

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

Yields:


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

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

#merge_children_with(node) ⇒ Object

rubocop:todo Metrics/MethodLength


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/api/core/io/json/grammar.rb', line 32

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

      store[k] = cloned
    end
end