kangaroo 0.0.1.pre2 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +11 -9
- data/README.md +41 -0
- data/bin/kang +80 -0
- data/kangaroo.gemspec +1 -0
- data/lib/kangaroo.rb +1 -0
- data/lib/kangaroo/hirb.rb +22 -0
- data/lib/kangaroo/util/client.rb +4 -0
- data/lib/kangaroo/version.rb +1 -1
- data/spec/model/open_object_orm_spec.rb +3 -3
- data/spec/ruby_adapter/class_definition_spec.rb +3 -0
- data/spec/server_helper.rb +1 -0
- data/spec/test_env/test.yml +1 -2
- data/spec/util/loader_spec.rb +4 -20
- metadata +31 -19
data/Gemfile.lock
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kangaroo (0.0.1.
|
4
|
+
kangaroo (0.0.1.pre2)
|
5
5
|
activerecord (>= 3.0.0)
|
6
6
|
activesupport (>= 3.0.0)
|
7
|
+
hirb
|
7
8
|
rapuncel (~> 0.0.2)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: http://rubygems.org/
|
11
12
|
specs:
|
12
|
-
activemodel (3.0.
|
13
|
-
activesupport (= 3.0.
|
13
|
+
activemodel (3.0.5)
|
14
|
+
activesupport (= 3.0.5)
|
14
15
|
builder (~> 2.1.2)
|
15
16
|
i18n (~> 0.4)
|
16
|
-
activerecord (3.0.
|
17
|
-
activemodel (= 3.0.
|
18
|
-
activesupport (= 3.0.
|
17
|
+
activerecord (3.0.5)
|
18
|
+
activemodel (= 3.0.5)
|
19
|
+
activesupport (= 3.0.5)
|
19
20
|
arel (~> 2.0.2)
|
20
21
|
tzinfo (~> 0.3.23)
|
21
|
-
activesupport (3.0.
|
22
|
-
arel (2.0.
|
22
|
+
activesupport (3.0.5)
|
23
|
+
arel (2.0.9)
|
23
24
|
builder (2.1.2)
|
24
25
|
columnize (0.3.2)
|
25
26
|
cucumber (0.10.0)
|
@@ -31,6 +32,7 @@ GEM
|
|
31
32
|
diff-lcs (1.1.2)
|
32
33
|
gherkin (2.3.3)
|
33
34
|
json (~> 1.4.6)
|
35
|
+
hirb (0.3.6)
|
34
36
|
i18n (0.5.0)
|
35
37
|
json (1.4.6)
|
36
38
|
linecache (0.43)
|
@@ -52,7 +54,7 @@ GEM
|
|
52
54
|
ruby-debug-base (0.10.4)
|
53
55
|
linecache (>= 0.3)
|
54
56
|
term-ansicolor (1.0.5)
|
55
|
-
tzinfo (0.3.
|
57
|
+
tzinfo (0.3.25)
|
56
58
|
yard (0.6.4)
|
57
59
|
|
58
60
|
PLATFORMS
|
data/README.md
CHANGED
@@ -60,6 +60,47 @@ You can use this models like ActiveRecord models:
|
|
60
60
|
|
61
61
|
Oo::Res::Country.create :code => 'DE', :name => 'Germany'
|
62
62
|
|
63
|
+
CLI
|
64
|
+
---
|
65
|
+
|
66
|
+
Kangaroo comes with a console based on IRB, try it:
|
67
|
+
|
68
|
+
$kang -c spec/test_env/test.yml
|
69
|
+
I, [2011-04-15T23:19:41.990623 #6834] INFO -- : Loading Kangaroo configuration "spec/test_env/test.yml"
|
70
|
+
I, [2011-04-15T23:19:41.991091 #6834] INFO -- : Configured OpenERP database "kangaroo_test_database" at "127.0.0.1"
|
71
|
+
I, [2011-04-15T23:19:41.996197 #6834] INFO -- : Authenticated user "admin" for OpenERP database "kangaroo_test_database"
|
72
|
+
ruby-1.8.7-p302 :001 > Oo::Res::Country
|
73
|
+
=> <Oo::Res::Country id, name, code>
|
74
|
+
ruby-1.8.7-p302 :002 > Oo::Res::Country.first
|
75
|
+
+---------+------+
|
76
|
+
| name | code |
|
77
|
+
+---------+------+
|
78
|
+
| Algeria | DZ |
|
79
|
+
+---------+------+
|
80
|
+
1 row in set
|
81
|
+
|
82
|
+
If you omit the -c command line option, you can initialize your Kangaroo connection from the
|
83
|
+
console:
|
84
|
+
|
85
|
+
$kang
|
86
|
+
ruby-1.8.7-p302 :001 > Kang.init "port"=>8069, "database"=>{"name"=>"kangaroo_test_database", "models"=>["res.*"], "password"=>"admin", "user"=>"admin"}, "host"=>"127.0.0.1"
|
87
|
+
I, [2011-04-15T23:23:59.789551 #7017] INFO -- : Loading Kangaroo configuration {"port"=>8069, "database"=>{"name"=>"kangaroo_test_database", "models"=>["res.*"], "user"=>"admin", "password"=>"admin"}, "host"=>"127.0.0.1"}
|
88
|
+
I, [2011-04-15T23:23:59.789706 #7017] INFO -- : Configured OpenERP database "kangaroo_test_database" at "127.0.0.1"
|
89
|
+
I, [2011-04-15T23:23:59.794861 #7017] INFO -- : Authenticated user "admin" for OpenERP database "kangaroo_test_database"
|
90
|
+
=> true
|
91
|
+
ruby-1.8.7-p302 :002 > Oo::Res::Country.limit(5).all
|
92
|
+
+------+-----------------------------+
|
93
|
+
| code | name |
|
94
|
+
+------+-----------------------------+
|
95
|
+
| DZ | Algeria |
|
96
|
+
| AS | American Samoa |
|
97
|
+
| AD | Andorra, Principality ofä ß |
|
98
|
+
| AO | Angola |
|
99
|
+
| AI | Anguilla |
|
100
|
+
+------+-----------------------------+
|
101
|
+
5 rows in set
|
102
|
+
|
103
|
+
|
63
104
|
etc.
|
64
105
|
Please refer to {file:docs/Usage.md Usage} to learn about limitations/features not yet
|
65
106
|
implemented.
|
data/bin/kang
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'kangaroo'
|
5
|
+
rescue LoadError
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
require 'kangaroo'
|
9
|
+
rescue LoadError
|
10
|
+
require 'bundler/setup'
|
11
|
+
require 'kangaroo'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'ostruct'
|
16
|
+
require 'optparse'
|
17
|
+
options = {}
|
18
|
+
|
19
|
+
optparse = OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage: kang -c config_file.yaml"
|
21
|
+
|
22
|
+
options[:config_file] = nil
|
23
|
+
opts.on '-c', '--config FILE', 'Specify config file' do |file|
|
24
|
+
options[:config_file] = file
|
25
|
+
end
|
26
|
+
|
27
|
+
# This displays the help screen, all programs are
|
28
|
+
# assumed to have this option.
|
29
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
optparse.parse!
|
36
|
+
|
37
|
+
Kang = OpenStruct.new
|
38
|
+
Kang.logger = Logger.new(STDOUT)
|
39
|
+
|
40
|
+
Kang.class_eval do
|
41
|
+
def inspect
|
42
|
+
"Kang console"
|
43
|
+
end
|
44
|
+
|
45
|
+
def init file_or_hash
|
46
|
+
Kang.logger.info "Loading Kangaroo configuration #{file_or_hash.inspect}"
|
47
|
+
Kang.config = Kangaroo::Util::Configuration.new file_or_hash, Kang.logger
|
48
|
+
Kang.config.login
|
49
|
+
|
50
|
+
Kangaroo::Util::Loader.new('res.*', Kang.config.database).load!
|
51
|
+
true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
options[:config_file] && Kang.init(options[:config_file])
|
56
|
+
|
57
|
+
require 'irb'
|
58
|
+
require 'irb/completion'
|
59
|
+
|
60
|
+
Hirb.enable
|
61
|
+
IRB.start
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
data/kangaroo.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'rapuncel', '~> 0.0.2'
|
22
22
|
s.add_dependency "activerecord", ">= 3.0.0"
|
23
23
|
s.add_dependency "activesupport", ">= 3.0.0"
|
24
|
+
s.add_dependency "hirb"
|
24
25
|
|
25
26
|
s.add_development_dependency 'yard'
|
26
27
|
s.add_development_dependency 'rspec'
|
data/lib/kangaroo.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'hirb'
|
2
|
+
|
3
|
+
module Hirb::Views::Kangaroo
|
4
|
+
def kangaroo__model__base_view obj
|
5
|
+
{ :fields => get_kangaroo_fields(obj) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_kangaroo_fields obj
|
9
|
+
fields = obj.class.attribute_names
|
10
|
+
|
11
|
+
# if query used select
|
12
|
+
if obj.attributes.keys.sort != obj.class.attribute_names.sort
|
13
|
+
selected_columns = obj.attributes.keys
|
14
|
+
sorted_columns = obj.class.attribute_names.dup.delete_if {|e| !selected_columns.include?(e) }
|
15
|
+
sorted_columns += (selected_columns - sorted_columns)
|
16
|
+
fields = sorted_columns.map {|e| e.to_sym}
|
17
|
+
end
|
18
|
+
fields
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Hirb::DynamicView.add Hirb::Views::Kangaroo, :helper => :auto_table
|
data/lib/kangaroo/util/client.rb
CHANGED
data/lib/kangaroo/version.rb
CHANGED
@@ -37,20 +37,20 @@ module Kangaroo
|
|
37
37
|
|
38
38
|
describe '#fields_get' do
|
39
39
|
it 'fetches details about fields of this model' do
|
40
|
-
object_service.should_receive(:xmlrpc_call).with('execute', 'some_class', 'fields_get', ['a'],
|
40
|
+
object_service.should_receive(:xmlrpc_call).with('execute', 'some_class', 'fields_get', ['a'], {}).
|
41
41
|
and_return({:a => {:type => "selection"}})
|
42
42
|
@klass.fields_get(:fields => ['a']).first.read_attribute(:type).should == 'selection'
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'stores the name in the Field model' do
|
46
|
-
object_service.should_receive(:xmlrpc_call).with('execute', 'some_class', 'fields_get', ['a'],
|
46
|
+
object_service.should_receive(:xmlrpc_call).with('execute', 'some_class', 'fields_get', ['a'], {}).
|
47
47
|
and_return({:a => {:type => "selection"}})
|
48
48
|
@klass.fields_get(:fields => ['a']).first.name.should == :a
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'uses attribute_names as default value for field list' do
|
52
52
|
object_service.should_receive(:xmlrpc_call).
|
53
|
-
with('execute', 'some_class', 'fields_get', ['a', 'b'],
|
53
|
+
with('execute', 'some_class', 'fields_get', ['a', 'b'], {}).
|
54
54
|
and_return({:a => {:type => 'selection'}})
|
55
55
|
@klass.fields_get
|
56
56
|
end
|
@@ -7,7 +7,10 @@ module Kangaroo
|
|
7
7
|
module RubyAdapter
|
8
8
|
describe ClassDefinition do
|
9
9
|
def stub_oo_model name
|
10
|
+
eval('module ::Oo ; end')
|
10
11
|
oo_model = mock 'oo_model'
|
12
|
+
oo_model.stub_chain(:class, :namespace).and_return(Oo)
|
13
|
+
oo_model.stub_chain(:class, :database)
|
11
14
|
oo_model.stub!('model_class_name').and_return(name)
|
12
15
|
oo_model
|
13
16
|
end
|
data/spec/server_helper.rb
CHANGED
data/spec/test_env/test.yml
CHANGED
data/spec/util/loader_spec.rb
CHANGED
@@ -13,38 +13,22 @@ module Kangaroo
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "replaces wildcards in model names" do
|
16
|
-
loader = Loader.new ['res.*']
|
16
|
+
loader = Loader.new ['res.*'], nil
|
17
17
|
|
18
18
|
loader.model_names.should == ['res.%']
|
19
19
|
end
|
20
20
|
|
21
21
|
it "uses global wildcard if model_names = :all" do
|
22
|
-
loader = Loader.new :all
|
22
|
+
loader = Loader.new :all, nil
|
23
23
|
|
24
24
|
loader.model_names.should == ['%']
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'raises error if model_names = nil or empty' do
|
28
|
-
lambda { Loader.new nil }.should raise_error
|
29
|
-
lambda { Loader.new [] }.should raise_error
|
28
|
+
lambda { Loader.new nil, nil }.should raise_error
|
29
|
+
lambda { Loader.new [], nil }.should raise_error
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'loads matching models from OpenERP' do
|
33
|
-
loader = Loader.new ['res.*']
|
34
|
-
|
35
|
-
loaded_model = mock 'loaded_model'
|
36
|
-
loaded_model.stub!('length_of_model_name').and_return(1)
|
37
|
-
ruby_adapter = mock 'ruby_adapter'
|
38
|
-
ruby_adapter.stub! 'to_ruby'
|
39
|
-
RubyAdapter::Base.should_receive(:new).with(loaded_model).and_return(ruby_adapter)
|
40
|
-
|
41
|
-
Oo::Ir::Model = mock 'model'
|
42
|
-
relation = mock 'relation'
|
43
|
-
relation.should_receive(:all).and_return([loaded_model])
|
44
|
-
Oo::Ir::Model.should_receive(:where).with(/res\.%/).and_return(relation)
|
45
|
-
|
46
|
-
loader.load!
|
47
|
-
end
|
48
32
|
end
|
49
33
|
end
|
50
34
|
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kangaroo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
- 1
|
10
|
-
- pre
|
11
9
|
- 2
|
12
|
-
version: 0.0.
|
10
|
+
version: 0.0.2
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Michael Eickenberg
|
@@ -18,7 +16,7 @@ autorequire:
|
|
18
16
|
bindir: bin
|
19
17
|
cert_chain: []
|
20
18
|
|
21
|
-
date: 2011-
|
19
|
+
date: 2011-04-15 00:00:00 +02:00
|
22
20
|
default_executable:
|
23
21
|
dependencies:
|
24
22
|
- !ruby/object:Gem::Dependency
|
@@ -70,7 +68,7 @@ dependencies:
|
|
70
68
|
type: :runtime
|
71
69
|
version_requirements: *id003
|
72
70
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
71
|
+
name: hirb
|
74
72
|
prerelease: false
|
75
73
|
requirement: &id004 !ruby/object:Gem::Requirement
|
76
74
|
none: false
|
@@ -81,10 +79,10 @@ dependencies:
|
|
81
79
|
segments:
|
82
80
|
- 0
|
83
81
|
version: "0"
|
84
|
-
type: :
|
82
|
+
type: :runtime
|
85
83
|
version_requirements: *id004
|
86
84
|
- !ruby/object:Gem::Dependency
|
87
|
-
name:
|
85
|
+
name: yard
|
88
86
|
prerelease: false
|
89
87
|
requirement: &id005 !ruby/object:Gem::Requirement
|
90
88
|
none: false
|
@@ -98,7 +96,7 @@ dependencies:
|
|
98
96
|
type: :development
|
99
97
|
version_requirements: *id005
|
100
98
|
- !ruby/object:Gem::Dependency
|
101
|
-
name:
|
99
|
+
name: rspec
|
102
100
|
prerelease: false
|
103
101
|
requirement: &id006 !ruby/object:Gem::Requirement
|
104
102
|
none: false
|
@@ -112,7 +110,7 @@ dependencies:
|
|
112
110
|
type: :development
|
113
111
|
version_requirements: *id006
|
114
112
|
- !ruby/object:Gem::Dependency
|
115
|
-
name:
|
113
|
+
name: ruby-debug
|
116
114
|
prerelease: false
|
117
115
|
requirement: &id007 !ruby/object:Gem::Requirement
|
118
116
|
none: false
|
@@ -125,10 +123,24 @@ dependencies:
|
|
125
123
|
version: "0"
|
126
124
|
type: :development
|
127
125
|
version_requirements: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: cucumber
|
128
|
+
prerelease: false
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
type: :development
|
139
|
+
version_requirements: *id008
|
128
140
|
description: ActiveRecord-ish OpenObject Wrapper
|
129
141
|
email: marian@cice-online.net
|
130
|
-
executables:
|
131
|
-
|
142
|
+
executables:
|
143
|
+
- kang
|
132
144
|
extensions: []
|
133
145
|
|
134
146
|
extra_rdoc_files: []
|
@@ -142,6 +154,7 @@ files:
|
|
142
154
|
- LICENSE
|
143
155
|
- README.md
|
144
156
|
- Rakefile
|
157
|
+
- bin/kang
|
145
158
|
- config/kangaroo.yml.sample
|
146
159
|
- docs/AdditionalServices.md
|
147
160
|
- docs/Architecture.md
|
@@ -156,6 +169,7 @@ files:
|
|
156
169
|
- kangaroo.gemspec
|
157
170
|
- lib/kangaroo.rb
|
158
171
|
- lib/kangaroo/exception.rb
|
172
|
+
- lib/kangaroo/hirb.rb
|
159
173
|
- lib/kangaroo/model/attributes.rb
|
160
174
|
- lib/kangaroo/model/base.rb
|
161
175
|
- lib/kangaroo/model/condition_normalizer.rb
|
@@ -222,14 +236,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
222
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
237
|
none: false
|
224
238
|
requirements:
|
225
|
-
- - "
|
239
|
+
- - ">="
|
226
240
|
- !ruby/object:Gem::Version
|
227
|
-
hash:
|
241
|
+
hash: 3
|
228
242
|
segments:
|
229
|
-
-
|
230
|
-
|
231
|
-
- 1
|
232
|
-
version: 1.3.1
|
243
|
+
- 0
|
244
|
+
version: "0"
|
233
245
|
requirements: []
|
234
246
|
|
235
247
|
rubyforge_project:
|