class Settings::Group

Groups contain a set of items - other groups and entries - that can be traversed by the Cursor to read out or set values.

Public Class Methods

new(parent, name = nil) click to toggle source

Create and set up a new group with the given name and optional parent

Calls superclass method Settings::Node::new
# File lib/iron/settings/group.rb, line 9
def initialize(parent, name = nil)
  super
  @nodes = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/iron/settings/group.rb, line 22
def [](key)
  find_item(key)
end
add_entry(name, type, default = nil, &block) click to toggle source
# File lib/iron/settings/group.rb, line 50
def add_entry(name, type, default = nil, &block)
  default = block unless block.nil?
  entry = Settings::Entry.new(self, type, name, default)
  @nodes[name] = entry
  entry
end
add_group(name) click to toggle source

Add a group to our list of items, and define a getter to access it by name

# File lib/iron/settings/group.rb, line 31
    def add_group(name)    
      # Add getter for the group
      instance_eval <<-eos
        def #{name}
          find_group('#{name}')
        end
      eos

      group = Group.new(self, name)
      @nodes[name] = group
      group
    end
entries(include_children = true) click to toggle source

Returns all child entries for this group, optionally recursing to extract sub-groups' entries as well

# File lib/iron/settings/group.rb, line 80
def entries(include_children = true)
  @nodes.values.collect do |item|
    if item.entry?
      item
    elsif include_children
      item.entries(include_children)
    else 
      []
    end
  end.flatten
end
find_entry(name) click to toggle source
# File lib/iron/settings/group.rb, line 57
def find_entry(name)
  entry = @nodes[name.to_s]
  entry.is_a?(Settings::Entry) ? entry : nil
end
find_group(key) click to toggle source

Simply access a given group by name

# File lib/iron/settings/group.rb, line 45
def find_group(key)
  group = @nodes[key.to_s]
  group.is_a?(Group) ? group : nil
end
find_item(key) click to toggle source
# File lib/iron/settings/group.rb, line 74
def find_item(key)
  @nodes[key.to_s]
end
get_entry_val(name) click to toggle source
# File lib/iron/settings/group.rb, line 62
def get_entry_val(name)
  entry = find_entry(name)
  return nil unless entry
  entry.value
end
group?() click to toggle source
# File lib/iron/settings/group.rb, line 18
def group?
  true
end
groups(include_children = false) click to toggle source

Returns all groups that are children of this group

# File lib/iron/settings/group.rb, line 93
def groups(include_children = false)
  list = @nodes.values.select {|i| i.group?}
  if include_children
    list += list.collect {|i| i.groups}.flatten
  end
  list
end
nodes() click to toggle source
# File lib/iron/settings/group.rb, line 14
def nodes
  @nodes
end
set_entry_val(name, value) click to toggle source
# File lib/iron/settings/group.rb, line 68
def set_entry_val(name, value)
  entry = find_entry(name)
  return unless entry
  entry.value = value
end