Skip to content

Commit

Permalink
extract filter matching to module method
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonborg committed Aug 6, 2017
1 parent ba74c5a commit 3c145a4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/allowable/allowable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
#
# hash # => {}
module Allowable
def self.filter_match?(obj, key, val)
Array(val).include?(obj[key]) || val == obj[key]
end

def allow(filters = {})
dup.allow!(filters)
end

def allow!(filters = {})
filters.each do |key, val|
delete(key) unless Array(val).include?(self[key]) || val == self[key]
delete(key) unless Allowable.filter_match?(self, key, val)
end
self
end
Expand All @@ -35,7 +39,7 @@ def forbid(filters = {})

def forbid!(filters = {})
filters.each do |key, val|
delete(key) if Array(val).include?(self[key]) || val == self[key]
delete(key) if Allowable.filter_match?(self, key, val)
end
self
end
Expand Down

0 comments on commit 3c145a4

Please sign in to comment.