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.

  • block (Proc)

    A block to use for default values.

See Also:

  • Hash#initialize


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

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

Class Method Details

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

Parameters:

  • name (String|Symbol)

    The new property name.

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

    The options for the property.

Options Hash (options):

  • :default (Boolean)

    Specify a default value for this property.

  • :required (Boolean)

    Set the value as required for this property, this will raise an error if the value is unset when creating or editing.

  • :readonly (Boolean)

    Specify if the property is readonly, which means that it can only defined during creation of the configuration.



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