Class: FmRest::Spyke::Base::OrmAdapter
- Inherits:
-
OrmAdapter::Base
- Object
- OrmAdapter::Base
- FmRest::Spyke::Base::OrmAdapter
- Defined in:
- lib/orm_adapter/fmrest/adapter.rb
Instance Method Summary collapse
-
#column_names ⇒ Object
Get a list of the attribute names (field names) in the Filemaker Layout.
-
#create!(attributes = {}) ⇒ Object
Create a model using attributes.
-
#destroy(object) ⇒ Object
Destroy an instance by passing in the instance itself.
-
#find_all(options = {}) ⇒ Object
Find all models, optionally matching conditions, and specifying order.
-
#find_first(options = {}) ⇒ Object
Find the first instance, optionally matching conditions, and specifying order.
-
#get(id) ⇒ Object
Get an instance by id of the model.
-
#get!(id) ⇒ Object
Get an instance by id of the model.
Instance Method Details
#column_names ⇒ Object
Get a list of the attribute names (field names) in the Filemaker Layout. Map attribute names
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 24 def column_names return [] unless klass.respond_to? :layout = klass.layout fields = .map{|f| f['name']} return fields unless klass.respond_to? :mapped_attributes # map attribute names fields + klass.mapped_attributes.keys - klass.mapped_attributes.values end |
#create!(attributes = {}) ⇒ Object
Create a model using attributes
84 85 86 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 84 def create!(attributes = {}) klass.new(attributes).save end |
#destroy(object) ⇒ Object
Destroy an instance by passing in the instance itself.
89 90 91 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 89 def destroy(object) object.destroy if valid_object?(object) end |
#find_all(options = {}) ⇒ Object
Find all models, optionally matching conditions, and specifying order
79 80 81 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 79 def find_all( = {}) base_relation() end |
#find_first(options = {}) ⇒ Object
Find the first instance, optionally matching conditions, and specifying order
You can call with just conditions, providing a hash
User.to_adapter.find_first :name => "Fred", :age => 23
Or you can specify :order, and :conditions as keys
User.to_adapter.find_first :conditions => {:name => "Fred", :age => 23}
User.to_adapter.find_first :order => [:age, :desc]
User.to_adapter.find_first :order => :name, :conditions => {:age => 18}
When specifying :order, it may be
-
a single arg e.g.
:order => :name
-
a single pair with :asc, or :desc as last, e.g.
:order => [:name, :desc]
-
an array of single args or pairs (with :asc or :desc as last), e.g.
:order => [[:name, :asc], [:age, :desc]]
72 73 74 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 72 def find_first( = {}) base_relation().first end |
#get(id) ⇒ Object
Get an instance by id of the model. Returns nil if a model is not found. This should comply with ActiveModel#to_key API, i.e.:
User.to_adapter.get(@user.to_key) == @user
49 50 51 52 53 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 49 def get(id) klass.find wrap_key(id) rescue FmRest::APIError::RecordMissingError nil end |
#get!(id) ⇒ Object
Get an instance by id of the model. Raises an error if a model is not found. This should comply with ActiveModel#to_key API, i.e.:
User.to_adapter.get!(@user.to_key) == @user
40 41 42 |
# File 'lib/orm_adapter/fmrest/adapter.rb', line 40 def get!(id) klass.find wrap_key(id) end |