smooth_operator 1.10.13 → 1.10.14

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
- ZmY5YjcxMjdiMTMzZGM1OTAwNGZhNmY4Mjc4MzRhZGQwNDk0OWY5Mw==
4
+ ZGUwNjgxZDAyZTJmMDg3ZTRhZWMwZjFhY2UxYjhjYTIyOTBlZWNlOQ==
5
5
  data.tar.gz: !binary |-
6
- ZGJlMTk3MTAxMWM5MmM1ZGIxNzliZjYxMTBjNjhmNjE3MjczYWRlMQ==
6
+ YWRiNzFhZjlmYTI2MTRjYzM0MTU2NGMzZjJkNTgwZGI5NzdmOTJjZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzVjN2JlOTI0OTllZDlmYTNlNzkxYjAzODU0NGEyNTQ5ZmY1YTQ1ZjRlYTMy
10
- Yzg2YTEwYWM3ZTU1OTJhMDk1M2I0ODk2NWU2M2VlMzY2MDUxMDlkMDU2YTU5
11
- MTZmMjgyNjhkZGY0NzdhOTgwYzExNzFhY2VlMTBkYTA1NmFhNWU=
9
+ MjI2ZTFjNjUyZTMwMWE0MWIyNDk2MTU1ZDEwZmU1OTBlNjAxMjRhZDhhNzZi
10
+ ZDljMmI5OTQyZDIzNDQ4ZDFkNjFhYWVlNTE0Y2YzMDAyZDdjYzA0ZWE3MTc0
11
+ MDY5YjM0NjcyOGIzNzNkMDdkYmY4MzA4MTEzNTE5MmYxNTUyMDQ=
12
12
  data.tar.gz: !binary |-
13
- MDUyMGNiMDllZDI5NjExNWEzMzMyYzY4YTQ1MGUzYjU3M2I2M2UwNzM2OTNm
14
- YTYwMDAwOWEwMjM2YjViY2JhMDFkNzE4MGU4ODc5OWViMTFiZjFhMmVkZmY3
15
- MWZkZjhhYmIzNzQ5N2Q2MjFkNGE5ZTE1NDk5YTM5ODYyOTA4MzE=
13
+ NDc2NWQ4Mzk2ZDk3YWFkMjZjZDI0MGYzZThkNmY4NzE0MDUyN2Y1NmQ2M2Rh
14
+ OGUyMWQ2MmU2ZTQxMzM2ODk4Mjk3YmE3MWRlODBkMmEwMjQzOTAyYTMxZjEx
15
+ YjQ4MmViM2VhYTViMzU2MTZjMzI0MTU3ODc2NTVkMTc0YjUzYjA=
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ group :development, :test do
9
9
  gem "pry"
10
10
  gem "sinatra"
11
11
  gem "typhoeus"
12
+ gem "activesupport"
12
13
  gem "sinatra-contrib"
13
14
  gem "rspec", "~> 3.0.0.beta1"
14
15
  gem "factory_girl", "~> 4.0"
data/README.md CHANGED
@@ -274,8 +274,5 @@ Methods | Behaviour | Arguments | Return
274
274
  ## 4) TODO
275
275
 
276
276
  1. Finish "Methods" and "Behaviours" documentation;
277
- 2. Allow changing the HTTP verb for a specific connection;
278
- 3. FinderMethods specs;
279
- 4. serialization_specs to test the json options for nested classes;
280
- 5. model_schema_specs;
281
- 6. Cache.
277
+ 2. ModelSchema specs;
278
+ 3. Cache.
data/console.rb CHANGED
@@ -7,7 +7,7 @@ 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
11
 
12
12
  #User::Base.post('', { user: { age: 1, posts: [{ body: 'post1' }, 2] } })
13
13
 
@@ -42,12 +42,6 @@ module SmoothOperator
42
42
  end
43
43
  end
44
44
 
45
- def to_int(string)
46
- return string if string.is_a?(Fixnum)
47
-
48
- to_float(string).to_i
49
- end
50
-
51
45
  def to_date(string)
52
46
  return string if string.is_a?(Date)
