Module: Glib::Json::Traversal

Defined in:
app/controllers/concerns/glib/json/traversal.rb

Defined Under Namespace

Classes: Visitor

Instance Method Summary collapse

Instance Method Details

#__json_traversal_on_complete(&block) ⇒ Object



7
8
9
10
# File 'app/controllers/concerns/glib/json/traversal.rb', line 7

def __json_traversal_on_complete(&block)
  @__json_traversal_on_completes ||= []
  @__json_traversal_on_completes << block
end

#__json_traversal_on_traverse(&block) ⇒ Object



2
3
4
5
# File 'app/controllers/concerns/glib/json/traversal.rb', line 2

def __json_traversal_on_traverse(&block)
  @__json_traversal_on_traverses ||= []
  @__json_traversal_on_traverses << block
end

#__json_traversal_performObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/concerns/glib/json/traversal.rb', line 12

def __json_traversal_perform
  if (hash = json_transformation_start).is_a?(Hash)
    traverse hash['header']&.[]('childViews')
    traverse hash['body']&.[]('childViews')
    traverse hash['footer']&.[]('childViews')

    @__json_traversal_on_completes.each do |block|
      block.call
    end
  end
end

#traverse(views) ⇒ Object



24
25
26
27
28
29
30
# File 'app/controllers/concerns/glib/json/traversal.rb', line 24

def traverse(views)
  Visitor.new.traverse_multiple views, ->(view) do
    @__json_traversal_on_traverses.each do |block|
      block.call(view)
    end
  end
end