kangaroo 0.0.3 → 0.1.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +6 -1
  2. data/Gemfile +11 -0
  3. data/README.md +23 -132
  4. data/Rakefile +0 -8
  5. data/bin/kang +5 -64
  6. data/bin/kangdoc +21 -0
  7. data/bin/kangviz +21 -0
  8. data/config/kangaroo.yml.sample +12 -2
  9. data/docs/Architecture.md +1 -0
  10. data/docs/Classes.md +67 -0
  11. data/docs/Installation.md +2 -1
  12. data/docs/Usage.md +1 -0
  13. data/kangaroo.gemspec +8 -8
  14. data/lib/kangaroo.rb +3 -2
  15. data/lib/kangaroo/commands/base.rb +123 -0
  16. data/lib/kangaroo/commands/cli.rb +65 -0
  17. data/lib/kangaroo/commands/doc.rb +44 -0
  18. data/lib/kangaroo/commands/endpoint.rb +33 -0
  19. data/lib/kangaroo/commands/viz.rb +58 -0
  20. data/lib/kangaroo/doc.rb +2 -0
  21. data/lib/kangaroo/exception.rb +3 -0
  22. data/lib/kangaroo/hirb.rb +2 -1
  23. data/lib/kangaroo/model/associations.rb +33 -0
  24. data/lib/kangaroo/model/associations/many2one.rb +43 -0
  25. data/lib/kangaroo/model/associations/one2many.rb +41 -0
  26. data/lib/kangaroo/model/attributes.rb +88 -93
  27. data/lib/kangaroo/model/base.rb +44 -15
  28. data/lib/kangaroo/model/condition_normalizer.rb +7 -7
  29. data/lib/kangaroo/model/data_import.rb +28 -0
  30. data/lib/kangaroo/model/default_attributes.rb +20 -14
  31. data/lib/kangaroo/model/dynamic_finder.rb +42 -0
  32. data/lib/kangaroo/model/field.rb +52 -1
  33. data/lib/kangaroo/model/field/readonly.rb +39 -0
  34. data/lib/kangaroo/model/finder.rb +6 -2
  35. data/lib/kangaroo/model/inspector.rb +1 -4
  36. data/lib/kangaroo/model/mass_import.rb +42 -0
  37. data/lib/kangaroo/model/open_object_orm.rb +51 -5
  38. data/lib/kangaroo/model/persistence.rb +43 -19
  39. data/lib/kangaroo/model/readonly_attributes.rb +43 -0
  40. data/lib/kangaroo/model/relation.rb +40 -9
  41. data/lib/kangaroo/model/remote_execute.rb +1 -1
  42. data/lib/kangaroo/model/required_attributes.rb +26 -0
  43. data/lib/kangaroo/railtie.rb +13 -3
  44. data/lib/kangaroo/ruby_adapter/base.rb +2 -1
  45. data/lib/kangaroo/ruby_adapter/class_definition.rb +18 -3
  46. data/lib/kangaroo/ruby_adapter/fields.rb +27 -2
  47. data/lib/kangaroo/ruby_adapter/many2one.rb +38 -0
  48. data/lib/kangaroo/ruby_adapter/one2many.rb +31 -0
  49. data/lib/kangaroo/util/client.rb +29 -4
  50. data/lib/kangaroo/util/configuration.rb +15 -10
  51. data/lib/kangaroo/util/database.rb +8 -8
  52. data/lib/kangaroo/util/loader.rb +18 -22
  53. data/lib/kangaroo/util/loader/information_repository.rb +56 -0
  54. data/lib/kangaroo/util/loader/namespace.rb +1 -1
  55. data/lib/kangaroo/util/loader/reflection.rb +61 -0
  56. data/lib/kangaroo/util/loader/root_namespace.rb +12 -21
  57. data/lib/kangaroo/util/proxy.rb +9 -0
  58. data/lib/kangaroo/util/proxy/common.rb +28 -4
  59. data/lib/kangaroo/util/proxy/db.rb +14 -0
  60. data/lib/kangaroo/util/proxy/object.rb +40 -1
  61. data/lib/kangaroo/util/proxy/superadmin.rb +13 -0
  62. data/lib/kangaroo/version.rb +1 -1
  63. data/lib/kangaroo/viz.rb +1 -0
  64. data/lib/kangaroo/viz/base.rb +92 -0
  65. data/spec/commands/base_spec.rb +42 -0
  66. data/spec/functional/associations/many2one_spec.rb +72 -0
  67. data/spec/functional/associations/one2many_spec.rb +65 -0
  68. data/spec/functional/common_service_spec.rb +25 -0
  69. data/spec/functional/data_import_spec.rb +48 -0
  70. data/spec/functional/dynamic_finder_spec.rb +35 -0
  71. data/spec/functional/exception_handling_spec.rb +18 -0
  72. data/spec/functional/identity_spec.rb +48 -0
  73. data/spec/functional/import_export_spec.rb +39 -0
  74. data/spec/functional/lazy_loading_spec.rb +18 -11
  75. data/spec/functional/ordering_spec.rb +33 -0
  76. data/spec/functional/readonly_attributes_spec.rb +37 -0
  77. data/spec/functional/required_attributes_spec.rb +37 -0
  78. data/spec/functional/root_namespace_spec.rb +19 -0
  79. data/spec/functional/select_relation_spec.rb +26 -0
  80. data/spec/model/attributes_spec.rb +1 -0
  81. data/spec/model/base_spec.rb +1 -0
  82. data/spec/model/default_attributes_spec.rb +3 -1
  83. data/spec/model/finder_spec.rb +2 -1
  84. data/spec/model/inspector_spec.rb +1 -0
  85. data/spec/model/open_object_orm_spec.rb +5 -2
  86. data/spec/model/persistence_spec.rb +1 -0
  87. data/spec/model/relation_spec.rb +2 -2
  88. data/spec/ruby_adapter/class_definition_spec.rb +1 -0
  89. data/spec/server_helper.rb +0 -1
  90. data/spec/spec_helper.rb +4 -1
  91. data/spec/util/loader_spec.rb +6 -6
  92. metadata +152 -159
  93. data/Gemfile.lock +0 -69
  94. data/features/configuration.feature +0 -10
  95. data/features/env.rb +0 -8
  96. data/features/step_definitions/basic_steps.rb +0 -18
  97. data/features/step_definitions/configuration_steps.rb +0 -21
  98. data/features/support/test.yml +0 -11
  99. data/features/utility_services.feature +0 -33
