Class: Mixture::AttributeList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable, Enumerable
Defined in:
lib/mixture/attribute_list.rb

Overview

A list of attributes. This is used instead of a hash in order to add in the #options and #callbacks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeList

Initializes the attribute list.



30
31
32
33
34
# File 'lib/mixture/attribute_list.rb', line 30

def initialize
  @list = {}
  @options = {}
  @callbacks = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#callbacksHash{Symbol => Array<Proc>} (readonly)

Returns a set of callbacks. This is used for coercion, but may be used for other things.

Returns:

  • (Hash{Symbol => Array<Proc>})


27
28
29
# File 'lib/mixture/attribute_list.rb', line 27

def callbacks
  @callbacks
end

#optionsHash{Symbol => Object} (readonly)

Returns a set of options used for the attributes. This isn't used at the moment.

Returns:

  • (Hash{Symbol => Object})


21
22
23
# File 'lib/mixture/attribute_list.rb', line 21

def options
  @options
end

Instance Method Details

#create(name, options = {}) ⇒ Attribute

Creates a new attribute with the given name and options.

Parameters:

  • name (Symbol)

    The name of the attribute.

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

    The options for the attribute.

Returns:



41
42
43
# File 'lib/mixture/attribute_list.rb', line 41

def create(name, options = {})
  @list[name] = Attribute.new(name, self, options)
end