Module: Squid::Settings

Included in:
Graph
Defined in:
lib/squid/settings.rb

Instance Method Summary collapse

Instance Method Details

#has_settings(*keys) ⇒ Object

For each key, create an attribute reader with a settings value. First, check if an option with the key exists. For example: [:currency] ->> [:currency] Then, check is an option with the singular version of the key exists. For example: :currency ->> [:currency] Finally, check whether the key has a value in Squid configuration. For example: config.formats = [:currency] ->> [:currency]


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/squid/settings.rb', line 13

def has_settings(*keys)
  keys.each do |key|
    define_method(key) do
      singular_key = key.to_s.singularize.to_sym
      if @settings.key? key
        @settings[key]
      elsif @settings.key? singular_key
        [@settings[singular_key]]
      else
        Squid.configuration.public_send key
      end
    end
  end
end