data/.gitignore CHANGED
@@ -1,2 +1,7 @@
1
1
  .yardoc
2
- *.gem
2
+ *.gem
3
+ .rvmrc
4
+ .bundle
5
+ Gemfile.lock
6
+ doc/
7
+ coverage/
data/Gemfile CHANGED
@@ -1,2 +1,13 @@
1
1
  source :rubygems
2
2
  gemspec
3
+
4
+ group :test do
5
+ gem 'autotest-growl'
6
+ gem 'autotest-fsevent'
7
+ gem 'simplecov', '>= 0.4.0', :require => false
8
+ end
9
+
10
+ group :development do
11
+ # gem 'ruby-debug19', :require => 'ruby-debug'
12
+ gem 'ruby-debug'
13
+ end
data/README.md CHANGED
@@ -5,153 +5,44 @@ Overview
5
5
  --------
6
6
 
7
7
  Kangaroo is an OpenObject client/wrapper for Ruby, based on ActiveModel. It provides CRUD access to OpenERP objects via XMLRPC.
8
- It's fast and provides default data for new objects.
8
+ It's fast and provides a lot of neat features.
9
9
 
10
- Installation
11
- ------------
10
+ Documentation and Feedback
11
+ --------------------------
12
12
 
13
- ### Rails 3
13
+ Please give us some feedback especially on the documentation, which surely requires a lot of work.
14
14
 
