Class: Dump::Env::Filter
- Inherits:
-
Object
- Object
- Dump::Env::Filter
- Defined in:
- lib/dump/env/filter.rb
Overview
Filter strings by simple pattern:
'a,b,c' will pass only 'a', 'b' and 'c'
'-a,b,c' will pass everything except 'a', 'b' and 'c'
Instance Attribute Summary collapse
-
#invert ⇒ Object
readonly
Returns the value of attribute invert.
-
#transparent ⇒ Object
readonly
Returns the value of attribute transparent.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #custom_pass?(&block) ⇒ Boolean
-
#initialize(string, splitter = nil) ⇒ Filter
constructor
A new instance of Filter.
- #pass?(value) ⇒ Boolean
Constructor Details
#initialize(string, splitter = nil) ⇒ Filter
Returns a new instance of Filter.
11 12 13 14 15 16 17 18 19 |
# File 'lib/dump/env/filter.rb', line 11 def initialize(string, splitter = nil) if string string = string.dup @invert = !!string.sub!(/^-/, '') @values = string.split(splitter || ',').map(&:strip).map(&:downcase).uniq.select(&:present?) else @transparent = true end end |
Instance Attribute Details
#invert ⇒ Object (readonly)
Returns the value of attribute invert.
10 11 12 |
# File 'lib/dump/env/filter.rb', line 10 def invert @invert end |
#transparent ⇒ Object (readonly)
Returns the value of attribute transparent.
10 11 12 |
# File 'lib/dump/env/filter.rb', line 10 def transparent @transparent end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
10 11 12 |
# File 'lib/dump/env/filter.rb', line 10 def values @values end |
Instance Method Details
#custom_pass?(&block) ⇒ Boolean
25 26 27 |
# File 'lib/dump/env/filter.rb', line 25 def custom_pass?(&block) transparent || (invert ^ values.any?(&block)) end |
#pass?(value) ⇒ Boolean
21 22 23 |
# File 'lib/dump/env/filter.rb', line 21 def pass?(value) transparent || (invert ^ values.include?(value.to_s.downcase)) end |