-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use same implementation for all Hash like objects, DRY code
- Loading branch information
1 parent
97d25a4
commit eb544ca
Showing
14 changed files
with
63 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Forbidium | ||
# Adds the #allow and #allow! methods | ||
module Allow | ||
def allow(filters = {}) | ||
dup.allow!(filters) | ||
end | ||
|
||
def allow!(filters = {}) | ||
filters.each do |key, val| | ||
delete(key) unless Array(val).include?(self[key]) | ||
end | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
# Add #allow, #allow!, #forbid, and #forbid! to Hash | ||
class Hash | ||
include Forbidium::Hash | ||
include Forbidium | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Forbidium | ||
# Adds the #forbid and #forbid! methods | ||
module Forbid | ||
def forbid(filters = {}) | ||
dup.forbid!(filters) | ||
end | ||
|
||
def forbid!(filters = {}) | ||
filters.each do |key, val| | ||
delete(key) if Array(val).include?(self[key]) | ||
end | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Forbidium do | ||
context 'Forbidium::ActionController::Parameters' do | ||
it 'includes namespaced Allow and Forbid modules when included' do | ||
class ForbidiumParametersTestObject; end | ||
it 'includes Forbidium::Allow and Forbidium::Forbid when included' do | ||
class ForbidiumTestObject; end | ||
|
||
expect( | ||
ForbidiumParametersTestObject.include?(Forbidium::ActionController::Parameters::Allow) | ||
).not_to be true | ||
expect( | ||
ForbidiumParametersTestObject.include?(Forbidium::ActionController::Parameters::Forbid) | ||
).not_to be true | ||
expect(ForbidiumTestObject.include?(Forbidium::Allow)).not_to be true | ||
expect(ForbidiumTestObject.include?(Forbidium::Forbid)).not_to be true | ||
|
||
ForbidiumParametersTestObject.class_eval { include Forbidium::ActionController::Parameters } | ||
ForbidiumTestObject.class_eval { include Forbidium } | ||
|
||
expect( | ||
ForbidiumParametersTestObject.include?(Forbidium::ActionController::Parameters::Allow) | ||
).to be true | ||
expect( | ||
ForbidiumParametersTestObject.include?(Forbidium::ActionController::Parameters::Forbid) | ||
).to be true | ||
end | ||
end | ||
|
||
context 'Forbidium::Hash' do | ||
it 'includes namespaced Allow and Forbid modules when included' do | ||
class ForbidiumHashTestObject; end | ||
|
||
expect( | ||
ForbidiumHashTestObject.include?(Forbidium::Hash::Allow) | ||
).not_to be true | ||
expect( | ||
ForbidiumHashTestObject.include?(Forbidium::Hash::Forbid) | ||
).not_to be true | ||
|
||
ForbidiumHashTestObject.class_eval { include Forbidium::Hash } | ||
|
||
expect( | ||
ForbidiumHashTestObject.include?(Forbidium::Hash::Allow) | ||
).to be true | ||
expect( | ||
ForbidiumHashTestObject.include?(Forbidium::Hash::Forbid) | ||
).to be true | ||
end | ||
expect(ForbidiumTestObject.include?(Forbidium::Allow)).to be true | ||
expect(ForbidiumTestObject.include?(Forbidium::Forbid)).to be true | ||
end | ||
|
||
it 'is included in Hash when required' do | ||
expect(Hash.include?(Forbidium::Hash)).to be true | ||
expect(Hash.include?(Forbidium)).to be true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters