Class: ComplexConfig::Settings

Inherits:
JSON::GenericObject
  • Object
show all
Includes:
Enumerable
Defined in:
lib/complex_config/settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *a, &b) ⇒ Object (private)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/complex_config/settings.rb', line 55

def method_missing(id, *a, &b)
  case
  when id =~ /\?\z/
    begin
      public_send $`.to_sym, *a, &b
    rescue ComplexConfig::AttributeMissing
      nil
    end
  when id =~ /=\z/
    super
  when value = ComplexConfig::Provider.apply_plugins(self, id)
    value
  else
    if attribute_set?(id)
      super
    else
      raise ComplexConfig::AttributeMissing, "no attribute named #{id.inspect}"
    end
  end
end

Class Method Details

.[](*a) ⇒ Object



5
6
7
# File 'lib/complex_config/settings.rb', line 5

def self.[](*a)
  from_hash *a
end

Instance Method Details

#attribute_namesObject



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

def attribute_names
  table.keys
end

#attribute_set?(name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/complex_config/settings.rb', line 14

def attribute_set?(name)
  table.key?(name.to_sym)
end

#attribute_valuesObject



22
23
24
# File 'lib/complex_config/settings.rb', line 22

def attribute_values
  table.values
end

#deep_freezeObject



38
39
40
41
42
43
# File 'lib/complex_config/settings.rb', line 38

def deep_freeze
  each do |_, v|
    v.ask_and_send(:deep_freeze) || (v.freeze rescue v)
  end
  freeze
end

#each(&block) ⇒ Object



9
10
11
# File 'lib/complex_config/settings.rb', line 9

def each(&block)
  table.each(&block)
end

#to_hObject



26
27
28
29
30
# File 'lib/complex_config/settings.rb', line 26

def to_h
  each_with_object({}) do |(k, v), h|
    h[k] = v.ask_and_send(:to_h) || v
  end
end

#to_sObject Also known as: inspect



32
33
34
# File 'lib/complex_config/settings.rb', line 32

def to_s
  to_h.to_yaml
end