Class: Recurly::Schema::Attribute
- Inherits:
-
Object
- Object
- Recurly::Schema::Attribute
- Defined in:
- lib/recurly/schema.rb
Direct Known Subclasses
ArrayAttribute, BooleanAttribute, DateTimeAttribute, PrimitiveAttribute, ResourceAttribute
Constant Summary collapse
- PRIMITIVE_TYPES =
[ String, Integer, Float, Hash, ].freeze
Instance Attribute Summary collapse
-
#type ⇒ Class, Symbol
readonly
The type of the attribute.
Class Method Summary collapse
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#initialize(type = nil) ⇒ Attribute
constructor
A new instance of Attribute.
- #recurly_class ⇒ Object
Constructor Details
#initialize(type = nil) ⇒ Attribute
Returns a new instance of Attribute.
86 87 88 |
# File 'lib/recurly/schema.rb', line 86 def initialize(type = nil) @type = type end |
Instance Attribute Details
#type ⇒ Class, Symbol (readonly)
The type of the attribute. Might be a class like `DateTime` or could be a Recurly object. In this case a symbol should be used. Example: :Account. To get the Recurly type use #recurly_class
60 61 62 |
# File 'lib/recurly/schema.rb', line 60 def type @type end |
Class Method Details
.build(type, options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/recurly/schema.rb', line 69 def self.build(type, = {}) if PRIMITIVE_TYPES.include? type PrimitiveAttribute.new(type) elsif type == :Boolean BooleanAttribute.new elsif type == DateTime DateTimeAttribute.new elsif type.is_a? Symbol ResourceAttribute.new(type) elsif type == Array item_attr = build([:item_type]) ArrayAttribute.new(item_attr) else throw ArgumentError end end |
Instance Method Details
#cast(value) ⇒ Object
90 91 92 |
# File 'lib/recurly/schema.rb', line 90 def cast(value) value end |
#recurly_class ⇒ Object
94 95 96 |
# File 'lib/recurly/schema.rb', line 94 def recurly_class @recurly_class ||= Schema.get_recurly_class(type) end |