fmrest 0.5.1 → 0.5.2

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
  SHA256:
3
- metadata.gz: 79fff3279b30b2bf4ba228646218abc622366aa97f48b1a60eee06d1cea249c8
4
- data.tar.gz: a7b9c8fb36117733176ec355e6e80ef6981ee0e990f1b42fb5721a0baca46ff4
3
+ metadata.gz: f72f9afbde054df91f3abc73b54752c7c19cca4f4ec1c5299ab6cc2edb8978fb
4
+ data.tar.gz: 3ff30b1db7976a76783cbe99c14d9224e5477a8f8d3ba68e8df27adb9d547678
5
5
  SHA512:
6
- metadata.gz: 1e38235d837ddd968164256c78f64bab77ed9464c2f33ee69d4e4f5920d093eeea082b0547f544edc409c5416d470bdd13998b42cb1ac2c501a2f485709ff5a5
7
- data.tar.gz: 813305093670cbe0a684f0d63d079e9a5d799373521099d6229cf22a4cf34d3107167ac5a6b8750bf6abd410bc24f89fd84ea7aacf040e696c8196e57d8f21b4
6
+ metadata.gz: 7aee8096187d1082475e941ae4f4b9509d7b16a8d3f660c0e6989632f1b11ae7d7da5569fd5788862975190810a4dd91643d5f0c66630191bbdea95c2fcd4c7f
7
+ data.tar.gz: 6775c47687abcf09a0a27e06697deaa90021114559675c82d1189420ee58d5181d8e6cac9d6b20628f468223aaed7e8a075838b06b9a818e68eaf8465eddfc05
@@ -1,5 +1,9 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.5.2
4
+
5
+ * Improved support for legacy ActiveModel 4.x
6
+
3
7
  ### 0.5.1
4
8
 
5
9
  * Alias `:username` option as `:account_name` for ginjo-rfm gem
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "spyke"
30
30
  spec.add_development_dependency "webmock"
31
31
  spec.add_development_dependency "pry-byebug"
32
- spec.add_development_dependency "activerecord"
33
- spec.add_development_dependency "sqlite3"
32
+ spec.add_development_dependency "activerecord", ENV["ACTIVE_RECORD_VERSION"]
33
+ spec.add_development_dependency "sqlite3", ENV["SQLITE3_VERSION"]
34
34
  spec.add_development_dependency "mock_redis"
35
35
  spec.add_development_dependency "moneta"
36
36
  spec.add_development_dependency "yard"
@@ -71,7 +71,16 @@ module FmRest
71
71
  # In case of an existing Spyke object return it as is so that we
72
72
  # don't accidentally remove dirty data from associations
73
73
  return super if attributes_or_object.is_a?(::Spyke::Base)
74
- super.tap { |record| record.clear_changes_information }
74
+ super.tap do |record|
75
+ # In ActiveModel 4.x #clear_changes_information is a private
76
+ # method, so we need to call it with send() in that case, but
77
+ # keep calling it normally for AM5+
78
+ if record.respond_to?(:clear_changes_information)
79
+ record.clear_changes_information
80
+ else
81
+ record.send(:clear_changes_information)
82
+ end
83
+ end
75
84
  end
76
85
 
77
86
  def _fmrest_attribute_methods_container
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fmrest/spyke/relation"
4
+ require "fmrest/spyke/validation_error"
4
5
 
5
6
  module FmRest
6
7
  module Spyke
@@ -155,6 +156,14 @@ module FmRest
155
156
  self.mod_id = reloaded.mod_id
156
157
  end
157
158
 
159
+ # ActiveModel 5+ implements this method, so we only needed if we're in
160
+ # the older AM4
161
+ if ActiveModel::VERSION::MAJOR == 4
162
+ def validate!(context = nil)
163
+ valid?(context) || raise_validation_error
164
+ end
165
+ end
166
+
158
167
  private
159
168
 
160
169
  def perform_save_validations(context, options)
@@ -190,6 +199,12 @@ module FmRest
190
199
  end
191
200
  end
192
201
  end
202
+
203
+ # Overwrite ActiveModel's raise_validation_error to use our own class
204
+ #
205
+ def raise_validation_error # :doc:
206
+ raise(ValidationError.new(self))
207
+ end
193
208
  end
194
209
  end
195
210
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FmRest
4
+ module Spyke
5
+ # ActiveModel 4 doesn't include a ValidationError class, which we want to
6
+ # raise when model.validate! fails.
7
+ #
8
+ # In order to break the least amount of code that uses AM5+, while still
9
+ # supporting AM4 we use this proxy class that inherits from
10
+ # AM::ValidationError if it's there, or reimplements it otherwise
11
+ if defined?(::ActiveModel::ValidationError)
12
+ class ValidationError < ::ActiveModel::ValidationError; end
13
+ else
14
+ class ValidationError < StandardError
15
+ attr_reader :model
16
+
17
+ def initialize(model)
18
+ @model = model
19
+ errors = @model.errors.full_messages.join(", ")
20
+ super("Invalid model: #{errors}")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FmRest
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carbajal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -240,6 +240,7 @@ files:
240
240
  - lib/fmrest/spyke/model/uri.rb
241
241
  - lib/fmrest/spyke/portal.rb
242
242
  - lib/fmrest/spyke/relation.rb
243
+ - lib/fmrest/spyke/validation_error.rb
243
244
  - lib/fmrest/token_store.rb
244
245
  - lib/fmrest/token_store/active_record.rb
245
246
  - lib/fmrest/token_store/base.rb