Class: Recurly::Schema
- Inherits:
-
Object
- Object
- Recurly::Schema
- Defined in:
- lib/recurly/schema.rb,
lib/recurly/schema/request_caster.rb,
lib/recurly/schema/schema_factory.rb,
lib/recurly/schema/resource_caster.rb,
lib/recurly/schema/schema_validator.rb
Overview
The class responsible for describing a schema. This is used for requests and resources.
Defined Under Namespace
Modules: RequestCaster, ResourceCaster, SchemaFactory, SchemaValidator Classes: ArrayAttribute, Attribute, BooleanAttribute, DateTimeAttribute, PrimitiveAttribute, ResourceAttribute
Instance Attribute Summary collapse
-
#attributes ⇒ Hash<String,Attribute>
readonly
The attributes in the schema.
Class Method Summary collapse
-
.get_recurly_class(type) ⇒ Request, Resource
Gets a recurly class given a symbol name.
Instance Method Summary collapse
-
#add_attribute(name, type, options) ⇒ Object
Adds an attribute to the schema definition.
-
#get_attribute(name) ⇒ Attribute?
Gets an attribute from this schema given a name.
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
9 10 11 |
# File 'lib/recurly/schema.rb', line 9 def initialize @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Hash<String,Attribute> (readonly)
The attributes in the schema
7 8 9 |
# File 'lib/recurly/schema.rb', line 7 def attributes @attributes end |
Class Method Details
.get_recurly_class(type) ⇒ Request, Resource
Gets a recurly class given a symbol name.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/recurly/schema.rb', line 41 def self.get_recurly_class(type) raise ArgumentError, "#{type.inspect} must be a symbol but is a #{type.class}" unless type.is_a?(Symbol) if type == :Address Recurly::Resources::Address elsif Recurly::Requests.const_defined?(type, false) Recurly::Requests.const_get(type, false) elsif Recurly::Resources.const_defined?(type, false) Recurly::Resources.const_get(type, false) else raise ArgumentError, "Recurly type '#{type}' is unknown" end end |
Instance Method Details
#add_attribute(name, type, options) ⇒ Object
Adds an attribute to the schema definition
18 19 20 21 22 |
# File 'lib/recurly/schema.rb', line 18 def add_attribute(name, type, ) attribute = Attribute.build(type, ) @attributes[name.to_s] = attribute attribute end |
#get_attribute(name) ⇒ Attribute?
Gets an attribute from this schema given a name
28 29 30 |
# File 'lib/recurly/schema.rb', line 28 def get_attribute(name) @attributes[name.to_s] end |