kangaroo 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +6 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +66 -0
  6. data/LICENSE +22 -0
  7. data/README.md +65 -0
  8. data/Rakefile +36 -0
  9. data/config/kangaroo.yml.sample +12 -0
  10. data/docs/AdditionalServices.md +3 -0
  11. data/docs/Architecture.md +50 -0
  12. data/docs/Installation.md +73 -0
  13. data/docs/Usage.md +161 -0
  14. data/features/connection.feature +5 -0
  15. data/features/env.rb +8 -0
  16. data/features/step_definitions/basic_steps.rb +24 -0
  17. data/features/step_definitions/connection_steps.rb +13 -0
  18. data/features/support/test.yml +11 -0
  19. data/features/utility_services.feature +39 -0
  20. data/kangaroo.gemspec +29 -0
  21. data/lib/kangaroo.rb +6 -0
  22. data/lib/kangaroo/exception.rb +7 -0
  23. data/lib/kangaroo/model/attributes.rb +124 -0
  24. data/lib/kangaroo/model/base.rb +70 -0
  25. data/lib/kangaroo/model/condition_normalizer.rb +63 -0
  26. data/lib/kangaroo/model/default_attributes.rb +22 -0
  27. data/lib/kangaroo/model/field.rb +20 -0
  28. data/lib/kangaroo/model/finder.rb +92 -0
  29. data/lib/kangaroo/model/inspector.rb +55 -0
  30. data/lib/kangaroo/model/open_object_orm.rb +117 -0
  31. data/lib/kangaroo/model/persistence.rb +180 -0
  32. data/lib/kangaroo/model/relation.rb +212 -0
  33. data/lib/kangaroo/model/remote_execute.rb +29 -0
  34. data/lib/kangaroo/railtie.rb +13 -0
  35. data/lib/kangaroo/ruby_adapter/base.rb +28 -0
  36. data/lib/kangaroo/ruby_adapter/class_definition.rb +46 -0
  37. data/lib/kangaroo/ruby_adapter/fields.rb +18 -0
  38. data/lib/kangaroo/util/client.rb +59 -0
  39. data/lib/kangaroo/util/configuration.rb +82 -0
  40. data/lib/kangaroo/util/database.rb +92 -0
  41. data/lib/kangaroo/util/loader.rb +98 -0
  42. data/lib/kangaroo/util/loader/model.rb +21 -0
  43. data/lib/kangaroo/util/loader/namespace.rb +15 -0
  44. data/lib/kangaroo/util/proxy.rb +35 -0
  45. data/lib/kangaroo/util/proxy/common.rb +111 -0
  46. data/lib/kangaroo/util/proxy/db.rb +34 -0
  47. data/lib/kangaroo/util/proxy/object.rb +153 -0
  48. data/lib/kangaroo/util/proxy/report.rb +24 -0
  49. data/lib/kangaroo/util/proxy/superadmin.rb +71 -0
  50. data/lib/kangaroo/util/proxy/wizard.rb +25 -0
  51. data/lib/kangaroo/util/proxy/workflow.rb +14 -0
  52. data/lib/kangaroo/version.rb +3 -0
  53. data/spec/model/attributes_spec.rb +70 -0
  54. data/spec/model/base_spec.rb +19 -0
  55. data/spec/model/default_attributes_spec.rb +37 -0
  56. data/spec/model/finder_spec.rb +104 -0
  57. data/spec/model/inspector_spec.rb +56 -0
  58. data/spec/model/open_object_orm_spec.rb +134 -0
  59. data/spec/model/persistence_spec.rb +53 -0
  60. data/spec/model/relation_spec.rb +122 -0
  61. data/spec/ruby_adapter/class_definition_spec.rb +51 -0
  62. data/spec/server_helper.rb +167 -0
  63. data/spec/spec_helper.rb +14 -0
  64. data/spec/test_env/test.yml +11 -0
  65. data/spec/util/configuration_spec.rb +36 -0
  66. data/spec/util/loader_spec.rb +50 -0
  67. data/spec/util/proxy_spec.rb +61 -0
  68. metadata +260 -0
