Class: Ooor::Session
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ooor::Session
- Includes:
- Transport
- Defined in:
- lib/ooor/session.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#id ⇒ Object
Returns the value of attribute id.
-
#web_session ⇒ Object
Returns the value of attribute web_session.
Instance Method Summary collapse
-
#[](model_key) ⇒ Object
TODO invert: define method here and use [].
- #[]=(key, value) ⇒ Object
- #common ⇒ Object
- #const_get(model_key, lang = nil) ⇒ Object
- #db ⇒ Object
-
#define_openerp_model(options) ⇒ Object
TODO param to tell if we define constants or not.
- #global_login(options) ⇒ Object
-
#initialize(connection, web_session, id) ⇒ Session
constructor
A new instance of Session.
- #load_models(model_names = , reload = ) ⇒ Object
- #logger ⇒ Object
- #models ⇒ Object
- #object ⇒ Object
- #report ⇒ Object
- #session_context(context = {}) ⇒ Object
- #set_model_template!(klass, options) ⇒ Object
Methods included from Transport
#base_jsonrpc2_url, #base_url, #get_client
Constructor Details
#initialize(connection, web_session, id) ⇒ Session
Returns a new instance of Session.
14 15 16 17 18 19 |
# File 'lib/ooor/session.rb', line 14 def initialize(connection, web_session, id) super(connection) @connection = connection @web_session = web_session || {} @id = id || web_session[:session_id] end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/ooor/session.rb', line 7 def connection @connection end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/ooor/session.rb', line 7 def id @id end |
#web_session ⇒ Object
Returns the value of attribute web_session.
7 8 9 |
# File 'lib/ooor/session.rb', line 7 def web_session @web_session end |
Instance Method Details
#[](model_key) ⇒ Object
TODO invert: define method here and use []
53 54 55 |
# File 'lib/ooor/session.rb', line 53 def [](key) @session[key] end |
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/ooor/session.rb', line 25 def []=(key, value) @session[key] = value end |
#common ⇒ Object
9 |
# File 'lib/ooor/session.rb', line 9 def common(); @common_service ||= CommonService.new(self); end |
#const_get(model_key, lang = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ooor/session.rb', line 38 def const_get(model_key, lang=nil); if config[:aliases] if lang && alias_data = config[:aliases][lang] openerp_model = alias_data[model_key] || model_key elsif alias_data = config[:aliases][connection_session['lang'] || :en_US] openerp_model = alias_data[model_key] || model_key else openerp_model = model_key end else openerp_model = model_key end define_openerp_model(model: openerp_model, scope_prefix: config[:scope_prefix], generate_constants: config[:generate_constants]) end |
#db ⇒ Object
10 |
# File 'lib/ooor/session.rb', line 10 def db(); @db_service ||= DbService.new(self); end |
#define_openerp_model(options) ⇒ Object
TODO param to tell if we define constants or not
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ooor/session.rb', line 93 def define_openerp_model() #TODO param to tell if we define constants or not if !models[[:model]] || [:reload]# || !scope.const_defined?(model_class_name) scope_prefix = [:scope_prefix] scope = scope_prefix ? Object.const_get(scope_prefix) : Object model_class_name = class_name_from_model_key([:model]) logger.debug "registering #{model_class_name}" klass = Class.new(Base) set_model_template!(klass, ) klass.name = model_class_name klass.scope_prefix = scope_prefix klass.connection = self if [:generate_constants] && ([:reload] || !scope.const_defined?(model_class_name)) scope.const_set(model_class_name, klass) end (Ooor.extensions[[:model]] || []).each do |block| klass.class_eval(&block) end models[[:model]] = klass end models[[:model]] end |
#global_login(options) ⇒ Object
29 30 31 32 |
# File 'lib/ooor/session.rb', line 29 def global_login() config.merge!() load_models(config[:models], [:reload]) end |
#load_models(model_names = , reload = ) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ooor/session.rb', line 57 def load_models(model_names=config[:models], reload=config[:reload]) helper_paths.each do |dir| Dir[dir].each { |file| require file } end domain = model_names ? [['model', 'in', model_names]] : [] search_domain = domain - [1] model_ids = object.object_service(:execute, "ir.model", :search, search_domain, 0, false, false, {}, false) models_records = object.object_service(:execute, "ir.model", :read, model_ids, ['model', 'name']) #TODO use search_read models_records.each do |opts| = HashWithIndifferentAccess.new(opts.merge(scope_prefix: config[:scope_prefix], reload: reload, generate_constants: config[:generate_constants])) define_openerp_model() end end |
#logger ⇒ Object
117 |
# File 'lib/ooor/session.rb', line 117 def logger; Ooor.logger; end |
#models ⇒ Object
115 |
# File 'lib/ooor/session.rb', line 115 def models; @models ||= {}; end |
#object ⇒ Object
11 |
# File 'lib/ooor/session.rb', line 11 def object(); @object_service ||= ObjectService.new(self); end |
#report ⇒ Object
12 |
# File 'lib/ooor/session.rb', line 12 def report(); @report_service ||= ReportService.new(self); end |
#session_context(context = {}) ⇒ Object
34 35 36 |
# File 'lib/ooor/session.rb', line 34 def session_context(context={}) connection_session.merge(web_session.slice('lang', 'tz')).merge(context) # not just lang and tz? end |
#set_model_template!(klass, options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ooor/session.rb', line 71 def set_model_template!(klass, ) template = Ooor.model_registry.get_template(config, [:model]) if template klass.t = template klass.one2many_associations.keys.each do |meth| klass.define_nested_attributes_method(meth) end else template = Ooor::ModelTemplate.new template.openerp_model = [:model] template.openerp_id = [:id] template.description = [:name] template.state = [:state] template.many2one_associations = {} template.one2many_associations = {} template.many2many_associations = {} template.polymorphic_m2o_associations = {} template.associations_keys = [] klass.t = template end end |