### Home Classes Methods

### In Files

- lib/state_machine/assertions.rb

### Methods

- #assert_exclusive_keys
- #assert_valid_keys

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StateMachine
- StateMachine::AllMatcher
- StateMachine::Assertions
- StateMachine::AttributeTransitionCollection
- StateMachine::BlacklistMatcher
- StateMachine::Branch
- StateMachine::Callback
- StateMachine::ClassMethods
- StateMachine::Error
- StateMachine::EvalHelpers
- StateMachine::Event
- StateMachine::EventCollection
- StateMachine::Graph
- StateMachine::InstanceMethods
- StateMachine::IntegrationNotFound
- StateMachine::Integrations
- StateMachine::Integrations::ActiveModel
- StateMachine::Integrations::ActiveModel::Observer
- StateMachine::Integrations::ActiveModel::ObserverUpdate
- StateMachine::Integrations::ActiveRecord
- StateMachine::Integrations::Base
- StateMachine::Integrations::Base::ClassMethods
- StateMachine::Integrations::DataMapper
- StateMachine::Integrations::DataMapper::Observer
- StateMachine::Integrations::MongoMapper
- StateMachine::Integrations::Mongoid
- StateMachine::Integrations::Sequel
- StateMachine::InvalidEvent
- StateMachine::InvalidParallelTransition
- StateMachine::InvalidTransition
- StateMachine::LoopbackMatcher
- StateMachine::Machine
- StateMachine::MachineCollection
- StateMachine::MacroMethods
- StateMachine::Matcher
- StateMachine::MatcherHelpers
- StateMachine::NodeCollection
- StateMachine::Path
- StateMachine::PathCollection
- StateMachine::RailsEngine
- StateMachine::State
- StateMachine::StateCollection
- StateMachine::StateContext
- StateMachine::Transition
- StateMachine::TransitionCollection
- StateMachine::WhitelistMatcher
- StateMachine::YARD
- StateMachine::YARD::Handlers
- StateMachine::YARD::Handlers::Base
- StateMachine::YARD::Handlers::Event
- StateMachine::YARD::Handlers::Machine
- StateMachine::YARD::Handlers::State
- StateMachine::YARD::Handlers::Transition
- Object

No matching classes.

# StateMachine::Assertions

Provides a set of helper methods for making assertions about the content of various objects

### Public Instance Methods

assert_exclusive_keys(hash, *exclusive_keys) click to toggle source

Validates that the given hash only includes at most one of a set of exclusive keys. If more than one key is found, an ArgumentError will be raised.

## Examples

    options = {:only => :on, :except => :off}
    assert_exclusive_keys(options, :only)                   # => nil
    assert_exclusive_keys(options, :except)                 # => nil
    assert_exclusive_keys(options, :only, :except)          # => ArgumentError: Conflicting keys: only, except
    assert_exclusive_keys(options, :only, :except, :with)   # => ArgumentError: Conflicting keys: only, except

    # File lib/state_machine/assertions.rb, line 31
    def assert_exclusive_keys(hash, *exclusive_keys)
      conflicting_keys = exclusive_keys & hash.keys
      raise ArgumentError, "Conflicting keys: #{conflicting_keys.join(', ')}" unless conflicting_keys.length <= 1
    end

assert_valid_keys(hash, *valid_keys) click to toggle source

Validates that the given hash only includes the specified valid keys. If any invalid keys are found, an ArgumentError will be raised.

## Examples

    options = {:name => 'John Smith', :age => 30}

    assert_valid_keys(options, :name)           # => ArgumentError: Invalid key(s): age
    assert_valid_keys(options, 'name', 'age')   # => ArgumentError: Invalid key(s): age, name
    assert_valid_keys(options, :name, :age)     # => nil

    # File lib/state_machine/assertions.rb, line 15
    def assert_valid_keys(hash, *valid_keys)
      invalid_keys = hash.keys - valid_keys
      raise ArgumentError, "Invalid key(s): #{invalid_keys.join(', ')}" unless invalid_keys.empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.