lib/loaf/configuration.rb in loaf-0.3.0 vs lib/loaf/configuration.rb in loaf-0.4.0

- old
+ new

@@ -1,22 +1,21 @@ # encoding: utf-8 module Loaf - module Configuration - + class Configuration VALID_ATTRIBUTES = [ :locales_path, :style_classes, :crumb_length, :last_crumb_linked, :capitalize, :root ] - attr_accessor *VALID_ATTRIBUTES + attr_accessor(*VALID_ATTRIBUTES) - DEFAULT_LOCALES_PATH = "/" + DEFAULT_LOCALES_PATH = '/' DEFAULT_STYLE_CLASSES = 'selected' DEFAULT_CRUMB_LENGTH = 30 @@ -24,30 +23,24 @@ DEFAULT_CAPITALIZE = false DEFAULT_ROOT = true - # Sets the Loaf configuration options. Best used by passing a block. + # Setup this configuration # - # Loaf.configure do |config| - # config.capitalize = true - # end - def configure - yield self - end - - def self.extended(base) - base.setup(self) - end - - def config - VALID_ATTRIBUTES.inject({}) { |hash, k| hash[k] = send(k); hash } - end - - def setup(parent) + # @api public + def initialize VALID_ATTRIBUTES.each do |attr| - send("#{attr}=", parent.const_get("DEFAULT_#{attr.to_s.upcase}")) + send("#{attr}=", self.class.const_get("DEFAULT_#{attr.to_s.upcase}")) end end + # Convert all properties into hash + # + # @return [Hash] + # + # @api public + def to_hash + VALID_ATTRIBUTES.reduce({}) { |acc, k| acc[k] = send(k); acc } + end end # Configuration end # Loaf