Class: ComplexConfig::Settings

Inherits:
JSON::GenericObject
  • Object
show all
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)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/complex_config/settings.rb', line 65

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
    elsif table.respond_to?(id)
      table.__send__(id, *a, &b)
    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



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

def attribute_names
  table.keys
end

#attribute_set?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#attribute_valuesObject



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

def attribute_values
  table.values
end

#deep_freezeObject



44
45
46
47
48
49
# File 'lib/complex_config/settings.rb', line 44

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

#to_ary(*a, &b) ⇒ Object



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

def to_ary(*a, &b)
  table_enumerator.__send__(:to_a, *a, &b)
end

#to_hObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/complex_config/settings.rb', line 21

def to_h
  table_enumerator.each_with_object({}) do |(k, v), h|
    h[k] =
      if Array === v
        v.to_ary.map { |x| (x.ask_and_send(:to_h) rescue x) || x }
      elsif v.respond_to?(:to_h)
        v.ask_and_send(:to_h) rescue v
      else
        v
      end
  end
end

#to_sObject Also known as: inspect



34
35
36
# File 'lib/complex_config/settings.rb', line 34

def to_s
  to_h.to_yaml
end