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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGUwNjgxZDAyZTJmMDg3ZTRhZWMwZjFhY2UxYjhjYTIyOTBlZWNlOQ==
4
+ NjZkODA4OWRkN2I5MTEwZjQ2ZThiZjU5NjViMTg0OWRkY2ZkOTIzMg==
5
5
  data.tar.gz: !binary |-
6
- YWRiNzFhZjlmYTI2MTRjYzM0MTU2NGMzZjJkNTgwZGI5NzdmOTJjZg==
6
+ ZDE1NmUwMWUxOWFlOGRlYmY1ZjM1ZWFlMTIxY2RiNzQ3NzU1ZDIxMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjI2ZTFjNjUyZTMwMWE0MWIyNDk2MTU1ZDEwZmU1OTBlNjAxMjRhZDhhNzZi
10
- ZDljMmI5OTQyZDIzNDQ4ZDFkNjFhYWVlNTE0Y2YzMDAyZDdjYzA0ZWE3MTc0
11
- MDY5YjM0NjcyOGIzNzNkMDdkYmY4MzA4MTEzNTE5MmYxNTUyMDQ=
9
+ NjE0NDA4NDNlNzFiN2EyNjUxZTY4NWNlZDg5YmM5NjgyMjhmMWNmNWYyMDdk
10
+ NDA0MDljOGI1YzczMTlhNTE0MzYxYjIxOWJjMmJiNTFhZDAzYzMyZGM1OGYx
11
+ NjZhYTU5Y2FlNjZkZmUzNGUxYjhlZGE2NTAzYWUwYjg4YzQwODQ=
12
12
  data.tar.gz: !binary |-
13
- NDc2NWQ4Mzk2ZDk3YWFkMjZjZDI0MGYzZThkNmY4NzE0MDUyN2Y1NmQ2M2Rh
14
- OGUyMWQ2MmU2ZTQxMzM2ODk4Mjk3YmE3MWRlODBkMmEwMjQzOTAyYTMxZjEx
15
- YjQ4MmViM2VhYTViMzU2MTZjMzI0MTU3ODc2NTVkMTc0YjUzYjA=
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
- # LocalhostServer.new(TestServer.new, 4567)
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
- returning_object = {}
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
- returning_object = remote_call
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
- HTTP_VERBS = [:get, :post, :put, :patch, :delete]
20
-
21
- HTTP_VERBS.each do |http_verb|
22
- define_method(http_verb) { |relative_path = '', params = {}, options = {}| make_the_call(http_verb, relative_path, params, options) }
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
- remote_call = {}
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)
@@ -41,9 +41,7 @@ module SmoothOperator
41
41
  RemoteCall::Errors::Timeout.new(response)
42
42
  end
43
43
 
44
- yield(remote_call) if block_given?
45
-
46
- remote_call
44
+ block_given? ? yield(remote_call) : remote_call
47
45
  end
48
46
 
49
47
 
@@ -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
- success = remote_call.status
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
- create_or_update(relative_path, data, options)
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
- create_or_update(relative_path, data, options) || raise('RecordNotSaved')
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
- success = remote_call.status
70
+ @destroyed = true if remote_call.status
69
71
 
70
- @destroyed = true if success
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
- success = remote_call.status
81
+ @new_record = false if remote_call.status
90
82
 
91
- @new_record = false if success
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
- success = remote_call.status
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)
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.14"
2
+ VERSION = "1.10.15"
3
3
  end
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.14
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 00:00:00.000000000 Z
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler