fmrest-spyke 0.21.0 → 0.23.1

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: 0d82defdc68f56e1e3e2a9f4d7e2fb09fcfe85fbfd4d839a72d07e13328301f0
4
- data.tar.gz: 80055c0eee52a2acc819c92d737ddb1eeb758f99b19f3864468379b10f461465
3
+ metadata.gz: a4e30c2055c096479e79ba9c5d4fd2d5376ba854b9295cb8936e81a86fc4e231
4
+ data.tar.gz: d18a1d36aca81732e4e90d67a13575d5e891f6504e48f8e7df529d23acaf576d
5
5
  SHA512:
6
- metadata.gz: 88b6edba4e6f98d53ddad102a7c9ae9d80589396487b623a08d0ec0470cac42c9d97fddabe0c91d87d30b6aa9003b34aa888f7d4e44680675b7abfca9fd53ed3
7
- data.tar.gz: 9f28167114c3c614705abd21256bbd53d30c11766802b98dc776729f5609a3742bf789a1fd63635745b186c61b49a1f397fda4af30820f935df5254339c4410d
6
+ metadata.gz: 4e1748cc9448aa032c4683ba809a7298e3f6a9ef4530ac7811ee0d24cabe9911ddd447f4773af06919a5bbb0c08fd85ae4e5908ee14f87f88f7fd6ae7778e05c
7
+ data.tar.gz: b8e6828dcf31aeb7a6443483d560e529833606b0a55e2454532db855d4d3bef9e4357aaa3c1bff073015df0d2370047826ba38f555631ed9a0ac8f4add2a9609
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,18 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.23.1
4
+
5
+ * Fix crash when booting in Rails and `config/fmrest.yml` didn't exist
6
+
7
+ ### 0.23.0
8
+
9
+ * Add `find_one!` (aliased as `first!`) exception-raising method
10
+ * Add mapping of API exceptions to HTTP responses in Rails
11
+
12
+ ### 0.22.0
13
+
14
+ * Add `fmrest-rails` gem with Rails integration (initializer, generators)
15
+
3
16
  ### 0.21.0
4
17
 
5
18
  * Support for Spyke 7 and Faraday 2
data/README.md CHANGED
@@ -19,13 +19,14 @@ Need Ruby or FileMaker consulting? Contact us at
19
19
 
20
20
  ## Gems
21
21
 
22
- The `fmrest` gem is a wrapper for two other gems:
22
+ The `fmrest` gem is a wrapper for these gems:
23
23
 
24
24
  * `fmrest-spyke`, providing an ActiveRecord-like ORM library built on top
25
25
  of `fmrest-core` and [Spyke](https://github.com/balvig/spyke).
26
26
  * `fmrest-core`, providing the core
27
27
  [Faraday](https://github.com/lostisland/faraday) connection builder, session
28
28
  management, and other core utilities.
29
+ * `fmrest-rails`, providing Rails integration.
29
30
 
30
31
  In addition, the optional `fmrest-cloud` gem adds support for FileMaker Cloud.
31
32
  See the [main document on connecting to FileMaker
@@ -42,6 +43,12 @@ gem 'fmrest'
42
43
  gem 'fmrest-cloud'
43
44
  ```
44
45
 
46
+ If you're using Rails you can now run:
47
+
48
+ ```
49
+ rails generate fmrest:config
50
+ ```
51
+
45
52
  ## Simple example
46
53
 
47
54
  ```ruby
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest-spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carbajal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-12 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fmrest-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.21.0
19
+ version: 0.23.1
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.21.0
26
+ version: 0.23.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: spyke
29
29
  requirement: !ruby/object:Gem::Requirement