Sha256: bae9a62fee2c242c40063fe96e3a2260a069c6632f423f5dcfe60e46558a2a3e

Contents?: true

Size: 911 Bytes

Versions: 9

Compression:

Stored size: 911 Bytes

Contents

require 'squid/config'

module Squid
  # @private
  module Settings
    # For each key, create an attribute reader with a settings value.
    # First, check if an option with the key exists.
    # For example: {formats: [:currency]} ->> [:currency]
    # Then, check is an option with the singular version of the key exists.
    # For example: {format: :currency} ->> [:currency]
    # Finally, check whether the key has a value in Squid configuration.
    # For example: config.formats = [:currency] ->> [:currency]
    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
squid-1.4.1 lib/squid/settings.rb
squid-1.4.0 lib/squid/settings.rb
squid-1.3.0 lib/squid/settings.rb
squid-1.2.0 lib/squid/settings.rb
squid-1.1.0 lib/squid/settings.rb
squid-1.0.1 lib/squid/settings.rb
squid-1.0.0 lib/squid/settings.rb
squid-1.0.0.beta4 lib/squid/settings.rb
squid-1.0.0.beta3 lib/squid/settings.rb