resourcerer 2.0.3 → 2.0.4
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 +5 -5
- data/CHANGELOG.md +7 -0
- data/README.md +24 -6
- data/lib/resourcerer/controller.rb +6 -5
- data/lib/resourcerer/version.rb +1 -1
- data/spec/features/guitars_controller_spec.rb +4 -4
- data/spec/resourcerer/controller_spec.rb +6 -0
- data/spec/spec_helper.rb +0 -2
- data/spec/support/rails_app.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1097af8bba31336db7caf41e84c05587cb1f43fb3561405c28e73f9a034d510d
|
4
|
+
data.tar.gz: fce0ba2273e4632d6ea879d97d3b3de6a66c9ba8398416ad488b8b81ade15bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8cc87a1601df6643f9abb2134b236379f00bca9a39ae088f2670051651b2e422f896c1684602c215d1a98c72576a2f8c46f3310839fd4cc0d2a392990febdc8
|
7
|
+
data.tar.gz: 9e9d1ab0976fcdccb8987b90d2368ae46dc65f1848787a51644e31ba213e16351b77a85739f9b2ab49ab7c02a3cda1687380e3f0dfc876273038c1cc3e2499ce
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
<h1 align="center">
|
2
|
+
Resourcerer
|
3
|
+
<p align="center">
|
4
|
+
<a href="https://github.com/ElMassimo/resourcerer/actions">
|
5
|
+
<img alt="Build Status" src="https://github.com/ElMassimo/resourcerer/workflows/build/badge.svg"/>
|
6
|
+
</a>
|
7
|
+
<a href="https://codeclimate.com/github/ElMassimo/vite_ruby">
|
8
|
+
<img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/vite_ruby/badges/gpa.svg"/>
|
9
|
+
</a>
|
10
|
+
<a href="https://codeclimate.com/github/ElMassimo/resourcerer">
|
11
|
+
<img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/resourcerer/badges/coverage.svg"/>
|
12
|
+
</a>
|
13
|
+
<a href="https://rubygems.org/gems/resourcerer">
|
14
|
+
<img alt="Gem Version" src="https://img.shields.io/gem/v/resourcerer.svg?colorB=e9573f"/>
|
15
|
+
</a>
|
16
|
+
<a href="https://github.com/ElMassimo/resourcerer/blob/master/LICENSE.txt">
|
17
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-428F7E.svg"/>
|
18
|
+
</a>
|
19
|
+
</p>
|
20
|
+
</h1>
|
3
21
|
|
4
22
|
A small library to help you avoid boilerplate for standard CRUD actions, while improving your controllers' readibility.
|
5
23
|
|
@@ -240,14 +258,14 @@ resource :band, assign: ->(band, attrs) { band.set_info(attrs) }
|
|
240
258
|
```
|
241
259
|
|
242
260
|
|
243
|
-
## Advanced Configuration with `
|
261
|
+
## Advanced Configuration with `resourcerer_config`
|
244
262
|
|
245
|
-
You can define configuration presets with the `
|
263
|
+
You can define configuration presets with the `resourcerer_config` method to reuse
|
246
264
|
them later in different resource definitions.
|
247
265
|
|
248
266
|
```ruby
|
249
|
-
|
250
|
-
|
267
|
+
resourcerer_config :cool_find, find: ->{ very_cool_find_code }
|
268
|
+
resourcerer_config :cool_build, build: ->{ very_cool_build_code }
|
251
269
|
|
252
270
|
resource :band, using: [:cool_find, :cool_build]
|
253
271
|
resource :another_band, using: :cool_build
|
@@ -16,19 +16,20 @@ module Resourcerer
|
|
16
16
|
instance_accessor: false, instance_predicate: false
|
17
17
|
end
|
18
18
|
|
19
|
-
def resource(
|
20
|
-
Resource.new(self,
|
19
|
+
def resource(name, **options)
|
20
|
+
Resource.new(self, name, **options).get(self)
|
21
21
|
end
|
22
22
|
|
23
23
|
module ClassMethods
|
24
24
|
# Public: Defines a Resource in a controller Class.
|
25
25
|
#
|
26
|
-
#
|
26
|
+
# name - The name of the method to define.
|
27
|
+
# **options - See Resource#initialize for details.
|
27
28
|
# block - If supplied, the block is executed to provide options.
|
28
29
|
#
|
29
30
|
# Returns the name of the defined resource.
|
30
|
-
def resource(
|
31
|
-
Resource.define(self,
|
31
|
+
def resource(name, **options, &block)
|
32
|
+
Resource.define(self, name, **options, &block)
|
32
33
|
end
|
33
34
|
|
34
35
|
# Public: Defines a Configuration preset that can be reused in different
|
data/lib/resourcerer/version.rb
CHANGED
@@ -18,7 +18,7 @@ RSpec.describe GuitarsController, type: :controller do
|
|
18
18
|
Given {
|
19
19
|
expect(Guitar).to receive(:find).with('ES-335').and_return(guitar)
|
20
20
|
}
|
21
|
-
When { get :show, request_params(id: 'ES-335') }
|
21
|
+
When { get :show, **request_params(id: 'ES-335') }
|
22
22
|
Then { controller.guitar == guitar }
|
23
23
|
end
|
24
24
|
|
@@ -26,7 +26,7 @@ RSpec.describe GuitarsController, type: :controller do
|
|
26
26
|
Given {
|
27
27
|
expect(Guitar).to receive(:find).with('ES-335').and_return(guitar)
|
28
28
|
}
|
29
|
-
When { get :new, request_params(guitar_id: 'ES-335') }
|
29
|
+
When { get :new, **request_params(guitar_id: 'ES-335') }
|
30
30
|
Then { controller.guitar == guitar }
|
31
31
|
end
|
32
32
|
|
@@ -37,7 +37,7 @@ RSpec.describe GuitarsController, type: :controller do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'when build params are used' do
|
40
|
-
When { post :create, request_params(guitar: { name: 'strat' }) }
|
40
|
+
When { post :create, **request_params(guitar: { name: 'strat' }) }
|
41
41
|
Then { controller.guitar.name == 'strat' }
|
42
42
|
end
|
43
43
|
|
@@ -45,7 +45,7 @@ RSpec.describe GuitarsController, type: :controller do
|
|
45
45
|
Given {
|
46
46
|
expect(Guitar).to receive(:find).with('ES-335').and_return(guitar)
|
47
47
|
}
|
48
|
-
When { get :show, request_params(id: 'ES-335') }
|
48
|
+
When { get :show, **request_params(id: 'ES-335') }
|
49
49
|
Then { controller.guitar? == true }
|
50
50
|
end
|
51
51
|
end
|
@@ -39,6 +39,12 @@ RSpec.describe Resourcerer::Controller do
|
|
39
39
|
And { controller.method(:thing=).parameters.size == 1 }
|
40
40
|
end
|
41
41
|
|
42
|
+
context 'incorrect proc options' do
|
43
|
+
Given { resource :thing, build: :thing }
|
44
|
+
When(:usage) { controller_thing }
|
45
|
+
Then { expect(usage).to have_failed(ArgumentError, /Can't handle :build => :thing option/) }
|
46
|
+
end
|
47
|
+
|
42
48
|
context 'memoization' do
|
43
49
|
Given { resource :thing, build: -> { SecureRandom.hex(32) } }
|
44
50
|
Then { controller_thing == controller_thing }
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/rails_app.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resourcerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: simplecov
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.18'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.18'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry-byebug
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files:
|
117
117
|
- README.md
|
118
118
|
files:
|
119
|
+
- CHANGELOG.md
|
119
120
|
- README.md
|
120
121
|
- lib/resourcerer.rb
|
121
122
|
- lib/resourcerer/configuration.rb
|
@@ -131,13 +132,13 @@ homepage: https://github.com/ElMassimo/resourcerer
|
|
131
132
|
licenses:
|
132
133
|
- MIT
|
133
134
|
metadata: {}
|
134
|
-
post_install_message:
|
135
|
+
post_install_message:
|
135
136
|
rdoc_options: []
|
136
137
|
require_paths:
|
137
138
|
- lib
|
138
139
|
required_ruby_version: !ruby/object:Gem::Requirement
|
139
140
|
requirements:
|
140
|
-
- - "
|
141
|
+
- - ">="
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '2.2'
|
143
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -146,9 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
147
|
- !ruby/object:Gem::Version
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
|
-
|
150
|
-
|
151
|
-
signing_key:
|
150
|
+
rubygems_version: 3.2.3
|
151
|
+
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Dry up your controllers by defining resources
|
154
154
|
test_files:
|