remotable 0.4.0.beta2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50bbb2463866bea7de985bdc5375aaac0b7c715b
4
- data.tar.gz: ee16e4675c4c3c8a7cd4420e9180a0d532575a80
3
+ metadata.gz: ddc9f37b1e04cbd48e85ae0b05e75e6b72f6e145
4
+ data.tar.gz: e019957e6c601abba1a6fc6c88ed1f2d357691cb
5
5
  SHA512:
6
- metadata.gz: 32767f6332fe922693bf2265c7dff1b73b916c491800e792b44e4d4104050335fcf562a5c729bf1ba9f1306d3bf14d2a0590e4211c98de7bf22a0f4a7865d26f
7
- data.tar.gz: 46c8039a5195b3a629761798b359c228ce8448caa72b59686402182f17ea70773fe8191ee5c80fcd13a3cd8af9ebbf73947ae4c53317ceef78fa4fa9ae730d46
6
+ metadata.gz: c50f5da9c4150f66a92d1ceb12e97f473e19d7c15f2743777885112b8e0b04b1b83aa2ee78113e225557a17a280a34d1bebaf8b25f060a0c564279eb9aa16f0a
7
+ data.tar.gz: 88b1a55add081c7312221d1855f03305d039e72603f093b1656f043bbba71d89dccd2f644d78ae0fd373cd2e266307663d15ef9fec529e6187d4259eca76f375
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.5.1
5
+
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: 2.5.1
9
+
10
+ script: bundle exec rake test
11
+
12
+ # To stop Travis from running tests for a new commit,
13
+ # add the following to your commit message: [ci skip]
14
+ # You should add this when you edit documentation or comments, etc.
@@ -1,113 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remotable (0.4.0.beta2)
4
+ remotable (0.4.0)
5
5
  activerecord
6
- activeresource
6
+ activeresource (>= 3.2)
7
7
  activesupport
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- actionmailer (4.0.2)
13
- actionpack (= 4.0.2)
14
- mail (~> 2.5.4)
15
- actionpack (4.0.2)
16
- activesupport (= 4.0.2)
17
- builder (~> 3.1.0)
18
- erubis (~> 2.7.0)
19
- rack (~> 1.5.2)
20
- rack-test (~> 0.6.2)
21
12
  active_resource_simulator (0.0.2)
22
13
  activeresource
23
- activemodel (4.0.2)
24
- activesupport (= 4.0.2)
14
+ activemodel (4.0.13)
15
+ activesupport (= 4.0.13)
25
16
  builder (~> 3.1.0)
26
- activerecord (4.0.2)
27
- activemodel (= 4.0.2)
17
+ activerecord (4.0.13)
18
+ activemodel (= 4.0.13)
28
19
  activerecord-deprecated_finders (~> 1.0.2)
29
- activesupport (= 4.0.2)
20
+ activesupport (= 4.0.13)
30
21
  arel (~> 4.0.0)
31
- activerecord-deprecated_finders (1.0.3)
32
- activeresource (4.0.0)
22
+ activerecord-deprecated_finders (1.0.4)
23
+ activeresource (4.1.0)
33
24
  activemodel (~> 4.0)
34
25
  activesupport (~> 4.0)
35
- rails-observers (~> 0.1.1)
36
- activesupport (4.0.2)
37
- i18n (~> 0.6, >= 0.6.4)
26
+ rails-observers (~> 0.1.2)
27
+ activesupport (4.0.13)
28
+ i18n (~> 0.6, >= 0.6.9)
38
29
  minitest (~> 4.2)
39
30
  multi_json (~> 1.3)
40
31
  thread_safe (~> 0.1)
41
32
  tzinfo (~> 0.3.37)
42
- ansi (1.4.3)
43
- arel (4.0.1)
44
- atomic (1.1.14)
33
+ ansi (1.5.0)
34
+ arel (4.0.2)
45
35
  builder (3.1.4)
46
- coderay (1.1.0)
36
+ coderay (1.1.2)
37
+ concurrent-ruby (1.0.5)
47
38
  database_cleaner (1.2.0)
