Class: Settings::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/iron/settings/node.rb

Overview

Base class for groups and entries - provides our structure

Direct Known Subclasses

Entry, Group

Constant Summary collapse

NODE_SEPARATOR =

Used to separate node names in a full key

'.'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject

All nodes have these items…



10
11
12
# File 'lib/iron/settings/node.rb', line 10

def key
  @key
end

#nameObject

All nodes have these items…



10
11
12
# File 'lib/iron/settings/node.rb', line 10

def name
  @name
end

#parentObject

All nodes have these items…



10
11
12
# File 'lib/iron/settings/node.rb', line 10

def parent
  @parent
end

#rootObject

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/iron/settings/node.rb', line 40

def entry?
  false
end

#group?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/iron/settings/node.rb', line 36

def group?
  false
end