motion-state-machine 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -3,6 +3,30 @@
3
3
  Hey, this is `motion-state-machine` — a state machine gem designed for
4
4
  [RubyMotion](http://rubymotion.com) for iOS.
5
5
 
6
+ It features:
7
+
8
+ - A simple, nice-looking definition syntax
9
+ - Reaction to sent events, defined timeouts and global NSNotifications
10
+ - Transition guards and actions
11
+ - State entry / exit actions
12
+ - Internal transitions that don't leave the machine's current state
13
+ - Optional verbose log output for easy debugging
14
+ - [Grand Central Dispatch](https://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html)-awareness — uses GCD queues for synchronization
15
+
16
+ Defining a state machine looks like this:
17
+
18
+ ```ruby
19
+ fsm = StateMachine::Base.new start_state: :awake
20
+
21
+ fsm.when :awake do |state|
22
+ state.on_entry { puts "I'm awake, started and alive!" }
23
+ state.transition_to :sleeping, on: :finished_hard_work,
24
+ state.die on: :too_hard_work
25
+ end
26
+ ```
27
+
28
+ See below for more examples and usage instructions.
29
+
6
30
  ## Motivation
7
31
 
8
32
  Undefined states and visual glitches in applications with complex UIs can
@@ -15,20 +39,6 @@ asynchronous event handling does not lead to undefined results (a.k.a. bugs).
15
39
  MacRuby and Cocoa don't provide a simple library to address this —
16
40
  motion-state-machine should fill the gap for RubyMotion developers.
17
41
 
18
- motion-state-machine comes with a simple and nice-looking syntax to define
19
- states and transitions:
20
-
21
- fsm = StateMachine::Base.new start_state: :awake
22
-
23
- fsm.when :awake do |state|
24
- state.on_entry { puts "I'm awake, started and alive!" }
25
- state.transition_to :sleeping, on: :finished_hard_work,
26
- state.die on: :too_hard_work
27
- end
28
-
29
- It is [Grand Central Dispatch](https://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html)-aware
30
- and uses GCD queues for synchronization.
31
-
32
42
  ## Installation
33
43
 
34
44
  1. If not done yet, add `bundler` gem management to your RubyMotion app.
@@ -37,18 +47,23 @@ and uses GCD queues for synchronization.
37
47
 
38
48
  2. Add this line to your application's Gemfile:
39
49
 
40
- gem 'motion-state-machine',
41
- git: "git://github.com/opyh/motion-state-machine.git"
50
+ ```ruby
51
+ gem 'motion-state-machine'
52
+ ```
42
53
 
43
54
  3. Execute:
44
55
 
45
- $ bundle
56
+ ```bash
57
+ $ bundle
58
+ ```
46
59
 
47
60
  ## Usage
48
61
 
49
62
  The following example shows how to initialize and define a state machine:
50
63
 
51
- fsm = StateMachine::Base.new start_state: :working, verbose: true
64
+ ```ruby
65
+ fsm = StateMachine::Base.new start_state: :working, verbose: true
66
+ ```
52
67
 
53
68
  This initializes a state machine. Calling `fsm.start!` would start the
54
69
  machine in the defined start state `:working`. Using `:verbose` activates
@@ -58,19 +73,21 @@ debug output on the console.
58
73
 
59
74
  After initialization, you can define states and transitions:
60
75
 
61
- fsm.when :working do |state|
76
+ ```ruby
77
+ fsm.when :working do |state|
62
78
 
63
- state.on_entry { puts "I'm awake, started and alive!" }
64
- state.on_exit { puts "Phew. That was enough work." }
79
+ state.on_entry { puts "I'm awake, started and alive!" }
80
+ state.on_exit { puts "Phew. That was enough work." }
65
81
 
66
- state.transition_to :sleeping,
67
- on: :finished_hard_work,
68
- if: proc { really_worked_enough_for_now? },
69
- action: proc { puts "Will go to sleep now." }
82
+ state.transition_to :sleeping,
83
+ on: :finished_hard_work,
84
+ if: proc { really_worked_enough_for_now? },
85
+ action: proc { puts "Will go to sleep now." }
70
86
 
71
- state.die on: :too_hard_work
87
+ state.die on: :too_hard_work
72
88
 
73
- end
89
+ end
90
+ ```
74
91
 
75
92
  This defines…
76
93
 
@@ -100,19 +117,22 @@ Transitions can be triggered…
100
117
  - by calling the state machine's `#event` method (see above).
101
118
 
102
119
  - automatically after a given timeout:
103
-
104
- fsm.when :sleeping do |state|
105
- state.transition_to :working, after: 20
106
- end
120
+
121
+ ```ruby
122
+ fsm.when :sleeping do |state|
123
+ state.transition_to :working, after: 20
124
+ end
125
+ ```
107
126
 
108
127
  (goes back to `:working` after 20 seconds in state `:sleeping`)
109
128
 
110
129
  - when a `NSNotification` is posted:
111
-
112
- fsm.when :awake do |state|
113
- state.transition_to :in_background,
114
- on_notification: UIApplicationDidEnterBackgroundNotification
115
- end
130
+ ```ruby
131
+ fsm.when :awake do |state|
132
+ state.transition_to :in_background,
133
+ on_notification: UIApplicationDidEnterBackgroundNotification
134
+ end
135
+ ```
116
136
 
117
137
  ### How fast is it?
118
138
 
data/Rakefile CHANGED
@@ -11,21 +11,11 @@ Bundler.setup
11
11
  Bundler.require
12
12
 
13
13
  Motion::Project::App.setup do |app|
14
- app.name = 'testSuite'
15
- app.identifier = 'com.screenfashion.motion-state-machine.spec-app'
16
- app.specs_dir = './spec/motion-state-machine'
14
+ app.name = 'Spec Suite'
15
+ app.identifier = 'com.screenfashion.motion.spec-app'
16
+ app.specs_dir = './spec'
17
17
  app.development do
18
18
  # TODO: How to use module namespacing here?
19
- app.delegate_class = 'MotionStateMachineSpecAppDelegate'
19
+ app.delegate_class = 'SpecAppDelegate'
20
20
  end
21
21
  end
22
-
23
- namespace :spec do
24
- task :lib do
25
- sh "bacon #{Dir.glob("spec/lib/**/*_spec.rb").join(' ')}"
26
- end
27
-
28
- task :motion => 'spec'
29
-
30
- task :all => [:lib, :motion]
31
- end
@@ -1,4 +1,4 @@
1
- class MotionStateMachineSpecAppDelegate
1
+ class SpecAppDelegate
2
2
  def application(application, didFinishLaunchingWithOptions:launchOptions)
3
3
  @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
4
4
  @window.rootViewController = UIViewController.alloc.init
@@ -1,3 +1,3 @@
1
1
  module StateMachine
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -0,0 +1 @@
1
+ Exception.log_exceptions = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-state-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-30 00:00:00.000000000Z
12
+ date: 2012-07-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70177501197480 !ruby/object:Gem::Requirement
16
+ requirement: &70164739051240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70177501197480
24
+ version_requirements: *70164739051240
25
25
  description: A finite state machine for RubyMotion with a flavor of Grand Central
26
26
  Dispatch.
27
27
  email:
@@ -42,13 +42,14 @@ files:
42
42
  - lib/motion-state-machine/transition.rb
43
43
  - lib/motion-state-machine/version.rb
44
44
  - motion-state-machine.gemspec
45
- - spec/motion-state-machine/base_spec.rb
46
- - spec/motion-state-machine/benchmark_spec.rb
47
- - spec/motion-state-machine/notification_transition_spec.rb
48
- - spec/motion-state-machine/send_event_transition_spec.rb
49
- - spec/motion-state-machine/state_spec.rb
50
- - spec/motion-state-machine/timed_transition_spec.rb
51
- - spec/motion-state-machine/transition_spec.rb
45
+ - spec/base_spec.rb
46
+ - spec/benchmark_spec.rb
47
+ - spec/helpers/no_exception_logging.rb
48
+ - spec/notification_transition_spec.rb
49
+ - spec/send_event_transition_spec.rb
50
+ - spec/state_spec.rb
51
+ - spec/timed_transition_spec.rb
52
+ - spec/transition_spec.rb
52
53
  homepage: https://github.com/opyh/motion-state-machine
53
54
  licenses: []
54
55
  post_install_message:
@@ -63,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
64
  version: '0'
64
65
  segments:
65
66
  - 0
66
- hash: 774551363156047026
67
+ hash: -1755037909543191418
67
68
  required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  none: false
69
70
  requirements:
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  version: '0'
73
74
  segments:
74
75
  - 0
75
- hash: 774551363156047026
76
+ hash: -1755037909543191418
76
77
  requirements: []
77
78
  rubyforge_project:
78
79
  rubygems_version: 1.8.10
@@ -81,10 +82,11 @@ specification_version: 3
81
82
  summary: Comes with a nice syntax for state and transition definition. Supports triggering
82
83
  via events, timeouts and NSNotifications.
83
84
  test_files:
84
- - spec/motion-state-machine/base_spec.rb
85
- - spec/motion-state-machine/benchmark_spec.rb
86
- - spec/motion-state-machine/notification_transition_spec.rb
87
- - spec/motion-state-machine/send_event_transition_spec.rb
88
- - spec/motion-state-machine/state_spec.rb
89
- - spec/motion-state-machine/timed_transition_spec.rb
90
- - spec/motion-state-machine/transition_spec.rb
85
+ - spec/base_spec.rb
86
+ - spec/benchmark_spec.rb
87
+ - spec/helpers/no_exception_logging.rb
88
+ - spec/notification_transition_spec.rb
89
+ - spec/send_event_transition_spec.rb
90
+ - spec/state_spec.rb
91
+ - spec/timed_transition_spec.rb
92
+ - spec/transition_spec.rb