53
47
 
@@ -66,12 +60,18 @@ module SmoothOperator
66
60
  ['1', 'true'].include?(value) ? true : ['0', 'false'].include?(value) ? false : nil
67
61
  end
68
62
 
63
+ def to_int(string)
64
+ return string if string.is_a?(Fixnum)
65
+
66
+ to_float(string).to_i
67
+ end
68
+
69
69
  def to_float(string)
70
70
  return string if string.is_a?(Float)
71
71
 
72
- return 0 if string.nil? || !string.is_a?(String)
72
+ return 0 if string.nil? || !(string.is_a?(String) || string.is_a?(Fixnum))
73
73
 
74
- value = string.scan(/-*\d+[,.]*\d*/).flatten.map(&:to_f).first
74
+ value = string.to_s.gsub(',', '.').scan(/-*\d+[.]*\d*/).flatten.map(&:to_f).first
75
75
 
76
76
  value.nil? ? 0 : value
77
77
  end
@@ -56,4 +56,4 @@ module SmoothOperator
56
56
 
57
57
  end
58
58
 
59
- end
59
+ end
@@ -1,4 +1,3 @@
1
- require "smooth_operator/operators/base"
2
1
  require "smooth_operator/remote_call/base"
3
2
  require "smooth_operator/operators/faraday"
4
3
  require "smooth_operator/operators/typhoeus"
@@ -9,16 +8,19 @@ module SmoothOperator
9
8
 
10
9
  module Operator
11
10
 
12
- HTTP_VERBS = [:get, :post, :put, :patch, :delete]
13
-
14
11
  OPTIONS = [:endpoint, :endpoint_user, :endpoint_pass, :timeout]
15
12
 
13
+ OPTIONS.each do |option|
14
+ define_method(option) { Helpers.get_instance_variable(self, option, '') }
15
+ end
16
16
 
17
17
  attr_writer *OPTIONS
18
18
 
19
- OPTIONS.each { |option| define_method(option) { Helpers.get_instance_variable(self, option, '') } }
19
+ HTTP_VERBS = [:get, :post, :put, :patch, :delete]
20
20
 
21
- HTTP_VERBS.each { |http_verb| define_method(http_verb) { |relative_path = '', params = {}, options = {}| make_the_call(http_verb, relative_path, params, options) } }
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) }
23
+ end
22
24
 
23
25
  def headers
24
26
  Helpers.get_instance_variable(self, :headers, {})
@@ -26,33 +28,19 @@ module SmoothOperator
26
28
 
27
29
  attr_writer :headers
28
30
 
29
-
30
- def generate_parallel_connection
31
- generate_connection(:typhoeus)
32
- end
33
-
34
- def generate_connection(adapter = nil, options = nil)
35
- adapter ||= :net_http
36
- options ||= {}
37
- url, timeout = (options[:endpoint] || self.endpoint), (options[:timeout] || self.timeout)
38
-
39
- ::Faraday.new(url: url) do |builder|
40
- builder.options[:timeout] = timeout unless Helpers.blank?(timeout)
41
- builder.request :url_encoded
42
- builder.adapter adapter
43
- end
44
- end
45
31
 
46
32
  def make_the_call(http_verb, relative_path = '', data = {}, options = {})
47
- if Helpers.present?(options[:hydra])
48
- operator_call = Operators::Typhoeus.new(self, http_verb, relative_path, data, options)
33
+ operator_args = operator_method_args(http_verb, relative_path, data, options)
34
+
35
+ if Helpers.present?(operator_args[4][:hydra])
36
+ operator_call = Operators::Typhoeus
49
37
  else
50
- operator_call = Operators::Faraday.new(self, http_verb, relative_path, data, options)
38
+ operator_call = Operators::Faraday
51
39
  end
52
-
40
+
53
41
  remote_call = {}
54
42
 
55
- operator_call.make_the_call do |_remote_call|
43
+ operator_call.make_the_call(*operator_args) do |_remote_call|
56
44
  remote_call = _remote_call
57
45
 
58
46
  yield(remote_call) if block_given?
