Class: Loaf::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/loaf/configuration.rb

Constant Summary collapse

VALID_ATTRIBUTES =
[
  :locales_path,
  :match
].freeze
DEFAULT_LOCALES_PATH =
'/'
DEFAULT_MATCH =
:inclusive

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Configuration

Setup this configuration



19
20
21
22
23
24
25
# File 'lib/loaf/configuration.rb', line 19

def initialize(attributes = {})
  VALID_ATTRIBUTES.each do |attr|
    default = self.class.const_get("DEFAULT_#{attr.to_s.upcase}")
    attr_value = attributes.fetch(attr) { default }
    send("#{attr}=", attr_value)
  end
end

Instance Method Details

#to_hashHash

Convert all properties into hash

Returns:

  • (Hash)


32
33
34
# File 'lib/loaf/configuration.rb', line 32

def to_hash
  VALID_ATTRIBUTES.reduce({}) { |acc, k| acc[k] = send(k); acc }
end