Class: Moka::SiteTree::SiteNode
- Defined in:
- lib/commands/lib/site_tree.rb
Instance Attribute Summary
Attributes inherited from TreeNode
Instance Method Summary collapse
-
#find_group(group_name) ⇒ Object
Returns the group having the name equal to the string passed as argument or nil if such group does not exist.
-
#groups ⇒ Object
Returns a NodeArray object containing all the site’s groups (the children of the site node).
-
#initialize(name, params = {}, parent = nil) ⇒ SiteNode
constructor
A new instance of SiteNode.
-
#save ⇒ Object
Save site variables in the variables.yml file.
Methods inherited from TreeNode
#children, #find_child, #params, #variables, #vars
Constructor Details
#initialize(name, params = {}, parent = nil) ⇒ SiteNode
Returns a new instance of SiteNode.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/commands/lib/site_tree.rb', line 68 def initialize(name, params = {}, parent = nil) super(name, params, parent) if File.exist? File.("project/site/variables.yml", MOKA_ROOT) site_vars = YAML.load_file(File.("project/site/variables.yml", MOKA_ROOT)) || {} site_vars.each do |key, value| unless RESERVED_NAMES.include? key self.instance_variable_set "@#{key}", value @variables[key.to_s] = value self.create_method(key) do self.instance_variable_get("@#{key}") end self.create_method("#{key}=") do |v| self.instance_variable_set("@#{key}", v); @variables[key.to_s] = v end end end end params.each do |key, value| key.gsub!(/\s/, "_") if value.is_a?(Hash) self.instance_variable_set "@#{key}", GroupNode.new(key, value, self) @children << instance_eval("@#{key}") else self.instance_variable_set "@#{key}", value @params[key.to_s] = value end self.create_method(key) do self.instance_variable_get("@#{key}") end end end |
Instance Method Details
#find_group(group_name) ⇒ Object
Returns the group having the name equal to the string passed as argument or nil if such group does not exist
101 102 103 |
# File 'lib/commands/lib/site_tree.rb', line 101 def find_group(group_name) children.find(group_name) end |
#groups ⇒ Object
Returns a NodeArray object containing all the site’s groups (the children of the site node)
96 97 98 |
# File 'lib/commands/lib/site_tree.rb', line 96 def groups self.children end |