@@ -65,6 +53,48 @@ module SmoothOperator
65
53
  params
66
54
  end
67
55
 
56
+
57
+ protected #################### PROTECTED ##################
58
+
59
+ def operator_method_args(http_verb, relative_path, data, options)
60
+ options = populate_options(options)
61
+
62
+ [http_verb, resource_path(relative_path, options), *strip_params(http_verb, data), options]
63
+ end
64
+
65
+
66
+ private #################### PRIVATE ##################
67
+
68
+ def populate_options(options)
69
+ options ||= {}
70
+
71
+ OPTIONS.each { |option| options[option] ||= send(option) }
72
+
73
+ options[:headers] = headers.merge(options[:headers] || {})
74
+
75
+ options
76
+ end
77
+
78
+ def resource_path(relative_path, options)
79
+ table_name = options[:table_name] || self.table_name
80
+
81
+ if Helpers.present?(table_name)
82
+ Helpers.present?(relative_path) ? "#{table_name}/#{relative_path}" : table_name
83
+ else
84
+ relative_path.to_s
85
+ end
86
+ end
87
+
88
+ def strip_params(http_verb, data)
89
+ data ||= {}
90
+
91
+ if [:get, :head, :delete].include?(http_verb)
92
+ [query_string(data), nil]
93
+ else
94
+ [query_string({}), data]
95
+ end
96
+ end
97
+
68
98
  end
69
99
 
70
100
  end
@@ -6,13 +6,33 @@ module SmoothOperator
6
6
 
7
7
  module Operators
8
8
 
9
- class Faraday < Base
9
+ module Faraday
10
+
11
+ extend self
12
+
13
+ # def generate_parallel_connection
14
+ # generate_connection(:typhoeus)
15
+ # end
16
+
17
+ def generate_connection(adapter = nil, options = nil)
18
+ adapter ||= :net_http
19
+
20
+ ::Faraday.new(url: options[:endpoint]) do |builder|
21
+ builder.options[:timeout] = options[:timeout].to_i unless Helpers.blank?(options[:timeout])
22
+ builder.request :url_encoded
23
+ builder.adapter adapter
24
+ end
25
+ end
26
+
27
+ def make_the_call(http_verb, resource_path, params, body, options)
28
+ connection, request_options, options = strip_options(options)
10
29
 
11
- def make_the_call
12
30
  remote_call = begin
13
- set_basic_authentication
31
+ set_basic_authentication(connection, options)
14
32
 
15
- response = connection.send(http_verb, relative_path) { |request| request_configuration(request) }
33
+ response = connection.send(http_verb, resource_path) do |request|
34
+ request_configuration(request, request_options, options, params, body)
35
+ end
16
36
 
17
37
  RemoteCall::Faraday.new(response)
18
38
  rescue ::Faraday::Error::ConnectionFailed
@@ -29,12 +49,20 @@ module SmoothOperator
29
49
 
30
50
  protected ################ PROTECTED ################
31
51
 
32
- def set_basic_authentication
33
- connection.basic_auth(endpoint_user, endpoint_pass) if Helpers.present?(endpoint_user)
52
+ def strip_options(options)
53
+ request_options = options.delete(:request_options) || {}
54
+
55
+ connection = options.delete(:connection) || generate_connection(nil, options)
56
+
57
+ [connection, request_options, options]
58
+ end
59
+
60
+ def set_basic_authentication(connection, options)
61
+ connection.basic_auth(options[:endpoint_user], options[:endpoint_pass]) if Helpers.present?(options[:endpoint_user])
34
62
  end
35
63
 
36
- def request_configuration(request)
37
- operator_options.each { |key, value| request.options.send("#{key}=", value) }
64
+ def request_configuration(request, request_options, options, params, body)
65
+ request_options.each { |key, value| request.options.send("#{key}=", value) }
38
66
 
39
67
  options[:headers].each { |key, value| request.headers[key] = value }
40
68
 
@@ -5,70 +5,72 @@ module SmoothOperator
5
5
 
6
6
  module Operators
7
7
 
