Class: PageEz::Visitors::RegisteredNameVisitor
- Inherits:
-
Object
- Object
- PageEz::Visitors::RegisteredNameVisitor
- Defined in:
- lib/page_ez/visitors/registered_name_visitor.rb
Instance Method Summary collapse
- #begin_block_evaluation ⇒ Object
- #define_method ⇒ Object
- #end_block_evaluation ⇒ Object
- #inherit_from ⇒ Object
-
#initialize ⇒ RegisteredNameVisitor
constructor
A new instance of RegisteredNameVisitor.
- #process_macro(_, name, construction_strategy) ⇒ Object
- #reset ⇒ Object
- #track_method_added(name, construction_strategy) ⇒ Object
- #track_method_delegated(name) ⇒ Object
- #track_method_renamed(from, to) ⇒ Object
- #track_method_undefined(name) ⇒ Object
Constructor Details
#initialize ⇒ RegisteredNameVisitor
Returns a new instance of RegisteredNameVisitor.
4 5 6 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 4 def initialize reset end |
Instance Method Details
#begin_block_evaluation ⇒ Object
8 9 10 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 8 def begin_block_evaluation @parents.push(@current_strategy) end |
#define_method ⇒ Object
16 17 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 16 def define_method(*) end |
#end_block_evaluation ⇒ Object
12 13 14 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 12 def end_block_evaluation @parents.pop end |
#inherit_from ⇒ Object
19 20 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 19 def inherit_from(*) end |
#process_macro(_, name, construction_strategy) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 58 def process_macro(_, name, construction_strategy) @declared_constructors[parent_id] ||= [] if @declared_constructors[parent_id].map { _1.first }.include?(name) raise DuplicateElementDeclarationError, "duplicate element :#{name} declared" end @declared_constructors[parent_id] += [[name, construction_strategy]] @current_strategy = construction_strategy end |
#reset ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 69 def reset @parents = [] @current_strategy = nil @declared_constructors = {} @all_methods = {} @delegated_methods = {} @renamed_methods = {} end |
#track_method_added(name, construction_strategy) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 38 def track_method_added(name, construction_strategy) @declared_constructors[parent_id] ||= [] found = @declared_constructors[parent_id].find { _1 == [name, construction_strategy] } if found && found[1]&.selector_type != :dynamic raise DuplicateElementDeclarationError, "duplicate element :#{name} declared" end if current_renamed_methods.include?(name) && current_all_methods.include?(name) raise DuplicateElementDeclarationError, "duplicate element :#{name} declared" end if current_delegated_methods.include?(name) && current_all_methods.include?(name) raise DuplicateElementDeclarationError, "duplicate element :#{name} declared" end current_all_methods.push(name) end |
#track_method_delegated(name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 30 def track_method_delegated(name) if current_all_methods.count { _1 == name } > 1 raise DuplicateElementDeclarationError, "duplicate element :#{name} declared" end current_delegated_methods.push(name) end |
#track_method_renamed(from, to) ⇒ Object
26 27 28 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 26 def track_method_renamed(from, to) current_renamed_methods.push(from) end |
#track_method_undefined(name) ⇒ Object
22 23 24 |
# File 'lib/page_ez/visitors/registered_name_visitor.rb', line 22 def track_method_undefined(name) current_all_methods.delete(name) end |