ooor 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app/models/serialization.rb +31 -0
- metadata +2 -1
@@ -0,0 +1,31 @@
|
|
1
|
+
module Ooor
|
2
|
+
module Serialization
|
3
|
+
|
4
|
+
def serializable_hash(options = nil)
|
5
|
+
options ||= {}
|
6
|
+
hash = super(options)
|
7
|
+
|
8
|
+
attribute_names = attributes.keys.sort
|
9
|
+
included_associations = {}
|
10
|
+
self.class.many2one_associations.keys.each do |k|
|
11
|
+
if loaded_associations[k].is_a? OpenObjectResource
|
12
|
+
included_associations[k] = loaded_associations[k].as_json[loaded_associations[k].class.openerp_model.gsub('.', '_')]
|
13
|
+
elsif associations[k].is_a? Array
|
14
|
+
included_associations[k] = {"id" => associations[k][0], "name" => associations[k][1]}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
(self.class.one2many_associations.keys + self.class.many2many_associations.keys).each do |k|
|
19
|
+
if loaded_associations[k].is_a? Array
|
20
|
+
included_associations[k] = loaded_associations[k].map {|item| item.as_json[item.class.openerp_model.gsub('.', '_')]}
|
21
|
+
else
|
22
|
+
included_associations[k] = associations[k].map {|id| {"id" => id}}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
method_names = Array.wrap(options[:methods]).map { |n| n if respond_to?(n.to_s) }.compact
|
27
|
+
Hash[(attribute_names + method_names).map { |n| [n, send(n)] }].merge(included_associations)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ooor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.6.
|
5
|
+
version: 1.6.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Raphael Valyi - www.akretion.com
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- ooor.yml
|
39
39
|
- lib/app/models/open_object_resource.rb
|
40
40
|
- lib/app/models/type_casting.rb
|
41
|
+
- lib/app/models/serialization.rb
|
41
42
|
- lib/app/models/uml.rb
|
42
43
|
- lib/app/models/base64.rb
|
43
44
|
- lib/app/models/ooor_client.rb
|