Class: Opium::Schema
- Includes:
- Model::Connectable
- Defined in:
- lib/opium/schema.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(attributes = {}) ⇒ Schema
constructor
A new instance of Schema.
- #model ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Schema
Returns a new instance of Schema.
27 28 29 30 31 32 33 34 |
# File 'lib/opium/schema.rb', line 27 def initialize( attributes = {} ) attributes.deep_symbolize_keys.tap do |a| @class_name = a[:className] @fields = ( a[:fields] || {} ).map do |field_name, | Opium::Model::Field.new( field_name, [:type], nil, false, nil ) end.index_by(&:name_to_ruby) end end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
25 26 27 |
# File 'lib/opium/schema.rb', line 25 def class_name @class_name end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
25 26 27 |
# File 'lib/opium/schema.rb', line 25 def fields @fields end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/opium/schema.rb', line 10 def all http_get[:results].map {|schema| new( schema ) }.index_by(&:class_name) end |
.find(model_name, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/opium/schema.rb', line 14 def find( model_name, = {} ) result = http_get( .merge id: model_name ) [:sent_headers] ? result : new( result ) end |
.model_name ⇒ Object
19 20 21 |
# File 'lib/opium/schema.rb', line 19 def model_name @model_name ||= ActiveModel::Name.new( self, nil, self.name ) end |