Class: Opium::Schema

Inherits:
Object show all
Includes:
Model::Connectable
Defined in:
lib/opium/schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options|
      Opium::Model::Field.new( field_name, options[:type], nil, false, nil )
    end.index_by(&:name_to_ruby)
  end
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



25
26
27
# File 'lib/opium/schema.rb', line 25

def class_name
  @class_name
end

#fieldsObject (readonly)

Returns the value of attribute fields.



25
26
27
# File 'lib/opium/schema.rb', line 25

def fields
  @fields
end

Class Method Details

.allObject



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, options = {} )
  result = http_get( options.merge id: model_name )
  options[:sent_headers] ? result : new( result )
end

.model_nameObject



19
20
21
# File 'lib/opium/schema.rb', line 19

def model_name
  @model_name ||= ActiveModel::Name.new( self, nil, self.name )
end

Instance Method Details

#deleteObject



40
41
42
# File 'lib/opium/schema.rb', line 40

def delete

end

#modelObject



44
45
46
# File 'lib/opium/schema.rb', line 44

def model

end

#saveObject



36
37
38
# File 'lib/opium/schema.rb', line 36

def save

end