48
- docile (1.1.2)
49
- erubis (2.7.0)
39
+ docile (1.3.1)
50
40
  factory_girl (2.0.5)
51
- hike (1.2.3)
52
- i18n (0.6.9)
53
- mail (2.5.4)
54
- mime-types (~> 1.16)
55
- treetop (~> 1.4.8)
56
- method_source (0.8.2)
57
- mime-types (1.25.1)
41
+ i18n (0.9.5)
42
+ concurrent-ruby (~> 1.0)
43
+ json (2.1.0)
44
+ method_source (0.9.0)
58
45
  minitest (4.7.5)
59
- multi_json (1.8.4)
60
- polyglot (0.3.3)
61
- pry (0.9.12.4)
62
- coderay (~> 1.0)
63
- method_source (~> 0.8)
64
- slop (~> 3.4)
65
- rack (1.5.2)
66
- rack-test (0.6.2)
67
- rack (>= 1.0)
68
- rails (4.0.2)
69
- actionmailer (= 4.0.2)
70
- actionpack (= 4.0.2)
71
- activerecord (= 4.0.2)
72
- activesupport (= 4.0.2)
73
- bundler (>= 1.3.0, < 2.0)
74
- railties (= 4.0.2)
75
- sprockets-rails (~> 2.0.0)
76
- rails-observers (0.1.2)
77
- activemodel (~> 4.0)
78
- railties (4.0.2)
79
- actionpack (= 4.0.2)
80
- activesupport (= 4.0.2)
81
- rake (>= 0.8.7)
82
- thor (>= 0.18.1, < 2.0)
83
- rake (10.1.1)
46
+ multi_json (1.13.1)
47
+ pry (0.11.3)
48
+ coderay (~> 1.1.0)
49
+ method_source (~> 0.9.0)
50
+ rails-observers (0.1.5)
51
+ activemodel (>= 4.0)
52
+ rake (12.3.1)
84
53
  rr (1.1.2)
85
- simplecov (0.8.2)
86
- docile (~> 1.1.0)
87
- multi_json
88
- simplecov-html (~> 0.8.0)
89
- simplecov-html (0.8.0)
90
- slop (3.4.7)
91
- sprockets (2.10.1)
92
- hike (~> 1.2)
93
- multi_json (~> 1.0)
94
- rack (~> 1.0)
95
- tilt (~> 1.1, != 1.3.0)
96
- sprockets-rails (2.0.1)
97
- actionpack (>= 3.0)
98
- activesupport (>= 3.0)
99
- sprockets (~> 2.8)
100
- sqlite3 (1.3.8)
101
- thor (0.18.1)
102
- thread_safe (0.1.3)
103
- atomic
104
- tilt (1.4.1)
105
- treetop (1.4.15)
106
- polyglot
107
- polyglot (>= 0.3.1)
108
- turn (0.9.6)
54
+ simplecov (0.16.1)
55
+ docile (~> 1.1)
56
+ json (>= 1.8, < 3)
57
+ simplecov-html (~> 0.10.0)
58
+ simplecov-html (0.10.2)
59
+ sqlite3 (1.3.13)
60
+ thread_safe (0.3.6)
61
+ turn (0.9.7)
109
62
  ansi
110
- tzinfo (0.3.38)
63
+ minitest (~> 4)
64
+ tzinfo (0.3.54)
111
65
 
112
66
  PLATFORMS
113
67
  ruby
@@ -117,12 +71,12 @@ DEPENDENCIES
117
71
  database_cleaner
118
72
  factory_girl (~> 2.0.4)
119
73
  pry
120
- rails (>= 3.1.0, < 5.0.0)
74
+ rake
121
75
  remotable!
122
76
  rr
123
77
  simplecov
124
- sqlite3
78
+ sqlite3 (~> 1.3.13)
125
79
  turn
126
80
 
127
81
  BUNDLED WITH
128
- 1.10.6
82
+ 1.16.1
@@ -1,5 +1,7 @@
1
1
  # Remotable
2
2
 
