rails_stuff 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +14 -0
- data/lib/rails_stuff/railtie.rb +6 -3
- data/lib/rails_stuff/resources_controller/actions.rb +6 -6
- data/lib/rails_stuff/strong_parameters.rb +6 -0
- data/lib/rails_stuff/url_for_keeping_params.rb +9 -0
- data/lib/rails_stuff/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c06d5c2ac89db00eb5633892fdf69367b9e9ced5
|
4
|
+
data.tar.gz: f0ba6b7bf860d9bb0931f9b8cb547df9f016ba7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b51f09107487046881c04e942df7bb649471944cc50b99cba5d33209b1689957310671393034e74ca5d210252152bcf2992204eb0a8cdcf68200616211ba2f18
|
7
|
+
data.tar.gz: 0eb990db1e6304d7126c92bd8e6a8759fad4d4eb798a19c53ae75219fa58c0294dc1e60a086dc5f77d6cdde6894fb1e05be563da19d898735815e09d24ff8d71
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -30,6 +30,10 @@ Collection of useful modules for Rails.
|
|
30
30
|
- __[RedisStorage](#redisstorage)__
|
31
31
|
Simple way to store collections in key-value storage. With scoping and
|
32
32
|
key generation.
|
33
|
+
- __[StrongParameters](#strongparameters)__
|
34
|
+
`require_permitted` helper.
|
35
|
+
- __UrlFor__
|
36
|
+
`#url_for_keeping_params` merges passed options with request's query params.
|
33
37
|
|
34
38
|
#### Helpers:
|
35
39
|
|
@@ -293,6 +297,16 @@ Model.next_id or Model.next_id(['composite', 'scope'])
|
|
293
297
|
Model.reset_id_seq or Model.reset_id_seq(['composite', 'scope'])
|
294
298
|
```
|
295
299
|
|
300
|
+
### StrongParameters
|
301
|
+
|
302
|
+
`#require_permitted` ensures that required values are scalar:
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
params.require_permitted(:access_token, :refresh_token)
|
306
|
+
# instead of
|
307
|
+
params.permit(:access_token, :refresh_token).require(:access_token, :refresh_token)
|
308
|
+
```
|
309
|
+
|
296
310
|
### Helpers
|
297
311
|
|
298
312
|
Include helper module into `ApplicationHelper`.
|
data/lib/rails_stuff/railtie.rb
CHANGED
@@ -10,6 +10,8 @@ module RailsStuff
|
|
10
10
|
-> { ResourcesController.kaminari! if defined?(::Kaminari) },
|
11
11
|
],
|
12
12
|
sort_scope: -> { defined?(::HasScope) && :controller },
|
13
|
+
strong_parameters: -> { defined?(ActionController::Parameters) && :require },
|
14
|
+
url_for_keeping_params: -> { defined?(ActionDispatch::Routing) && :require },
|
13
15
|
}
|
14
16
|
|
15
17
|
class << self
|
@@ -34,12 +36,13 @@ module RailsStuff
|
|
34
36
|
def setup_modules!
|
35
37
|
modules_to_load = load_modules || MODULES.keys
|
36
38
|
MODULES.slice(*modules_to_load).each do |m, (type, init)|
|
37
|
-
m = const_get m.to_s.camelize
|
38
39
|
case type.respond_to?(:call) ? type.call : type
|
39
40
|
when :controller
|
40
|
-
RailsStuff.base_controller.extend m
|
41
|
+
RailsStuff.base_controller.extend const_get(m.to_s.camelize)
|
41
42
|
when :model
|
42
|
-
RailsStuff.base_model.extend m
|
43
|
+
RailsStuff.base_model.extend const_get(m.to_s.camelize)
|
44
|
+
when :require
|
45
|
+
require "rails_stuff/#{m}"
|
43
46
|
end
|
44
47
|
init.try!(:call)
|
45
48
|
end
|
@@ -6,25 +6,25 @@ module RailsStuff
|
|
6
6
|
build_resource
|
7
7
|
end
|
8
8
|
|
9
|
-
def create(options = {})
|
9
|
+
def create(options = {}, &block)
|
10
10
|
if create_resource
|
11
11
|
options[:location] = after_save_url
|
12
12
|
end
|
13
|
-
respond_with(resource, options)
|
13
|
+
respond_with(resource, options, &block)
|
14
14
|
end
|
15
15
|
|
16
|
-
def update(options = {})
|
16
|
+
def update(options = {}, &block)
|
17
17
|
if update_resource
|
18
18
|
options[:location] = after_save_url
|
19
19
|
end
|
20
|
-
respond_with(resource, options)
|
20
|
+
respond_with(resource, options, &block)
|
21
21
|
end
|
22
22
|
|
23
|
-
def destroy(options = {})
|
23
|
+
def destroy(options = {}, &block)
|
24
24
|
resource.destroy
|
25
25
|
options[:location] = after_destroy_url
|
26
26
|
flash_errors!
|
27
|
-
respond_with(resource, options)
|
27
|
+
respond_with(resource, options, &block)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
ActionDispatch::Routing::UrlFor.class_eval do
|
2
|
+
# Safe way to generate url keeping params from request.
|
3
|
+
#
|
4
|
+
# It requires `request` to be present. Please don't use it in mailers
|
5
|
+
# or in other places where it's not supposed to.
|
6
|
+
def url_for_keeping_params(params)
|
7
|
+
url_for params: request.query_parameters.merge(params)
|
8
|
+
end
|
9
|
+
end
|
data/lib/rails_stuff/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_stuff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".rspec"
|
64
64
|
- ".rubocop.yml"
|
65
65
|
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE.txt
|
68
69
|
- README.md
|
@@ -94,9 +95,11 @@ files:
|
|
94
95
|
- lib/rails_stuff/resources_controller/sti_helpers.rb
|
95
96
|
- lib/rails_stuff/sort_scope.rb
|
96
97
|
- lib/rails_stuff/statusable.rb
|
98
|
+
- lib/rails_stuff/strong_parameters.rb
|
97
99
|
- lib/rails_stuff/test_helpers/rails.rb
|
98
100
|
- lib/rails_stuff/test_helpers/response.rb
|
99
101
|
- lib/rails_stuff/types_tracker.rb
|
102
|
+
- lib/rails_stuff/url_for_keeping_params.rb
|
100
103
|
- lib/rails_stuff/version.rb
|
101
104
|
- rails_stuff.gemspec
|
102
105
|
homepage: https://github.com/printercu/rails_stuff
|