forbidium 1.1.1 → 1.2.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 +18 -0
- data/README.md +21 -0
- data/lib/forbidium.rb +0 -2
- data/lib/forbidium/allow.rb +17 -0
- data/lib/forbidium/core_ext/hash.rb +1 -1
- data/lib/forbidium/forbid.rb +17 -0
- data/lib/forbidium/forbidium.rb +5 -11
- data/lib/forbidium/railtie.rb +1 -3
- data/lib/forbidium/version.rb +1 -1
- metadata +5 -4
- data/lib/forbidium/action_controller/parameters.rb +0 -40
- data/lib/forbidium/hash.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b41e5cb910d5e3f0c7bc288c1bef273770f904d
|
4
|
+
data.tar.gz: b629928ec78b528e5d85b48073eebf32cf95fbf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70373e7f8f34e3a1e31c27c02bfe1fcaaf08434718661f90e620f66987a7b53cf9d6aef56339fbc175fccbb2e3413333aa36b43a4b1ca223be4969520a6b4a6d
|
7
|
+
data.tar.gz: 24599ce3d6152468d7239364844281ef3f1689607bc4b68538c8382320f06d95ce6908f84fd31c21a61d5788a04bfe2c62a51868b861b544ff788e3f7582ce1a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
1.2.0
|
3
|
+
-----
|
4
|
+
* `HashWithIndifferentAccess` and `Hash` do not need different implementations. Same module can be included in both and achieve the correct results. To mixin the methods to any `Hash`-like class just `include Forbidium`
|
5
|
+
|
6
|
+
1.1.1
|
7
|
+
-----
|
8
|
+
* Relax Ruby version back to >= 2.0.0, since it will work and should be compatible with `ActiveSupport` >= 4.2.0, but only test >= 2.2.2 because of compatibility with Rails 5.x in dummy app testing.
|
9
|
+
|
10
|
+
1.1.0
|
11
|
+
-----
|
12
|
+
* Respect key types in `Hash`es: filter key types must match hash key types to affect output. Different implementation for `ActionController::Parameters`, since it is `HashWithIndifferentAccess`; symbol key filters will affect string keys in params.
|
13
|
+
* Require Ruby >= 2.2.0
|
14
|
+
|
15
|
+
1.0.1
|
16
|
+
-----
|
17
|
+
* Require Ruby >= 2.0.0
|
18
|
+
* Substantial performance improvement by accessing hash keys directly instead of iterating with `#delete_if`
|
data/README.md
CHANGED
@@ -43,6 +43,16 @@ hash.forbid!(two: 'two') # => {}
|
|
43
43
|
hash # => {}
|
44
44
|
```
|
45
45
|
|
46
|
+
### Type sensitive for `Hash`
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
hash = { 'one' => 'one', 'two' => 'two' }
|
50
|
+
|
51
|
+
hash.forbid(one: 'one') # => { "one" => "one", "two" => "two" }
|
52
|
+
|
53
|
+
hash.forbid('one' => 'one') # => { "two" => "two" }
|
54
|
+
```
|
55
|
+
|
46
56
|
When added to the `Gemfile` in a Rails project, `ActionController::Parameters` will also receive these methods so you can use them with your `strong_parameters`:
|
47
57
|
|
48
58
|
```ruby
|
@@ -51,6 +61,17 @@ def user_params
|
|
51
61
|
end
|
52
62
|
```
|
53
63
|
|
64
|
+
### Type insensitive for `HashWithIndifferentAccess`
|
65
|
+
```ruby
|
66
|
+
params = ActionController::Parameters.new('one' => 'one', 'two' => 'two').permit(:one, :two)
|
67
|
+
|
68
|
+
params.forbid(one: 'one').to_h # => { "two" => "two" }
|
69
|
+
|
70
|
+
params.forbid('one' => 'one').to_h # => { "two" => "two" }
|
71
|
+
```
|
72
|
+
|
73
|
+
If your custom `Hash`-like class implements the `#[]` finder and `#delete`, you can `include Forbidium` to mix in the methods.
|
74
|
+
|
54
75
|
## Platform support
|
55
76
|
|
56
77
|
Tested against:
|
data/lib/forbidium.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Forbidium
|
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])
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Forbidium
|
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])
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/forbidium/forbidium.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forbidium/allow'
|
4
|
+
require 'forbidium/forbid'
|
5
|
+
|
3
6
|
# Filter hashes by setting allowed or forbidden values for specific keys.
|
4
7
|
#
|
5
8
|
# hash = { one: 'one', two: 'two' }
|
@@ -18,15 +21,6 @@
|
|
18
21
|
#
|
19
22
|
# hash # => {}
|
20
23
|
module Forbidium
|
21
|
-
|
22
|
-
|
23
|
-
dup.allow!(filters)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module Forbid # :nodoc:
|
28
|
-
def forbid(filters = {})
|
29
|
-
dup.forbid!(filters)
|
30
|
-
end
|
31
|
-
end
|
24
|
+
include Forbid
|
25
|
+
include Allow
|
32
26
|
end
|
data/lib/forbidium/railtie.rb
CHANGED
@@ -7,9 +7,7 @@ module Forbidium
|
|
7
7
|
class Railtie < ::Rails::Railtie
|
8
8
|
initializer :forbidium do
|
9
9
|
ActiveSupport.on_load :action_controller do
|
10
|
-
|
11
|
-
:include, Forbidium::ActionController::Parameters
|
12
|
-
)
|
10
|
+
ActionController::Parameters.send :include, Forbidium
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
data/lib/forbidium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forbidium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -45,13 +45,14 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- CHANGELOG.md
|
48
49
|
- LICENSE.txt
|
49
50
|
- README.md
|
50
51
|
- lib/forbidium.rb
|
51
|
-
- lib/forbidium/
|
52
|
+
- lib/forbidium/allow.rb
|
52
53
|
- lib/forbidium/core_ext/hash.rb
|
54
|
+
- lib/forbidium/forbid.rb
|
53
55
|
- lib/forbidium/forbidium.rb
|
54
|
-
- lib/forbidium/hash.rb
|
55
56
|
- lib/forbidium/railtie.rb
|
56
57
|
- lib/forbidium/version.rb
|
57
58
|
homepage: https://github.com/msimonborg/forbidium
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Forbidium
|
4
|
-
module ActionController # :nodoc:
|
5
|
-
module Parameters # :nodoc:
|
6
|
-
# Adds the #forbid and #forbid! methods
|
7
|
-
module Forbid # :nodoc:
|
8
|
-
include Forbidium::Forbid
|
9
|
-
|
10
|
-
def forbid!(filters = {})
|
11
|
-
filters.each do |key, val|
|
12
|
-
delete(key) if Array(val).include?(self[key])
|
13
|
-
if key.is_a? Symbol
|
14
|
-
delete(key.to_s) if Array(val).include?(self[key.to_s])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
self
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Adds the #allow and #allow! methods
|
22
|
-
module Allow # :nodoc:
|
23
|
-
include Forbidium::Allow
|
24
|
-
|
25
|
-
def allow!(filters = {})
|
26
|
-
filters.each do |key, val|
|
27
|
-
delete(key) unless Array(val).include?(self[key])
|
28
|
-
if key.is_a? Symbol
|
29
|
-
delete(key.to_s) unless Array(val).include?(self[key.to_s])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
self
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
include Allow
|
37
|
-
include Forbid
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/forbidium/hash.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Forbidium
|
4
|
-
module Hash # :nodoc:
|
5
|
-
# Adds the #forbid and #forbid! methods
|
6
|
-
module Forbid # :nodoc:
|
7
|
-
include Forbidium::Forbid
|
8
|
-
|
9
|
-
def forbid!(filters = {})
|
10
|
-
filters.each do |key, val|
|
11
|
-
delete(key) if Array(val).include?(self[key])
|
12
|
-
end
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Adds the #allow and #allow! methods
|
18
|
-
module Allow # :nodoc:
|
19
|
-
include Forbidium::Allow
|
20
|
-
|
21
|
-
def allow!(filters = {})
|
22
|
-
filters.each do |key, val|
|
23
|
-
delete(key) unless Array(val).include?(self[key])
|
24
|
-
end
|
25
|
-
self
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
include Forbid
|
30
|
-
include Allow
|
31
|
-
end
|
32
|
-
end
|