Class: AttributesDSL::Attribute Private

Inherits:
Object
  • Object
show all
Defined in:
lib/attributes_dsl/attribute.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Describes settings for PORO attribute

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &coercer) ⇒ Attribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the attribute

Parameters:

  • name (Symbol)
  • options (Hash) (defaults to: {})
  • coercer (Proc)

Options Hash (options):

  • :default (Object)
  • :required (Boolean)


48
49
50
51
52
53
54
55
# File 'lib/attributes_dsl/attribute.rb', line 48

def initialize(name, options = {}, &coercer)
  @name = name
  @default = options.fetch(:default) {}
  @required = default.nil? && options.fetch(:required) { false }
  @coercer = coercer

  IceNine.deep_freeze(self)
end

Instance Attribute Details

#coercerProc? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the coercer for the attribute.

Returns:

  • (Proc, nil)

    the coercer for the attribute



37
38
39
# File 'lib/attributes_dsl/attribute.rb', line 37

def coercer
  @coercer
end

#defaultObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the default value of the attribute.

Returns:

  • (Object)

    the default value of the attribute



25
26
27
# File 'lib/attributes_dsl/attribute.rb', line 25

def default
  @default
end

#nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the attribute.

Returns:

  • (Symbol)

    the name of the attribute



19
20
21
# File 'lib/attributes_dsl/attribute.rb', line 19

def name
  @name
end

#requiredBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether the attribute is required.

Returns:

  • (Boolean)

    whether the attribute is required



31
32
33
# File 'lib/attributes_dsl/attribute.rb', line 31

def required
  @required
end

Instance Method Details

#value(input) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerces an input assigned to the attribute

Parameters:

  • input (Object)

Returns:

  • (Object)


63
64
65
# File 'lib/attributes_dsl/attribute.rb', line 63

def value(input)
  coercer ? coercer[input] : input
end