Class: MMTop::Filter
- Inherits:
-
Object
- Object
- MMTop::Filter
- Defined in:
- lib/mmtop/filter.rb
Class Attribute Summary collapse
-
.filters ⇒ Object
Returns the value of attribute filters.
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .add_filter(name, default = true, &block) ⇒ Object
- .default_filters ⇒ Object
- .from_string(string) ⇒ Object
Instance Method Summary collapse
-
#initialize(name, default, &block) ⇒ Filter
constructor
A new instance of Filter.
- #run(query_list, host, config) ⇒ Object
Constructor Details
#initialize(name, default, &block) ⇒ Filter
Returns a new instance of Filter.
23 24 25 26 27 |
# File 'lib/mmtop/filter.rb', line 23 def initialize(name, default, &block) @name = name @default = default @block = block.to_proc end |
Class Attribute Details
.filters ⇒ Object
Returns the value of attribute filters.
4 5 6 |
# File 'lib/mmtop/filter.rb', line 4 def filters @filters end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
39 40 41 |
# File 'lib/mmtop/filter.rb', line 39 def default @default end |
#name ⇒ Object
Returns the value of attribute name.
39 40 41 |
# File 'lib/mmtop/filter.rb', line 39 def name @name end |
Class Method Details
.add_filter(name, default = true, &block) ⇒ Object
6 7 8 9 |
# File 'lib/mmtop/filter.rb', line 6 def add_filter(name, default=true, &block) @filters ||= [] @filters.push self.new(name, default, &block) end |
.default_filters ⇒ Object
11 12 13 |
# File 'lib/mmtop/filter.rb', line 11 def default_filters @filters.select(&:default) end |
.from_string(string) ⇒ Object
15 16 17 18 19 |
# File 'lib/mmtop/filter.rb', line 15 def from_string(string) final = string.sub(/^\s*\{/, '').sub(/\}$/, '') p = eval("Proc.new { |qlist| qlist.reject! { |query| !(#{final}) } }") new(string, false, &p) end |
Instance Method Details
#run(query_list, host, config) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mmtop/filter.rb', line 29 def run(query_list, host, config) case @block.arity when 1 @block.call(query_list) when 2 @block.call(query_list, host) when 3 @block.call(query_list, host, config) end end |