15
- If you're on Rails 3, just add Kangaroo to your Gemfile:
16
-
17
- gem 'kangaroo'
18
-
19
- And create a **kangaroo.yml** configuration file in **[RAILS\_ROOT]/config**, containing these options:
20
-
21
- host: 127.0.0.1
22
- port: 8069
23
-
24
- database:
25
- name: my_openerp
26
- user: admin
27
- password: admin
28
-
29
- models:
30
- - account.*
31
- - product.*
32
- - res.company
33
-
34
- Adjust your connection and database settings and specify the models you need.
35
-
36
- ### Ruby
37
-
38
- Use Kangaroo in any Ruby project!
15
+ Quick Start
16
+ -----------
39
17
 
40
18
  gem install kangaroo
41
19
 
42
- In your code
20
+ kang -u admin -p admin -d some_database
21
+ > Oo::Res::Country.limit(5).order(:name).all
22
+ # +------+-----------------------------+
23
+ # | code | name |
24
+ # +------+-----------------------------+
25
+ # | DZ | Algeria |
26
+ # | AS | American Samoa |
27
+ # | AD | Andorra, Principality of |
28
+ # | AO | Angola |
29
+ # | AI | Anguilla |
30
+ # +------+-----------------------------+
43
31
 
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
-
59
- Usage
60
- -----
61
-
62
- OpenObject models are mapped to ruby classes:
63
-
64
- Oo::Res::Country
65
- # represents 'res.country'
66
-
67
- Oo::Product::Product
68
- # represents 'product.product'
69
-
70
- Oo::Sale::Order::Line
71
- # represents 'sale.order.line
72
32
 
