Class: Glib::Json::Traversal::Visitor
- Inherits:
-
Object
- Object
- Glib::Json::Traversal::Visitor
- Defined in:
- app/controllers/concerns/glib/json/traversal.rb
Instance Attribute Summary collapse
-
#component_registries ⇒ Object
readonly
Used in test crawler.
-
#deferred_actions ⇒ Object
readonly
Used in test crawler.
-
#forms ⇒ Object
readonly
Used in test crawler.
Instance Method Summary collapse
- #begin_page(spec) ⇒ Object
- #current_component_registry ⇒ Object
- #current_deferred_actions ⇒ Object
- #defer_action(action_crawler, target_id) ⇒ Object
- #end_page(spec) ⇒ Object
- #fullPageForm(spec) ⇒ Object
-
#initialize(crawler_test: false) ⇒ Visitor
constructor
A new instance of Visitor.
- #traverse_multiple(views, block) ⇒ Object
- #traverse_single(view, block) ⇒ Object
- #traverse_vertical_content(view, block) ⇒ Object
Constructor Details
#initialize(crawler_test: false) ⇒ Visitor
Returns a new instance of Visitor.
38 39 40 41 42 43 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 38 def initialize(crawler_test: false) @crawler_test = crawler_test @component_registries = [] @forms = [] @deferred_actions = [] end |
Instance Attribute Details
#component_registries ⇒ Object (readonly)
Used in test crawler
36 37 38 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 36 def component_registries @component_registries end |
#deferred_actions ⇒ Object (readonly)
Used in test crawler
36 37 38 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 36 def deferred_actions @deferred_actions end |
#forms ⇒ Object (readonly)
Used in test crawler
36 37 38 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 36 def forms @forms end |
Instance Method Details
#begin_page(spec) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 49 def begin_page(spec) return unless @crawler_test if (form = fullPageForm(spec)) @forms << form end @component_registries << {} @deferred_actions << [] end |
#current_component_registry ⇒ Object
106 107 108 109 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 106 def current_component_registry # Add "|| {}" because it broke on hz @component_registries.last || {} end |
#current_deferred_actions ⇒ Object
101 102 103 104 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 101 def current_deferred_actions # Add "|| []" because it broke on hz @deferred_actions.last || [] end |
#defer_action(action_crawler, target_id) ⇒ Object
111 112 113 114 115 116 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 111 def defer_action(action_crawler, target_id) current_deferred_actions << { action: action_crawler, target_id: target_id } end |
#end_page(spec) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 60 def end_page(spec) return unless @crawler_test if fullPageForm(spec) @forms.pop end current_actions = @deferred_actions.pop # Execute actions with target IDs to ensure the target components have been loade. current_actions.each do |action| action, target_id = action.values if (view_spec = current_component_registry[target_id]) action.execute(view_spec) if action else # raise "View not found for ID: #{target_id}" end end @component_registries.pop end |
#fullPageForm(spec) ⇒ Object
45 46 47 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 45 def fullPageForm(spec) spec['fullPageForm'] end |
#traverse_multiple(views, block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 82 def traverse_multiple(views, block) if views.is_a? Array views.each do |view| case view['view'] when 'panels/form-v1' @forms << view traverse_single view, block @forms.pop else traverse_single view, block end end end end |
#traverse_single(view, block) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 118 def traverse_single(view, block) if @crawler_test && (view_id = view['id']) current_component_registry[view_id] = view end block.call view # Generic view children traverse_multiple view['childViews'], block # Generic menu buttons traverse_multiple view['buttons'], block traverse_multiple view['childButtons'], block # Split panel traverse_vertical_content view['left'], block traverse_vertical_content view['center'], block traverse_vertical_content view['right'], block # List template traverse_multiple view['editButtons'], block traverse_multiple view['leftButtons'], block traverse_multiple view['rightButtons'], block # Select field traverse_vertical_content view['header'], block traverse_vertical_content view['footer'], block # Table row traverse_multiple view['cellViews'], block # Table/List if (sections = view['sections']).is_a? Array sections.each do |section| traverse_vertical_content section['header'], block traverse_multiple section['rows'], block traverse_vertical_content section['footer'], block end end end |
#traverse_vertical_content(view, block) ⇒ Object
97 98 99 |
# File 'app/controllers/concerns/glib/json/traversal.rb', line 97 def traverse_vertical_content(view, block) traverse_multiple view['childViews'], block if view end |