Class: Lazier::Configuration

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

Overview

A configuration class to set properties.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new configuration object.

Parameters:

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

    The initial values of properties of this configuration.



12
13
14
15
# File 'lib/lazier/configuration.rb', line 12

def initialize(attributes = {}, &block)
  @i18n = Lazier::I18n.instance
  super(attributes, &block)
end

Class Method Details

.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:

  • name (String|Symbol)

    The new property name.

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

    The options for the property.



26
27
28
29
30
31
32
33
34
# File 'lib/lazier/configuration.rb', line 26

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

  if options[:readonly]
    send(:define_method, "#{name}=") do |_|
      assert_readonly_property!(name)
    end
  end
end