smooth_operator 1.10.3 → 1.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDQ4MTZhNjkzMDYwMjRmNTUwYzZhMjU3YzZlZjFlZWE2YTJjODE3Zg==
4
+ MjFkNjcxMjZmMWFkYzYzY2E1NWE3ZDA5ODdkYzJmYTkwMWZhZTExOA==
5
5
  data.tar.gz: !binary |-
6
- MGVhNzg5MzQyNTU0ZWVlMDZmMmEwZjcxNjlkOTI4MWMxNTc0MWQxYg==
6
+ ODBjZTE5NzQwNDU0MmQwY2M0MGQ1ZWZmM2VhNmM0YThmNDQ4Y2U3MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmUzOTIxOTgwNWE2ZGM1NjhiNmMzYzE0YjA1MGNhYTRiMzhlMTRlOWVhY2Mw
10
- NDdlZWU2YmEyZmVkMDY2MTFhYTdjYmFjN2Q4ZGIyYjM5YTFkMzllNmY2M2Jl
11
- NmRlYjRkZGIwM2Q1NTAzZTg3ZjcxNWJkNzEzMmJiNmMzZTcyZWE=
9
+ NDc2OTA2NWFkZTBkN2I5Y2FiNGEwNDQ2YTAyNTg0NDc4ZDYxYWMwYTk2Y2Y3
10
+ YzY3ZTVlZDUwNjNlNDEzMjc3NGM4YThjODZkYjNiYTZmY2EzYTA4MzMxYjg0
11
+ MDQxM2Y4ZDA0NGRmNTUwNjRhOTExZWQ4YjY5NDhiZDhkYzllNzk=
12
12
  data.tar.gz: !binary |-
13
- MTE2YzIyNzVkMjRhZGY3MGMyOTdmNzAyODQ5ODY0NjI3ZDNkMmVkYzYwZTBk
14
- MmY0MDVhNmQ4ZDM3Mjc0MTc2NzMxMjFlN2I0ZjY2NTBjMjY0ZGUxZWU4MmM1
15
- MjE5YjE0NDc3Y2Y1ZWUyYWE5MjU4ZjY0NzcyY2ZlYzM4NjM0MTA=
13
+ MzMyODcyNTZhZDY1MzE3MWUzNDg1NjI0NzRmODEyN2NiMWViMmNhZTdkZmQ3
14
+ M2EzOTlhZmZkMjQ5ZDkyYjAzODIyYmQ5MzM3NTQ2ZGM2YmRiMzlmZGJhZTll
15
+ ZWNhMDBmMGNlYjA3NTFlNGU2ZjAyYmE3YjQ4NWY1ZmM1YzgxZGM=
data/Gemfile CHANGED
@@ -12,4 +12,5 @@ group :development, :test do
12
12
  gem "sinatra-contrib"
13
13
  gem "rspec", "~> 3.0.0.beta1"
14
14
  gem "factory_girl", "~> 4.0"
15
+ gem "ethon", :git => 'https://github.com/goncalvesjoao/ethon'
15
16
  end
data/console.rb CHANGED
@@ -3,7 +3,11 @@
3
3
  $LOAD_PATH << './'
4
4
  $LOAD_PATH << './lib'
5
5
 
6
- require "spec/spec_helper"
6
+ require 'spec/require_helper'
7
+
8
+ FactoryGirl.find_definitions
9
+
10
+ LocalhostServer.new(TestServer.new, 4567)
7
11
 
8
12
  #User::Base.post('', { user: { age: 1, posts: [{ body: 'post1' }, 2] } })
9
13
 
@@ -15,7 +15,7 @@ module SmoothOperator
15
15
 
16
16
  @table_name, @object_class = table_name, object_class
17
17
 
18
- @internal_array = [*_attributes[table_name]].map { |array_entry| object_class.new(array_entry) }
18
+ @internal_array = [*_attributes[table_name]].map { |array_entry| object_class.new(array_entry).tap { |object| object.reloaded = true } }
19
19
  _attributes.delete(table_name)
20
20
 
21
21
  @meta_data = _attributes
@@ -118,7 +118,7 @@ module SmoothOperator
118
118
  if self.class.dirty_attributes?
119
119
  internal_data[attribute_name].set_value(attribute_value)
120
120
  else
121
- internal_data[attribute_name] = new_attribute_object(attribute_name, attribute_value)
121
+ internal_data[attribute_name] = new_attribute_object(attribute_name, attribute_value).value
122
122
  end
123
123
  end
124
124
 
@@ -11,9 +11,15 @@ module SmoothOperator
11
11
  def find(relative_path, data = {}, options = {})
12
12
  relative_path = '' if relative_path == :all
13
13
 
14
+ returning_object = {}
15
+
14
16
  get(relative_path, data, options).tap do |remote_call|
15
17
  remote_call.object = build_object(remote_call.parsed_response, options) if remote_call.success?
