Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing invalid whitespace with sake strip

  • Loading branch information...
commit 101ccefa6454d198bee0515bf67187de403b31b4 1 parent 0ec0edd
Bernerd Schaefer authored
Showing with 65 additions and 66 deletions.
  1. +1 −1  dm-is-state_machine/TODO
  2. +4 −5 dm-is-state_machine/lib/dm-is-state_machine/is/data/event.rb
  3. +7 −7 dm-is-state_machine/lib/dm-is-state_machine/is/data/machine.rb
  4. +3 −3 dm-is-state_machine/lib/dm-is-state_machine/is/data/state.rb
  5. +1 −1  dm-is-state_machine/lib/dm-is-state_machine/is/dsl/event_dsl.rb
  6. +3 −3 dm-is-state_machine/lib/dm-is-state_machine/is/dsl/state_dsl.rb
  7. +6 −6 dm-is-state_machine/lib/dm-is-state_machine/is/state_machine.rb
  8. +1 −1  dm-is-state_machine/lib/dm-is-state_machine/is/version.rb
  9. +2 −2 dm-is-state_machine/spec/examples/invalid_events.rb
  10. +1 −1  dm-is-state_machine/spec/examples/invalid_states.rb
  11. +3 −3 dm-is-state_machine/spec/examples/invalid_transitions_1.rb
  12. +3 −3 dm-is-state_machine/spec/examples/invalid_transitions_2.rb
  13. +2 −2 dm-is-state_machine/spec/examples/traffic_light.rb
  14. +11 −11 dm-is-state_machine/spec/integration/traffic_light_spec.rb
  15. +3 −3 dm-is-state_machine/spec/unit/data/event_spec.rb
  16. +5 −5 dm-is-state_machine/spec/unit/data/machine_spec.rb
  17. +2 −2 dm-is-state_machine/spec/unit/data/state_spec.rb
  18. +3 −3 dm-is-state_machine/spec/unit/dsl/event_dsl_spec.rb
  19. +1 −1  dm-is-state_machine/spec/unit/dsl/state_dsl_spec.rb
  20. +3 −3 dm-is-state_machine/spec/unit/state_machine_spec.rb
