Class: Component::Utils::ComponentNode
- Inherits:
-
Object
- Object
- Component::Utils::ComponentNode
- Defined in:
- app/concepts/component/utils/component_node.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(component_instance) ⇒ ComponentNode
constructor
A new instance of ComponentNode.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(component_instance) ⇒ ComponentNode
Returns a new instance of ComponentNode.
12 13 14 15 16 17 18 19 |
# File 'app/concepts/component/utils/component_node.rb', line 12 def initialize(component_instance) @hash = {} @node_start_id = 0 @component_instance = component_instance component_instance.instance_variables.each do |component_instance_var_key| self.instance_variable_set(component_instance_var_key, component_instance.instance_variable_get(component_instance_var_key)) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/concepts/component/utils/component_node.rb', line 21 def method_missing meth, *args, &block begin @component_instance.send(meth, *args, &block) rescue node_id = @node_start_id + 1 @node_start_id = node_id current_node = "#{meth}_#{@node_start_id}" @hash[current_node] = {} @hash[current_node]["component_name"] = meth.to_s @hash[current_node]["config"] = {} @hash[current_node]["argument"] = nil if meth == :partial @hash[current_node]["components"] = @component_instance.send(args.first, *args.drop(1)) else if args.first.is_a?(Hash) @hash[current_node]["config"] = args.first else @hash[current_node]["argument"] = args.first end if block_given? @hash[current_node]["components"] = ComponentNode.build(@component_instance, &block) end end end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'app/concepts/component/utils/component_node.rb', line 10 def hash @hash end |
Class Method Details
.build(component_instance, &block) ⇒ Object
4 5 6 7 8 |
# File 'app/concepts/component/utils/component_node.rb', line 4 def self.build(component_instance, &block) node = ComponentNode.new(component_instance) node.instance_eval(&block) node.hash end |