class Recurly::Schema

The class responsible for describing a schema. This is used for requests and resources.

Attributes

attributes[R]

The attributes in the schema @return [Hash<String,Attribute>]

Public Class Methods

get_recurly_class(type) click to toggle source

Gets a recurly class given a symbol name.

@example

Schema.get_recurly_class(:Account)
#=> Recurly::Resources::Account

@param type [Symbol] The name of the class you wish to find @return [Request,Resource] @raise ArgumentError If class can’t be found.

# 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
new() click to toggle source
# File lib/recurly/schema.rb, line 9
def initialize
  @attributes = {}
end

Public Instance Methods

add_attribute(name, type, options) click to toggle source

Adds an attribute to the schema definition

@param name [Symbol] The name of the attribute @param type [Class,Symbol] The type of the attribute. Use capitalized symbol for Recurly class. Example: :Account. @param options [Schema::Attribute] The created and registered attribute object.

# File lib/recurly/schema.rb, line 18
def add_attribute(name, type, options)
  attribute = Attribute.build(type, options)
  @attributes[name.to_s] = attribute
  attribute
end
get_attribute(name) click to toggle source

Gets an attribute from this schema given a name

@param name [String,Symbol] The name/key of the attribute @return [Attribute,nil] The found Attribute. nil if not found.

# File lib/recurly/schema.rb, line 28
def get_attribute(name)
  @attributes[name.to_s]
end