Method: Configurations::Configurable::ClassMethods#configurable

Defined in:
lib/configurations/configurable.rb

#configurable(*properties, &block) ⇒ Object

configurable can be used to set the properties which should be configurable, as well as a type which the given property should be asserted to

Examples:

Define a configurable property

configurable :foo

Define a type asserted, nested property for type String

configurable String, bar: :baz

Define a custom assertion for a property

configurable biz: %i(bi bu) do |value|
  unless %w(a b c).include?(value)
    fail ArgumentError, 'must be one of a, b, c'
  end
end

Parameters:

  • properties (Class, Symbol, Hash)

    a type as a first argument to type assert (if any) or nested properties to allow for setting

  • block (Proc)

    a block with arity 2 to evaluate when a property is set. It will be given: property name and value



119
120
121
122
123
124
125
126
127
128
# File 'lib/configurations/configurable.rb', line 119

def configurable(*properties, &block)
  @configurable_properties ||= Maps::Properties.new
  @configurable_types ||= Maps::Types.new
  @configurable_blocks ||= Maps::Blocks.new

  type, properties = extract_type(properties)
  @configurable_properties.add(properties)
  @configurable_types.add(type, properties)
  @configurable_blocks.add(block, properties)
end