spyke 7.0.0 → 7.1.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: 6d4ddb1fd345f49012040e7f462f63003f1a1ff57ddc7173bb14cb5ca03c5bed
4
- data.tar.gz: bd1674887dc87a21ca4bad570d7375299add2312a3af7183d466078b6510367f
3
+ metadata.gz: afa71f6b303e245253b8b9a3948efce3a294caee1c7732d745e21112af09adbb
4
+ data.tar.gz: 95cb5cfaeb6d244c9a1bd40a812ae1cc3c46bb9b878cf995ce26272066da3fb5
5
5
  SHA512:
6
- metadata.gz: c83ab8e4a46d6afff3624e7a1b2baccef8b5fe97c875271268c0dd7c51b65a76e85e019cf4ed749b06ef5414566203f6e618e22aaafe12c6494ac39f113abc75
7
- data.tar.gz: c2f0f2bb8bbce8cb8047be70f0f946305efdff464f6c0e4ad4a46b13cfc2fba19f87ff98c8139102a107e9c64e45035246f5f66d055ed7402772685ca16d348e
6
+ metadata.gz: ece326bbc2bcf5f56413c8358d739604e4f1699eb1f6f244494bbbb729d65aa19132c196240cfab6d8755c04133bf2781c6fce1a82fea4c21b2d958149892431
7
+ data.tar.gz: e68a9130999bd24160a183171bcaa21f39992c64d9044adee457a3a828ad55628db061562257e170fc8ff197934339735925dd9330ba06deb9ff421cd1657986
data/.circleci/config.yml CHANGED
@@ -79,7 +79,7 @@ workflows:
79
79
  alias: Rails 7
80
80
  parameters:
81
81
  rails_version: ["~> 7.0"]
82
- ruby_version: ["2.7.5", "3.0.3", "3.1.1"]
82
+ ruby_version: ["2.7.5", "3.0.3", "3.1.1", "3.2.0"]
83
83
  faraday_version: ["< 2.0", ">= 2.0"]
84
84
  - coverage:
85
85
  requires: ["Rails 4", "Rails 5", "Rails 6", "Rails 7"]
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  <div align="center">
2
- <img src="spyke.svg" width="250" alt="Spyke" />
2
+ <img src="spyke.svg#gh-light-mode-only" width="250" alt="Spyke" />
3
+ <img src="spyke-dark.svg#gh-dark-mode-only" width="250" alt="Spyke" />
3
4
  <br/>
4
5
  Interact with remote <strong>REST services</strong> in an <strong>ActiveRecord-like</strong> manner.
5
6
  <br /><br />
@@ -241,5 +242,5 @@ Completed 200 OK in 75ms (Views: 64.6ms | Spyke: 40.3ms | ActiveRecord: 0ms)
241
242
 
242
243
  ### Other examples
243
244
 
