Class: PcQueues::QueueRules::StringMatchQueueRule
- Inherits:
-
PcQueues::QueueRule
- Object
- ActiveRecord::Base
- PcQueues::QueueRule
- PcQueues::QueueRules::StringMatchQueueRule
- Defined in:
- lib/pc_queues/queue_rules/string_match_queue_rule.rb
Overview
A StringMatchQueueRule is a QueueRule that will ‘pass’ if the current value exactly matches a regular expression.
Class Method Summary collapse
-
.options(opts = {}) ⇒ Object
Possible options for StringMatchQueueRule include:.
Instance Method Summary collapse
- #passes?(obj, *args) ⇒ Boolean
- #regular_expression ⇒ Object
-
#value(obj, *args) ⇒ Object
Implementors must provide an implementation of this method that takes the args splat passed to the queue and returns a String.
Methods inherited from PcQueues::QueueRule
Class Method Details
.options(opts = {}) ⇒ Object
Possible options for StringMatchQueueRule include:
-
:regular_expression - an exact regular expression
-
:contains - an exact string exists within the value
-
:icontains - ignore case with string contained within the value
20 21 22 23 24 25 26 |
# File 'lib/pc_queues/queue_rules/string_match_queue_rule.rb', line 20 def self.(opts = {}) opts[:string_value] ||= "/^#{opts[:regular_expression]}$/" if opts.key? :regular_expression opts[:string_value] ||= "/#{opts[:contains]}/" if opts.key? :contains opts[:string_value] ||= "/#{opts[:icontains]}/i" if opts.key? :icontains opts.except! :regular_expression, :contains, :icontains super end |
Instance Method Details
#passes?(obj, *args) ⇒ Boolean
38 39 40 |
# File 'lib/pc_queues/queue_rules/string_match_queue_rule.rb', line 38 def passes?(obj, *args) !regular_expression.match(value(obj, *args)).nil? end |
#regular_expression ⇒ Object
28 29 30 |
# File 'lib/pc_queues/queue_rules/string_match_queue_rule.rb', line 28 def regular_expression eval(string_value) end |
#value(obj, *args) ⇒ Object
Implementors must provide an implementation of this method that takes the args splat passed to the queue and returns a String
34 35 36 |
# File 'lib/pc_queues/queue_rules/string_match_queue_rule.rb', line 34 def value(obj, *args) raise NotImplementedError, "The class: #{self.class.name} requires an implementation of #{__method__}" end |