3
+ [![Build Status](https://travis-ci.org/cph/remotable.svg)](https://travis-ci.org/cph/remotable)
4
+
3
5
  Remotable associates an ActiveRecord model with a remote resource (like an ActiveResource model) and keeps the two synchronized.
4
6
 
5
7
  - When a local record is loaded, Remotable ensures that it is up-to-date.
@@ -108,6 +108,16 @@ module Remotable
108
108
  @local_attribute_routes.merge!(local_key => options[:path])
109
109
  end
110
110
 
111
+ attr_accessor :remotable_skip_validation_on_sync
112
+
113
+ def remotable_skip_validation!
114
+ self.remotable_skip_validation_on_sync = true
115
+ end
116
+
117
+ def remotable_skip_validation_on_sync?
118
+ self.remotable_skip_validation_on_sync
119
+ end
120
+
111
121
 
112
122
 
113
123
  attr_reader :remote_attribute_map,
@@ -168,6 +178,8 @@ module Remotable
168
178
  report_ignored_network_error($!)
169
179
  rescue Remotable::ServiceUnavailableError
170
180
  report_ignored_503_error($!)
181
+ rescue Remotable::SSLError
182
+ report_ignored_ssl_error($!)
171
183
  end
172
184
  end
173
185
  record
@@ -185,6 +197,10 @@ module Remotable
185
197
  Remotable.logger.error "[remotable:#{name.underscore}:instantiate] #{error.message}"
186
198
  end
187
199
 
200
+ def report_ignored_ssl_error(error)
201
+ Remotable.logger.error "[remotable:#{name.underscore}:instantiate] #{error.message}"
202
+ end
203
+
188
204
 
189
205
 
190
206
  # !todo: create these methods on an anonymous module and mix it in
@@ -330,7 +346,6 @@ module Remotable
330
346
  end
331
347
 
332
348
 
333
-
334
349
  def all_by_remote
335
350
  find_by_remote_query(:all)
336
351
  end
@@ -338,6 +353,7 @@ module Remotable
338
353
  def find_by_remote_query(remote_method_name, *args)
339
354
  remote_set_timeout :list
340
355
  remote_resources = Array.wrap(remote_model.send(remote_method_name, *args))
356
+
341
357
  map_remote_resources_to_local(remote_resources)
342
358
  end
343
359
 
@@ -421,6 +437,7 @@ module Remotable
421
437
  :local_attribute_names,
422
438
  :local_attribute_name,
423
439
  :expires_after,
440
+ :remotable_skip_validation_on_sync?,
424
441
  :to => "self.class"
425
442
 
426
443
  def expired?
@@ -487,7 +504,7 @@ module Remotable
487
504
  def merge_remote_data!(remote_resource)
488
505
  merge_remote_data(remote_resource)
489
506
  reset_expiration_date
490
- nosync { save! }
507
+ nosync { save!(validate: !remotable_skip_validation_on_sync?) }
491
508
  self
492
509
  end
493
510
 
@@ -547,6 +564,7 @@ module Remotable
547
564
 
548
565
  def initialize_expiration_date
549
566
  reset_expiration_date unless self.expires_at
567
+ true
550
568
  end
551
569
 
552
570
  def reset_expiration_date
@@ -34,68 +34,6 @@ module ActiveResourceFixes
34
34
 
35
35
  end
36
36
 
37
-
38
- module ActiveResourceFixes30
39
-
40
- # ActiveResource hacks method_missing without hacking respond_to?
41
- # In fact, it responds to any method that ends in an equals sign.
42
- # It also responds to any method that matches an attribute name.
43
- def respond_to?(method_symbol, include_private=false)
44
- method_name = method_symbol.to_s
45
- if method_name =~ /\w+=/
46
- true
47
- elsif attributes.include?(method_name)
48
- true
49
- else
50
- super(method_symbol, include_private)
51
- end
52
- end
53
-
54
- # ! in this method, don't check the Content-Type header: rack doesn't always return it
55
- def load_attributes_from_response(response)
56
- if !response.body.nil? && response.body.strip.size > 0
57
- load(self.class.format.decode(response.body))
58
- end
59
- end
60
-
61
- end
62
-
63
-
64
- module ActiveResourceFixes31
65
-
66
- # ActiveResource hacks method_missing without hacking respond_to?
67
- # In fact, it responds to any method that ends in an equals sign.
68
- # It also responds to any method that matches an attribute name.
69
- def respond_to?(method_symbol, include_private=false)
70
- method_name = method_symbol.to_s
71
- if method_name =~ /\w+=/
72
- true
73
- elsif attributes.include?(method_name)
74
- true
75
- else
76
- super(method_symbol, include_private)
77
- end
78
- end
79
-
80
- # ! in this method, don't check the Content-Type header: rack doesn't always return it
81
- def load_attributes_from_response(response)
82
- if !response.body.nil? && response.body.strip.size > 0
83
- load(self.class.format.decode(response.body), true)
84
- @persisted = true
85
- end
86
- end
87
-
88
- end
89
-
90
- if Rails.version >= '3.2'
91
- #
92
- elsif Rails.version < '3.1'
93
- ActiveResource::Base.send(:include, ActiveResourceFixes30)
94
- else
95
- ActiveResource::Base.send(:include, ActiveResourceFixes31)
96
- end
97
-
98
-
99
37
  ActiveResource::Base.send(:include, ActiveResourceFixes)
100
38
 
101
39
 
@@ -98,8 +98,11 @@ module Remotable
98
98
  $!.extend Remotable::TimeoutError
99
99
  raise
100
100
  rescue ::ActiveResource::ServerError
101
- $!.extend Remotable::ServiceUnavailableError if $!.response.code == 503
102
- $!.extend Remotable::TimeoutError if $!.response.code == 504
101
+ $!.extend Remotable::ServiceUnavailableError if $!.response.code.to_i == 503
102
+ $!.extend Remotable::TimeoutError if $!.response.code.to_i == 504
103
+ raise
104
+ rescue ::ActiveResource::SSLError
105
+ $!.extend Remotable::SSLError
103
106
  raise
104
107
  end
105
108
 
@@ -4,4 +4,5 @@ module Remotable
4
4
  module ServiceUnavailableError; include Error; end
5
5
  module NetworkError; include Error; end
6
6
  module NotFound; include Error; end
7
+ module SSLError; include Error; end
7
8
  end
@@ -7,7 +7,7 @@ module Remotable
7
7
  end
8
8
 
9
9
  def nosync(new_value=true)
10
- old_value = @nosync
10
+ old_value = _nosync
11
11
  self.nosync = new_value
12
12
  yield
13
13
  ensure
@@ -19,13 +19,19 @@ module Remotable
19
19
  end
20
20
 
21
21
  def nosync_value?
22
- !@nosync.nil?
22
+ !_nosync.nil?
23
23
  end
24
24
 
25
25
  def nosync?
26
26
  @nosync == true
27
27
  end
28
28
 
29
+ private
30
+
31
+ def _nosync
32
+ @nosync if instance_variable_defined?(:@nosync)
33
+ end
34
+
29
35
 
30
36
  end
31
37
  end
@@ -1,3 +1,3 @@
1
1
  module Remotable
2
- VERSION = "0.4.0.beta2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -10,23 +10,23 @@ Gem::Specification.new do |s|
10
10
  s.homepage = ""
11
11
  s.summary = %q{Binds an ActiveRecord model to a remote resource and keeps the two synchronized}
12
12
  s.description = %q{Remotable keeps a locally-stored ActiveRecord synchronized with a remote resource.}
13
-
13
+
14
14
  s.rubyforge_project = "remotable"
15
-
16
- s.add_dependency "activeresource"
15
+
16
+ s.add_dependency "activeresource", ">= 3.2"
17
17
  s.add_dependency "activerecord"
18
18
  s.add_dependency "activesupport"
19
-
20
- s.add_development_dependency "rails", ">= 3.1.0", "< 5.0.0"
19
+
20
+ s.add_development_dependency "rake"
21
21
  s.add_development_dependency "turn"
22
22
  s.add_development_dependency "pry"
23
23
  s.add_development_dependency "factory_girl", "~> 2.0.4"
24
- s.add_development_dependency "sqlite3"
24
+ s.add_development_dependency "sqlite3", "~> 1.3.13"
25
25
  s.add_development_dependency "active_resource_simulator"
26
26
  s.add_development_dependency "simplecov"
27
27
  s.add_development_dependency "rr"
28
28
  s.add_development_dependency "database_cleaner"
29
-
29
+
30
30
  s.files = `git ls-files`.split("\n")
31
31
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
32
32
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -207,7 +207,7 @@ class ActiveResourceTest < ActiveSupport::TestCase
207
207
  assert_nothing_raised do
208
208
  tenant = Tenant.find_by_remote_id(tenant.remote_id)
209
209
  end
210
- assert_equal expired_at, tenant.expires_at, "Tenant's expiration date should not have changed"
210
+ assert_in_delta expired_at, tenant.expires_at, 0.1, "Tenant's expiration date should not have changed"
211
211
  end
212
212
  end
213
213
 
@@ -1,15 +1,13 @@
1
- require 'rubygems'
2
- require 'simplecov'
3
- require 'rails'
4
- require 'rails/test_help'
5
- require 'active_support/core_ext'
6
- require 'factory_girl'
7
- require 'turn'
8
- require 'pry'
9
- require 'database_cleaner'
10
-
11
-
12
- require 'active_record'
1
+ require "rubygems"
2
+ require "simplecov"
3
+ require "active_support/core_ext"
4
+ require "factory_girl"
5
+ require "turn"
6
+ require "pry"
7
+ require "database_cleaner"
8
+ require "active_record"
9
+ require "factories/tenants"
10
+ require "minitest/autorun"
13
11
 
14
12
  ActiveRecord::Base.establish_connection(
15
13
  :adapter => "sqlite3",
@@ -18,10 +16,6 @@ ActiveRecord::Base.establish_connection(
18
16
 
19
17
  load File.join(File.dirname(__FILE__), "support", "schema.rb")
20
18
 
21
-
22
- require 'factories/tenants'
23
-
24
-
25
19
  DatabaseCleaner.strategy = :transaction
26
20
 
27
21
  class ActiveSupport::TestCase
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.beta2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,25 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rails
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.1.0
62
- - - "<"
63
- - !ruby/object:Gem::Version
64
- version: 5.0.0
61
+ version: '0'
65
62
  type: :development
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - ">="
70
67
  - !ruby/object:Gem::Version
71
- version: 3.1.0
72
- - - "<"
73
- - !ruby/object:Gem::Version
74
- version: 5.0.0
68
+ version: '0'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: turn
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,16 +112,16 @@ dependencies:
118
112
  name: sqlite3
119
113
  requirement: !ruby/object:Gem::Requirement
120
114
  requirements:
121
- - - ">="
115
+ - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: '0'
117
+ version: 1.3.13
124
118
  type: :development
125
119
  prerelease: false
126
120
  version_requirements: !ruby/object:Gem::Requirement
127
121
  requirements:
128
- - - ">="
122
+ - - "~>"
129
123
  - !ruby/object:Gem::Version
130
- version: '0'
124
+ version: 1.3.13
131
125
  - !ruby/object:Gem::Dependency
132
126
  name: active_resource_simulator
133
127
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +188,7 @@ extra_rdoc_files: []
194
188
  files:
195
189
  - ".gitignore"
196
190
  - ".simplecov"
191
+ - ".travis.yml"
197
192
  - Gemfile
198
193
  - Gemfile.lock
199
194
  - MIT-LICENSE
@@ -243,12 +238,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
238
  version: '0'
244
239
  required_rubygems_version: !ruby/object:Gem::Requirement
245
240
  requirements:
246
- - - ">"
241
+ - - ">="
247
242
  - !ruby/object:Gem::Version
248
- version: 1.3.1
243
+ version: '0'
249
244
  requirements: []
250
245
  rubyforge_project: remotable
251
- rubygems_version: 2.2.2
246
+ rubygems_version: 2.6.11
252
247
  signing_key:
253
248
  specification_version: 4
254
249
  summary: Binds an ActiveRecord model to a remote resource and keeps the two synchronized