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.


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

def initialize
  @list = {}
  @options = {}
  @callbacks = Hash.new { |h, k| h[k] = Set.new }
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>})

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

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})

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

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:


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

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