fmrest-spyke 0.22.0 → 0.23.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f606d5d9365cdd3e3dfdbd9eca86f03f95c950ad793d695b692c3177c2e695e
4
- data.tar.gz: 17b268ee1f2ed93de74f624e90044dd60407c56c47b05b91cba1e5f634aaf835
3
+ metadata.gz: f9956beb060ba224625cbc91c6d15169fcc24002d8868c8736fa8ee474d64afc
4
+ data.tar.gz: 9991f5c849f766a9a0660c3072f2ac6cb677d311888a9d536ecbe0c0c18dfeb5
5
5
  SHA512:
6
- metadata.gz: e74e883a25912e28813e60a18ec74f0ea51e2ec0e160706dec7a8c056b5a3e98d6003b01b9cafe86495e19a4d81a9d5ea45ff842a58858ab150eec286dfbb4af
7
- data.tar.gz: babc9b457c7260fb4332aeeee2ba8b442161ac26a42d840c1410ba4ce0676e595ab7ca2de82c51eb8df6c5276b3c828cf364356b2f9b1aeed2a3d4320986635a
6
+ metadata.gz: b11f7d8f9e582185534aec7ba8497d2f74a371a8bc5322e4f48849ec8fe84f841bca705cf0cfb884b8f96298c677883ccaaf98e5816a7923b414a4dd6f815bc3
7
+ data.tar.gz: 41063c5e3993b525131ab84c27eda309eadfec7fe5ba4c0458605221a707e1e60ce87e3ba7f6737476e7cdb2b735fe686aeba68064b66e130b905a5d6550e3d3
data/.yardopts CHANGED
@@ -1,5 +1,6 @@
1
1
  --markup markdown
2
2
  --plugin activesupport-concern
3
- lib/**/*.rb
3
+ --exclude lib/generators/*
4
4
  -
5
+ lib/**/*.rb
5
6
  docs/*
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.23.0
4
+
5
+ * Add `find_one!` (aliased as `first!`) exception-raising method
6
+ * Add mapping of API exceptions to HTTP responses in Rails
7
+
8
+ ### 0.22.0
9
+
10
+ * Add `fmrest-rails` gem with Rails integration (initializer, generators)
11
+
3
12
  ### 0.21.0
4
13
 
5
14
  * Support for Spyke 7 and Faraday 2
@@ -18,10 +18,6 @@ module FmRest
18
18
  class_attribute :default_limit, instance_accessor: false, instance_predicate: false
19
19
 
20
20
  class_attribute :default_sort, instance_accessor: false, instance_predicate: false
21
-
22
- # Whether to raise an FmRest::APIError::NoMatchingRecordsError when a
23
- # _find request has no results
24
- class_attribute :raise_on_no_matching_records, instance_accessor: false, instance_predicate: false
25
21
  end
26
22
 
27
23
  class_methods do
@@ -42,10 +38,14 @@ module FmRest
42
38
  # options, as well as using the appropriate HTTP method/URL depending
43
39
  # on whether there's a query present in the current scope.
44
40
  #
41
+ # @option options [Boolean] :raise_on_no_matching_records whether to
42
+ # raise `APIError::NoMatchingRecordsError` when no records match (FM
43
+ # error 401). If not given it returns an empty resultset.
44
+ #
45
45
  # @example
46
46
  # Person.query(first_name: "Stefan").fetch # -> POST .../_find
47
47
  #
48
- def fetch
48
+ def fetch(options = {})
49
49
  if current_scope.has_query?
50
50
  scope = extend_scope_with_fm_params(current_scope, prefixed: false)
51
51
  scope = scope.where(query: scope.query_params)
@@ -60,9 +60,9 @@ module FmRest
60
60
  # nothing matches a _find request, so we need to catch it in order
61
61
  # to provide sane behavior (i.e. return an empty resultset)
62
62
  begin
63
- current_scope.has_query? ? scoped_request(:post) : super
63
+ current_scope.has_query? ? scoped_request(:post) : super()
64
64
  rescue FmRest::APIError::NoMatchingRecordsError => e
65
- raise e if raise_on_no_matching_records
65
+ raise e if options[:raise_on_no_matching_records]
66
66
  ::Spyke::Result.new({})
67
67
  end
68
68
  ensure
@@ -276,13 +276,15 @@ module FmRest
276
276
  # Finds a single instance of the model by forcing limit = 1, or simply
277
277
  # fetching the record by id if the primary key was set
278
278
  #
279
+ # @option (see FmRest::Spyke::Model::ORM.fetch)
280
+ #
279
281
  # @return [FmRest::Spyke::Base]
280
- def find_one
282
+ def find_one(options = {})
281
283
  @find_one ||=
282
284
  if primary_key_set?
283
- without_collection_params { super }
285
+ without_collection_params { super() }
284
286
  else
285
- klass.new_collection_from_result(limit(1).fetch).first
287
+ klass.new_collection_from_result(limit(1).fetch(options)).first
286
288
  end
287
289
  rescue ::Spyke::ConnectionError => error
288
290
  fallback_or_reraise(error, default: nil)
@@ -290,6 +292,18 @@ module FmRest
290
292
  alias_method :first, :find_one
291
293
  alias_method :any, :find_one
292
294
 
295
+ # Same as `#find_one`, but raises `APIError::NoMatchingRecordsError` when
296
+ # no records match.
297
+ # Equivalent to calling `find_one(raise_on_no_matching_records: true)`.
298
+ #
299
+ # @option (see FmRest::Spyke::Model::ORM.fetch)
300
+ #
301
+ # @return [FmRest::Spyke::Base]
302
+ def find_one!(options = {})
303
+ find_one(options.merge(raise_on_no_matching_records: true))
304
+ end
305
+ alias_method :first!, :find_one!
306
+
293
307
  # Yields each batch of records that was found by the find options.
294
308
  #
295
309
  # NOTE: By its nature, batch processing is subject to race conditions if
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest-spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carbajal
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.22.0
19
+ version: 0.23.0
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.22.0
26
+ version: 0.23.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: spyke
29
29
  requirement: !ruby/object:Gem::Requirement