Class: Ooor::MiniActiveResource

Inherits:
Object
  • Object
show all
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

Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



21
22
23
# File 'lib/ooor/mini_active_resource.rb', line 21

def attributes
  @attributes
end

#idObject

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_nameObject



16
17
18
# File 'lib/ooor/mini_active_resource.rb', line 16

def element_name
  @element_name ||= model_name.element
end

Instance Method Details

#errorsObject

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.

Returns:

  • (Boolean)


32
33
34
# File 'lib/ooor/mini_active_resource.rb', line 32

def new?
  !@persisted
end

#persisted?Boolean

Returns:

  • (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(options = nil)
  self.class.find(id, options)
end

#to_json(options = {}) ⇒ Object



23
24
25
# File 'lib/ooor/mini_active_resource.rb', line 23

def to_json(options={})
  super(include_root_in_json ? { :root => self.class.element_name }.merge(options) : options)
end

#to_xml(options = {}) ⇒ Object



27
28
29
# File 'lib/ooor/mini_active_resource.rb', line 27

def to_xml(options={})
  super({ :root => self.class.element_name }.merge(options))
end