8
- class Typhoeus < Base
8
+ module Typhoeus
9
9
 
10
- def make_the_call
11
- set_basic_authentication
10
+ extend self
12
11
 
13
- request = ::Typhoeus::Request.new(url, typhoeus_options)
12
+ def make_the_call(http_verb, resource_path, params, body, options)
13
+ request = ::Typhoeus::Request.new *typhoeus_request_args(http_verb, resource_path, params, body, options)
14
14
 
15
- remote_call = {}
16
-
17
- # hydra.queue(request)
18
-
19
- request.on_complete do |typhoeus_response|
20
- remote_call_class = if typhoeus_response.return_code == :couldnt_connect
21
- RemoteCall::Errors::ConnectionFailed
22
- elsif typhoeus_response.timed_out?
23
- RemoteCall::Errors::Timeout
24
- else
25
- RemoteCall::Typhoeus
26
- end
27
-
28
- remote_call = remote_call_class.new(typhoeus_response)
29
-
30
- yield(remote_call) if block_given?
15
+ hydra = options[:hydra] || ::Typhoeus::Hydra::hydra
16
+
17
+ _remote_call = {}
18
+
19
+ hydra.queue(request)
20
+
21
+ request.on_complete do |typhoeus_response|
22
+ _remote_call = remote_call(typhoeus_response)
23
+
24
+ yield(_remote_call) if block_given?
31
25
  end
32
26
 
33
- # hydra.run
27
+ hydra.run
34
28
 
35
- request.run
29
+ # request.run
36
30
 
37
- remote_call
31
+ _remote_call
38
32
  end
39
33
 
40
34
 
41
35
  protected ################ PROTECTED ################
42
36
 
43
- def set_basic_authentication
44
- typhoeus_options[:userpwd] = "#{endpoint_user}:#{endpoint_pass}" if Helpers.present?(endpoint_user)
37
+ def typhoeus_request_args(http_verb, relative_path, params, body, options)
38
+ [url(options, relative_path), build_typhoeus_options(http_verb, params, body, options)]
45
39
  end
46
40
 
47
- def url
48
- url = (options[:endpoint] || operator_class.endpoint)
49
-
50
- slice = url[-1] != '/' ? '/' : ''
51
-
52
- url = "#{url}#{slice}#{relative_path}" if Helpers.present?(relative_path)
41
+ def remote_call(typhoeus_response)
42
+ if typhoeus_response.return_code == :couldnt_connect
43
+ RemoteCall::Errors::ConnectionFailed
44
+ elsif typhoeus_response.timed_out?
45
+ RemoteCall::Errors::Timeout
46
+ else
47
+ RemoteCall::Typhoeus
48
+ end.new(typhoeus_response)
53
49
  end
54
50
 
55
- def typhoeus_options
56
- return @typhoeus_options if defined?(@typhoeus_options)
57
-
58
- @typhoeus_options = { method: http_verb, headers: options[:headers].merge({ "Content-type" => "application/x-www-form-urlencoded" }) }
59
51
 
60
- timeout = (options[:timeout] || operator_class.timeout)
52
+ private ################### PRIVATE ###############
53
+
54
+ def build_typhoeus_options(http_verb, params, body, options)
55
+ typhoeus_options = { method: http_verb, headers: options[:headers].merge({ "Content-type" => "application/x-www-form-urlencoded" }) }
61
56
 
62
- @typhoeus_options[:timeout] = timeout if Helpers.present?(timeout)
57
+ typhoeus_options[:timeout] = options[:timeout] if Helpers.present?(options[:timeout])
58
+
59
+ typhoeus_options[:body] = body if Helpers.present?(body)
60
+
61
+ typhoeus_options[:params] = params if Helpers.present?(params)
63
62
 
64
- @typhoeus_options[:body] = body if Helpers.present?(body)
65
- # @typhoeus_options[:params] = params if Helpers.present?(params)
63
+ typhoeus_options[:userpwd] = "#{options[:endpoint_user]}:#{options[:endpoint_pass]}" if Helpers.present?(options[:endpoint_user])
66
64
 