18
+
19
+ returning_object = remote_call
16
20
  end
21
+
22
+ returning_object
17
23
  end
18
24
 
19
25
 
@@ -27,7 +33,7 @@ module SmoothOperator
27
33
  if parsed_response.is_a?(Array)
28
34
  parsed_response.map { |array_entry| build_object(array_entry, options) }
29
35
  elsif parsed_response.is_a?(Hash)
30
- parsed_response.include?(table_name) ? ArrayWithMetaData.new(parsed_response, table_name, self) : new(parsed_response)
36
+ parsed_response.include?(table_name) ? ArrayWithMetaData.new(parsed_response, table_name, self) : new(parsed_response).tap { |object| object.reloaded = true }
31
37
  else
32
38
  parsed_response
33
39
  end
@@ -61,9 +61,6 @@ module SmoothOperator
61
61
  remote_call
62
62
  end
63
63
 
64
-
65
- protected ################ PROTECTED ################
66
-
67
64
  def query_string(params)
68
65
  params
69
66
  end
@@ -14,21 +14,25 @@ module SmoothOperator
14
14
 
15
15
  remote_call = {}
16
16
 
17
- hydra.queue(request)
17
+ # hydra.queue(request)
18
18
 
19
19
  request.on_complete do |typhoeus_response|
20
- remote_call_class = if typhoeus_response.timed_out?
20
+ remote_call_class = if typhoeus_response.return_code == :couldnt_connect
21
+ RemoteCall::Errors::ConnectionFailed
22
+ elsif typhoeus_response.timed_out?
21
23
  RemoteCall::Errors::Timeout
22
24
  else
23
25
  RemoteCall::Typhoeus
24
26
  end
25
- binding.pry
27
+
26
28
  remote_call = remote_call_class.new(typhoeus_response)
27
29
 
28
30
  yield(remote_call) if block_given?
29
31
  end
30
32
 
31
- hydra.run
33
+ # hydra.run
34
+
35
+ request.run
32
36
 
33
37
  remote_call
34
38
  end
@@ -51,14 +55,14 @@ binding.pry
51
55
  def typhoeus_options
52
56
  return @typhoeus_options if defined?(@typhoeus_options)
53
57
 
54
- @typhoeus_options = { method: http_verb, headers: options[:headers] }
58
+ @typhoeus_options = { method: http_verb, headers: options[:headers].merge({ "Content-type" => "application/x-www-form-urlencoded" }) }
55
59
 
56
60
  timeout = (options[:timeout] || operator_class.timeout)
57
61
 
58
62
  @typhoeus_options[:timeout] = timeout if Helpers.present?(timeout)
59
63
 
60
64
  @typhoeus_options[:body] = body if Helpers.present?(body)
61
- @typhoeus_options[:params] = params if Helpers.present?(params)
65
+ # @typhoeus_options[:params] = params if Helpers.present?(params)
62
66
 
63
67
  @typhoeus_options
64
68
  end
@@ -27,7 +27,18 @@ module SmoothOperator
27
27
  end
28
28
 
29
29
 
30
- attr_accessor :extra_params
30
+ attr_accessor :extra_params, :reloaded, :meta_data
31
+
32
+ def reload(relative_path = nil, data = {}, options = {})
33
+ relative_path = id.to_s if Helpers.blank?(relative_path)
34
+ success = {}
35
+
36
+ make_remote_call(:get, relative_path, data, options) do |remote_call|
37
+ success = remote_call.status
38
+ end
39
+
40
+ success
41
+ end
31
42
 
32
43
  def new_record?
33
44
  return @new_record if defined?(@new_record)
@@ -41,6 +52,12 @@ module SmoothOperator
41
52
  @destroyed = false
42
53
  end
43
54
 
55
+ def reloaded?
56
+ return @reloaded if defined?(@reloaded)
57
+
58
+ @reloaded = false
59
+ end
60
+
44
61
  def persisted?
45
62
  !(new_record? || destroyed?)
46
63
  end
@@ -115,7 +132,16 @@ module SmoothOperator
115
132
  returning_data = @last_remote_call.parsed_response
116
133
 
117
134
  if !@last_remote_call.error? && returning_data.is_a?(Hash)
118
- assign_attributes returning_data.include?(model_name) ? returning_data[model_name] : returning_data
135
+ @reloaded = true
136
+
137
+ attributes = returning_data
138
+
139
+ if returning_data.include?(model_name)
140
+ attributes = returning_data.delete(model_name)
141
+ @meta_data = returning_data
142
+ end
143
+
144
+ assign_attributes attributes
119
145
  end
120
146
 
121
147
  yield(remote_call)
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.3"
2
+ VERSION = "1.10.6"
3
3
  end
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
 
26
26
  spec.add_dependency "json"
