Class: WCC::Filters
- Inherits:
-
Object
- Object
- WCC::Filters
- Defined in:
- lib/wcc/filter.rb
Constant Summary collapse
- @@filters =
{}
Class Method Summary collapse
-
.accept(data, filters) ⇒ Boolean
Called by wcc check routine to evaluate all filters and produce and’ed result of their boolean returns.
-
.add(id, &block) ⇒ Object
API method - register a filters code block under given ID.
-
.call(data, id, args = {}) ⇒ Boolean
API method - invoke the specfied filter and give it’s result.
-
.debug(msg) ⇒ Object
API method - log msg as debug.
-
.error(msg) ⇒ Object
API method - log msg as error.
-
.info(msg) ⇒ Object
API method - log msg as info.
-
.warn(msg) ⇒ Object
API method - log msg as warn.
Class Method Details
.accept(data, filters) ⇒ Boolean
Called by wcc check routine to evaluate all filters and produce and’ed result of their boolean returns.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/wcc/filter.rb', line 60 def self.accept(data, filters) return true if filters.nil? WCC.logger.info "Testing with filters: #{filters.join(', ')}" filters.each do |fref| block = @@filters[fref.id] if block.nil? WCC.logger.error "Requested filter '#{fref.id}' not found, skipping it." next end if not block.call(data, fref.arguments) WCC.logger.info "Filter '#{fref.id}' failed!" return false end end true end |
.add(id, &block) ⇒ Object
API method - register a filters code block under given ID. Should be called by filters the following way:
WCC::Filters.add 'filter-name' { block }
25 26 27 28 |
# File 'lib/wcc/filter.rb', line 25 def self.add(id, &block) WCC.logger.info "Adding filter '#{id}'" @@filters[id] = block end |
.call(data, id, args = {}) ⇒ Boolean
API method - invoke the specfied filter and give it’s result.
36 37 38 39 40 41 42 |
# File 'lib/wcc/filter.rb', line 36 def self.call(data, id, args = {}) block = @@filters[id] if block.nil? raise "Call to requested filter '#{id}' failed - filter not found!" end block.call(data, args) end |
.debug(msg) ⇒ Object
API method - log msg as debug
51 |
# File 'lib/wcc/filter.rb', line 51 def self.debug(msg); WCC.logger.debug "filter: #{msg}" end |
.error(msg) ⇒ Object
API method - log msg as error
45 |
# File 'lib/wcc/filter.rb', line 45 def self.error(msg); WCC.logger.error "filter: #{msg}" end |