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, type = :unknown, **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, type = :unknown, **options) ⇒ ActiveAttr::AttributeDefinition
Creates a new AttributeDefinition
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/active_remote/attribute_definition.rb', line 58 def initialize(name, type = :unknown, **) raise TypeError, "can't convert #{name.class} into Symbol" unless name.respond_to? :to_sym @name = name.to_sym @options = @options[:typecaster] = ::ActiveRemote::Type.lookup(type) unless type == :unknown if @options[:type] typecaster = ::ActiveRemote::Typecasting::TYPECASTER_MAP[@options[:type]] fail ::ActiveRemote::UnknownType unless typecaster @options[:typecaster] = typecaster end end |
Instance Attribute Details
#name ⇒ Object (readonly)
The attribute name
15 16 17 |
# File 'lib/active_remote/attribute_definition.rb', line 15 def name @name end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compare attribute definitions
28 29 30 31 32 |
# File 'lib/active_remote/attribute_definition.rb', line 28 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
42 43 44 |
# File 'lib/active_remote/attribute_definition.rb', line 42 def [](key) @options[key] end |
#inspect ⇒ String
Returns the code that would generate the attribute definition
80 81 82 83 84 |
# File 'lib/active_remote/attribute_definition.rb', line 80 def inspect = .map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(", ") = ", #{}" unless .empty? "attribute :#{name}#{}" end |
#to_s ⇒ String
The attribute name
91 92 93 |
# File 'lib/active_remote/attribute_definition.rb', line 91 def to_s name.to_s end |
#to_sym ⇒ Symbol
The attribute name
100 101 102 |
# File 'lib/active_remote/attribute_definition.rb', line 100 def to_sym name end |