Class: Recurly::Schema::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/recurly/schema.rb

Constant Summary collapse

PRIMITIVE_TYPES =
[
  String,
  Integer,
  Float,
  Hash,
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#typeClass, 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

Returns:

  • (Class, Symbol)


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, options = {})
  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(options[: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_classObject



94
95
96
# File 'lib/recurly/schema.rb', line 94

def recurly_class
  @recurly_class ||= Schema.get_recurly_class(type)
end