Skip to content

Commit

Permalink
DRY up by subclassing State from StatePredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr authored and floehopper committed Jan 20, 2020
1 parent e3be26c commit ca83014
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions lib/mocha/state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,11 @@ def mocha_inspect
end

# Provides a mechanism to change the state of a {StateMachine} at some point in the future.
class State
# @private
def initialize(state_machine, state, description, &active_check)
@state_machine = state_machine
@state = state
@description = description
@active_check = active_check
end

class State < StatePredicate
# @private
def activate
@state_machine.current_state = @state
end

# @private
def active?
@active_check.call(@state_machine.current_state, @state)
end

# @private
def mocha_inspect
"#{@state_machine.name} #{@description} #{@state.mocha_inspect}"
end
end

# @private
Expand Down

0 comments on commit ca83014

Please sign in to comment.