73
- You can use this models like ActiveRecord models:
74
-
75
- country = Oo::Res::Country.find 1
76
- country = Oo::Res::Country.where(:code => 'DE').first
77
-
78
- country.name = "Schland"
79
- country.save
80
-
81
- country.reload
82
-
83
- countries = Oo::Res::Country.limit(100).all
84
- countries = Oo::Res::Country.limit(100).order('code').all
85
-
86
- Oo::Res::Country.create :code => 'DE', :name => 'Germany'
87
-
88
- CLI
89
- ---
90
-
91
- Kangaroo comes with a console based on IRB, try it:
92
-
93
- $kang -c spec/test_env/test.yml
94
- I, [2011-04-15T23:19:41.990623 #6834] INFO -- : Loading Kangaroo configuration "spec/test_env/test.yml"
95
- I, [2011-04-15T23:19:41.991091 #6834] INFO -- : Configured OpenERP database "kangaroo_test_database" at "127.0.0.1"
96
- I, [2011-04-15T23:19:41.996197 #6834] INFO -- : Authenticated user "admin" for OpenERP database "kangaroo_test_database"
97
- ruby-1.8.7-p302 :001 > Oo::Res::Country
98
- => <Oo::Res::Country id, name, code>
99
- ruby-1.8.7-p302 :002 > Oo::Res::Country.first
100
- +---------+------+
101
- | name | code |
102
- +---------+------+
103
- | Algeria | DZ |
104
- +---------+------+
105
- 1 row in set
106
-
107
- If you omit the -c command line option, you can initialize your Kangaroo connection from the
108
- console:
109
-
110
- $kang
111
- 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"
112
- 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"}
113
- I, [2011-04-15T23:23:59.789706 #7017] INFO -- : Configured OpenERP database "kangaroo_test_database" at "127.0.0.1"
114
- I, [2011-04-15T23:23:59.794861 #7017] INFO -- : Authenticated user "admin" for OpenERP database "kangaroo_test_database"
115
- => true
116
- ruby-1.8.7-p302 :002 > Oo::Res::Country.limit(5).all
117
- +------+-----------------------------+
118
- | code | name |
119
- +------+-----------------------------+
120
- | DZ | Algeria |
121
- | AS | American Samoa |
122
- | AD | Andorra, Principality ofä ß |
123
- | AO | Angola |
124
- | AI | Anguilla |
125
- +------+-----------------------------+
126
- 5 rows in set
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>
143
-
144
- Please refer to {file:docs/Usage.md Usage} to learn about limitations/features not yet
145
- implemented.
33
+ [a lot more here](http://kangaroogem.org)
146
34
 
147
35
  Development
148
36
  -----------
149
37
 
38
+ Homepage:
39
+ [http://kangaroogem.org](http://kangaroogem.org)
40
+
150
41
  SCM:
151
- [https://github.com/cice/kangARoo](https://github.com/cice/kangARoo)
42
+ [https://github.com/kayoom/kangaroo](https://github.com/kayoom/kangaroo)
152
43
 
153
44
  Issues:
154
- [https://kayoom.lighthouseapp.com/projects/73738-kangaroo/tickets](https://kayoom.lighthouseapp.com/projects/73738-kangaroo/tickets)
45
+ [http://github.com/kayoom/kangaroo/issues](http://github.com/kayoom/kangaroo/issues)
155
46
 
156
47
  Rubygems:
157
48
  [https://rubygems.org/gems/kangaroo](https://rubygems.org/gems/kangaroo)
data/Rakefile CHANGED
@@ -22,14 +22,6 @@ rescue LoadError
22
22
  puts "RSpec is not available. In order to run specs, you must: gem install rspec"
23
23
  end
24
24
 
25
- begin
26
- require 'cucumber/rake/task'
27
- desc "Run Cucumber features."
28
- Cucumber::Rake::Task.new(:features)
29
- rescue LoadError
30
- puts "Cucumber is not available. In order to run features, you must: gem install cucumber"
31
- end
32
-
33
25
 
34
26
 
35
27
  # If you want to make this the default task
data/bin/kang CHANGED
@@ -1,80 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  begin
4
+ # Try to just load kangaroo
4
5
  require 'kangaroo'
5
6
  rescue LoadError
6
7
  begin
8
+ # Try kangaroo as installed gem
7
9
  require 'rubygems'
8
10
  require 'kangaroo'
9
11
  rescue LoadError
12
+ # Used for development, if you exec 'bin/kang' from kangaroo source dir and gem not installed
10
13
  require 'bundler/setup'
11
14
  require 'kangaroo'
12
15
  end
13
16
  end
14
17
 
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
-
18
+ require 'kangaroo/commands/cli'
79
19
 
20
+ Kangaroo::Commands::CLI.new(*ARGV).run
80
21
 
data/bin/kangdoc ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ # Try to just load kangaroo
5
+ require 'kangaroo'
6
+ rescue LoadError
7
+ begin
8
+ # Try kangaroo as installed gem
9
+ require 'rubygems'
10
+ require 'kangaroo'
11
+ rescue LoadError
12
+ # Used for development, if you exec 'bin/kang' from kangaroo source dir and gem not installed
13
+ require 'bundler/setup'
14
+ require 'kangaroo'
15
+ end
16
+ end
17
+
18
+ require 'kangaroo/commands/doc'
19
+
20
+ Kangaroo::Commands::Doc.new(*ARGV).run
21
+
data/bin/kangviz ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ # Try to just load kangaroo
5
+ require 'kangaroo'
6
+ rescue LoadError
7
+ begin
8
+ # Try kangaroo as installed gem
9
+ require 'rubygems'
10
+ require 'kangaroo'
11
+ rescue LoadError
12
+ # Used for development, if you exec 'bin/kang' from kangaroo source dir and gem not installed
13
+ require 'bundler/setup'
14
+ require 'kangaroo'
15
+ end
16
+ end
17
+
18
+ require 'kangaroo/commands/viz'
19
+
20
+ Kangaroo::Commands::Viz.new(*ARGV).run
21
+
@@ -1,12 +1,22 @@
1
+ # Hostname or ip address and XMLRPC port of your OpenERP Server
1
2
  host: 127.0.0.1
2
3
  port: 8069
3
4
 
5
+ # Configure the database you want to use
4
6
  database:
5
- name: my_openerp
7
+ # Database name and credentials
8
+ name: kangaroo_test_database
6
9
  user: admin
7
10
  password: admin
8
11
 
12
+ # Namespace (top-level Module) for your OpenObject classes, e.g.
13
+ # OpenObjects 'product.product' will be accessible via Ruby class Abc::Product::Product
14
+ # __must__ begin with a capital letter!
15
+ namespace: 'Abc'
16
+
17
+ # Specify models to load on startup, e.g. all models in the 'product' namespace, and the single 'res.company' model
18
+ # Keep in mind, that Kangaroo will lazy load any model not specified here on first access. You can even leave this
19
+ # blank to load all models as late as they're needed.
9
20
  models:
10
- - account.*
11
21
  - product.*
12
22
  - res.company
data/docs/Architecture.md CHANGED
@@ -7,6 +7,7 @@ Architecture
7
7
  {file:docs/Usage.md Usage}
8
8
  {file:docs/Architecture.md Architecture}
9
9
  {file:docs/AdditionalServices.md Additional Services}
10
+ {file:docs/Classes.md Classes}
10
11
 
11
12
 
12
13
  Components
data/docs/Classes.md ADDED
@@ -0,0 +1,67 @@
1
+ Classes
2
+ =======
3
+
4
+ #### Index
5
+ {file:README.md Readme}
6
+ {file:docs/Installation.md Installation}
7
+ {file:docs/Usage.md Usage}
8
+ {file:docs/Architecture.md Architecture}
9
+ {file:docs/AdditionalServices.md Additional Services}
10
+ {file:docs/Classes.md Classes}
11
+
12
+ {Kangaroo}
13
+ --------
14
+
15
+ ### Railtie
16
+ * {Kangaroo::Railtie}
17
+
18
+ ### Model
19
+ * {Kangaroo::Model}
20
+ * * {Kangaroo::Model::Attributes}
21
+ * * {Kangaroo::Model::Base}
22
+ * * {Kangaroo::Model::ConditionNormalizer}
23
+ * * {Kangaroo::Model::DefaultAttributes}
24
+ * * {Kangaroo::Model::Field}
25
+ * * {Kangaroo::Model::Finder}
26
+ * * {Kangaroo::Model::Inspector}
27
+ * * {Kangaroo::Model::OpenObjectOrm}
28
+ * * {Kangaroo::Model::Persistence}
29
+ * * {Kangaroo::Model::ReadonlyAttributes}
30
+ * * {Kangaroo::Model::Relation}
31
+ * * {Kangaroo::Model::RemoteExecute}
32
+
33
+ ### RubyAdapter
34
+ * {Kangaroo::RubyAdapter}
35
+ * * {Kangaroo::RubyAdapter::Base}
36
+ * * {Kangaroo::RubyAdapter::ClassDefinition}
37
+ * * {Kangaroo::RubyAdapter::Fields}
38
+
39
+ ### Util
40
+ * {Kangaroo::Util}
41
+ * * {Kangaroo::Util::Client}
42
+ * * {Kangaroo::Util::Configuration}
43
+ * * {Kangaroo::Util::Database}
44
+ * * {Kangaroo::Util::Loader}
45
+ * * * {Kangaroo::Util::Loader::Model}
46
+ * * * {Kangaroo::Util::Loader::Namespace}
47
+ * * * {Kangaroo::Util::Loader::RootNamespace}
48
+ * * {Kangaroo::Util::Proxy}
49
+ * * * {Kangaroo::Util::Proxy::Common}
50
+ * * * {Kangaroo::Util::Proxy::Db}
51
+ * * * {Kangaroo::Util::Proxy::Object}
52
+ * * * {Kangaroo::Util::Proxy::Report}
53
+ * * * {Kangaroo::Util::Proxy::Superadmin}
54
+ * * * {Kangaroo::Util::Proxy::Wizard}
55
+ * * * {Kangaroo::Util::Proxy::Workflow}
56
+
57
+ ### Hirb
58
+ * {Hirb::Views::Kangaroo}
59
+
60
+ ### Exceptions
61
+ * {Kangaroo::Exception}
62
+ * * {Kangaroo::RecordNotFound}
63
+ * * {Kangaroo::ReadonlyRecord}
64
+ * * {Kangaroo::RecordSavingFailed}
65
+ * * {Kangaroo::InstantiatedRecordNeedsIDError}
66
+ * * {Kangaroo::ChildDefinedBeforeParentError}
67
+ * * {Kangaroo::NoMethodError}