@@ -0,0 +1,21 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Loader
4
+ module Model
5
+ def self.included klass
6
+ klass.class_attribute :column_names
7
+ klass.column_names = %w(state osv_memory name model info field_id access_ids)
8
+ klass.define_multiple_accessors *klass.column_names
9
+ end
10
+
11
+ def length_of_model_name
12
+ model.length
13
+ end
14
+
15
+ def model_class_name
16
+ self.class.namespace.oo_to_ruby model
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Loader
4
+ module Namespace
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
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require 'rapuncel'
2
+
3
+ module Kangaroo
4
+ module Util
5
+ class Proxy < Rapuncel::Proxy
6
+ autoload :Common, 'kangaroo/util/proxy/common'
7
+ autoload :Db, 'kangaroo/util/proxy/db'
8
+ autoload :Superadmin, 'kangaroo/util/proxy/superadmin'
9
+ autoload :Object, 'kangaroo/util/proxy/object'
10
+ autoload :Workflow, 'kangaroo/util/proxy/workflow'
11
+ autoload :Report, 'kangaroo/util/proxy/report'
12
+ autoload :Wizard, 'kangaroo/util/proxy/wizard'
13
+
14
+ def __initialize__ client, *curry_args
15
+ super client, nil
16
+ @curry_args = curry_args
17
+ end
18
+
19
+ def call! name, *args
20
+ super name, *__curry__(*args)
21
+ end
22
+
23
+ def self.new *args
24
+ allocate.__tap__ do |proxy|
25
+ proxy.__initialize__ *args
26
+ end
27
+ end
28
+
29
+ protected
30
+ def __curry__ *args
31
+ @curry_args + args
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,111 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Proxy::Common < Proxy
4
+ # Login to an OpenERP database
5
+ #
6
+ # @param [String] db_name The database to log in
7
+ # @param [String] user Username
8
+ # @param [String] password Password
9
+ def login db_name, user, password
10
+ call! :login, db_name, user, password
11
+ end
12
+
13
+ # Get information about the OpenERP Server
14
+ #
15
+ # @param [boolean] extended Display extended information
16
+ # @return About information
17
+ def about extended = false
18
+ call! :about, extended
19
+ end
20
+
21
+ # Get OpenERP Servers timezone configuration
22
+ #
23
+ # @param database
24
+ # @param login
25
+ # @param password
26
+ # @return Timezone information
27
+ def timezone_get database, login, password
28
+ call! :timezone_get, database, login, password
29
+ end
30
+
31
+ # Get server environment
32
+ #
33
+ # @return Details about server environment
34
+ def get_server_environment
35
+ call! :get_server_environment
36
+ end
37
+
38
+ # Get login message
39
+ #
40
+ # @return login message
41
+ def login_message
42
+ call! :login_message
43
+ end
44
+
45
+ # Set log level
46
+ #
47
+ # @param super_password Superadmin password
48
+ # @param loglevel Loglevel to set
49
+ # @return true
50
+ def set_loglevel super_password, loglevel
51
+ call! :set_loglevel, loglevel.upcase
52
+ end
53
+
54
+ # Get server stats
55
+ #
56
+ # @return Server stats
57
+ def get_stats
58
+ call! :get_stats
59
+ end
60
+
61
+ # List HTTP services
62
+ #
63
+ # @return List of HTTP services
64
+ def list_http_services
65
+ call! :list_http_services
66
+ end
67
+
68
+ # Check connectivity
69
+ #
70
+ # @return [boolean] true/false
71
+ def check_connectivity
72
+ call! :check_connectivity
73
+ end
74
+
75
+ # Get servers OS time
76
+ #
77
+ # @param [String] super_password Superadmin password
78
+ # @return servers OS time
79
+ def get_os_time super_password
80
+ call! :get_os_time, super_password
81
+ end
82
+
83
+ # Get SQL count, needs loglevel DEBUG_SQL
84
+ #
85
+ # @return Count of SQL queries
86
+ def get_sqlcount
87
+ call! :get_sqlcount
88
+ end
89
+
90
+ # Get list of available updates, needs valid Publisher's Warranty
91
+ #
92
+ # @param super_password Superadmin password
93
+ # @param contract_id Publisher's Warranty ID
94
+ # @param contract_password Publisher's Warranty Password
95
+ # @return list of available updates
96
+ def get_available_updates super_password, contract_id, contract_password
97
+ call! :get_available_updates, contract_id, contract_password
98
+ end
99
+
100
+ # Get migration scripts, needs valid Publisher's Warranty
101
+ #
102
+ # @param super_password Superadmin password
103
+ # @param contract_id Publisher's Warranty ID
104
+ # @param contract_password Publisher's Warranty Password
105
+ # @return migration scripts
106
+ def get_migration_scripts super_password, contract_id, contract_password
107
+ call! :get_migration_scripts, contract_id, contract_password
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,34 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Proxy::Db < Proxy
4
+ # Check if a database exists
5
+ #
6
+ # @param db_name Name of database to check
7
+ # @return [boolean] true if database exists
8
+ def db_exist db_name
9
+ call! :db_exist, db_name
10
+ end
11
+
12
+ # Get a list of available databases
13
+ #
14
+ # @return list of databases
15
+ def list
16
+ call! :list
17
+ end
18
+
19
+ # Get a list of available languages
20
+ #
21
+ # @return list of languages
22
+ def list_lang
23
+ call! :list_lang
24
+ end
25
+
26
+ # Get running server version
27
+ #
28
+ # @return server version
29
+ def server_version
30
+ call! :server_version
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,153 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Proxy::Object < Proxy
4
+ # Call function via execute on OpenERPs object service.
5
+ #
6
+ # @param name function name to call
7
+ # @return returned value
8
+ def call! name, *args
9
+ puts "#{name.to_s.upcase}: #{args.inspect}"
10
+ super :execute, name, *args
11
+ end
12
+
13
+ # Get for a model
14
+ #
15
+ # @param [Array] list of field names, nil for all
16
+ # @param [Hash] context
17
+ # @return [Hash] field names and properties
18
+ def fields_get fields = nil, context = {}
19
+ call! :fields_get, fields, context
20
+ end
21
+
22
+ # Get default values for a model
23
+ #
24
+ # @param [Array] fields list of field names
25
+ # @param [Hash] context
26
+ # @return [Hash]
27
+ def default_get fields = nil, context = nil
28
+ call! :default_get, fields, context
29
+ end
30
+
31
+ # Get names of records for to-many relationships
32
+ #
33
+ # @param [Array] ids
34
+ # @param [Hash] context
35
+ # @return [Array<Array>] List of arrays [id, name]
36
+ def name_get ids, context = nil
37
+ call! :name_get, ids, context
38
+ end
39
+
40
+ # Search for records by name
41
+ #
42
+ # @param [String] name
43
+ # @param [Array] args
44
+ # @param [String] operator
45
+ # @param [Hash] context
46
+ # @param [Number] limit
47
+ # @return list of object names
48
+ def name_search name = '', args = nil, operator = 'ilike', context = nil, limit = 100
49
+ call! :name_search, name, args, operator, context, limit
50
+ end
51
+
52
+ # Read metadata for records, including
53
+ # - create user
54
+ # - create date
55
+ # - write user
56
+ # - write date
57
+ # - xml id
58
+ #
59
+ # @param [Array] ids
60
+ # @param [Hash] context
61
+ # @param [boolean] details
62
+ # @return [Array] list of Hashes with metadata
63
+ def read_perm ids, context = nil, details = false
64
+ call! :read_perm, ids, context, details
65
+ end
66
+
67
+ # Copy a record
68
+ #
69
+ # @param id
70
+ # @param default values to override on copy (defaults to nil)
71
+ # @param [Hash] context
72
+ # @return attributes of copied record
73
+ def copy id, default = nil, context = nil
74
+ call! :copy, id, default, context
75
+ end
76
+
77
+ # Check if records with given ids exist
78
+ #
79
+ # @param ids
80
+ # @param context
81
+ # @return [boolean] true if all exist, else false
82
+ def exists ids, context = nil
83
+ call! :exists, ids, context
84
+ end
85
+
86
+ # Get xml ids for records
87
+ #
88
+ # @param ids
89
+ # @return [Hash] Hash with ids as keys and xml_ids as values
90
+ def get_xml_id ids
91
+ call! :get_xml_id, ids
92
+ end
93
+
94
+ # Create a new record
95
+ #
96
+ # @param [Hash] attributes attributes to set on new record
97
+ # @return id of new record
98
+ def create attributes, context = nil
99
+ call! :create, attributes, context
100
+ end
101
+
102
+ # Search for records
103
+ #
104
+ # @param model_name OpenERP model to search
105
+ # @param [Array] conditions search conditions
106
+ # @param offset number of records to skip, defaults to 0
107
+ # @param limit max number of records, defaults to nil
108
+ def search conditions, offset = 0, limit = nil, order = nil, context = nil, count = false
109
+ call! :search, conditions, offset, limit, order, context, count
110
+ end
111
+
112
+ # Read fields from records
113
+ #
114
+ # @param [Array] ids ids of record to read fields from
115
+ # @param [Array] fields fields to read
116
+ # @param [Hash] context
117
+ # @return [Array] Array of Hashes with field names and values
118
+ def read ids, fields = [], context = nil
119
+ call! :read, ids, fields
120
+ end
121
+
122
+ # Update records
123
+ #
124
+ # @param [Array] ids ids of record to update
125
+ # @param [Hash] values Hash of field names => values
126
+ # @return true
127
+ def write ids, values, context = nil
128
+ call! :write, ids, values, context
129
+ end
130
+
131
+ # Delete records
132
+ #
133
+ # @param [Array] ids ids to to remove
134
+ # @return true
135
+ def unlink ids, context = nil
136
+ call! :unlink, ids, context
137
+ end
138
+
139
+ # Read records grouped by a field
140
+ #
141
+ # @param [Array] domain search conditions
142
+ # @param [Array] fields field names to read
143
+ # @param [Array] groupby field names to group by
144
+ # @param offset number of records to skip (defaults to 0)
145
+ # @param limit max number of records to retrieve (defaults to nil)
146
+ # @param order order by clause
147
+ # @return [Array]
148
+ def read_group domain, fields, groupby, offset = 0, limit = nil, order = nil
149
+ call! :read_group, domain, fields, groupby, offset, limit, order
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,24 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Proxy::Report < Proxy
4
+ # Initiate report generation
5
+ #
6
+ # @param object
7
+ # @param ids
8
+ # @param datas
9
+ # @param context
10
+ # @return id to check status on/get report
11
+ def report object, ids, datas = {}, context = {}
12
+ call! :report, object, ids, data, context
13
+ end
14
+
15
+ # Check status on/get report by id
16
+ #
17
+ # @param id
18
+ # @return [Hash] report state, report result and format
19
+ def report_get id
20
+ call! report_get, id
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ module Kangaroo
2
+ module Util
3
+ class Proxy::Superadmin < Proxy
4
+ # Create a new database
5
+ #
6
+ # @param [String] db_name name for new database
7
+ # @param [boolean] demo preload database with demo data
8
+ # @param [String] lang default language for new database
9
+ # @param [String] password set administrator password for new database
10
+ # @return [Integer] thread id to check progress
11
+ def create db_name, demo, lang, password
12
+ call! :create, db_name, demo, lang, password
13
+ end
14
+
15
+ # Check progress on database creation. Pass the id you get
16
+ # from #create as only parameter
17
+ #
18
+ # @param id id from #create
19
+ # @return progress as float between 0.0 and 1.0
20
+ def get_progress id
21
+ call! :get_progress, id
22
+ end
23
+
24
+ # Drop a database by name
25
+ #
26
+ # @param db_name name of database to drop
27
+ def drop db_name
28
+ call! :drop, db_name
29
+ end
30
+
31
+ # Dump/Backup a database by name
32
+ #
33
+ # @param db_name name of database to backup
34
+ # @return database dump
35
+ def dump db_name
36
+ call! :dump, db_name
37
+ end
38
+
39
+ # Load/Restore a database
40
+ #
41
+ # @param db_name name of database to restore to (or create)
42
+ # @param data dump data to load into database
43
+ def restore db_name, data
44
+ call! :restore, db_name, data
45
+ end
46
+
47
+ # Rename a database
48
+ #
49
+ # @param old_name database to rename
50
+ # @param new_name new name for database
51
+ def rename old_name, new_name
52
+ call! :rename, old_name, new_name
53
+ end
54
+
55
+ # Change superadmin password
56
+ #
57
+ # @param new_password new superadmin password
58
+ # @return true
59
+ def change_admin_password new_password
60
+ call! :change_admin_password, new_password
61
+ end
62
+
63
+ # Migrate specified databases
64
+ #
65
+ # @param databases list of databases to migrate
66
+ def migrate_databases databases
67
+ call! :migrate_databases, databases
68
+ end
69
+ end
70
+ end
71
+ end