Class: ActiveAttr::AttributeDefinition
- Inherits:
-
Object
- Object
- ActiveAttr::AttributeDefinition
- Includes:
- Comparable
- Defined in:
- lib/active_attr/attribute_definition.rb
Overview
Represents an attribute for reflection
Instance Attribute Summary (collapse)
-
- (Object) name
readonly
The attribute name.
Instance Method Summary (collapse)
-
- (-1, ...) <=>(other)
Compare attribute definitions.
-
- (Object) [](key)
Read an attribute option.
-
- (ActiveAttr::AttributeDefinition) initialize(name, options = {})
constructor
Creates a new AttributeDefinition.
-
- (String) inspect
Returns the code that would generate the attribute definition.
-
- (String) to_s
The attribute name.
-
- (Symbol) to_sym
The attribute name.
Constructor Details
- (ActiveAttr::AttributeDefinition) initialize(name, options = {})
Creates a new AttributeDefinition
54 55 56 57 58 |
# File 'lib/active_attr/attribute_definition.rb', line 54 def initialize(name, ={}) raise TypeError, "can't convert #{name.class} into Symbol" unless name.respond_to? :to_sym @name = name.to_sym @options = end |
Instance Attribute Details
- (Object) name (readonly)
The attribute name
13 14 15 |
# File 'lib/active_attr/attribute_definition.rb', line 13 def name @name end |
Instance Method Details
- (-1, ...) <=>(other)
Compare attribute definitions
26 27 28 29 30 |
# File 'lib/active_attr/attribute_definition.rb', line 26 def <=>(other) return nil unless other.instance_of? self.class return nil if name == other.name && != other. self.name.to_s <=> other.name.to_s end |
- (Object) [](key)
Read an attribute option
40 41 42 |
# File 'lib/active_attr/attribute_definition.rb', line 40 def [](key) @options[key] end |
- (String) inspect
Returns the code that would generate the attribute definition
69 70 71 72 73 |
# File 'lib/active_attr/attribute_definition.rb', line 69 def inspect = .map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(", ") = ", #{}" unless .empty? "attribute :#{name}#{}" end |
- (String) to_s
The attribute name
80 81 82 |
# File 'lib/active_attr/attribute_definition.rb', line 80 def to_s name.to_s end |
- (Symbol) to_sym
The attribute name
89 90 91 |
# File 'lib/active_attr/attribute_definition.rb', line 89 def to_sym name end |