Sha256: 1ac14dcb55668a1480b22661f1626094a0d38bfd11660009d2d19a77a1e04c1d

Contents?: true

Size: 928 Bytes

Versions: 2

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module Loaf
  class Configuration
    VALID_ATTRIBUTES = [
      :locales_path,
      :crumb_length,
      :capitalize
    ].freeze

    attr_accessor(*VALID_ATTRIBUTES)

    DEFAULT_LOCALES_PATH = '/'

    DEFAULT_STYLE_CLASSES = 'selected'

    DEFAULT_CRUMB_LENGTH = 30

    DEFAULT_LAST_CRUMB_LINKED = false

    DEFAULT_CAPITALIZE = false

    DEFAULT_ROOT = true

    # Setup this configuration
    #
    # @api public
    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

    # 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
loaf-0.6.1 lib/loaf/configuration.rb
loaf-0.6.0 lib/loaf/configuration.rb