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) ⇒ Object (private)



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/asetus/configstruct.rb', line 36

def method_missing name, *args
  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?
    @cfg[name[0..-2]] if @cfg.has_key? name[0..-2]
  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



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

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

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/asetus/configstruct.rb', line 13

def empty?
  @cfg.empty?
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_key?(key)
  @cfg.has_key? key
end

#keysObject



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

def keys
  @cfg.keys
end