Class: Settings::Node
- Inherits:
-
Object
- Object
- Settings::Node
- Defined in:
- lib/iron/settings/node.rb
Overview
Base class for groups and entries - provides our structure
Constant Summary collapse
- NODE_SEPARATOR =
Used to separate node names in a full key
'.'.freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
All nodes have these items…
-
#name ⇒ Object
All nodes have these items…
-
#parent ⇒ Object
All nodes have these items…
-
#root ⇒ Object
All nodes have these items…
Instance Method Summary collapse
- #entry? ⇒ Boolean
- #group? ⇒ Boolean
-
#initialize(parent, name = nil) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(parent, name = nil) ⇒ Node
Returns a new instance of Node.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/iron/settings/node.rb', line 12 def initialize(parent, name = nil) # Validate name unless parent.nil? || name.match(/[a-z0-9_]+/) raise ArgumentError.new("Invalid settings key name '#{name}' - may only contain a-z, 0-9 and _ characters") end @parent = parent @name = name if @parent.nil? # We are the root! @root = self @key = nil else # Normal node, chain ourselves @root = parent.root if parent.key.blank? @key = name else @key = [@parent.key, name].join(NODE_SEPARATOR) end end end |
Instance Attribute Details
#key ⇒ Object
All nodes have these items…
10 11 12 |
# File 'lib/iron/settings/node.rb', line 10 def key @key end |
#name ⇒ Object
All nodes have these items…
10 11 12 |
# File 'lib/iron/settings/node.rb', line 10 def name @name end |
#parent ⇒ Object
All nodes have these items…
10 11 12 |
# File 'lib/iron/settings/node.rb', line 10 def parent @parent end |
#root ⇒ Object
All nodes have these items…
10 11 12 |
# File 'lib/iron/settings/node.rb', line 10 def root @root end |
Instance Method Details
#entry? ⇒ Boolean
40 41 42 |
# File 'lib/iron/settings/node.rb', line 40 def entry? false end |
#group? ⇒ Boolean
36 37 38 |
# File 'lib/iron/settings/node.rb', line 36 def group? false end |