Class: AttributesDSL::Attributes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/attributes_dsl/attributes.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 a collection of attributes declaration with methods to validate and extract instance attributes from a hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesSet (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.

Uses the set of attributes to ensure their uniqueness (by name)

Returns:

  • (Set)

    the set of registered attributes



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

def attributes
  @attributes ||= {}
end

Instance Method Details

#add(name, options = {}, &coercer) ⇒ AttributesDSL::Attributes

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 from given arguments and returns new immutable collection with the attribute

Parameters:

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

Returns:



30
31
32
33
34
35
36
37
# File 'lib/attributes_dsl/attributes.rb', line 30

def add(name, options = {}, &coercer)
  name  = name.to_sym
  value = Attribute.new(name, options, &coercer)
  clone_with do
    @attributes  = attributes.merge(name => value)
    @transformer = nil
  end
end

#reader?(name) ⇒ Boolean

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.

Checks whether an attribute reader should be defined

Parameters:

  • name (#to_sym)

Returns:

  • (Boolean)


53
54
55
# File 'lib/attributes_dsl/attributes.rb', line 53

def reader?(name)
  attributes[name.to_sym].reader
end

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

Returns the proc that converts a hash of attributes using current setting

Returns:

  • (Proc)


43
44
45
# File 'lib/attributes_dsl/attributes.rb', line 43

def transformer
  @transformer ||= transprocs.flatten.compact.reduce(:>>)
end