Class: Ooor::MiniActiveResource
- Inherits:
-
Object
- Object
- Ooor::MiniActiveResource
- Includes:
- ActiveModel::Conversion, ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml
- Defined in:
- lib/ooor/mini_active_resource.rb
Overview
Ooor::MiniActiveResource is a shrinked version of ActiveResource::Base with the bare minimum we need for Ooor. as a reminder ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application. Ooor is a bit like ActiveResource but eventually it can use more OpenERP metadata and a richer API to become closer to ActiveRecord or Mongoid than Activeresource. Also OpenERP isn’t really good at REST so the part of ActiveResource dedicated to REST is of little help here. An other fundamental difference is Ooor is multi OpenERP instances and multi-sessions. for each session, proxies to OpenERP may be different.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages.
-
#new? ⇒ Boolean
(also: #new_record?)
Returns
true
if this object hasn’t yet been saved, otherwise, returnsfalse
. - #persisted? ⇒ Boolean
-
#reload(options = nil) ⇒ Object
Reloads the record from the database.
- #to_json(options = {}) ⇒ Object
- #to_xml(options = {}) ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
21 22 23 |
# File 'lib/ooor/mini_active_resource.rb', line 21 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
21 22 23 |
# File 'lib/ooor/mini_active_resource.rb', line 21 def id @id end |
Class Method Details
.element_name ⇒ Object
16 17 18 |
# File 'lib/ooor/mini_active_resource.rb', line 16 def element_name @element_name ||= model_name.element end |
Instance Method Details
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages.
60 61 62 |
# File 'lib/ooor/mini_active_resource.rb', line 60 def errors @errors ||= ActiveModel::Errors.new(self) end |
#new? ⇒ Boolean Also known as: new_record?
Returns true
if this object hasn’t yet been saved, otherwise, returns false
.
32 33 34 |
# File 'lib/ooor/mini_active_resource.rb', line 32 def new? !@persisted end |
#persisted? ⇒ Boolean
37 38 39 |
# File 'lib/ooor/mini_active_resource.rb', line 37 def persisted? @persisted end |
#reload(options = nil) ⇒ Object
Reloads the record from the database.
This method finds record by its primary key (which could be assigned manually) and modifies the receiver in-place NOTE in Ooor, like ActiveRecord and unlike ActiveResource, reload can take an options parameter
55 56 57 |
# File 'lib/ooor/mini_active_resource.rb', line 55 def reload( = nil) self.class.find(id, ) end |
#to_json(options = {}) ⇒ Object
23 24 25 |
# File 'lib/ooor/mini_active_resource.rb', line 23 def to_json(={}) super(include_root_in_json ? { :root => self.class.element_name }.merge() : ) end |
#to_xml(options = {}) ⇒ Object
27 28 29 |
# File 'lib/ooor/mini_active_resource.rb', line 27 def to_xml(={}) super({ :root => self.class.element_name }.merge()) end |