27
- spec.add_dependency 'typhoeus'
28
- spec.add_dependency 'faraday', '~> 0.8.9'
27
+ spec.add_dependency "faraday", "~> 0.8.9"
28
+ spec.add_dependency "typhoeus", "~> 0.6.8"
29
+
30
+ # this is necessary if you want to typhoeus to correctly encode arrays
31
+ # spec.add_dependency "ethon", :git => 'https://github.com/goncalvesjoao/ethon'
29
32
  end
@@ -9,7 +9,8 @@ FactoryGirl.define do
9
9
 
10
10
  trait :with_address_and_posts do
11
11
  address { { street: 'my_street' } }
12
- posts [{ body: 'post1' }, { body: 'post2' }]
12
+ # posts [{ id: 1, body: 'post1' }, { id: 2, body: 'post2' }]
13
+ posts [{ id: 1 }, { id: 2 }]
13
14
  end
14
15
  factory :user_with_address_and_posts, traits: [:with_address_and_posts]
15
16
 
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ require 'bundler/setup'
5
+ require 'smooth_operator'
6
+
7
+ Bundler.require :test, :default
8
+
9
+ Dir.chdir("spec/") do
10
+ Dir["support/**/*.rb"].each { |file| require file }
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,17 +6,7 @@ SimpleCov.start do
6
6
  coverage_dir('../tmp/coverage/')
7
7
  end
8
8
 
9
- $LOAD_PATH.unshift(File.dirname(__FILE__))
10
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
11
-
12
- require 'bundler'
13
- require 'smooth_operator'
14
-
15
- Bundler.require :test, :default
16
-
17
- Dir.chdir("spec/") do
18
- Dir["support/**/*.rb"].each { |file| require file }
19
- end
9
+ require 'require_helper'
20
10
 
21
11
  FactoryGirl.find_definitions
22
12
 
@@ -1,5 +1,9 @@
1
1
  class Post < SmoothOperator::Base
2
-
3
- self.endpoint = 'http://localhost:3000/api/v0'
2
+
3
+ self.endpoint_user = 'admin'
4
+
5
+ self.endpoint_pass = 'admin'
6
+
7
+ self.endpoint = 'http://localhost:4567/'
4
8
 
5
9
  end
@@ -1,6 +1,8 @@
1
1
  module UserWithAddressAndPosts
2
2
 
3
3
  class Father < User::Base
4
+
5
+ self.table_name = 'users'
4
6
 
5
7
  schema(
6
8
  posts: Post,
@@ -1,5 +1,6 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/json'
3
+ require 'pry'
3
4
 
4
5
  class TestServer < Sinatra::Base
5
6
 
@@ -7,6 +8,13 @@ class TestServer < Sinatra::Base
7
8
  username == 'admin' and password == 'admin'
8
9
  end
9
10
 
11
+
12
+ get '/posts/:id' do
13
+ post_data = { id: 1, body: 'test' }
14
+ json post_data
15
+ end
16
+
17
+
10
18
  get '/users/test_hash_with_array' do
11
19
  status test_hash_with_array
12
20
  end
@@ -69,7 +77,7 @@ class TestServer < Sinatra::Base
69
77
  end
70
78
 
71
79
  not_found do
72
- binding.pry
80
+ # binding.pry
73
81
  end
74
82
 
75
83
 
@@ -116,7 +124,8 @@ class TestServer < Sinatra::Base
116
124
  end
117
125
 
118
126
  if app_file == $0
119
- require './spec/spec_helper' unless defined? SmoothOperator
127
+ # require './spec/spec_helper' unless defined? SmoothOperator
128
+ # require './spec/require_helper' unless defined? SmoothOperator
120
129
  run!
121
130
  end
122
131
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth_operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.3
4
+ version: 1.10.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: typhoeus
42
+ name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.8.9
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.8.9
55
55
  - !ruby/object:Gem::Dependency
56
- name: faraday
56
+ name: typhoeus
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.9
61
+ version: 0.6.8
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 0.8.9
68
+ version: 0.6.8
69
69
  description: ActiveResource alternative
70
70
  email:
71
71
  - goncalves.joao@gmail.com
@@ -107,6 +107,7 @@ files:
107
107
  - lib/smooth_operator/version.rb
108
108
  - smooth_operator.gemspec
109
109
  - spec/factories/user_factory.rb
110
+ - spec/require_helper.rb
110
111
  - spec/smooth_operator/attribute_assignment_spec.rb
111
112
  - spec/smooth_operator/attributes_dirty_spec.rb
112
113
  - spec/smooth_operator/delegation_spec.rb
@@ -152,6 +153,7 @@ summary: Simple and fully customizable alternative to ActiveResource, using fara
152
153
  gem to stablish parallel remote calls"
153
154
  test_files:
154
155
  - spec/factories/user_factory.rb
156
+ - spec/require_helper.rb
155
157
  - spec/smooth_operator/attribute_assignment_spec.rb
156
158
  - spec/smooth_operator/attributes_dirty_spec.rb
157
159
  - spec/smooth_operator/delegation_spec.rb