Class: Lazier::Configuration

Inherits:
Hashie::Dash
  • Object
show all
Includes:
I18n
Defined in:
lib/lazier/configuration.rb

Overview

A configuration class to set properties.

Instance Attribute Summary

Attributes included from I18n

#i18n_locale, #i18n_locales_path, #i18n_root

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I18n

#i18n, #i18n=, #i18n_setup

Constructor Details

#initialize(attributes = {}, &block) ⇒ Configuration

Initializes a new configuration object.

Parameters:

  • attributes (Hash) (defaults to: {})

    The initial values of properties of this configuration.



15
16
17
18
19
# File 'lib/lazier/configuration.rb', line 15

def initialize(attributes = {}, &block)
  @lazier_i18n = Lazier::Localizer.new(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")).i18n
  i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
  super(attributes, &block)
end

Class Method Details

.property(property_name, options = {}) ⇒ Object

Defines a property on the configuration. Options are as follows:

  • :default - Specify a default value for this property.
  • :required - Specify the value as required for this property, to raise an error if a value is unset in a new or existing configuration.
  • :readonly - Specify if the property is readonly, which means that it can only defined during creation of the configuration.

Parameters:

  • property_name (String|Symbol)

    The new property name.

  • options (Hash) (defaults to: {})

    The options for the property.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lazier/configuration.rb', line 30

def self.property(property_name, options = {})
  super(property_name, options)

  if options[:readonly] then
    class_eval <<-ACCESSOR
      def #{property_name}=(_)
        raise ArgumentError.new(@lazier_i18n.configuration.readonly("#{property_name}", "#{name}"))
      end
    ACCESSOR
  end
end