Class: Settings::Builder

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

Overview

Mirror to the Cursor class, this class helps extend and expand a settings hierarchy.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group) ⇒ Builder

Bind to a group/root



13
14
15
# File 'lib/iron/settings/builder.rb', line 13

def initialize(group)
  @group = group
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/iron/settings/builder.rb', line 37

def method_missing(method, *args, &block)
  type = method.to_s
  
  if Settings.data_types.include?(type.gsub('_list','').to_sym)
    type = type.to_sym
    name = args[0]
    default = args[1]
    verify_key?(name)
    verify_available?(name, :entry)
    @group.add_entry(name, type, default, &block)
  else
    super
  end
end

Class Method Details

.define(group, &block) ⇒ Object



7
8
9
10
# File 'lib/iron/settings/builder.rb', line 7

def self.define(group, &block)
  builder = self.new(group)
  builder.define(&block)
end

Instance Method Details

#define(&block) ⇒ Object

Define in block mode



18
19
20
# File 'lib/iron/settings/builder.rb', line 18

def define(&block)
  DslProxy.exec(self, &block)
end

#group(name, &block) ⇒ Object

Create a new sub-group, yield for definition if block passed



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/iron/settings/builder.rb', line 23

def group(name, &block)
  verify_key?(name)
  group = @group.find_group(name)
  unless group
    verify_available?(name, :group)
    group = @group.add_group(name)
  end
  
  # Chain it
  builder = self.class.new(group)
  builder.define(&block) if block
  builder
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/iron/settings/builder.rb', line 52

def respond_to_missing?(method, include_private = false)
  Settings.data_types.include?(method.to_s.gsub('_list','').to_sym)
end