Class: Page::Utils::PageNode
- Inherits:
-
Object
- Object
- Page::Utils::PageNode
- Defined in:
- app/concepts/page/utils/page_node.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page_instance) ⇒ PageNode
constructor
A new instance of PageNode.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(page_instance) ⇒ PageNode
Returns a new instance of PageNode.
12 13 14 15 16 17 18 19 |
# File 'app/concepts/page/utils/page_node.rb', line 12 def initialize(page_instance) @hash = {} @node_start_id = 0 @page_instance = page_instance page_instance.instance_variables.each do |page_instance_var_key| self.instance_variable_set(page_instance_var_key, page_instance.instance_variable_get(page_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/page/utils/page_node.rb', line 21 def method_missing meth, *args, &block begin @page_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"] = @page_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"] = PageNode.build(@page_instance, &block) end end end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'app/concepts/page/utils/page_node.rb', line 10 def hash @hash end |