Class: MMTop::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/mmtop/filter.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.filtersObject

Returns the value of attribute filters.



4
5
6
# File 'lib/mmtop/filter.rb', line 4

def filters
  @filters
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



39
40
41
# File 'lib/mmtop/filter.rb', line 39

def default
  @default
end

#nameObject

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_filtersObject



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