67
- @typhoeus_options
65
+ typhoeus_options
68
66
  end
69
67
 
70
- def hydra
71
- @hydra ||= operator_options[:hydra] || ::Typhoeus::Hydra::hydra
68
+ def url(options, relative_path)
69
+ url = options[:endpoint]
70
+
71
+ slice = url[-1] != '/' ? '/' : ''
72
+
73
+ url = "#{url}#{slice}#{relative_path}" if Helpers.present?(relative_path)
72
74
  end
73
75
 
74
76
  end
@@ -3,7 +3,7 @@ module SmoothOperator
3
3
  module Serialization
4
4
 
5
5
  def to_hash(options = nil)
6
- Helpers.symbolyze_keys serializable_hash(options)
6
+ Helpers.symbolyze_keys(serializable_hash(options) || {})
7
7
  end
8
8
 
9
9
  # alias :attributes :to_hash
@@ -12,7 +12,7 @@ module SmoothOperator
12
12
  def to_json(options = nil)
13
13
  require 'json' unless defined? JSON
14
14
 
15
- JSON(serializable_hash(options))
15
+ JSON(serializable_hash(options) || {})
16
16
  end
17
17
 
18
18
  def read_attribute_for_serialization(attribute)
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.13"
2
+ VERSION = "1.10.14"
3
3
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.authors = ["João Gonçalves"]
13
13
  spec.email = ["goncalves.joao@gmail.com"]
14
14
  spec.description = %q{ActiveResource alternative}
