smooth_operator 1.10.14 → 1.10.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/console.rb +12 -1
- data/lib/smooth_operator/finder_methods.rb +2 -6
- data/lib/smooth_operator/operator.rb +12 -13
- data/lib/smooth_operator/operators/faraday.rb +1 -3
- data/lib/smooth_operator/operators/typhoeus.rb +2 -4
- data/lib/smooth_operator/persistence.rb +16 -30
- data/lib/smooth_operator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjZkODA4OWRkN2I5MTEwZjQ2ZThiZjU5NjViMTg0OWRkY2ZkOTIzMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDE1NmUwMWUxOWFlOGRlYmY1ZjM1ZWFlMTIxY2RiNzQ3NzU1ZDIxMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjE0NDA4NDNlNzFiN2EyNjUxZTY4NWNlZDg5YmM5NjgyMjhmMWNmNWYyMDdk
|
10
|
+
NDA0MDljOGI1YzczMTlhNTE0MzYxYjIxOWJjMmJiNTFhZDAzYzMyZGM1OGYx
|
11
|
+
NjZhYTU5Y2FlNjZkZmUzNGUxYjhlZGE2NTAzYWUwYjg4YzQwODQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWExOWNjNzZlYjhlZWRjN2UyZDFmODNlZTAyMGE0MWM5M2EyYTBjNmZjYzBj
|
14
|
+
Yzg3MDI5ZDU1MDJjMjhmNDg2NzQxYzQ3YWM0ZDgwZjdmYTQ3N2ExNTMyMTY3
|
15
|
+
ZDM3OTY3YWU3Yjg3ZGRjYjY1ZTI0Y2EwNGU4NjI4ZjVjYzlhODg=
|
data/console.rb
CHANGED
@@ -7,7 +7,18 @@ require 'spec/require_helper'
|
|
7
7
|
|
8
8
|
FactoryGirl.find_definitions
|
9
9
|
|
10
|
-
|
10
|
+
LocalhostServer.new(TestServer.new, 4567)
|
11
|
+
|
12
|
+
# user = nil
|
13
|
+
|
14
|
+
# hydra = Typhoeus::Hydra::hydra
|
15
|
+
|
16
|
+
# user = User::Base.new(id: 1)
|
17
|
+
# user.reload(nil, nil, { hydra: hydra })
|
18
|
+
|
19
|
+
# User::Base.find(1, nil, { hydra: hydra }) do |remote_call|
|
20
|
+
# user = remote_call.data
|
21
|
+
# end
|
11
22
|
|
12
23
|
#User::Base.post('', { user: { age: 1, posts: [{ body: 'post1' }, 2] } })
|
13
24
|
|
@@ -11,15 +11,11 @@ module SmoothOperator
|
|
11
11
|
def find(relative_path, data = {}, options = {})
|
12
12
|
relative_path = '' if relative_path == :all
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
get(relative_path, data, options).tap do |remote_call|
|
14
|
+
get(relative_path, data, options) do |remote_call|
|
17
15
|
remote_call.object = build_object(remote_call.parsed_response, options) if remote_call.ok?
|
18
16
|
|
19
|
-
|
17
|
+
block_given? ? yield(remote_call) : remote_call
|
20
18
|
end
|
21
|
-
|
22
|
-
returning_object
|
23
19
|
end
|
24
20
|
|
25
21
|
|
@@ -15,13 +15,18 @@ module SmoothOperator
|
|
15
15
|
end
|
16
16
|
|
17
17
|
attr_writer *OPTIONS
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
|
19
|
+
%w[get post put patch delete].each do |method|
|
20
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
21
|
+
def #{method}(relative_path = '', params = {}, options = {})
|
22
|
+
make_the_call(:#{method}, relative_path, params, options) do |remote_call|
|
23
|
+
block_given? ? yield(remote_call) : remote_call
|
24
|
+
end
|
25
|
+
end
|
26
|
+
RUBY
|
23
27
|
end
|
24
28
|
|
29
|
+
|
25
30
|
def headers
|
26
31
|
Helpers.get_instance_variable(self, :headers, {})
|
27
32
|
end
|
@@ -38,15 +43,9 @@ module SmoothOperator
|
|
38
43
|
operator_call = Operators::Faraday
|
39
44
|
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
operator_call.make_the_call(*operator_args) do |_remote_call|
|
44
|
-
remote_call = _remote_call
|
45
|
-
|
46
|
-
yield(remote_call) if block_given?
|
46
|
+
operator_call.make_the_call(*operator_args) do |remote_call|
|
47
|
+
block_given? ? yield(remote_call) : remote_call
|
47
48
|
end
|
48
|
-
|
49
|
-
remote_call
|
50
49
|
end
|
51
50
|
|
52
51
|
def query_string(params)
|
@@ -14,7 +14,7 @@ module SmoothOperator
|
|
14
14
|
|
15
15
|
hydra = options[:hydra] || ::Typhoeus::Hydra::hydra
|
16
16
|
|
17
|
-
_remote_call =
|
17
|
+
_remote_call = nil
|
18
18
|
|
19
19
|
hydra.queue(request)
|
20
20
|
|
@@ -24,9 +24,7 @@ module SmoothOperator
|
|
24
24
|
yield(_remote_call) if block_given?
|
25
25
|
end
|
26
26
|
|
27
|
-
hydra.run
|
28
|
-
|
29
|
-
# request.run
|
27
|
+
hydra.run if Helpers.blank?(options[:hydra])
|
30
28
|
|
31
29
|
_remote_call
|
32
30
|
end
|
@@ -26,13 +26,9 @@ module SmoothOperator
|
|
26
26
|
def reload(relative_path = nil, data = {}, options = {})
|
27
27
|
raise 'UnknownPath' if Helpers.blank?(relative_path) && (!respond_to?(:id) || Helpers.blank?(id))
|
28
28
|
|
29
|
-
success = {}
|
30
|
-
|
31
29
|
make_the_call(*persistent_method_args(:reload, relative_path, data, options)) do |remote_call|
|
32
|
-
|
30
|
+
block_given? ? yield(remote_call) : remote_call.status
|
33
31
|
end
|
34
|
-
|
35
|
-
success
|
36
32
|
end
|
37
33
|
|
38
34
|
def new_record?
|
@@ -52,56 +48,46 @@ module SmoothOperator
|
|
52
48
|
end
|
53
49
|
|
54
50
|
def save(relative_path = nil, data = {}, options = {})
|
55
|
-
|
51
|
+
data = data_with_object_attributes(data, options)
|
52
|
+
|
53
|
+
if new_record?
|
54
|
+
create(relative_path, data, options) { |remote_call| block_given? ? yield(remote_call) : remote_call.status }
|
55
|
+
else
|
56
|
+
update(relative_path, data, options) { |remote_call| block_given? ? yield(remote_call) : remote_call.status }
|
57
|
+
end
|
56
58
|
end
|
57
59
|
|
58
60
|
def save!(relative_path = nil, data = {}, options = {})
|
59
|
-
|
61
|
+
save(relative_path, data, options) do |remote_call|
|
62
|
+
block_given? ? yield(remote_call) : remote_call.status
|
63
|
+
end || raise('RecordNotSaved')
|
60
64
|
end
|
61
65
|
|
62
66
|
def destroy(relative_path = nil, data = {}, options = {})
|
63
67
|
return false unless persisted?
|
64
68
|
|
65
|
-
success = {}
|
66
|
-
|
67
69
|
make_the_call(*persistent_method_args(:destroy, relative_path, data, options)) do |remote_call|
|
68
|
-
|
70
|
+
@destroyed = true if remote_call.status
|
69
71
|
|
70
|
-
|
72
|
+
block_given? ? yield(remote_call) : remote_call.status
|
71
73
|
end
|
72
|
-
|
73
|
-
success
|
74
74
|
end
|
75
75
|
|
76
76
|
|
77
77
|
protected ######################### PROTECTED ##################
|
78
78
|
|
79
|
-
def create_or_update(relative_path, data, options)
|
80
|
-
data = data_with_object_attributes(data, options)
|
81
|
-
|
82
|
-
new_record? ? create(relative_path, data, options) : update(relative_path, data, options)
|
83
|
-
end
|
84
|
-
|
85
79
|
def create(relative_path, data, options)
|
86
|
-
success = {}
|
87
|
-
|
88
80
|
make_the_call(http_verb_for(:create, options), relative_path, data, options) do |remote_call|
|
89
|
-
|
81
|
+
@new_record = false if remote_call.status
|
90
82
|
|
91
|
-
|
83
|
+
block_given? ? yield(remote_call) : remote_call
|
92
84
|
end
|
93
|
-
|
94
|
-
success
|
95
85
|
end
|
96
86
|
|
97
87
|
def update(relative_path, data, options)
|
98
|
-
success = {}
|
99
|
-
|
100
88
|
make_the_call(*persistent_method_args(:update, relative_path, data, options)) do |remote_call|
|
101
|
-
|
89
|
+
block_given? ? yield(remote_call) : remote_call
|
102
90
|
end
|
103
|
-
|
104
|
-
success
|
105
91
|
end
|
106
92
|
|
107
93
|
def make_the_call(http_verb, relative_path, data, options)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smooth_operator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|