Class: ActiveAttr::AttributeDefinition

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/active_attr/attribute_definition.rb

Overview

Represents an attribute for reflection

Examples:

Usage

AttributeDefinition.new(:amount)

Since:

  • 0.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ ActiveAttr::AttributeDefinition

Creates a new AttributeDefinition

Examples:

Create an attribute defintion

AttributeDefinition.new(:amount)

Parameters:

  • attribute (Symbol, String, #to_sym)

    name

Raises:

  • (TypeError)

Since:

  • 0.2.0



40
41
42
43
# File 'lib/active_attr/attribute_definition.rb', line 40

def initialize(name, options={})
  raise TypeError, "can't convert #{name.class} into Symbol" unless name.respond_to? :to_sym
  @name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

The attribute name

Since:

  • 0.2.0



13
14
15
# File 'lib/active_attr/attribute_definition.rb', line 13

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Compare attribute definitions

Examples:

attribute_definition <=> other

Parameters:

Returns:

  • (-1, 0, 1, nil)

Since:

  • 0.2.1



25
26
27
28
# File 'lib/active_attr/attribute_definition.rb', line 25

def <=>(other)
  return nil unless other.instance_of? self.class
  self.name.to_s <=> other.name.to_s
end

#to_sString Also known as: inspect

The attribute name

Returns:

  • (String)

    the attribute name

Since:

  • 0.2.0



50
51
52
# File 'lib/active_attr/attribute_definition.rb', line 50

def to_s
  name.to_s
end

#to_symSymbol

The attribute name

Returns:

  • (Symbol)

    the attribute name

Since:

  • 0.2.1



60
61
62
# File 'lib/active_attr/attribute_definition.rb', line 60

def to_sym
  name
end