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
trueif 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.
35 36 37 |
# File 'lib/ooor/mini_active_resource.rb', line 35 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
35 36 37 |
# File 'lib/ooor/mini_active_resource.rb', line 35 def id @id end |
Class Method Details
.element_name ⇒ Object
30 31 32 |
# File 'lib/ooor/mini_active_resource.rb', line 30 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.
76 77 78 |
# File 'lib/ooor/mini_active_resource.rb', line 76 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.
48 49 50 |
# File 'lib/ooor/mini_active_resource.rb', line 48 def new? !@persisted end |
#persisted? ⇒ Boolean
53 54 55 |
# File 'lib/ooor/mini_active_resource.rb', line 53 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
71 72 73 |
# File 'lib/ooor/mini_active_resource.rb', line 71 def reload( = nil) self.class.find(id, ) end |
#to_json(options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/ooor/mini_active_resource.rb', line 37 def to_json(={}) raise "you should add gem 'active_model_serializers' in your Gemfile" unless defined?(ActiveModel::Serializers::JSON) super(include_root_in_json ? { :root => self.class.element_name }.merge() : ) end |
#to_xml(options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/ooor/mini_active_resource.rb', line 42 def to_xml(={}) raise "you should add gem 'activemodel-serializers-xml' in your Gemfile" unless defined?(ActiveModel::Serializers::Xml) super({ :root => self.class.element_name }.merge()) end |