Class: Asetus::ConfigStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/asetus/configstruct.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/asetus/configstruct.rb', line 39

def method_missing name, *args, &block
  name = name.to_s
  name = args.shift if name[0..1] == '[]' # asetus.cfg['foo']
  arg = args.first
  if    name[-1..-1] == '?'               # asetus.cfg.foo.bar?
    if @cfg.has_key? name[0..-2]
      @cfg[name[0..-2]]
    else
      nil
    end
  elsif name[-1..-1] == '='               # asetus.cfg.foo.bar = 'quux'
    _asetus_set name[0..-2], arg
  else
    _asetus_get name, arg                 # asetus.cfg.foo.bar
  end
end

Instance Method Details

#_asetus_to_hashObject


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/asetus/configstruct.rb', line 4

def _asetus_to_hash
  hash = {}
  @cfg.each do |key, value|
    if value.class == ConfigStruct
      value = value._asetus_to_hash
    end
    key = key.to_s if @key_to_s
    hash[key] = value
  end
  hash
end

#each(&block) ⇒ Object


20
21
22
# File 'lib/asetus/configstruct.rb', line 20

def each &block
  @cfg.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/asetus/configstruct.rb', line 16

def empty?
  @cfg.empty?
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/asetus/configstruct.rb', line 28

def has_key? key
  @cfg.has_key? key
end

#keysObject


24
25
26
# File 'lib/asetus/configstruct.rb', line 24

def keys
  @cfg.keys
end