allowable 1.0.2 → 1.1.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -6
- data/lib/allowable.rb +8 -0
- data/lib/allowable/allowable.rb +21 -5
- data/lib/allowable/core_ext/hash.rb +2 -0
- data/lib/allowable/railtie.rb +5 -3
- data/lib/allowable/version.rb +1 -1
- metadata +2 -4
- data/lib/allowable/allow.rb +0 -17
- data/lib/allowable/forbid.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efa2ac1dd6e30afa5a91724b2eec484f143c978e
|
4
|
+
data.tar.gz: 68b89445aa30b0b245210f4e5eb0da1fffef917c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a7f2d873f4c981ec505373e842e19a1591545b5152bd63d7fea1342b48962426c699896c95d8167e95fbd49b634caab02908573e9209faa4f85ea324d78bf0a
|
7
|
+
data.tar.gz: f646f7720e71e9b444aefc5d0dbff1f4074e6a291042406f64f42df12efb4198924476e5738a6aa2c6953a9b1991ed415616ac73b611fc2f7d0e4c7deece38bd
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# Changelog
|
2
|
+
1.1.0
|
3
|
+
-----
|
4
|
+
* Include in `ActiveSupport::HashWithIndifferentAccess`, which also expands Rails compatibility down to version 3.2.
|
5
|
+
* Expand testing with `Appraisal` gem. Test against Rails 3.2, 4.2, and 5.1, and Ruby >= 1.9.3
|
6
|
+
* Consolidate all methods into `Allowable` module, remove `Allowable::Allow` and `Allowable::Forbid`
|
7
|
+
|
2
8
|
1.0.2
|
3
9
|
-----
|
4
10
|
* Match array values e.g. `{ key: ['val_one', 'val_two'] }.forbid(key: ['val_one', 'val_two']) # => {}` TODO: Slows down benchmarked performance of `#allow`, need to figure out why
|
data/README.md
CHANGED
@@ -42,9 +42,9 @@ hash.forbid!(two: 'two') # => {}
|
|
42
42
|
|
43
43
|
hash # => {}
|
44
44
|
|
45
|
-
hash.merge(one: ['one', 1]) # => { one: ["one", 1]
|
45
|
+
hash.merge(one: ['one', 1]).forbid(one: 'one') # => { one: ["one", 1] }
|
46
46
|
|
47
|
-
hash.merge(one: ['one', 1]).forbid(one: ['one', 1]) # => {
|
47
|
+
hash.merge(one: ['one', 1]).forbid(one: ['one', 1]) # => {}
|
48
48
|
```
|
49
49
|
|
50
50
|
#### Type sensitive for `Hash`
|
@@ -59,7 +59,9 @@ hash.forbid('one' => 'one') # => { "two" => "two" }
|
|
59
59
|
|
60
60
|
## With Rails and strong parameters
|
61
61
|
|
62
|
-
|
62
|
+
If `ActiveSupport::HashWithIndifferentAccess` is defined it will receive the methods. This automatically makes them available in `ActionController::Parameters` for Rails 4 and 3. Rails 3 requires that you add `gem 'strong_parameters'` to your `Gemfile` in order to use strong parameters.
|
63
|
+
|
64
|
+
Starting in Rails 5, `ActionController::Parameters` no longer inherits from `ActiveSupport::HashWithIndifferentAccess`. When `allowable` is added to the `Gemfile` in a Rails 5+ project, load hooks will add the methods directly to `ActionController::Parameters` so you can use them with your strong parameters.
|
63
65
|
|
64
66
|
```ruby
|
65
67
|
def user_params
|
@@ -67,7 +69,7 @@ def user_params
|
|
67
69
|
end
|
68
70
|
```
|
69
71
|
|
70
|
-
#### Type insensitive for `HashWithIndifferentAccess`
|
72
|
+
#### Type insensitive for `HashWithIndifferentAccess` and `ActionController::Parameters`
|
71
73
|
```ruby
|
72
74
|
params = ActionController::Parameters.new('one' => 'one', 'two' => 'two').permit(:one, :two)
|
73
75
|
|
@@ -86,11 +88,14 @@ end
|
|
86
88
|
|
87
89
|
## Platform support
|
88
90
|
|
89
|
-
The core module should work with all rubies
|
91
|
+
The core module should work with all rubies. It is tested for MRI Ruby >= 1.9.3 and JRuby 9.1.6.0
|
90
92
|
|
91
|
-
|
93
|
+
Rails compatibility is currently being tested only for versions ~> 3.2, ~> 4.2, and ~> 5.1.
|
92
94
|
|
93
95
|
Tested against:
|
96
|
+
* MRI 1.9.3
|
97
|
+
* MRI 2.0.0
|
98
|
+
* MRI 2.1.10
|
94
99
|
* MRI 2.2.2
|
95
100
|
* MRI 2.3.0
|
96
101
|
* MRI 2.3.4
|
data/lib/allowable.rb
CHANGED
@@ -3,4 +3,12 @@
|
|
3
3
|
require 'allowable/version'
|
4
4
|
require 'allowable/allowable'
|
5
5
|
require 'allowable/core_ext/hash'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
9
|
+
ActiveSupport::HashWithIndifferentAccess.send :include, Allowable
|
10
|
+
rescue LoadError
|
11
|
+
# do nothing
|
12
|
+
end
|
13
|
+
|
6
14
|
require 'allowable/railtie' if defined? Rails
|
data/lib/allowable/allowable.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'allowable/allow'
|
4
|
-
require 'allowable/forbid'
|
5
|
-
|
6
3
|
# Filter hashes by setting allowed or forbidden values for specific keys.
|
7
4
|
#
|
8
5
|
# hash = { one: 'one', two: 'two' }
|
@@ -21,6 +18,25 @@ require 'allowable/forbid'
|
|
21
18
|
#
|
22
19
|
# hash # => {}
|
23
20
|
module Allowable
|
24
|
-
|
25
|
-
|
21
|
+
def allow(filters = {})
|
22
|
+
dup.allow!(filters)
|
23
|
+
end
|
24
|
+
|
25
|
+
def allow!(filters = {})
|
26
|
+
filters.each do |key, val|
|
27
|
+
delete(key) unless Array(val).include?(self[key]) || val == self[key]
|
28
|
+
end
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def forbid(filters = {})
|
33
|
+
dup.forbid!(filters)
|
34
|
+
end
|
35
|
+
|
36
|
+
def forbid!(filters = {})
|
37
|
+
filters.each do |key, val|
|
38
|
+
delete(key) if Array(val).include?(self[key]) || val == self[key]
|
39
|
+
end
|
40
|
+
self
|
41
|
+
end
|
26
42
|
end
|
data/lib/allowable/railtie.rb
CHANGED
@@ -5,9 +5,11 @@ require 'rails/railtie'
|
|
5
5
|
module Allowable
|
6
6
|
# Railtie initializer that adds Allowable methods to controller params
|
7
7
|
class Railtie < ::Rails::Railtie
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if Rails::VERSION::MAJOR >= 5
|
9
|
+
initializer :allowable do
|
10
|
+
ActiveSupport.on_load :action_controller do
|
11
|
+
ActionController::Parameters.send :include, ::Allowable
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/allowable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allowable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Simon Borg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -49,10 +49,8 @@ files:
|
|
49
49
|
- LICENSE.txt
|
50
50
|
- README.md
|
51
51
|
- lib/allowable.rb
|
52
|
-
- lib/allowable/allow.rb
|
53
52
|
- lib/allowable/allowable.rb
|
54
53
|
- lib/allowable/core_ext/hash.rb
|
55
|
-
- lib/allowable/forbid.rb
|
56
54
|
- lib/allowable/railtie.rb
|
57
55
|
- lib/allowable/version.rb
|
58
56
|
homepage: https://github.com/msimonborg/allowable
|
data/lib/allowable/allow.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Allowable
|
4
|
-
# Adds the #allow and #allow! methods
|
5
|
-
module Allow
|
6
|
-
def allow(filters = {})
|
7
|
-
dup.allow!(filters)
|
8
|
-
end
|
9
|
-
|
10
|
-
def allow!(filters = {})
|
11
|
-
filters.each do |key, val|
|
12
|
-
delete(key) unless Array(val).include?(self[key]) || val == self[key]
|
13
|
-
end
|
14
|
-
self
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/allowable/forbid.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Allowable
|
4
|
-
# Adds the #forbid and #forbid! methods
|
5
|
-
module Forbid
|
6
|
-
def forbid(filters = {})
|
7
|
-
dup.forbid!(filters)
|
8
|
-
end
|
9
|
-
|
10
|
-
def forbid!(filters = {})
|
11
|
-
filters.each do |key, val|
|
12
|
-
delete(key) if Array(val).include?(self[key]) || val == self[key]
|
13
|
-
end
|
14
|
-
self
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|