Class: Lagoon::Analyzer::ControllerScopeCollector
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Lagoon::Analyzer::ControllerScopeCollector
- Defined in:
- lib/lagoon/analyzer/ast/controller_scope_collector.rb
Defined Under Namespace
Classes: Callback
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
Instance Method Summary collapse
- #callbacks_for(action) ⇒ Object
-
#initialize(controller_names: nil) ⇒ ControllerScopeCollector
constructor
A new instance of ControllerScopeCollector.
- #visit_class_node(node) ⇒ Object
- #visit_module_node(node) ⇒ Object
Constructor Details
#initialize(controller_names: nil) ⇒ ControllerScopeCollector
Returns a new instance of ControllerScopeCollector.
17 18 19 20 21 22 23 |
# File 'lib/lagoon/analyzer/ast/controller_scope_collector.rb', line 17 def initialize(controller_names: nil) super() @controller_names = Array(controller_names).compact.to_set(&:to_s) @methods = {} @callbacks = [] @namespace = [] end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
15 16 17 |
# File 'lib/lagoon/analyzer/ast/controller_scope_collector.rb', line 15 def methods @methods end |
Instance Method Details
#callbacks_for(action) ⇒ Object
25 26 27 |
# File 'lib/lagoon/analyzer/ast/controller_scope_collector.rb', line 25 def callbacks_for(action) @callbacks.select { |callback| callback.applies_to?(action) }.map(&:method_name) end |
#visit_class_node(node) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lagoon/analyzer/ast/controller_scope_collector.rb', line 33 def visit_class_node(node) class_name = qualified_name(node.constant_path) return unless @controller_names.empty? || @controller_names.include?(class_name) Array(node.body&.body).each do |child| case child when Prism::DefNode then @methods[child.name.to_s] = child when Prism::CallNode then collect_callback(child) end end end |
#visit_module_node(node) ⇒ Object
29 30 31 |
# File 'lib/lagoon/analyzer/ast/controller_scope_collector.rb', line 29 def visit_module_node(node) with_namespace(constant_path_name(node.constant_path)) { super } end |