kangaroo 0.0.2 → 0.0.3

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kangaroo (0.0.1.pre2)
4
+ kangaroo (0.0.2)
5
5
  activerecord (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
  hirb
@@ -10,57 +10,58 @@ PATH
10
10
  GEM
11
11
  remote: http://rubygems.org/
12
12
  specs:
13
- activemodel (3.0.5)
14
- activesupport (= 3.0.5)
13
+ activemodel (3.0.6)
14
+ activesupport (= 3.0.6)
15
15
  builder (~> 2.1.2)
16
- i18n (~> 0.4)
17
- activerecord (3.0.5)
18
- activemodel (= 3.0.5)
19
- activesupport (= 3.0.5)
16
+ i18n (~> 0.5.0)
17
+ activerecord (3.0.6)
18
+ activemodel (= 3.0.6)
19
+ activesupport (= 3.0.6)
20
20
  arel (~> 2.0.2)
21
21
  tzinfo (~> 0.3.23)
22
- activesupport (3.0.5)
22
+ activesupport (3.0.6)
23
23
  arel (2.0.9)
24
24
  builder (2.1.2)
25
25
  columnize (0.3.2)
26
- cucumber (0.10.0)
26
+ cucumber (0.10.2)
27
27
  builder (>= 2.1.2)
28
- diff-lcs (~> 1.1.2)
29
- gherkin (~> 2.3.2)
30
- json (~> 1.4.6)
31
- term-ansicolor (~> 1.0.5)
28
+ diff-lcs (>= 1.1.2)
29
+ gherkin (>= 2.3.5)
30
+ json (>= 1.4.6)
31
+ term-ansicolor (>= 1.0.5)
32
32
  diff-lcs (1.1.2)
33
- gherkin (2.3.3)
34
- json (~> 1.4.6)
35
- hirb (0.3.6)
33
+ gherkin (2.3.5)
34
+ json (>= 1.4.6)
35
+ hirb (0.4.3)
36
36
  i18n (0.5.0)
37
- json (1.4.6)
37
+ json (1.5.1)
38
38
  linecache (0.43)
39
39
  nokogiri (1.4.4)
40
40
  rapuncel (0.0.2)
41
41
  activesupport (>= 3.0.0)
42
42
  nokogiri
43
- rspec (2.4.0)
44
- rspec-core (~> 2.4.0)
45
- rspec-expectations (~> 2.4.0)
46
- rspec-mocks (~> 2.4.0)
47
- rspec-core (2.4.0)
48
- rspec-expectations (2.4.0)
43
+ rspec (2.5.0)
44
+ rspec-core (~> 2.5.0)
45
+ rspec-expectations (~> 2.5.0)
46
+ rspec-mocks (~> 2.5.0)
47
+ rspec-core (2.5.1)
48
+ rspec-expectations (2.5.0)
49
49
  diff-lcs (~> 1.1.2)
50
- rspec-mocks (2.4.0)
50
+ rspec-mocks (2.5.0)
51
51
  ruby-debug (0.10.4)
52
52
  columnize (>= 0.1)
53
53
  ruby-debug-base (~> 0.10.4.0)
54
54
  ruby-debug-base (0.10.4)
55
55
  linecache (>= 0.3)
56
56
  term-ansicolor (1.0.5)
57
- tzinfo (0.3.25)
58
- yard (0.6.4)
57
+ tzinfo (0.3.26)
58
+ yard (0.6.8)
59
59
 
60
60
  PLATFORMS
61
61
  ruby
62
62
 
63
63
  DEPENDENCIES
64
+ bundler
64
65
  cucumber
65
66
  kangaroo!
66
67
  rspec
data/README.md CHANGED
@@ -4,12 +4,14 @@ Kangaroo
4
4
  Overview
5
5
  --------
6
6
 
7
- Kangaroo is an OpenObject client/wrapper for Rails 3, based on ActiveModel. It provides CRUD access to OpenERP objects via XMLRPC.
7
+ Kangaroo is an OpenObject client/wrapper for Ruby, based on ActiveModel. It provides CRUD access to OpenERP objects via XMLRPC.
8
8
  It's fast and provides default data for new objects.
9
9
 
10
10
  Installation
11
11
  ------------
12
12
 
13
+ ### Rails 3
14
+
13
15
  If you're on Rails 3, just add Kangaroo to your Gemfile:
14
16
 
15
17
  gem 'kangaroo'
@@ -31,6 +33,29 @@ And create a **kangaroo.yml** configuration file in **[RAILS\_ROOT]/config**, co
31
33
 
32
34
  Adjust your connection and database settings and specify the models you need.
33
35
 
36
+ ### Ruby
37
+
38
+ Use Kangaroo in any Ruby project!
39
+
40
+ gem install kangaroo
41
+
42
+ In your code
43
+
44
+ require 'rubygems'
45
+ require 'kangaroo'
46
+
47
+ # Configure a connection to an OpenERP server
48
+ config = Kangaroo::Util::Configuration.new yaml_file_or_hash, Logger.new(STDOUT)
49
+ config.login
50
+
51
+ # Load OpenERP models matching "res.*" into namespace ::Oo
52
+ # Kangaroo::Util::Loader can be called several times, whenever needed.
53
+ Kangaroo::Util::Loader.new('res.*', config.database, 'Oo').load!
54
+
55
+ ### Console
56
+
57
+ See CLI below.
58
+
34
59
  Usage
35
60
  -----
36
61
 
@@ -100,7 +125,33 @@ console:
100
125
  +------+-----------------------------+
101
126
  5 rows in set
102
127
 
128
+
129
+ Lazy model loading
130
+ ------------------
131
+
132
+ You don't have to specify all models you ever need in your configuration file. Kangaroo will lazy load
133
+ models as they are accessed:
134
+
135
+ ruby-1.8.7-p302 :001 > Oo.const_defined? "Product"
136
+ => false
137
+ ruby-1.8.7-p302 :002 > Oo::Product
138
+ => Module 'Oo::Product' contains loaded OpenERP Models/Namespaces:
139
+ ruby-1.8.7-p302 :003 > Oo::Product.const_defined? "Product"
140
+ => false
141
+ ruby-1.8.7-p302 :004 > Oo::Product::Product
142
+ => <Oo::Product::Product id, loc_case, volume, type, uos_coeff, incoming_qty, price_margin, sale_ok, loc_rack, description_purchase, code, ean13, warranty, description_sale, outgoing_qty, product_tmpl_id, standard_price, rental, uom_po_id, default_code, supply_method, categ_id, procure_method, virtual_available, variants, packaging, pricelist_id, name_template, uos_id, lst_price, cost_method, description, seller_delay, price_extra, seller_id, price, active, company_id, qty_available, list_price, produce_delay, partner_ref, state, name, purchase_ok, mes_type, sale_delay, weight_net, seller_qty, weight, seller_ids, loc_row, product_manager, uom_id>
103
143
 
104
- etc.
105
144
  Please refer to {file:docs/Usage.md Usage} to learn about limitations/features not yet
106
- implemented.
145
+ implemented.
146
+
147
+ Development
148
+ -----------
149
+
150
+ SCM:
151
+ [https://github.com/cice/kangARoo](https://github.com/cice/kangARoo)
152
+
153
+ Issues:
154
+ [https://kayoom.lighthouseapp.com/projects/73738-kangaroo/tickets](https://kayoom.lighthouseapp.com/projects/73738-kangaroo/tickets)
155
+
156
+ Rubygems:
157
+ [https://rubygems.org/gems/kangaroo](https://rubygems.org/gems/kangaroo)
@@ -27,4 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency 'rspec'
28
28
  s.add_development_dependency 'ruby-debug'
29
29
  s.add_development_dependency 'cucumber'
30
+ s.add_development_dependency 'bundler'
30
31
  end
@@ -28,7 +28,9 @@ module Kangaroo
28
28
  @namespace = @root_namespace
29
29
 
30
30
  constant_names[1..-2].each do |mod|
31
- @namespace = set_const_in @namespace, mod, Module.new
31
+ const = Module.new
32
+ const.send :extend, Util::Loader::Namespace
33
+ @namespace = set_const_in @namespace, mod, const
32
34
  end
33
35
  end
34
36
 
@@ -6,6 +6,7 @@ module Kangaroo
6
6
  class Loader
7
7
  autoload :Model, 'kangaroo/util/loader/model'
8
8
  autoload :Namespace, 'kangaroo/util/loader/namespace'
9
+ autoload :RootNamespace, 'kangaroo/util/loader/root_namespace'
9
10
  attr_accessor :model_names, :models, :database, :namespace
10
11
 
11
12
  # Initialize a Loader instance
@@ -35,6 +36,7 @@ module Kangaroo
35
36
  rescue NameError
36
37
  eval <<-RUBY
37
38
  module #{namespace}
39
+ extend Kangaroo::Util::Loader::RootNamespace
38
40
  extend Kangaroo::Util::Loader::Namespace
39
41
  end
40
42
  RUBY
@@ -2,12 +2,33 @@ module Kangaroo
2
2
  module Util
3
3
  class Loader
4
4
  module Namespace
5
- def oo_to_ruby oo_name
6
- name + "::" + oo_name.gsub('.','/').camelize
5
+ def inspect
6
+ "Module '#{name}' contains loaded OpenERP Models/Namespaces: #{constants.join(', ')}"
7
7
  end
8
-
9
- def ruby_to_oo ruby_name
10
- ruby_name.sub(name + "::",'').underscore.gsub '/', '.'
8
+
9
+ def namespace_name
10
+ name.match(/^([^\:]+)/)[1]
11
+ end
12
+
13
+ def namespace
14
+ namespace_name.constantize
15
+ end
16
+
17
+ def const_missing const_name
18
+ namespaced_const_name = "#{name}::#{const_name}"
19
+
20
+ if namespace.model_exists?(namespaced_const_name)
21
+ namespace.load_model(namespaced_const_name)
22
+ elsif namespace.models_in?(namespaced_const_name)
23
+ Module.new.tap do |mod|
24
+ mod.send :extend, Namespace
25
+ const_set const_name, mod
26
+ end
27
+ else
28
+ super
29
+ end
30
+ rescue
31
+ super
11
32
  end
12
33
  end
13
34
  end
@@ -0,0 +1,35 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Loader
4
+ module RootNamespace
5
+ def oo_to_ruby oo_name
6
+ name + "::" + oo_name.gsub('.','/').camelize
7
+ end
8
+
9
+ def ruby_to_oo ruby_name
10
+ ruby_name.sub(name + "::",'').underscore.gsub '/', '.'
11
+ end
12
+
13
+ def reflection_model
14
+ const_get('Ir').const_get('Model')
15
+ end
16
+
17
+ def model_exists? name
18
+ name = ruby_to_oo name
19
+ reflection_model.where(:model => name).exists?
20
+ end
21
+
22
+ def models_in? name
23
+ name = ruby_to_oo name
24
+
25
+ reflection_model.where("model like #{name}.%").exists?
26
+ end
27
+
28
+ def load_model model_name
29
+ model_name = ruby_to_oo model_name
30
+ Loader.new([model_name], reflection_model.database, name).load!.first
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Kangaroo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ module Kangaroo
5
+ describe 'Lazy Loading' do
6
+ before :all do
7
+ config = Kangaroo::Util::Configuration.new 'spec/test_env/test.yml'
8
+ config.login
9
+
10
+ Kangaroo::Util::Loader.new('res.partner', config.database).load!
11
+ end
12
+
13
+ it 'should raise error if trying to access constant without corresponding OpenERP Model' do
14
+ lambda {
15
+ Oo::Abcd
16
+ }.should raise_error
17
+
18
+ lambda {
19
+ Oo::Res::Bcde
20
+ }.should raise_error
21
+ end
22
+
23
+ it 'should lazy load additional models in an OpenERP namespace' do
24
+ lambda {
25
+ Oo::Res::Country
26
+ }.should_not raise_error
27
+ end
28
+
29
+ it 'should create namespace modules on demand' do
30
+ lambda {
31
+ Oo::Product
32
+ }.should_not raise_error
33
+ end
34
+
35
+ it 'should lazy load missing models in other namespaces' do
36
+ lambda {
37
+ Oo::Product::Product
38
+ }.should_not raise_error
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kangaroo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Eickenberg
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-15 00:00:00 +02:00
19
+ date: 2011-04-16 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,20 @@ dependencies:
137
137
  version: "0"
138
138
  type: :development
139
139
  version_requirements: *id008
140
+ - !ruby/object:Gem::Dependency
141
+ name: bundler
142
+ prerelease: false
143
+ requirement: &id009 !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ type: :development
153
+ version_requirements: *id009
140
154
  description: ActiveRecord-ish OpenObject Wrapper
141
155
  email: marian@cice-online.net
142
156
  executables:
@@ -191,6 +205,7 @@ files:
191
205
  - lib/kangaroo/util/loader.rb
192
206
  - lib/kangaroo/util/loader/model.rb
193
207
  - lib/kangaroo/util/loader/namespace.rb
208
+ - lib/kangaroo/util/loader/root_namespace.rb
194
209
  - lib/kangaroo/util/proxy.rb
195
210
  - lib/kangaroo/util/proxy/common.rb
196
211
  - lib/kangaroo/util/proxy/db.rb
@@ -200,6 +215,7 @@ files:
200
215
  - lib/kangaroo/util/proxy/wizard.rb
201
216
  - lib/kangaroo/util/proxy/workflow.rb
202
217
  - lib/kangaroo/version.rb
218
+ - spec/functional/lazy_loading_spec.rb
203
219
  - spec/model/attributes_spec.rb
204
220
  - spec/model/base_spec.rb
205
221
  - spec/model/default_attributes_spec.rb
@@ -256,6 +272,7 @@ test_files:
256
272
  - features/step_definitions/configuration_steps.rb
257
273
  - features/support/test.yml
258
274
  - features/utility_services.feature
275
+ - spec/functional/lazy_loading_spec.rb
259
276
  - spec/model/attributes_spec.rb
260
277
  - spec/model/base_spec.rb
261
278
  - spec/model/default_attributes_spec.rb