perry 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/perry/adapters/bertrpc_adapter.rb +59 -2
- data/lib/perry/persistence.rb +1 -1
- data/lib/perry/version.rb +2 -2
- metadata +5 -5
@@ -13,14 +13,71 @@ module Perry::Adapters
|
|
13
13
|
|
14
14
|
def read(options)
|
15
15
|
query = options[:relation].to_hash
|
16
|
+
query[:mode] = :read
|
16
17
|
log(query, "RPC #{config[:service]}") {
|
17
|
-
self.
|
18
|
-
|
18
|
+
self.call_server(query)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(options)
|
23
|
+
query = options.dup
|
24
|
+
object = query.delete(:object)
|
25
|
+
if object
|
26
|
+
query[:fields] = object.attributes
|
27
|
+
if object.new_record?
|
28
|
+
query[:mode] = :create
|
29
|
+
else
|
30
|
+
query[:mode] = :update
|
31
|
+
query[:where] = self.where_for_primary_key(object)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
query[:mode] = :update
|
35
|
+
end
|
36
|
+
log(query, "RPC #{config[:service]}") {
|
37
|
+
self.parse_response(self.call_server(query))
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(options)
|
42
|
+
query = options.dup
|
43
|
+
object = query.delete(:object)
|
44
|
+
if object
|
45
|
+
query[:where] = self.where_for_primary_key(object)
|
46
|
+
end
|
47
|
+
log(query, "RPC #{config[:service]}") {
|
48
|
+
self.parse_response(self.call_server(query))
|
19
49
|
}
|
20
50
|
end
|
21
51
|
|
22
52
|
protected
|
23
53
|
|
54
|
+
def call_server(options)
|
55
|
+
service_options = (options || {}).merge(config[:default_options])
|
56
|
+
request = self.service.call
|
57
|
+
namespace = request.send(self.namespace)
|
58
|
+
namespace.send(self.service_name, service_options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_response(raw)
|
62
|
+
response = Perry::Persistence::Response.new
|
63
|
+
response.raw = raw
|
64
|
+
|
65
|
+
if raw.key?('fields')
|
66
|
+
response.success = true
|
67
|
+
response.parsed = raw['fields']
|
68
|
+
elsif raw.key?('success')
|
69
|
+
response.success = raw['success']
|
70
|
+
end
|
71
|
+
|
72
|
+
response
|
73
|
+
end
|
74
|
+
|
75
|
+
def where_for_primary_key(object)
|
76
|
+
pk_attr = self.config[:primary_key] || object.primary_key
|
77
|
+
pk_value = object[pk_attr]
|
78
|
+
[{ pk_attr => pk_value }]
|
79
|
+
end
|
80
|
+
|
24
81
|
def namespace
|
25
82
|
self.config[:namespace]
|
26
83
|
end
|
data/lib/perry/persistence.rb
CHANGED
@@ -45,7 +45,7 @@ module Perry::Persistence
|
|
45
45
|
|
46
46
|
def destroy
|
47
47
|
raise Perry::PerryError.new("cannot destroy a frozen object") if frozen?
|
48
|
-
unless self.new_record? || self
|
48
|
+
unless self.new_record? || self[primary_key].nil?
|
49
49
|
write_adapter.call(:delete, :object => self).success
|
50
50
|
end
|
51
51
|
end
|
data/lib/perry/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Petticrew
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|