View
2  dm-is-state_machine/TODO
@@ -8,4 +8,4 @@ TODO
* Consider trying out a nested state machine.
* Not real happy with spec/unit/dsl:
- specs are brittle
- - specs don't actually test much
+ - specs don't actually test much
View
9 dm-is-state_machine/lib/dm-is-state_machine/is/data/event.rb
@@ -2,7 +2,7 @@ module DataMapper
module Is
module StateMachine
module Data
-
+
class Event
attr_reader :name, :machine, :transitions
@@ -12,15 +12,14 @@ def initialize(name, machine)
@machine = machine
@transitions = []
end
-
+
def add_transition(from, to)
@transitions << { :from => from, :to => to }
end
-
+
end
-
+
end # Data
end # StateMachine
end # Is
end # DataMapper
-
View
14 dm-is-state_machine/lib/dm-is-state_machine/is/data/machine.rb
@@ -2,20 +2,20 @@ module DataMapper
module Is
module StateMachine
module Data
-
+
# Represents one state machine
class Machine
attr_reader :column, :initial
attr_accessor :current_state_name
attr_accessor :events, :states
-
+
def initialize(column, initial)
@column, @initial = column, initial
@events, @states = [], []
@current_state_name = initial
end
-
+
# Fire (activate) the event with name +event_name+
#
# @api public
@@ -44,7 +44,7 @@ def current_state
find_state(@current_state_name)
# TODO: add caching, i.e. with `@current_state ||= ...`
end
-
+
# Find event whose name is +event_name+
#
# @api semipublic
@@ -52,7 +52,7 @@ def find_event(event_name)
@events.find { |event| event.name.to_s == event_name.to_s }
# TODO: use a data structure that prevents duplicates
end
-
+
# Find state whose name is +event_name+
#
# @api semipublic
@@ -60,9 +60,9 @@ def find_state(state_name)
@states.find { |state| state.name.to_s == state_name.to_s }
# TODO: use a data structure that prevents duplicates
end
-
+
end
-
+
end # Data
end # StateMachine
end # Is
View
6 dm-is-state_machine/lib/dm-is-state_machine/is/data/state.rb
@@ -6,15 +6,15 @@ module Data
class State
attr_reader :name, :machine, :options
-
+
def initialize(name, machine, options = {})
@name = name
@options = options
@machine = machine
end
-
+
end
-
+
end # Data
end # StateMachine
end # Is
View
2  dm-is-state_machine/lib/dm-is-state_machine/is/dsl/event_dsl.rb
@@ -61,7 +61,7 @@ def transitions(options)
end
event_name = @is_state_machine[:event][:name]
event_object = @is_state_machine[:event][:object]
-
+
from = options[:from]
to = options[:to]
event_object.add_transition(from, to)
View
6 dm-is-state_machine/lib/dm-is-state_machine/is/dsl/state_dsl.rb
@@ -15,10 +15,10 @@ module StateDsl
# state :green, :enter => Proc.new { |o| o.log("G") }
# state :yellow, :enter => Proc.new { |o| o.log("Y") }
# state :red, :enter => Proc.new { |o| o.log("R") }
- #
+ #
# # event definitions go here...
# end
- #
+ #
# def log(string)
# Merb::Logger.info(string)
# end
@@ -33,7 +33,7 @@ def state(name, options = {})
state = Data::State.new(name, machine, options)
machine.states << state
end
-
+
end # StateDsl
end # StateMachine
end # Is
View
12 dm-is-state_machine/lib/dm-is-state_machine/is/state_machine.rb
@@ -27,7 +27,7 @@ def is_state_machine(options = {}, &block)
extend DataMapper::Is::StateMachine::EventDsl
extend DataMapper::Is::StateMachine::StateDsl
include DataMapper::Is::StateMachine::InstanceMethods
-
+
# ===== Setup context =====
options = { :column => :state, :initial => nil }.merge(options)
column = options[:column]
@@ -59,9 +59,9 @@ def is_state_machine(options = {}, &block)
# ===== Teardown context =====
pop_state_machine_context
end
-
+
protected
-
+
def push_state_machine_context(label)
((@is_state_machine ||= {})[:context] ||= []) << label
@@ -70,18 +70,18 @@ def push_state_machine_context(label)
# @is_state_machine[:context] ||= []
# @is_state_machine[:context] << label
end
-
+
def pop_state_machine_context
@is_state_machine[:context].pop
end
-
+
def state_machine_context?(label)
(i = @is_state_machine) && (c = i[:context]) &&
c.respond_to?(:include?) && c.include?(label)
end
module InstanceMethods
-
+
def initialize(*args)
super
# ===== Call :enter Proc if present =====
View
2  dm-is-state_machine/lib/dm-is-state_machine/is/version.rb
@@ -4,4 +4,4 @@ module StateMachine
VERSION = "0.9.3"
end
end
-end
+end
View
4 dm-is-state_machine/spec/examples/invalid_events.rb
@@ -1,14 +1,14 @@
# An invalid example.
class InvalidEvents
include DataMapper::Resource
-
+
property :id, Serial
is :state_machine do
state :day
state :night
end
-
+
# The next lines are intentionally incorrect.
#
# 'event' only makes sense in a block under 'is :state_machine'
View
2  dm-is-state_machine/spec/examples/invalid_states.rb
@@ -1,7 +1,7 @@
# An invalid example.
class InvalidStates
include DataMapper::Resource
-
+
property :id, Serial
is :state_machine do
View
6 dm-is-state_machine/spec/examples/invalid_transitions_1.rb
@@ -1,15 +1,15 @@
# An invalid example.
class InvalidTransitions1
include DataMapper::Resource
-
+
property :id, Serial
is :state_machine do
state :happy
state :sad
-
+
event :toggle
-
+
# The next lines are intentionally incorrect.
#
# 'transitions' is only valid when nested beneath 'event'
View
6 dm-is-state_machine/spec/examples/invalid_transitions_2.rb
@@ -1,16 +1,16 @@
# An invalid example.
class InvalidTransitions2
include DataMapper::Resource
-
+
property :id, Serial
is :state_machine do
state :happy
state :sad
-
+
event :toggle
end
-
+
# The next lines are intentionally incorrect.
#
# 'transitions' is only valid when nested beneath 'event'
View
4 dm-is-state_machine/spec/examples/traffic_light.rb
@@ -8,7 +8,7 @@ class TrafficLight
state :green, :enter => Proc.new { |o| o.log << "G" }
state :yellow, :enter => Proc.new { |o| o.log << "Y" }
state :red, :enter => Proc.new { |o| o.log << "R" }
-
+
event :forward do
transitions :from => :green, :to => :yellow
transitions :from => :yellow, :to => :red
@@ -21,7 +21,7 @@ class TrafficLight
transitions :from => :red, :to => :yellow
end
end
-
+
def log; @log ||= [] end
def log=(x); @log ||= [] end
View
22 dm-is-state_machine/spec/integration/traffic_light_spec.rb
@@ -19,31 +19,31 @@
it "should not have a 'state' column" do
@t.attributes.should_not include(:state)
end
-
+
it "should start off in the green state" do
@t.color.should == :green
end
-
+
it "should allow the color to be set" do
@t.color = :yellow
@t.save
@t.color.should == "yellow"
end
-
+
it "should have called the :enter Proc" do
@t.log.should == %w(G)
end
-
+
it "should call the original initialize method" do
@t.init.should == [:init]
end
-
+
describe 'forward!' do
-
+
it "should respond to :forward!" do
@t.respond_to?(:forward!).should == true
end
-
+
it "should transition to :yellow, :red, :green" do
@t.color.should == :green
@t.forward!
@@ -57,7 +57,7 @@
@t.log.should == %w(G Y R G)
@t.new_record?.should == true
end
-
+
it "should skip to :yellow then transition to :red, :green, :yellow" do
@t.color = :yellow
@t.color.should == "yellow"
@@ -89,15 +89,15 @@
@t.log.should == %w(G G Y R)
@t.new_record?.should == true
end
-
+
end
describe 'backward!' do
-
+
it "should respond to 'backward!'" do
@t.respond_to?(:backward!).should == true
end
-
+
it "should transition to :red, :yellow, :green" do
@t.color.should == :green
@t.log.should == %w(G)
View
6 dm-is-state_machine/spec/unit/data/event_spec.rb
@@ -9,18 +9,18 @@ def new_event(*args)
describe DataMapper::Is::StateMachine::Data::Event do
include EventHelper
-
+
before(:each) do
@machine = mock("machine")
@event = new_event(:ping, @machine)
end
-
+
it "#initialize should work" do
@event.name.should == :ping
@event.machine.should == @machine
@event.transitions.should == []
end
-
+
it "#add_transition should work" do
@event.add_transition(:nothing, :pinged)
@event.transitions.should == [{:from => :nothing, :to => :pinged }]
View
10 dm-is-state_machine/spec/unit/data/machine_spec.rb
@@ -5,11 +5,11 @@ module MachineHelper
def new_machine(*args)
DataMapper::Is::StateMachine::Data::Machine.new(*args)
end
-
+
def new_state(name, machine, options = {})
mock(name, :name => name, :machine => machine, :options => options)
end
-
+
def new_event(name, machine)
mock(name, :name => name, :machine => machine)
end
@@ -17,7 +17,7 @@ def new_event(name, machine)
describe DataMapper::Is::StateMachine::Data::Machine do
include MachineHelper
-
+
describe "new Machine, no events" do
before(:each) do
@machine = new_machine(:power, :off)
@@ -82,7 +82,7 @@ def new_event(name, machine)
it "#current_state_name should work" do
@machine.current_state_name.should == :off
end
-
+
it "#find_event should return nothing" do
@machine.find_event(:turn_on).should == @turn_on
end
@@ -93,5 +93,5 @@ def new_event(name, machine)
@machine.current_state_name.should == :on
end
end
-
+
end
View
4 dm-is-state_machine/spec/unit/data/state_spec.rb
@@ -9,12 +9,12 @@ def new_state(*args)
describe DataMapper::Is::StateMachine::Data::State do
include StateHelper
-
+
before(:each) do
@machine = mock("machine")
@state = new_state(:off, @machine)
end
-
+
it "#initialize should work" do
@state.name.should == :off
@state.machine.should == @machine
View
6 dm-is-state_machine/spec/unit/dsl/event_dsl_spec.rb
@@ -2,7 +2,7 @@
require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "EventDsl" do
-
+
describe "event" do
before(:each) do
@@ -23,7 +23,7 @@ class Earth
end
end
-
+
describe "transitions" do
before(:each) do
@@ -52,5 +52,5 @@ class Earth
end
end
-
+
end
View
2  dm-is-state_machine/spec/unit/dsl/state_dsl_spec.rb
@@ -2,7 +2,7 @@
require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "StateDsl" do
-
+
describe "state" do
before(:each) do
View
6 dm-is-state_machine/spec/unit/state_machine_spec.rb
@@ -2,7 +2,7 @@
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe "StateMachine" do
-
+
describe "is_state_machine" do
before(:each) do
@@ -18,13 +18,13 @@ class Earth
stub!(:pop_state_machine_context)
end
end
-
+
it "declaration should succeed" do
class Earth
is_state_machine
end
end
-
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.