Class: ActiveResource::Schema
- Inherits:
-
Object
- Object
- ActiveResource::Schema
- Defined in:
- activeresource/lib/active_resource/schema.rb
Overview
:nodoc:
Constant Summary
- KNOWN_ATTRIBUTE_TYPES =
attributes can be known to be one of these types. They are easy to cast to/from.
%w( string
Instance Attribute Summary (collapse)
-
- (Object) attrs
An array of attribute definitions, representing the attributes that have been defined.
Instance Method Summary (collapse)
- - (Object) attribute(name, type, options = {})
-
- (Schema) initialize
constructor
The internals of an Active Resource Schema are very simple - unlike an Active Record TableDefinition (on which it is based).
Constructor Details
- (Schema) initialize
The internals of an Active Resource Schema are very simple - unlike an Active Record TableDefinition (on which it is based). It provides a set of convenience methods for people to define their schema using the syntax:
schema do
string :foo
integer :bar
end
The schema stores the name and type of each attribute. That is then
read out by the schema method to populate the actual
Resource's schema
25 26 27 |
# File 'activeresource/lib/active_resource/schema.rb', line 25 def initialize @attrs = {} end |
Instance Attribute Details
- (Object) attrs
An array of attribute definitions, representing the attributes that have been defined.
11 12 13 |
# File 'activeresource/lib/active_resource/schema.rb', line 11 def attrs @attrs end |
Instance Method Details
- (Object) attribute(name, type, options = {})
29 30 31 32 33 34 35 36 37 38 |
# File 'activeresource/lib/active_resource/schema.rb', line 29 def attribute(name, type, = {}) raise ArgumentError, "Unknown Attribute type: #{type.inspect} for key: #{name.inspect}" unless type.nil? || Schema::KNOWN_ATTRIBUTE_TYPES.include?(type.to_s) the_type = type.to_s # TODO: add defaults #the_attr = [type.to_s] #the_attr << options[:default] if options.has_key? :default @attrs[name.to_s] = the_type self end |