Class: StateMachines::WhitelistMatcher
- Defined in:
- lib/state_machines/matcher.rb
Overview
Matches a specific set of values
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
-
#description ⇒ Object
A human-readable description of this matcher.
-
#matches?(value, context = {}) ⇒ Boolean
Checks whether the given value exists within the whitelist configured for this matcher.
Methods inherited from Matcher
Constructor Details
This class inherits a constructor from StateMachines::Matcher
Instance Method Details
#description ⇒ Object
A human-readable description of this matcher
68 69 70 |
# File 'lib/state_machines/matcher.rb', line 68 def description values.length == 1 ? values.first.inspect : values.inspect end |
#matches?(value, context = {}) ⇒ Boolean
Checks whether the given value exists within the whitelist configured for this matcher.
Examples
matcher = StateMachines::WhitelistMatcher.new([:parked, :idling])
matcher.matches?(:parked) # => true
matcher.matches?(:first_gear) # => false
63 64 65 |
# File 'lib/state_machines/matcher.rb', line 63 def matches?(value, context = {}) values.include?(value) end |