Class: StateMachine::WhitelistMatcher
- Inherits:
-
Matcher
- Object
- Matcher
- StateMachine::WhitelistMatcher
- Defined in:
- lib/state_machine/matcher.rb
Overview
Matches a specific set of values
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary (collapse)
-
- (Object) description
A human-readable description of this matcher.
-
- (Boolean) matches?(value, context = {})
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 StateMachine::Matcher
Instance Method Details
- (Object) description
A human-readable description of this matcher
70 71 72 |
# File 'lib/state_machine/matcher.rb', line 70 def description values.length == 1 ? values.first.inspect : values.inspect end |
- (Boolean) matches?(value, context = {})
Checks whether the given value exists within the whitelist configured for this matcher.
Examples
matcher = StateMachine::WhitelistMatcher.new([:parked, :idling])
matcher.matches?(:parked) # => true
matcher.matches?(:first_gear) # => false
65 66 67 |
# File 'lib/state_machine/matcher.rb', line 65 def matches?(value, context = {}) values.include?(value) end |