Class: Console::Filter
- Inherits:
-
Object
- Object
- Console::Filter
- Defined in:
- lib/console/filter.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
- #all! ⇒ Object
- #call(*arguments, &block) ⇒ Object
- #disable(subject) ⇒ Object
- #dup(**options) ⇒ Object
- #enable(subject) ⇒ Object
- #enabled?(subject) ⇒ Boolean
-
#initialize(output, verbose: true, level: 0, **options) ⇒ Filter
constructor
A new instance of Filter.
- #off! ⇒ Object
- #verbose!(value = true) ⇒ Object
Constructor Details
#initialize(output, verbose: true, level: 0, **options) ⇒ Filter
Returns a new instance of Filter.
58 59 60 61 62 63 64 65 66 |
# File 'lib/console/filter.rb', line 58 def initialize(output, verbose: true, level: 0, **) @level = level @verbose = verbose @subjects = {} @output = output @options = end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
74 75 76 |
# File 'lib/console/filter.rb', line 74 def level @level end |
#options ⇒ Object
Returns the value of attribute options.
80 81 82 |
# File 'lib/console/filter.rb', line 80 def @options end |
#output ⇒ Object
Returns the value of attribute output.
79 80 81 |
# File 'lib/console/filter.rb', line 79 def output @output end |
#subjects ⇒ Object (readonly)
Returns the value of attribute subjects.
77 78 79 |
# File 'lib/console/filter.rb', line 77 def subjects @subjects end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
75 76 77 |
# File 'lib/console/filter.rb', line 75 def verbose @verbose end |
Class Method Details
.[](**levels) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/console/filter.rb', line 27 def self.[] **levels klass = Class.new(self) klass.instance_exec do const_set(:LEVELS, levels) const_set(:MAXIMUM_LEVEL, levels.values.max) levels.each do |name, level| const_set(name.to_s.upcase, level) define_method(name) do |subject = nil, *arguments, **, &block| enabled = @subjects[subject.class] if enabled == true or (enabled != false and level >= @level) self.call(subject, *arguments, severity: name, **, **@options, &block) end end define_method("#{name}!") do @level = level end define_method("#{name}?") do @level >= level end end end return klass end |
Instance Method Details
#all! ⇒ Object
99 100 101 |
# File 'lib/console/filter.rb', line 99 def all! @level = self.class::MAXIMUM_LEVEL end |
#call(*arguments, &block) ⇒ Object
115 116 117 |
# File 'lib/console/filter.rb', line 115 def call(*arguments, &block) @output.call(*arguments, &block) end |
#disable(subject) ⇒ Object
111 112 113 |
# File 'lib/console/filter.rb', line 111 def disable(subject) @subjects[subject.class] = false end |
#dup(**options) ⇒ Object
68 69 70 71 72 |
# File 'lib/console/filter.rb', line 68 def dup(**) super().tap do |logger| logger. = @options.merge() end end |
#enable(subject) ⇒ Object
107 108 109 |
# File 'lib/console/filter.rb', line 107 def enable(subject) @subjects[subject.class] = true end |
#enabled?(subject) ⇒ Boolean
103 104 105 |
# File 'lib/console/filter.rb', line 103 def enabled?(subject) @subjects[subject.class] == true end |
#off! ⇒ Object
95 96 97 |
# File 'lib/console/filter.rb', line 95 def off! @level = -1 end |
#verbose!(value = true) ⇒ Object
90 91 92 93 |
# File 'lib/console/filter.rb', line 90 def verbose!(value = true) @verbose = value @output.verbose!(value) end |