244
- For more examples of how Spyke can be used, check out [fixtures.rb](https://github.com/balvig/spyke/blob/master/test/support/fixtures.rb) and the
245
- [test suite](https://github.com/balvig/spyke/tree/master/test).
245
+ For more examples of how Spyke can be used, check out [fixtures.rb](https://github.com/balvig/spyke/blob/main/test/support/fixtures.rb) and the
246
+ [test suite](https://github.com/balvig/spyke/tree/main/test).
data/lib/spyke/orm.rb CHANGED
@@ -25,9 +25,14 @@ module Spyke
25
25
  callback_methods[callback]
26
26
  end
27
27
 
28
- def find(id)
29
- raise ResourceNotFound if id.blank?
30
- where(primary_key => id).find_one || raise(ResourceNotFound)
28
+ def find(id = nil, &block)
29
+ if block_given?
30
+ all.find_some.find(&block)
31
+ else
32
+ raise ResourceNotFound if id.blank?
33
+
34
+ where(primary_key => id).find_one || raise(ResourceNotFound)
35
+ end
31
36
  end
32
37
 
33
38
  def fetch
@@ -41,8 +41,8 @@ module Spyke
41
41
  end
42
42
 
43
43
  # Overrides Enumerable find
44
- def find(id)
45
- scoping { klass.find(id) }
44
+ def find(id = nil, &block)
45
+ scoping { klass.find(id, &block) }
46
46
  end
47
47
 
48
48
  def find_one
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '7.0.0'
2
+ VERSION = '7.1.1'
3
3
  end
data/spyke-dark.svg ADDED
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="180" height="70" viewBox="0 0 180 70" xml:space="preserve">
4
+ <desc>Created with Fabric.js 4.6.0</desc>
5
+ <defs>
6
+ </defs>
7
+ <g transform="matrix(0.83 0 0 0.8 31.5 36)" id="6X9shhn5tjKNE9PTybgYf" >
8
+ <path style="stroke: rgb(252,0,51); stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-opacity: 0; fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(0, 0)" d="M -19.8939 12.44496 L 19.8939 -12.44496 L 19.8939 12.44496" stroke-linecap="round" />
9
+ </g>
10
+ <g transform="matrix(1 0 0 1 48 26)" id="qfktuO63U17zxOoFBmSIk" >
11
+ <path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
12
+ </g>
13
+ <g transform="matrix(1 0 0 1 48 45)" id="CoP4qh0-57aRlWWd5gWpq" >
14
+ <path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
15
+ </g>
16
+ <g transform="matrix(1 0 0 1 16 45)" id="0AYtWnywiPmVyWgmd3Nax" >
17
+ <path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
18
+ </g>
19
+ <g transform="matrix(1.01 0 0 1.02 111 35.5)" id="0CUp8y4TleogKJWzIB5ti" >
20
+ <path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-115.71, -44.78)" d="M 72.39608287 59.952 L 72.39608287 59.952 Q 69.77208287 59.952 67.88608287 59.1525 Q 66.00008287 58.353 64.99558287 57.3075 Q 63.99108287 56.262 63.99108287 55.524 L 63.99108287 55.524 Q 63.99108287 55.196 64.17558287 54.827 Q 64.36008287 54.458 64.64708287 54.2325 Q 64.93408287 54.007 65.22108287 54.007 L 65.22108287 54.007 Q 65.63108287 54.007 66.06158287 54.5195 Q 66.49208287 55.032 67.20958287 55.7085 Q 67.92708287 56.385 69.11608287 56.8975 Q 70.30508287 57.41 72.23208287 57.41 L 72.23208287 57.41 Q 74.15908287 57.41 75.53258287 56.7745 Q 76.90608287 56.139 77.62358287 54.8885 Q 78.34108287 53.638 78.34108287 51.752 L 78.34108287 51.752 Q 78.34108287 49.784 77.60308287 48.5745 Q 76.86508287 47.365 75.65558287 46.6065 Q 74.44608287 45.848 73.01108287 45.2945 Q 71.57608287 44.741 70.12058287 44.1875 Q 68.66508287 43.634 67.45558287 42.7935 Q 66.24608287 41.953 65.48758287 40.5795 Q 64.72908287 39.206 64.72908287 37.074 L 64.72908287 37.074 Q 64.72908287 34.819 65.54908287 33.384 Q 66.36908287 31.949 67.66058287 31.129 Q 68.95208287 30.309 70.46908287 29.9605 Q 71.98608287 29.612 73.42108287 29.612 L 73.42108287 29.612 Q 74.56908287 29.612 75.77858287 29.7965 Q 76.98808287 29.981 78.01308287 30.309 Q 79.03808287 30.637 79.67358287 31.088 Q 80.30908287 31.539 80.30908287 32.113 L 80.30908287 32.113 Q 80.30908287 32.4 80.16558287 32.7485 Q 80.02208287 33.097 79.77608287 33.3635 Q 79.53008287 33.63 79.12008287 33.63 L 79.12008287 33.63 Q 78.75108287 33.63 78.09508287 33.2405 Q 77.43908287 32.851 76.31158287 32.4615 Q 75.18408287 32.072 73.38008287 32.072 L 73.38008287 32.072 Q 71.90408287 32.072 70.53058287 32.5025 Q 69.15708287 32.933 68.29608287 33.958 Q 67.43508287 34.983 67.43508287 36.828 L 67.43508287 36.828 Q 67.43508287 38.468 68.19358287 39.4725 Q 68.95208287 40.477 70.16158287 41.092 Q 71.37108287 41.707 72.80608287 42.2195 Q 74.24108287 42.732 75.69658287 43.3675 Q 77.15208287 44.003 78.36158287 44.9665 Q 79.57108287 45.93 80.30908287 47.488 Q 81.04708287 49.046 81.04708287 51.506 L 81.04708287 51.506 Q 81.04708287 54.417 79.94008287 56.2825 Q 78.83308287 58.148 76.88558287 59.05 Q 74.93808287 59.952 72.39608287 59.952 Z M 87.23808287 59.665 L 87.23808287 59.665 Q 86.70508287 59.665 86.29508287 59.3985 Q 85.88508287 59.132 85.88508287 58.599 L 85.88508287 58.599 L 85.88508287 30.678 Q 85.88508287 30.268 86.19258287 30.0015 Q 86.50008287 29.735 87.03308287 29.694 L 87.03308287 29.694 L 94.57708287 29.694 Q 96.95508287 29.694 98.88208287 30.555 Q 100.80908287 31.416 101.91608287 33.3225 Q 103.02308287 35.229 103.02308287 38.386 L 103.02308287 38.386 L 103.02308287 38.796 Q 103.02308287 41.994 101.89558287 43.9005 Q 100.76808287 45.807 98.82058287 46.668 Q 96.87308287 47.529 94.49508287 47.529 L 94.49508287 47.529 L 88.59108287 47.529 L 88.59108287 58.599 Q 88.59108287 59.132 88.16058287 59.3985 Q 87.73008287 59.665 87.23808287 59.665 Z M 88.59108287 32.195 L 88.59108287 45.192 L 94.49508287 45.192 Q 97.24208287 45.192 98.77958287 43.6545 Q 100.31708287 42.117 100.31708287 38.919 L 100.31708287 38.919 L 100.31708287 38.427 Q 100.31708287 35.229 98.77958287 33.712 Q 97.24208287 32.195 94.49508287 32.195 L 94.49508287 32.195 L 88.59108287 32.195 Z M 115.15908287 59.665 L 115.15908287 59.665 Q 114.66708287 59.665 114.23658287 59.3985 Q 113.80608287 59.132 113.80608287 58.599 L 113.80608287 58.599 L 113.80608287 48.185 Q 113.80608287 47.98 113.76508287 47.857 L 113.76508287 47.857 L 105.27808287 31.58 Q 105.15508287 31.334 105.11408287 31.1495 Q 105.07308287 30.965 105.07308287 30.842 L 105.07308287 30.842 Q 105.07308287 30.473 105.29858287 30.227 Q 105.52408287 29.981 105.87258287 29.8375 Q 106.22108287 29.694 106.54908287 29.694 L 106.54908287 29.694 Q 106.87708287 29.694 107.14358287 29.899 Q 107.41008287 30.104 107.61508287 30.514 L 107.61508287 30.514 L 115.15908287 45.479 L 122.74408287 30.514 Q 122.99008287 30.104 123.25658287 29.899 Q 123.52308287 29.694 123.81008287 29.694 L 123.81008287 29.694 Q 124.17908287 29.694 124.50708287 29.8375 Q 124.83508287 29.981 125.06058287 30.227 Q 125.28608287 30.473 125.28608287 30.842 L 125.28608287 30.842 Q 125.28608287 30.965 125.24508287 31.1495 Q 125.20408287 31.334 125.12208287 31.58 L 125.12208287 31.58 L 116.59408287 47.857 Q 116.51208287 47.98 116.51208287 48.185 L 116.51208287 48.185 L 116.51208287 58.599 Q 116.51208287 59.132 116.10208287 59.3985 Q 115.69208287 59.665 115.15908287 59.665 Z M 130.49308287 59.665 L 130.49308287 59.665 Q 129.96008287 59.665 129.55008287 59.3985 Q 129.14008287 59.132 129.14008287 58.599 L 129.14008287 58.599 L 129.14008287 30.678 Q 129.14008287 30.145 129.55008287 29.9195 Q 129.96008287 29.694 130.49308287 29.694 L 130.49308287 29.694 Q 130.98508287 29.694 131.41558287 29.9195 Q 131.84608287 30.145 131.84608287 30.678 L 131.84608287 30.678 L 131.84608287 45.192 L 143.69508287 30.104 Q 143.98208287 29.694 144.55608287 29.694 L 144.55608287 29.694 Q 144.88408287 29.694 145.23258287 29.899 Q 145.58108287 30.104 145.80658287 30.4115 Q 146.03208287 30.719 146.03208287 31.088 L 146.03208287 31.088 Q 146.03208287 31.211 145.99108287 31.3955 Q 145.95008287 31.58 145.82708287 31.703 L 145.82708287 31.703 L 137.01208287 42.65 L 147.09808287 57.82 Q 147.26208287 58.066 147.26208287 58.353 L 147.26208287 58.353 Q 147.26208287 58.722 147.03658287 59.0295 Q 146.81108287 59.337 146.46258287 59.5215 Q 146.11408287 59.706 145.70408287 59.706 L 145.70408287 59.706 Q 145.41708287 59.706 145.15058287 59.5625 Q 144.88408287 59.419 144.67908287 59.132 L 144.67908287 59.132 L 135.20808287 44.905 L 131.84608287 49.169 L 131.84608287 58.599 Q 131.84608287 59.132 131.41558287 59.3985 Q 130.98508287 59.665 130.49308287 59.665 Z M 166.40908287 59.665 L 151.81308287 59.665 Q 151.36208287 59.665 150.97258287 59.3985 Q 150.58308287 59.132 150.58308287 58.599 L 150.58308287 58.599 L 150.58308287 30.719 Q 150.58308287 30.227 150.97258287 29.9605 Q 151.36208287 29.694 151.81308287 29.694 L 151.81308287 29.694 L 166.40908287 29.694 Q 166.94208287 29.694 167.18808287 30.0835 Q 167.43408287 30.473 167.43408287 30.883 L 167.43408287 30.883 Q 167.43408287 31.416 167.16758287 31.8055 Q 166.90108287 32.195 166.40908287 32.195 L 166.40908287 32.195 L 153.28908287 32.195 L 153.28908287 43.47 L 159.72608287 43.47 Q 160.21808287 43.47 160.48458287 43.839 Q 160.75108287 44.208 160.75108287 44.7 L 160.75108287 44.7 Q 160.75108287 45.069 160.50508287 45.438 Q 160.25908287 45.807 159.72608287 45.807 L 159.72608287 45.807 L 153.28908287 45.807 L 153.28908287 57.164 L 166.40908287 57.164 Q 166.90108287 57.164 167.16758287 57.533 Q 167.43408287 57.902 167.43408287 58.435 L 167.43408287 58.435 Q 167.43408287 58.886 167.18808287 59.2755 Q 166.94208287 59.665 166.40908287 59.665 L 166.40908287 59.665 Z" stroke-linecap="round" />
21
+ </g>
22
+ </svg>
data/spyke.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
@@ -92,6 +92,14 @@ module Spyke
92
92
  assert_equal 'Fish', recipe.groups.first.name
93
93
  end
94
94
 
95
+ def test_find_with_block
96
+ stub_request(:get, 'http://sushi.com/recipes/1/groups').to_return_json(result: [{ name: 'Fish' }, { name: 'Fruit' }, { name: 'Bread' }])
97
+
98
+ recipe = Recipe.new(id: 1)
99
+
100
+ assert_equal 'Fruit', recipe.groups.find { |g| g.name == 'Fruit' }.name
101
+ end
102
+
95
103
  def test_nil_has_one_association
96
104
  stub_request(:get, 'http://sushi.com/recipes/1/image')
97
105
 
data/test/orm_test.rb CHANGED
@@ -14,6 +14,16 @@ module Spyke
14
14
  assert_equal 'Bob', user.name
15
15
  end
16
16
 
17
+ def test_find_with_block
18
+ stub_request(:get, 'http://sushi.com/users').to_return_json(result: [{ id: 1, name: 'Bob' }, id: 2, name: 'Alice'])
19
+
20
+ user = User.find do |u|
21
+ u.name == 'Bob'
22
+ end
23
+
24
+ assert_equal 'Bob', user.name
25
+ end
26
+
17
27
  def test_reload
18
28
  stub_request(:get, 'http://sushi.com/recipes/1').to_return_json(result: { id: 1, title: 'Sushi' })
19
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-26 00:00:00.000000000 Z
11
+ date: 2023-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -257,8 +257,7 @@ dependencies:
257
257
  description: Interact with REST services in an ActiveRecord-like manner
258
258
  email:
259
259
  - jens@balvig.com
260
- executables:
261
- - console
260
+ executables: []
262
261
  extensions: []
263
262
  extra_rdoc_files: []
264
263
  files:
@@ -295,6 +294,7 @@ files:
295
294
  - lib/spyke/scope_registry.rb
296
295
  - lib/spyke/scoping.rb
297
296
  - lib/spyke/version.rb
297
+ - spyke-dark.svg
298
298
  - spyke.gemspec
299
299
  - spyke.svg
300
300
  - test/activemodel_dirty_test.rb