Class: OooREST

Inherits:
Object
  • Object
show all
Defined in:
lib/ooorest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ooor) ⇒ OooREST

Returns a new instance of OooREST.



7
8
9
10
11
12
# File 'lib/ooorest.rb', line 7

def initialize(ooor)
  @ooor = ooor
  models = @ooor.config[:models] && @ooor.all_loaded_models.select {|model| ooor.config[:models].index(model.openerp_model)} || @ooor.all_loaded_models
  OpenObjectsController.logger = @ooor.logger
  models.each {|model| define_openerp_controller(model)}
end

Instance Attribute Details

#ooorObject

Returns the value of attribute ooor.



5
6
7
# File 'lib/ooorest.rb', line 5

def ooor
  @ooor
end

Instance Method Details

#define_openerp_controller(model_class) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ooorest.rb', line 14

def define_openerp_controller(model_class)
  controller_class_name = model_class.to_s + "Controller"
  OpenObjectsController.logger.info "registering #{controller_class_name} as a Rails ActiveResource Controller wrapper for OpenObject #{model_class} model"
  klass = Class.new(OpenObjectsController)
  klass.model_class = model_class
  Object.const_set(controller_class_name, klass)
  klass
end

#load_all_controllers(map) ⇒ Object



23
24
25
26
27
# File 'lib/ooorest.rb', line 23

def load_all_controllers(map)
  @ooor.all_loaded_models.each do |model|
    map.resources model.openerp_model.gsub('.', '_').to_sym
  end
end