ooor 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ooor.rb +7 -2
- data/lib/ooor/associations.rb +37 -13
- data/lib/ooor/autosave_association.rb +197 -0
- data/lib/ooor/base.rb +21 -28
- data/lib/ooor/errors.rb +1 -1
- data/lib/ooor/field_methods.rb +37 -27
- data/lib/ooor/mini_active_resource.rb +16 -22
- data/lib/ooor/model_registry.rb +6 -1
- data/lib/ooor/model_schema.rb +25 -0
- data/lib/ooor/naming.rb +27 -13
- data/lib/ooor/nested_attributes.rb +57 -0
- data/lib/ooor/persistence.rb +247 -49
- data/lib/ooor/reflection.rb +9 -7
- data/lib/ooor/reflection_ooor.rb +17 -17
- data/lib/ooor/relation.rb +0 -1
- data/lib/ooor/relation/finder_methods.rb +4 -4
- data/lib/ooor/report.rb +9 -9
- data/lib/ooor/services.rb +1 -1
- data/lib/ooor/session.rb +72 -22
- data/lib/ooor/session_handler.rb +17 -21
- data/lib/ooor/type_casting.rb +34 -37
- data/lib/ooor/version.rb +1 -1
- data/spec/ooor_spec.rb +192 -43
- metadata +7 -9
- data/lib/ooor/connection.rb +0 -37
- data/spec/install_nightly.sh +0 -17
- data/spec/requirements.txt +0 -19
data/lib/ooor/version.rb
CHANGED
data/spec/ooor_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# OOOR: OpenObject On Ruby
|
2
|
-
# Copyright (C) 2009-
|
2
|
+
# Copyright (C) 2009-2014 Akretion LTDA (<http://www.akretion.com>).
|
3
3
|
# Author: Raphaël Valyi
|
4
4
|
# Licensed under the MIT license, see MIT-LICENSE file
|
5
5
|
|
@@ -65,9 +65,10 @@ describe Ooor do
|
|
65
65
|
|
66
66
|
describe "Finders operations" do
|
67
67
|
it "should be able to find data by id" do
|
68
|
-
|
68
|
+
first_product_id = ProductProduct.search([], 0, 1).first
|
69
|
+
product1 = ProductProduct.find(first_product_id)
|
69
70
|
expect(product1).not_to be_nil
|
70
|
-
|
71
|
+
product1.attributes.should be_kind_of(Hash)
|
71
72
|
end
|
72
73
|
|
73
74
|
it "fetches data given an array of ids" do
|
@@ -76,7 +77,7 @@ describe Ooor do
|
|
76
77
|
end
|
77
78
|
|
78
79
|
it "should fetches data given an implicit array of ids" do
|
79
|
-
products = ProductProduct.find(1,2)
|
80
|
+
products = ProductProduct.find(1, 2)
|
80
81
|
products.size.should == 2
|
81
82
|
end
|
82
83
|
|
@@ -143,19 +144,20 @@ describe Ooor do
|
|
143
144
|
partner.should be_kind_of ResPartner
|
144
145
|
end
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
p.
|
149
|
-
|
150
|
-
products.
|
151
|
-
|
147
|
+
# NOTE: in Ooor 2.1 we don't support this anymore, use session.with_context(context) {} instead
|
148
|
+
# it "should support OpenERP context in finders" do #TODO
|
149
|
+
# p = ProductProduct.find(1, :context => {:my_key => 'value'})
|
150
|
+
# p.should_not be_nil
|
151
|
+
# products = ProductProduct.find(:all, :context => {:lang => 'es_ES'})
|
152
|
+
# products.should be_kind_of(Array)
|
153
|
+
# end
|
152
154
|
|
153
|
-
it "should support writing with a context" do
|
154
|
-
p = ProductProduct.find(1, fields: ['name'])
|
155
|
-
ProductProduct.write(1, {name: p.name}, {lang: 'en_US'})
|
156
|
-
ProductProduct.write(1, {name: p.name}, lang: 'en_US')
|
157
|
-
p.write({name: p.name}, lang: 'en_US')
|
158
|
-
end
|
155
|
+
# it "should support writing with a context" do #TODO
|
156
|
+
# p = ProductProduct.find(1, fields: ['name'])
|
157
|
+
# ProductProduct.write(1, {name: p.name}, {lang: 'en_US'})
|
158
|
+
# ProductProduct.write(1, {name: p.name}, lang: 'en_US')
|
159
|
+
# p.write({name: p.name}, lang: 'en_US')
|
160
|
+
# end
|
159
161
|
|
160
162
|
it "should support OpenERP search method" do
|
161
163
|
partners = ResPartner.search([['name', 'ilike', 'a']], 0, 2)
|
@@ -170,7 +172,7 @@ describe Ooor do
|
|
170
172
|
end
|
171
173
|
|
172
174
|
it "should not load false values in empty strings (for HTML forms)" do
|
173
|
-
ResPartner.first.
|
175
|
+
ResPartner.first.mobile.should be_nil
|
174
176
|
end
|
175
177
|
|
176
178
|
it "should map OpenERP types to Rails types" do
|
@@ -184,26 +186,26 @@ describe Ooor do
|
|
184
186
|
|
185
187
|
describe "Relations reading" do
|
186
188
|
it "should read many2one relations" do
|
187
|
-
o = SaleOrder.find(
|
189
|
+
o = SaleOrder.find(:first)
|
188
190
|
o.partner_id.should be_kind_of(ResPartner)
|
189
191
|
p = ProductProduct.find(1) #inherited via product template
|
190
192
|
p.categ_id.should be_kind_of(ProductCategory)
|
191
193
|
end
|
192
194
|
|
193
195
|
it "should read one2many relations" do
|
194
|
-
o = SaleOrder.find(
|
196
|
+
o = SaleOrder.find(:first)
|
195
197
|
o.order_line.each do |line|
|
196
198
|
line.should be_kind_of(SaleOrderLine)
|
197
199
|
end
|
198
200
|
end
|
199
201
|
|
200
202
|
it "should read many2many relations" do
|
201
|
-
s = SaleOrder.find(
|
203
|
+
s = SaleOrder.find(:first)
|
202
204
|
s.order_policy = 'manual'
|
203
205
|
s.save
|
204
206
|
s.wkf_action('order_confirm')
|
205
207
|
s.wkf_action('manual_invoice')
|
206
|
-
SaleOrder.find(
|
208
|
+
SaleOrder.find(:first).order_line[1].invoice_lines.should be_kind_of(Array)
|
207
209
|
end
|
208
210
|
|
209
211
|
it "should read polymorphic references" do
|
@@ -279,19 +281,19 @@ describe Ooor do
|
|
279
281
|
|
280
282
|
it "should skipped inherited default fields properly, for instance at product variant creation" do
|
281
283
|
#note that we force [] here for the default_get_fields otherwise OpenERP will blows up while trying to write in the product template!
|
282
|
-
ProductProduct.create({:product_tmpl_id => 25, :code => 'OOOR variant'},
|
284
|
+
ProductProduct.create({:product_tmpl_id => 25, :code => 'OOOR variant'}, []).should be_kind_of(ProductProduct)
|
283
285
|
end
|
284
286
|
end
|
285
287
|
|
286
288
|
describe "Basic updates" do
|
287
289
|
it "should cast properly from Ruby to OpenERP" do
|
288
|
-
o = SaleOrder.find(
|
290
|
+
o = SaleOrder.find(:first).copy()
|
289
291
|
o.date_order = 2.days.ago
|
290
292
|
o.save
|
291
293
|
end
|
292
294
|
|
293
295
|
it "should be able to reload resource" do
|
294
|
-
s = SaleOrder.find(
|
296
|
+
s = SaleOrder.find(:first)
|
295
297
|
s.reload.should be_kind_of(SaleOrder)
|
296
298
|
end
|
297
299
|
end
|
@@ -343,8 +345,7 @@ describe Ooor do
|
|
343
345
|
|
344
346
|
it "should support Rails nested attributes methods" do
|
345
347
|
so = SaleOrder.find :first
|
346
|
-
so.respond_to?(:order_line_attributes).should
|
347
|
-
so.respond_to?(:order_line_attributes=).should be_true
|
348
|
+
so.respond_to?(:order_line_attributes=).should == true
|
348
349
|
end
|
349
350
|
|
350
351
|
it "should support CRUD on o2m via nested attributes" do
|
@@ -354,7 +355,7 @@ describe Ooor do
|
|
354
355
|
p = ProductProduct.find p.id
|
355
356
|
pack1 = p.packaging[0]
|
356
357
|
pack2 = p.packaging[1]
|
357
|
-
pack2.name.should ==
|
358
|
+
pack2.name.index('pack').should == 0
|
358
359
|
p.packaging_attributes = {'1' => {name: 'pack1', '_destroy'=> true, id: pack1.id}, '2' => {name: 'pack2_modified', id: pack2.id}}
|
359
360
|
p.save
|
360
361
|
p.packaging.size.should == 1
|
@@ -398,18 +399,39 @@ describe Ooor do
|
|
398
399
|
include Ooor
|
399
400
|
|
400
401
|
it "should call customized before_save callback" do
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
end
|
402
|
+
probe = nil
|
403
|
+
Ooor.xtend('ir.ui.menu') do
|
404
|
+
before_save do |record|
|
405
|
+
probe = record.name
|
406
406
|
end
|
407
|
+
end
|
408
|
+
|
409
|
+
with_ooor_session username: 'admin', password: 'admin' do |session|
|
410
|
+
menu = session['ir.ui.menu'].first
|
411
|
+
menu.save
|
412
|
+
probe.should == menu.name
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
it "should call customized before_save callback on nested o2m" do
|
417
|
+
with_ooor_session({username: 'admin', password: 'admin'}, 'noshare1') do |session|
|
418
|
+
# we purposely make reflections happen to ensure they won't be reused in next session
|
419
|
+
p = session['product.product'].create name: 'noise', packaging_attributes: {'1' => {name: 'pack'}}
|
420
|
+
end
|
407
421
|
|
408
|
-
|
409
|
-
|
422
|
+
probe = nil
|
423
|
+
Ooor.xtend('product.packaging') do
|
424
|
+
before_save do |record|
|
425
|
+
probe = record.name
|
410
426
|
end
|
411
|
-
end
|
427
|
+
end
|
428
|
+
|
429
|
+
with_ooor_session({username: 'admin', password: 'admin'}, 'noshare2') do |session|
|
430
|
+
p = session['product.product'].create name: 'nested callback test', packaging_attributes: {'1' => {name: 'pack'}, '2' => {name: 'pack'}}
|
431
|
+
probe.should == 'pack'
|
432
|
+
end
|
412
433
|
end
|
434
|
+
|
413
435
|
end
|
414
436
|
|
415
437
|
describe "ARel emulation" do
|
@@ -472,7 +494,7 @@ describe Ooor do
|
|
472
494
|
end
|
473
495
|
|
474
496
|
it "should be possible to call resource actions and workflow actions" do
|
475
|
-
s = SaleOrder.find(
|
497
|
+
s = SaleOrder.find(:first).copy()
|
476
498
|
s.wkf_action('order_confirm')
|
477
499
|
s.wkf_action('manual_invoice')
|
478
500
|
i = s.invoice_ids[0]
|
@@ -504,21 +526,30 @@ describe Ooor do
|
|
504
526
|
|
505
527
|
describe "Object context abilities" do
|
506
528
|
before(:all) do
|
507
|
-
@ooor = Ooor.new(:url => @url, :database => @database)
|
529
|
+
@ooor = Ooor.new(:url => @url, :database => @database, :username => @username, :password => @password)
|
508
530
|
end
|
509
531
|
|
510
532
|
it "should support context when instanciating collections" do
|
511
533
|
@ooor.const_get('product.product')
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
534
|
+
Ooor.default_session.with_context(lang: 'fr_FR') do
|
535
|
+
products = ProductProduct.find([1, 2, 3])
|
536
|
+
p = products[0]
|
537
|
+
p.save #TODO check that actions keep executing with proper context
|
538
|
+
end
|
516
539
|
end
|
517
540
|
end
|
518
541
|
|
519
542
|
describe "Web SEO utilities" do
|
520
543
|
include Ooor
|
521
544
|
|
545
|
+
it "should support ActiveModel::Naming" do
|
546
|
+
with_ooor_session(:url => @url, :database => @database, :username => @username, :password => @password) do |session|
|
547
|
+
session['product.product'].name.should == "ProductProduct"
|
548
|
+
session['product.product'].model_name.route_key.should == "product-product"
|
549
|
+
session['product.product'].model_name.param_key.should == "product_product" #TODO add more expectations
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
522
553
|
it "should support model aliases" do
|
523
554
|
Ooor.session_handler.reset!() # alias isn't part of the connection spec, we don't want connectio reuse here
|
524
555
|
with_ooor_session(:url => @url, :database => @database, :username => @username, :password => @password, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
|
@@ -557,16 +588,28 @@ describe Ooor do
|
|
557
588
|
|
558
589
|
it "should test correct class name matching with class name" do
|
559
590
|
object = Ooor::Reflection::AssociationReflection.new(:test, 'product_product', {class_name: 'product.product'}, nil)
|
560
|
-
object.
|
591
|
+
object.session = @ooor
|
561
592
|
object.klass.should == ProductProduct
|
562
593
|
end
|
563
594
|
|
564
|
-
it "should reflect on association (used in simple_form, cocoon...)" do
|
595
|
+
it "should reflect on m2o association (used in simple_form, cocoon...)" do
|
565
596
|
reflection = ProductProduct.reflect_on_association(:categ_id)
|
566
597
|
reflection.should be_kind_of(Ooor::Reflection::AssociationReflection)
|
567
598
|
reflection.klass.should == ProductCategory
|
568
599
|
end
|
569
600
|
|
601
|
+
it "should reflect on o2m association (used in simple_form, cocoon...)" do
|
602
|
+
reflection = ProductProduct.reflect_on_association(:packaging)
|
603
|
+
reflection.should be_kind_of(Ooor::Reflection::AssociationReflection)
|
604
|
+
reflection.klass.openerp_model == 'product.packaging'
|
605
|
+
end
|
606
|
+
|
607
|
+
it "should reflect on m2m association (used in simple_form, cocoon...)" do
|
608
|
+
reflection = ResPartner.reflect_on_association(:category_id)
|
609
|
+
reflection.should be_kind_of(Ooor::Reflection::AssociationReflection)
|
610
|
+
reflection.klass.should == ResPartnerCategory
|
611
|
+
end
|
612
|
+
|
570
613
|
it "should support column_for_attribute (used by simple_form)" do
|
571
614
|
@ooor.const_get('ir.cron').find(:first).column_for_attribute('name')[:type].should == :string
|
572
615
|
end
|
@@ -616,6 +659,112 @@ describe Ooor do
|
|
616
659
|
user_obj.search().should be_kind_of(Array)
|
617
660
|
end
|
618
661
|
end
|
662
|
+
|
663
|
+
it "should raise AccessDenied/UnAuthorizedError errors" do
|
664
|
+
expect do
|
665
|
+
with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session|
|
666
|
+
session['ir.ui.menu'].first.save
|
667
|
+
end
|
668
|
+
end.to raise_error(Ooor::UnAuthorizedError)
|
669
|
+
end
|
670
|
+
|
671
|
+
it "should assign a secure web session_id to a new web session" do
|
672
|
+
session = Ooor.session_handler.retrieve_session({}, nil, {})
|
673
|
+
session.id.should be_kind_of String
|
674
|
+
session.id.size.should == 32
|
675
|
+
end
|
676
|
+
|
677
|
+
it "should keep existing web session_id" do
|
678
|
+
session = Ooor.session_handler.retrieve_session({}, "12345678912345", {})
|
679
|
+
session.id.should == "12345678912345"
|
680
|
+
end
|
681
|
+
|
682
|
+
it "should reuse the same session and proxies with session with same spec" do
|
683
|
+
obj1 = 1
|
684
|
+
obj2 = 2
|
685
|
+
s1 = 1
|
686
|
+
s2 = 2
|
687
|
+
with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session1|
|
688
|
+
s1 = session1
|
689
|
+
obj1 = session1['ir.ui.menu']
|
690
|
+
end
|
691
|
+
with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session2|
|
692
|
+
s2 = session2
|
693
|
+
obj2 = session2['ir.ui.menu']
|
694
|
+
end
|
695
|
+
s1.object_id.should == s2.object_id
|
696
|
+
obj1.object_id.should == obj2.object_id
|
697
|
+
end
|
698
|
+
|
699
|
+
it "should not reuse the same session and proxies with session with different spec" do
|
700
|
+
obj1 = 1
|
701
|
+
obj2 = 2
|
702
|
+
s1 = 1
|
703
|
+
s2 = 2
|
704
|
+
with_ooor_session(:url => @url, :username => 'admin', :password => 'admin', :database => @database) do |session1|
|
705
|
+
s1 = session1
|
706
|
+
obj1 = session1['ir.ui.menu']
|
707
|
+
end
|
708
|
+
|
709
|
+
with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session2|
|
710
|
+
s2 = session2
|
711
|
+
obj2 = session2['ir.ui.menu']
|
712
|
+
end
|
713
|
+
|
714
|
+
s1.object_id.should_not == s2.object_id
|
715
|
+
obj1.object_id.should_not == obj2.object_id
|
716
|
+
end
|
717
|
+
|
718
|
+
it "when using different web sessions, it should still share model schemas" do
|
719
|
+
obj1 = 1
|
720
|
+
obj2 = 2
|
721
|
+
s1 = 1
|
722
|
+
s2 = 2
|
723
|
+
with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 111) do |session1|
|
724
|
+
s1 = session1
|
725
|
+
obj1 = Ooor.model_registry.get_template(session1.config, 'ir.ui.menu')
|
726
|
+
end
|
727
|
+
|
728
|
+
with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session2|
|
729
|
+
s2 = session2
|
730
|
+
obj2 = Ooor.model_registry.get_template(session2.config, 'ir.ui.menu')
|
731
|
+
end
|
732
|
+
|
733
|
+
s1.object_id.should_not == s2.object_id
|
734
|
+
obj1.should == obj2 unless ActiveModel::VERSION::STRING.start_with? "3.2" #for some reason this doesn't work with Rails 3.2
|
735
|
+
end
|
736
|
+
|
737
|
+
|
738
|
+
it "should use the same session when its session_id is specified and session spec matches (web)" do
|
739
|
+
s1 = 1
|
740
|
+
s2 = 2
|
741
|
+
|
742
|
+
with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session1|
|
743
|
+
s1 = session1
|
744
|
+
end
|
745
|
+
|
746
|
+
with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session1|
|
747
|
+
s2 = session1
|
748
|
+
end
|
749
|
+
|
750
|
+
s1.object_id.should == s2.object_id
|
751
|
+
end
|
752
|
+
|
753
|
+
it "should not use the same session when session spec matches but session_id is different (web)" do
|
754
|
+
s1 = 1
|
755
|
+
s2 = 2
|
756
|
+
|
757
|
+
with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 111) do |session1|
|
758
|
+
s1 = session1
|
759
|
+
end
|
760
|
+
|
761
|
+
with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session1|
|
762
|
+
s2 = session1
|
763
|
+
end
|
764
|
+
|
765
|
+
s1.object_id.should_not == s2.object_id
|
766
|
+
end
|
767
|
+
|
619
768
|
end
|
620
769
|
|
621
770
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ooor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Valyi - www.akretion.com
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,17 +53,19 @@ files:
|
|
53
53
|
- bin/ooor
|
54
54
|
- lib/ooor.rb
|
55
55
|
- lib/ooor/associations.rb
|
56
|
+
- lib/ooor/autosave_association.rb
|
56
57
|
- lib/ooor/base.rb
|
57
58
|
- lib/ooor/base64.rb
|
58
59
|
- lib/ooor/callbacks.rb
|
59
|
-
- lib/ooor/connection.rb
|
60
60
|
- lib/ooor/errors.rb
|
61
61
|
- lib/ooor/field_methods.rb
|
62
62
|
- lib/ooor/helpers/core_helpers.rb
|
63
63
|
- lib/ooor/locale.rb
|
64
64
|
- lib/ooor/mini_active_resource.rb
|
65
65
|
- lib/ooor/model_registry.rb
|
66
|
+
- lib/ooor/model_schema.rb
|
66
67
|
- lib/ooor/naming.rb
|
68
|
+
- lib/ooor/nested_attributes.rb
|
67
69
|
- lib/ooor/persistence.rb
|
68
70
|
- lib/ooor/rack.rb
|
69
71
|
- lib/ooor/railtie.rb
|
@@ -82,9 +84,7 @@ files:
|
|
82
84
|
- lib/ooor/type_casting.rb
|
83
85
|
- lib/ooor/version.rb
|
84
86
|
- spec/helpers/test_helper.rb
|
85
|
-
- spec/install_nightly.sh
|
86
87
|
- spec/ooor_spec.rb
|
87
|
-
- spec/requirements.txt
|
88
88
|
homepage: http://github.com/akretion/ooor
|
89
89
|
licenses: []
|
90
90
|
metadata: {}
|
@@ -109,7 +109,5 @@ signing_key:
|
|
109
109
|
specification_version: 4
|
110
110
|
summary: OOOR - OpenObject On Ruby
|
111
111
|
test_files:
|
112
|
-
- spec/requirements.txt
|
113
|
-
- spec/helpers/test_helper.rb
|
114
|
-
- spec/install_nightly.sh
|
115
112
|
- spec/ooor_spec.rb
|
113
|
+
- spec/helpers/test_helper.rb
|
data/lib/ooor/connection.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# OOOR: OpenObject On Ruby
|
2
|
-
# Copyright (C) 2009-2012 Akretion LTDA (<http://www.akretion.com>).
|
3
|
-
# Author: Raphaël Valyi
|
4
|
-
# Licensed under the MIT license, see MIT-LICENSE file
|
5
|
-
|
6
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
7
|
-
|
8
|
-
module Ooor
|
9
|
-
class Connection
|
10
|
-
attr_accessor :config, :connection_session
|
11
|
-
|
12
|
-
def initialize(config, env=false)
|
13
|
-
@config = _config(config)
|
14
|
-
Object.const_set(@config[:scope_prefix], Module.new) if @config[:scope_prefix]
|
15
|
-
end
|
16
|
-
|
17
|
-
def connection_session
|
18
|
-
@connection_session ||= {}.merge!(@config[:connection_session] || {})
|
19
|
-
end
|
20
|
-
|
21
|
-
def helper_paths
|
22
|
-
[File.dirname(__FILE__) + '/helpers/*', *@config[:helper_paths]]
|
23
|
-
end
|
24
|
-
|
25
|
-
def class_name_from_model_key(model_key)
|
26
|
-
model_key.split('.').collect {|name_part| name_part.capitalize}.join
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def _config(config)
|
32
|
-
c = config.is_a?(String) ? Ooor.load_config(config, env) : config
|
33
|
-
HashWithIndifferentAccess.new(c)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|