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 (#to_sym)
  • options (Hash) (defaults to: {})
  • coercer (Proc)


32
33
34
35
36
# File 'lib/attributes_dsl/attribute.rb', line 32

def initialize(name, options = {}, &coercer)
  @name    = name.to_sym
  @options = { coercer: coercer }.merge(options)
  @reader  = @options.fetch(:reader) { true }
end

Instance Attribute Details

#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



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

def name
  @name
end

#readerBoolean (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 an attribute should be readable.

Returns:

  • (Boolean)

    whether an attribute should be readable



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

def reader
  @reader
end

Instance Method Details

#transformerProc

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.

A proc that transform a hash of attributes using current settings

Returns:

  • (Proc)


42
43
44
# File 'lib/attributes_dsl/attribute.rb', line 42

def transformer
  convert unless @options.empty?
end