15
- spec.summary = %q{Simple and fully customizable alternative to ActiveResource, using faraday gem to stablish parallel remote calls"}
15
+ spec.summary = %q{Simple and fully customizable alternative to ActiveResource, using faraday gem to stablish remote calls"}
16
16
  spec.homepage = "https://github.com/goncalvesjoao/smooth_operator"
17
17
  spec.license = "MIT"
18
18
 
@@ -157,6 +157,50 @@ describe SmoothOperator::AttributeAssignment do
157
157
 
158
158
  end
159
159
 
160
+ context "that is declared (in schema) as an float" do
161
+
162
+ it "when the attributes's value is '1', should be converted to 1" do
163
+ expect(subject.new(price: '1').price).to eq(1.0)
164
+ end
165
+
166
+ it "when the attributes's value is '-1', should be converted to -1" do
167
+ expect(subject.new(price: '-1').price).to eq(-1.0)
168
+ end
169
+
170
+ it "when the attributes's value is 's-10s', should be converted to -10" do
171
+ expect(subject.new(price: 's-10s').price).to eq(-10.0)
172
+ end
173
+
174
+ it "when the attributes's value is ' 10s', should be converted to 10" do
175
+ expect(subject.new(price: ' 10s').price).to eq(10.0)
176
+ end
177
+
178
+ it "when the attributes's value is 123, should be converted to 123" do
179
+ expect(subject.new(price: 123).price).to eq(123.0)
180
+ end
181
+
182
+ it "when the attributes's value is -5, should be converted to -5" do
183
+ expect(subject.new(price: -5).price).to eq(-5.0)
184
+ end
185
+
186
+ it "when the attributes's value is '12.3', should be converted to 12.3" do
187
+ expect(subject.new(price: '12.3').price).to eq(12.3)
188
+ end
189
+
190
+ it "when the attributes's value is 's12.3s', should be converted to 12.3" do
191
+ expect(subject.new(price: 's12.3s').price).to eq(12.3)
192
+ end
193
+
194
+ it "when the attributes's value is 's12,3s', should be converted to 12.3" do
195
+ expect(subject.new(price: 's12,3s').price).to eq(12.3)
196
+ end
197
+
198
+ it "when the attributes's value is 1.2, should be converted to 1.2" do
199
+ expect(subject.new(price: 1.2).price).to eq(1.2)
200
+ end
201
+
202
+ end
203
+
160
204
  context "that is declared (in schema) as an boolean" do
161
205
 
162
206
  it "when the attributes's value is true, should be converted to true" do
@@ -245,6 +289,33 @@ describe SmoothOperator::AttributeAssignment do
245
289
 
246
290
  end
247
291
 
292
+ context "that is declared (in schema) as a datetime" do
293
+
294
+ it "if the attribute's value is a valid datetime string" do
295
+ date = subject.new(date: '2-2-2222 12:30').date
296
+
297
+ expect(date).to be_instance_of(DateTime)
298
+ expect(date.day).to be(2)
299
+ expect(date.month).to be(2)
300
+ expect(date.year).to be(2222)
301
+ expect(date.hour).to be(12)
302
+ expect(date.min).to be(30)
303
+ end
304
+
305
+ it "if the attribute's value is a valid datetime" do
306
+ date_now = DateTime.now
307
+ date = subject.new(date: date_now).date
308
+
309
+ expect(date).to be_instance_of(DateTime)
310
+ expect(date).to eq(date_now)
311
+ end
312
+
313
+ it "if the attribute's value is an invalid datetime string, the returning value should be nil" do
314
+ expect(subject.new(date: '2s-2-2222').date).to be_nil
315
+ end
316
+
317
+ end
318
+
248
319
  end
249
320
 
250
321
  end
@@ -123,7 +123,7 @@ end
123
123
 
124
124
  describe SmoothOperator::Persistence, helpers: :persistence do
125
125
 
126
- describe "#reload", current: true do
126
+ describe "#reload" do
127
127
  subject { new_user }
128
128
  let(:method_to_execute) { :reload }
129
129
 
@@ -20,9 +20,33 @@ describe SmoothOperator::Serialization do
20
20
  describe "#to_hash" do
21
21
  subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
22
22
 
23
+ it 'it should call #serializable_hash with the same arguments' do
24
+ options = { option1: 'option1', option2: 'option2' }
25
+
26
+ expect(subject).to receive(:serializable_hash).with(options)
27
+
28
+ subject.to_hash(options)
29
+ end
30
+ end
31
+
32
+ describe "#to_json" do
33
+ subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
34
+
35
+ it 'it should call #serializable_hash with the same arguments' do
36
+ options = { option1: 'option1', option2: 'option2' }
37
+
38
+ expect(subject).to receive(:serializable_hash).with(options)
39
+
40
+ subject.to_json(options)
41
+ end
42
+ end
43
+
44
+ describe "#serializable_hash" do
45
+ subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
46
+
23
47
  context "when no options are given" do
24
48
  it 'it should return all attributes' do
25
- expect(subject.to_hash).to eq(attributes_for(:user_with_address_and_posts))
49
+ expect(subject.serializable_hash).to eq(SmoothOperator::Helpers.stringify_keys(attributes_for(:user_with_address_and_posts)))
26
50
  end
27
51
  end
28
52
 
@@ -30,7 +54,7 @@ describe SmoothOperator::Serialization do
30
54
  let(:options_with_only) { { only: [:id, :first_name] } }
31
55
 
32
56
  it 'it should only return the filtered options' do
33
- expect(subject.to_hash(options_with_only)).to eq(attributes_for(:white_list))
57
+ expect(subject.serializable_hash(options_with_only)).to eq(SmoothOperator::Helpers.stringify_keys(attributes_for(:white_list)))
34
58
  end
35
59
  end
36
60
 
@@ -38,7 +62,7 @@ describe SmoothOperator::Serialization do
38
62
  let(:options_with_except) { { except: [:last_name, :admin] } }
39
63
 
40
64
  it 'it should return all fields except for the filtered options' do
41
- expect(subject.to_hash(options_with_except)).not_to include(attributes_for(:black_list))
65
+ expect(subject.serializable_hash(options_with_except)).not_to include(attributes_for(:black_list))
42
66
  end
43
67
  end
44
68
 
@@ -47,7 +71,7 @@ describe SmoothOperator::Serialization do
47
71
  subject(:user_with_my_method) { UserWithAddressAndPosts::UserWithMyMethod.new(attributes_for(:user_with_address_and_posts)) }
48
72
 
49
73
  it 'it should return all fields including the expected method and its returning value' do
50
- expect(user_with_my_method.to_hash(options_with_method)).to eq(attributes_for(:user_with_my_method))
74
+ expect(user_with_my_method.serializable_hash(options_with_method)).to eq(SmoothOperator::Helpers.stringify_keys(attributes_for(:user_with_my_method)))
51
75
  end
52
76
  end
53
77
 
@@ -35,7 +35,7 @@ module User
35
35
  end
36
36
 
37
37
  class TimeoutConnection < Base
38
- self.timeout = 0
38
+ self.timeout = 1
39
39
  self.model_name = 'user'
40
40
  end
41
41
 
@@ -18,7 +18,10 @@ module UserWithAddressAndPosts
18
18
  schema(
19
19
  age: :int,
20
20
  dob: :date,
21
- manager: :bool
21
+ price: :float,
22
+ manager: :bool,
23
+ date: :datetime,
24
+ first_name: :string
22
25
  )
23
26
 
24
27
  end
@@ -79,7 +79,7 @@ class TestServer < Sinatra::Base
79
79
  end
80
80
 
81
81
  post '/users/timeout' do
82
- sleep 1
82
+ sleep 2
83
83
  json 'ok'
84
84
  end
85
85
 
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.13
4
+ version: 1.10.14
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-10 00:00:00.000000000 Z
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,7 +92,6 @@ files:
92
92
  - lib/smooth_operator/model_schema.rb
93
93
  - lib/smooth_operator/open_struct.rb
94
94
  - lib/smooth_operator/operator.rb
95
- - lib/smooth_operator/operators/base.rb
96
95
  - lib/smooth_operator/operators/faraday.rb
97
96
  - lib/smooth_operator/operators/typhoeus.rb
98
97
  - lib/smooth_operator/persistence.rb
@@ -150,7 +149,7 @@ rubygems_version: 2.1.10
150
149
  signing_key:
151
150
  specification_version: 4
152
151
  summary: Simple and fully customizable alternative to ActiveResource, using faraday
153
- gem to stablish parallel remote calls"
152
+ gem to stablish remote calls"
154
153
  test_files:
155
154
  - spec/factories/user_factory.rb
156
155
  - spec/require_helper.rb
@@ -1,55 +0,0 @@
1
- module SmoothOperator
2
-
3
- module Operators
4
-
5
- class Base
6
-
7
- attr_reader :operator_class, :http_verb, :params, :body, :connection, :operator_options, :options, :relative_path, :endpoint_user, :endpoint_pass
8
-
9
- def initialize(operator_class, http_verb, relative_path, data, options)
10
- @operator_class, @http_verb = operator_class, http_verb
11
-
12
- @params, @body = strip_params(http_verb, data)
13
-
14
- @connection, @operator_options, @options = strip_options(options)
15
-
16
- @relative_path = resource_path(relative_path, options)
17
-
18
- @endpoint_user = options[:endpoint_user] || @operator_class.endpoint_user
19
-
20
- @endpoint_pass = options[:endpoint_pass] || @operator_class.endpoint_pass
21
- end
22
-
23
-
24
- protected ################# PROTECTED ###################
25
-
26
- def strip_params(http_verb, data)
27
- data ||= {}
28
-
29
- ([:get, :head, :delete].include?(http_verb) ? [@operator_class.query_string(data), nil] : [@operator_class.query_string({}), data])
30
- end
31
-
32
- def strip_options(options)
33
- options ||= {}
34
-
35
- options[:headers] = @operator_class.headers.merge(options[:headers] || {})
36
- operator_options = options.delete(:operator_options) || {}
37
- connection = options.delete(:connection) || @operator_class.generate_connection(nil, operator_options)
38
-
39
- [connection, operator_options, options]
40
- end
41
-
42
- def resource_path(relative_path, options)
43
- table_name = options[:table_name] || @operator_class.table_name
44
-
45
- if Helpers.present?(table_name)
46
- Helpers.present?(relative_path) ? "#{table_name}/#{relative_path}" : table_name
47
- else
48
- relative_path
49
- end
50
- end
51
-
52
- end
53
-
54
- end
55
- end