Class: ActiveRemote::AttributeDefinition
- Inherits:
-
Object
- Object
- ActiveRemote::AttributeDefinition
- Includes:
- Comparable
- Defined in:
- lib/active_remote/attribute_definition.rb
Overview
Represents an attribute for reflection
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The attribute name.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compare attribute definitions.
-
#[](key) ⇒ Object
Read an attribute option.
-
#initialize(name, options = {}) ⇒ ActiveAttr::AttributeDefinition
constructor
Creates a new AttributeDefinition.
-
#inspect ⇒ String
Returns the code that would generate the attribute definition.
-
#to_s ⇒ String
The attribute name.
-
#to_sym ⇒ Symbol
The attribute name.
Constructor Details
#initialize(name, options = {}) ⇒ ActiveAttr::AttributeDefinition
Creates a new AttributeDefinition
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/active_remote/attribute_definition.rb', line 55 def initialize(name, ={}) raise TypeError, "can't convert #{name.class} into Symbol" unless name.respond_to? :to_sym @name = name.to_sym = if [:type] typecaster = ::ActiveRemote::Typecasting::TYPECASTER_MAP[[:type]] fail ::ActiveRemote::UnknownType unless typecaster [:typecaster] = typecaster end end |
Instance Attribute Details
#name ⇒ Object (readonly)
The attribute name
13 14 15 |
# File 'lib/active_remote/attribute_definition.rb', line 13 def name @name end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compare attribute definitions
26 27 28 29 30 |
# File 'lib/active_remote/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 |
#[](key) ⇒ Object
Read an attribute option
40 41 42 |
# File 'lib/active_remote/attribute_definition.rb', line 40 def [](key) [key] end |
#inspect ⇒ String
Returns the code that would generate the attribute definition
76 77 78 79 80 |
# File 'lib/active_remote/attribute_definition.rb', line 76 def inspect = .map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(", ") = ", #{options_description}" unless .empty? "attribute :#{name}#{inspected_options}" end |
#to_s ⇒ String
The attribute name
87 88 89 |
# File 'lib/active_remote/attribute_definition.rb', line 87 def to_s name.to_s end |
#to_sym ⇒ Symbol
The attribute name
96 97 98 |
# File 'lib/active_remote/attribute_definition.rb', line 96 def to_sym name end |