state_machine_updated_for_ruby_3_2 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (308) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +72 -0
  4. data/.yardopts +5 -0
  5. data/Appraisals +491 -0
  6. data/CHANGELOG.md +506 -0
  7. data/Dockerfile +13 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE +20 -0
  10. data/README.md +1244 -0
  11. data/Rakefile +41 -0
  12. data/examples/AutoShop_state.png +0 -0
  13. data/examples/Car_state.png +0 -0
  14. data/examples/Gemfile +5 -0
  15. data/examples/Gemfile.lock +14 -0
  16. data/examples/TrafficLight_state.png +0 -0
  17. data/examples/Vehicle_state.png +0 -0
  18. data/examples/auto_shop.rb +13 -0
  19. data/examples/car.rb +21 -0
  20. data/examples/doc/AutoShop.html +2856 -0
  21. data/examples/doc/AutoShop_state.png +0 -0
  22. data/examples/doc/Car.html +919 -0
  23. data/examples/doc/Car_state.png +0 -0
  24. data/examples/doc/TrafficLight.html +2230 -0
  25. data/examples/doc/TrafficLight_state.png +0 -0
  26. data/examples/doc/Vehicle.html +7921 -0
  27. data/examples/doc/Vehicle_state.png +0 -0
  28. data/examples/doc/_index.html +136 -0
  29. data/examples/doc/class_list.html +47 -0
  30. data/examples/doc/css/common.css +1 -0
  31. data/examples/doc/css/full_list.css +55 -0
  32. data/examples/doc/css/style.css +322 -0
  33. data/examples/doc/file_list.html +46 -0
  34. data/examples/doc/frames.html +13 -0
  35. data/examples/doc/index.html +136 -0
  36. data/examples/doc/js/app.js +205 -0
  37. data/examples/doc/js/full_list.js +173 -0
  38. data/examples/doc/js/jquery.js +16 -0
  39. data/examples/doc/method_list.html +734 -0
  40. data/examples/doc/top-level-namespace.html +105 -0
  41. data/examples/merb-rest/controller.rb +51 -0
  42. data/examples/merb-rest/model.rb +28 -0
  43. data/examples/merb-rest/view_edit.html.erb +24 -0
  44. data/examples/merb-rest/view_index.html.erb +23 -0
  45. data/examples/merb-rest/view_new.html.erb +13 -0
  46. data/examples/merb-rest/view_show.html.erb +17 -0
  47. data/examples/rails-rest/controller.rb +43 -0
  48. data/examples/rails-rest/migration.rb +7 -0
  49. data/examples/rails-rest/model.rb +23 -0
  50. data/examples/rails-rest/view__form.html.erb +34 -0
  51. data/examples/rails-rest/view_edit.html.erb +6 -0
  52. data/examples/rails-rest/view_index.html.erb +25 -0
  53. data/examples/rails-rest/view_new.html.erb +5 -0
  54. data/examples/rails-rest/view_show.html.erb +19 -0
  55. data/examples/traffic_light.rb +9 -0
  56. data/examples/vehicle.rb +33 -0
  57. data/gemfiles/active_model_3.0.0.gemfile +7 -0
  58. data/gemfiles/active_model_3.0.0.gemfile.lock +35 -0
  59. data/gemfiles/active_model_3.0.5.gemfile +7 -0
  60. data/gemfiles/active_model_3.0.5.gemfile.lock +35 -0
  61. data/gemfiles/active_model_3.1.1.gemfile +7 -0
  62. data/gemfiles/active_model_3.1.1.gemfile.lock +36 -0
  63. data/gemfiles/active_model_3.2.1.gemfile +7 -0
  64. data/gemfiles/active_model_3.2.12.gemfile +7 -0
  65. data/gemfiles/active_model_3.2.12.gemfile.lock +36 -0
  66. data/gemfiles/active_model_3.2.13.rc1.gemfile +7 -0
  67. data/gemfiles/active_model_3.2.13.rc1.gemfile.lock +36 -0
  68. data/gemfiles/active_model_4.0.0.gemfile +9 -0
  69. data/gemfiles/active_model_4.0.0.gemfile.lock +78 -0
  70. data/gemfiles/active_record_2.0.0.gemfile +9 -0
  71. data/gemfiles/active_record_2.0.0.gemfile.lock +39 -0
  72. data/gemfiles/active_record_2.0.5.gemfile +9 -0
  73. data/gemfiles/active_record_2.0.5.gemfile.lock +39 -0
  74. data/gemfiles/active_record_2.1.0.gemfile +9 -0
  75. data/gemfiles/active_record_2.1.0.gemfile.lock +39 -0
  76. data/gemfiles/active_record_2.1.2.gemfile +9 -0
  77. data/gemfiles/active_record_2.1.2.gemfile.lock +39 -0
  78. data/gemfiles/active_record_2.2.3.gemfile +9 -0
  79. data/gemfiles/active_record_2.2.3.gemfile.lock +39 -0
  80. data/gemfiles/active_record_2.3.12.gemfile +9 -0
  81. data/gemfiles/active_record_2.3.12.gemfile.lock +39 -0
  82. data/gemfiles/active_record_2.3.5.gemfile +9 -0
  83. data/gemfiles/active_record_2.3.5.gemfile.lock +39 -0
  84. data/gemfiles/active_record_3.0.0.gemfile +9 -0
  85. data/gemfiles/active_record_3.0.0.gemfile.lock +51 -0
  86. data/gemfiles/active_record_3.0.5.gemfile +9 -0
  87. data/gemfiles/active_record_3.0.5.gemfile.lock +50 -0
  88. data/gemfiles/active_record_3.1.1.gemfile +9 -0
  89. data/gemfiles/active_record_3.1.1.gemfile.lock +51 -0
  90. data/gemfiles/active_record_3.2.12.gemfile +9 -0
  91. data/gemfiles/active_record_3.2.12.gemfile.lock +51 -0
  92. data/gemfiles/active_record_3.2.13.rc1.gemfile +9 -0
  93. data/gemfiles/active_record_3.2.13.rc1.gemfile.lock +51 -0
  94. data/gemfiles/active_record_4.0.0.gemfile +11 -0
  95. data/gemfiles/active_record_4.0.0.gemfile.lock +83 -0
  96. data/gemfiles/data_mapper_0.10.2.gemfile +13 -0
  97. data/gemfiles/data_mapper_0.10.2.gemfile.lock +56 -0
  98. data/gemfiles/data_mapper_0.9.11.gemfile +13 -0
  99. data/gemfiles/data_mapper_0.9.11.gemfile.lock +71 -0
  100. data/gemfiles/data_mapper_0.9.4.gemfile +12 -0
  101. data/gemfiles/data_mapper_0.9.4.gemfile.lock +70 -0
  102. data/gemfiles/data_mapper_0.9.7.gemfile +13 -0
  103. data/gemfiles/data_mapper_0.9.7.gemfile.lock +67 -0
  104. data/gemfiles/data_mapper_1.0.0.gemfile +12 -0
  105. data/gemfiles/data_mapper_1.0.0.gemfile.lock +63 -0
  106. data/gemfiles/data_mapper_1.0.1.gemfile +12 -0
  107. data/gemfiles/data_mapper_1.0.1.gemfile.lock +63 -0
  108. data/gemfiles/data_mapper_1.0.2.gemfile +12 -0
  109. data/gemfiles/data_mapper_1.0.2.gemfile.lock +63 -0
  110. data/gemfiles/data_mapper_1.1.0.gemfile +12 -0
  111. data/gemfiles/data_mapper_1.1.0.gemfile.lock +61 -0
  112. data/gemfiles/data_mapper_1.2.0.gemfile +12 -0
  113. data/gemfiles/data_mapper_1.2.0.gemfile.lock +61 -0
  114. data/gemfiles/default.gemfile +7 -0
  115. data/gemfiles/default.gemfile.lock +27 -0
  116. data/gemfiles/graphviz_0.9.17.gemfile +7 -0
  117. data/gemfiles/graphviz_0.9.17.gemfile.lock +29 -0
  118. data/gemfiles/graphviz_0.9.21.gemfile +7 -0
  119. data/gemfiles/graphviz_0.9.21.gemfile.lock +29 -0
  120. data/gemfiles/graphviz_1.0.0.gemfile +7 -0
  121. data/gemfiles/graphviz_1.0.0.gemfile.lock +29 -0
  122. data/gemfiles/graphviz_1.0.3.gemfile +7 -0
  123. data/gemfiles/graphviz_1.0.3.gemfile.lock +29 -0
  124. data/gemfiles/graphviz_1.0.8.gemfile +7 -0
  125. data/gemfiles/graphviz_1.0.8.gemfile.lock +29 -0
  126. data/gemfiles/mongo_mapper_0.10.0.gemfile +8 -0
  127. data/gemfiles/mongo_mapper_0.10.0.gemfile.lock +47 -0
  128. data/gemfiles/mongo_mapper_0.11.2.gemfile +9 -0
  129. data/gemfiles/mongo_mapper_0.11.2.gemfile.lock +48 -0
  130. data/gemfiles/mongo_mapper_0.12.0.gemfile +9 -0
  131. data/gemfiles/mongo_mapper_0.12.0.gemfile.lock +48 -0
  132. data/gemfiles/mongo_mapper_0.5.5.gemfile +8 -0
  133. data/gemfiles/mongo_mapper_0.5.5.gemfile.lock +36 -0
  134. data/gemfiles/mongo_mapper_0.5.8.gemfile +8 -0
  135. data/gemfiles/mongo_mapper_0.5.8.gemfile.lock +36 -0
  136. data/gemfiles/mongo_mapper_0.6.0.gemfile +8 -0
  137. data/gemfiles/mongo_mapper_0.6.0.gemfile.lock +36 -0
  138. data/gemfiles/mongo_mapper_0.6.10.gemfile +8 -0
  139. data/gemfiles/mongo_mapper_0.6.10.gemfile.lock +36 -0
  140. data/gemfiles/mongo_mapper_0.7.0.gemfile +8 -0
  141. data/gemfiles/mongo_mapper_0.7.0.gemfile.lock +36 -0
  142. data/gemfiles/mongo_mapper_0.7.5.gemfile +8 -0
  143. data/gemfiles/mongo_mapper_0.7.5.gemfile.lock +39 -0
  144. data/gemfiles/mongo_mapper_0.8.0.gemfile +10 -0
  145. data/gemfiles/mongo_mapper_0.8.0.gemfile.lock +43 -0
  146. data/gemfiles/mongo_mapper_0.8.3.gemfile +10 -0
  147. data/gemfiles/mongo_mapper_0.8.3.gemfile.lock +43 -0
  148. data/gemfiles/mongo_mapper_0.8.4.gemfile +8 -0
  149. data/gemfiles/mongo_mapper_0.8.4.gemfile.lock +42 -0
  150. data/gemfiles/mongo_mapper_0.8.6.gemfile +8 -0
  151. data/gemfiles/mongo_mapper_0.8.6.gemfile.lock +42 -0
  152. data/gemfiles/mongo_mapper_0.9.0.gemfile +7 -0
  153. data/gemfiles/mongo_mapper_0.9.0.gemfile.lock +45 -0
  154. data/gemfiles/mongoid_2.0.0.gemfile +9 -0
  155. data/gemfiles/mongoid_2.0.0.gemfile.lock +49 -0
  156. data/gemfiles/mongoid_2.1.4.gemfile +9 -0
  157. data/gemfiles/mongoid_2.1.4.gemfile.lock +47 -0
  158. data/gemfiles/mongoid_2.2.4.gemfile +9 -0
  159. data/gemfiles/mongoid_2.2.4.gemfile.lock +47 -0
  160. data/gemfiles/mongoid_2.3.3.gemfile +9 -0
  161. data/gemfiles/mongoid_2.3.3.gemfile.lock +47 -0
  162. data/gemfiles/mongoid_2.4.0.gemfile +9 -0
  163. data/gemfiles/mongoid_2.4.0.gemfile.lock +47 -0
  164. data/gemfiles/mongoid_2.4.10.gemfile +9 -0
  165. data/gemfiles/mongoid_2.4.10.gemfile.lock +47 -0
  166. data/gemfiles/mongoid_2.5.2.gemfile +9 -0
  167. data/gemfiles/mongoid_2.5.2.gemfile.lock +47 -0
  168. data/gemfiles/mongoid_2.6.0.gemfile +9 -0
  169. data/gemfiles/mongoid_2.6.0.gemfile.lock +47 -0
  170. data/gemfiles/mongoid_3.0.0.gemfile +8 -0
  171. data/gemfiles/mongoid_3.0.0.gemfile.lock +45 -0
  172. data/gemfiles/mongoid_3.0.22.gemfile +8 -0
  173. data/gemfiles/mongoid_3.0.22.gemfile.lock +45 -0
  174. data/gemfiles/mongoid_3.1.0.gemfile +8 -0
  175. data/gemfiles/mongoid_3.1.0.gemfile.lock +45 -0
  176. data/gemfiles/sequel_2.11.0.gemfile +9 -0
  177. data/gemfiles/sequel_2.11.0.gemfile.lock +33 -0
  178. data/gemfiles/sequel_2.12.0.gemfile +9 -0
  179. data/gemfiles/sequel_2.12.0.gemfile.lock +33 -0
  180. data/gemfiles/sequel_2.8.0.gemfile +9 -0
  181. data/gemfiles/sequel_2.8.0.gemfile.lock +33 -0
  182. data/gemfiles/sequel_3.0.0.gemfile +9 -0
  183. data/gemfiles/sequel_3.0.0.gemfile.lock +33 -0
  184. data/gemfiles/sequel_3.10.0.gemfile +9 -0
  185. data/gemfiles/sequel_3.10.0.gemfile.lock +33 -0
  186. data/gemfiles/sequel_3.13.0.gemfile +9 -0
  187. data/gemfiles/sequel_3.13.0.gemfile.lock +33 -0
  188. data/gemfiles/sequel_3.14.0.gemfile +9 -0
  189. data/gemfiles/sequel_3.14.0.gemfile.lock +33 -0
  190. data/gemfiles/sequel_3.23.0.gemfile +9 -0
  191. data/gemfiles/sequel_3.23.0.gemfile.lock +33 -0
  192. data/gemfiles/sequel_3.24.0.gemfile +9 -0
  193. data/gemfiles/sequel_3.24.0.gemfile.lock +33 -0
  194. data/gemfiles/sequel_3.29.0.gemfile +9 -0
  195. data/gemfiles/sequel_3.29.0.gemfile.lock +33 -0
  196. data/gemfiles/sequel_3.34.0.gemfile +9 -0
  197. data/gemfiles/sequel_3.34.0.gemfile.lock +33 -0
  198. data/gemfiles/sequel_3.35.0.gemfile +9 -0
  199. data/gemfiles/sequel_3.35.0.gemfile.lock +33 -0
  200. data/gemfiles/sequel_3.4.0.gemfile +9 -0
  201. data/gemfiles/sequel_3.4.0.gemfile.lock +33 -0
  202. data/gemfiles/sequel_3.44.0.gemfile +9 -0
  203. data/gemfiles/sequel_3.44.0.gemfile.lock +33 -0
  204. data/init.rb +1 -0
  205. data/lib/state_machine/assertions.rb +36 -0
  206. data/lib/state_machine/branch.rb +225 -0
  207. data/lib/state_machine/callback.rb +236 -0
  208. data/lib/state_machine/core.rb +12 -0
  209. data/lib/state_machine/core_ext/class/state_machine.rb +5 -0
  210. data/lib/state_machine/core_ext.rb +2 -0
  211. data/lib/state_machine/error.rb +13 -0
  212. data/lib/state_machine/eval_helpers.rb +87 -0
  213. data/lib/state_machine/event.rb +257 -0
  214. data/lib/state_machine/event_collection.rb +141 -0
  215. data/lib/state_machine/extensions.rb +149 -0
  216. data/lib/state_machine/graph.rb +92 -0
  217. data/lib/state_machine/helper_module.rb +17 -0
  218. data/lib/state_machine/initializers/merb.rb +1 -0
  219. data/lib/state_machine/initializers/rails.rb +25 -0
  220. data/lib/state_machine/initializers.rb +4 -0
  221. data/lib/state_machine/integrations/active_model/locale.rb +11 -0
  222. data/lib/state_machine/integrations/active_model/observer.rb +33 -0
  223. data/lib/state_machine/integrations/active_model/observer_update.rb +42 -0
  224. data/lib/state_machine/integrations/active_model/versions.rb +31 -0
  225. data/lib/state_machine/integrations/active_model.rb +585 -0
  226. data/lib/state_machine/integrations/active_record/locale.rb +20 -0
  227. data/lib/state_machine/integrations/active_record/versions.rb +123 -0
  228. data/lib/state_machine/integrations/active_record.rb +548 -0
  229. data/lib/state_machine/integrations/base.rb +100 -0
  230. data/lib/state_machine/integrations/data_mapper/observer.rb +210 -0
  231. data/lib/state_machine/integrations/data_mapper/versions.rb +85 -0
  232. data/lib/state_machine/integrations/data_mapper.rb +511 -0
  233. data/lib/state_machine/integrations/mongo_mapper/locale.rb +4 -0
  234. data/lib/state_machine/integrations/mongo_mapper/versions.rb +89 -0
  235. data/lib/state_machine/integrations/mongo_mapper.rb +389 -0
  236. data/lib/state_machine/integrations/mongoid/locale.rb +4 -0
  237. data/lib/state_machine/integrations/mongoid/versions.rb +81 -0
  238. data/lib/state_machine/integrations/mongoid.rb +461 -0
  239. data/lib/state_machine/integrations/sequel/versions.rb +95 -0
  240. data/lib/state_machine/integrations/sequel.rb +486 -0
  241. data/lib/state_machine/integrations.rb +121 -0
  242. data/lib/state_machine/machine.rb +2292 -0
  243. data/lib/state_machine/machine_collection.rb +86 -0
  244. data/lib/state_machine/macro_methods.rb +522 -0
  245. data/lib/state_machine/matcher.rb +123 -0
  246. data/lib/state_machine/matcher_helpers.rb +54 -0
  247. data/lib/state_machine/node_collection.rb +222 -0
  248. data/lib/state_machine/path.rb +120 -0
  249. data/lib/state_machine/path_collection.rb +90 -0
  250. data/lib/state_machine/state.rb +297 -0
  251. data/lib/state_machine/state_collection.rb +112 -0
  252. data/lib/state_machine/state_context.rb +138 -0
  253. data/lib/state_machine/transition.rb +470 -0
  254. data/lib/state_machine/transition_collection.rb +245 -0
  255. data/lib/state_machine/version.rb +3 -0
  256. data/lib/state_machine/yard/handlers/base.rb +32 -0
  257. data/lib/state_machine/yard/handlers/event.rb +25 -0
  258. data/lib/state_machine/yard/handlers/machine.rb +344 -0
  259. data/lib/state_machine/yard/handlers/state.rb +25 -0
  260. data/lib/state_machine/yard/handlers/transition.rb +47 -0
  261. data/lib/state_machine/yard/handlers.rb +12 -0
  262. data/lib/state_machine/yard/templates/default/class/html/setup.rb +30 -0
  263. data/lib/state_machine/yard/templates/default/class/html/state_machines.erb +12 -0
  264. data/lib/state_machine/yard/templates.rb +3 -0
  265. data/lib/state_machine/yard.rb +8 -0
  266. data/lib/state_machine.rb +8 -0
  267. data/lib/tasks/state_machine.rake +1 -0
  268. data/lib/tasks/state_machine.rb +30 -0
  269. data/lib/yard-state_machine.rb +2 -0
  270. data/state_machine.gemspec +23 -0
  271. data/test/files/en.yml +17 -0
  272. data/test/files/switch.rb +15 -0
  273. data/test/functional/state_machine_test.rb +1066 -0
  274. data/test/test_helper.rb +7 -0
  275. data/test/unit/assertions_test.rb +40 -0
  276. data/test/unit/branch_test.rb +969 -0
  277. data/test/unit/callback_test.rb +704 -0
  278. data/test/unit/error_test.rb +43 -0
  279. data/test/unit/eval_helpers_test.rb +272 -0
  280. data/test/unit/event_collection_test.rb +398 -0
  281. data/test/unit/event_test.rb +1196 -0
  282. data/test/unit/graph_test.rb +98 -0
  283. data/test/unit/helper_module_test.rb +17 -0
  284. data/test/unit/integrations/active_model_test.rb +1245 -0
  285. data/test/unit/integrations/active_record_test.rb +2551 -0
  286. data/test/unit/integrations/base_test.rb +104 -0
  287. data/test/unit/integrations/data_mapper_test.rb +2194 -0
  288. data/test/unit/integrations/mongo_mapper_test.rb +2026 -0
  289. data/test/unit/integrations/mongoid_test.rb +2309 -0
  290. data/test/unit/integrations/sequel_test.rb +1896 -0
  291. data/test/unit/integrations_test.rb +83 -0
  292. data/test/unit/invalid_event_test.rb +20 -0
  293. data/test/unit/invalid_parallel_transition_test.rb +18 -0
  294. data/test/unit/invalid_transition_test.rb +115 -0
  295. data/test/unit/machine_collection_test.rb +603 -0
  296. data/test/unit/machine_test.rb +3407 -0
  297. data/test/unit/matcher_helpers_test.rb +37 -0
  298. data/test/unit/matcher_test.rb +155 -0
  299. data/test/unit/node_collection_test.rb +362 -0
  300. data/test/unit/path_collection_test.rb +266 -0
  301. data/test/unit/path_test.rb +485 -0
  302. data/test/unit/state_collection_test.rb +352 -0
  303. data/test/unit/state_context_test.rb +441 -0
  304. data/test/unit/state_machine_test.rb +31 -0
  305. data/test/unit/state_test.rb +1101 -0
  306. data/test/unit/transition_collection_test.rb +2168 -0
  307. data/test/unit/transition_test.rb +1558 -0
  308. metadata +450 -0
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.13.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.13.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.14.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.14.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.14.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.23.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.23.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.23.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.24.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.24.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.24.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.29.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.29.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.29.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.34.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.34.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.34.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.35.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.35.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.35.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.4.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.4.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.4.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://www.rubygems.org"
4
+
5
+ gem "sqlite3-ruby", "1.3.1", :platform=>[:ruby, :mswin, :mingw]
6
+ gem "jdbc-sqlite3", "3.7.2", :platform=>:jruby
7
+ gem "sequel", "3.44.0"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
+ specs:
4
+ state_machine (1.2.0)
5
+
6
+ GEM
7
+ remote: http://www.rubygems.org/
8
+ specs:
9
+ appraisal (0.5.1)
10
+ bundler
11
+ rake
12
+ jdbc-sqlite3 (3.7.2)
13
+ multi_json (1.6.1)
14
+ rake (10.0.3)
15
+ sequel (3.44.0)
16
+ simplecov (0.7.1)
17
+ multi_json (~> 1.0)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ sqlite3-ruby (1.3.1)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ appraisal (~> 0.5.0)
28
+ jdbc-sqlite3 (= 3.7.2)
29
+ rake
30
+ sequel (= 3.44.0)
31
+ simplecov
32
+ sqlite3-ruby (= 1.3.1)
33
+ state_machine!
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'state_machine'
@@ -0,0 +1,36 @@
1
+ module StateMachine
2
+ # Provides a set of helper methods for making assertions about the content
3
+ # of various objects
4
+ module Assertions
5
+ # Validates that the given hash *only* includes the specified valid keys.
6
+ # If any invalid keys are found, an ArgumentError will be raised.
7
+ #
8
+ # == Examples
9
+ #
10
+ # options = {:name => 'John Smith', :age => 30}
11
+ #
12
+ # assert_valid_keys(options, :name) # => ArgumentError: Invalid key(s): age
13
+ # assert_valid_keys(options, 'name', 'age') # => ArgumentError: Invalid key(s): age, name
14
+ # assert_valid_keys(options, :name, :age) # => nil
15
+ def assert_valid_keys(hash, *valid_keys)
16
+ invalid_keys = hash.keys - valid_keys
17
+ raise ArgumentError, "Invalid key(s): #{invalid_keys.join(', ')}" unless invalid_keys.empty?
18
+ end
19
+
20
+ # Validates that the given hash only includes at *most* one of a set of
21
+ # exclusive keys. If more than one key is found, an ArgumentError will be
22
+ # raised.
23
+ #
24
+ # == Examples
25
+ #
26
+ # options = {:only => :on, :except => :off}
27
+ # assert_exclusive_keys(options, :only) # => nil
28
+ # assert_exclusive_keys(options, :except) # => nil
29
+ # assert_exclusive_keys(options, :only, :except) # => ArgumentError: Conflicting keys: only, except
30
+ # assert_exclusive_keys(options, :only, :except, :with) # => ArgumentError: Conflicting keys: only, except
31
+ def assert_exclusive_keys(hash, *exclusive_keys)
32
+ conflicting_keys = exclusive_keys & hash.keys
33
+ raise ArgumentError, "Conflicting keys: #{conflicting_keys.join(', ')}" unless conflicting_keys.length <= 1
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,225 @@
1
+ require 'state_machine/matcher'
2
+ require 'state_machine/eval_helpers'
3
+ require 'state_machine/assertions'
4
+
5
+ module StateMachine
6
+ # Represents a set of requirements that must be met in order for a transition
7
+ # or callback to occur. Branches verify that the event, from state, and to
8
+ # state of the transition match, in addition to if/unless conditionals for
9
+ # an object's state.
10
+ class Branch
11
+ include Assertions
12
+ include EvalHelpers
13
+
14
+ # The condition that must be met on an object
15
+ attr_reader :if_condition
16
+
17
+ # The condition that must *not* be met on an object
18
+ attr_reader :unless_condition
19
+
20
+ # The requirement for verifying the event being matched
21
+ attr_reader :event_requirement
22
+
23
+ # One or more requirements for verifying the states being matched. All
24
+ # requirements contain a mapping of {:from => matcher, :to => matcher}.
25
+ attr_reader :state_requirements
26
+
27
+ # A list of all of the states known to this branch. This will pull states
28
+ # from the following options (in the same order):
29
+ # * +from+ / +except_from+
30
+ # * +to+ / +except_to+
31
+ attr_reader :known_states
32
+
33
+ # Creates a new branch
34
+ def initialize(options = {}) #:nodoc:
35
+ # Build conditionals
36
+ @if_condition = options.delete(:if)
37
+ @unless_condition = options.delete(:unless)
38
+
39
+ # Build event requirement
40
+ @event_requirement = build_matcher(options, :on, :except_on)
41
+
42
+ if (options.keys - [:from, :to, :on, :except_from, :except_to, :except_on]).empty?
43
+ # Explicit from/to requirements specified
44
+ @state_requirements = [{:from => build_matcher(options, :from, :except_from), :to => build_matcher(options, :to, :except_to)}]
45
+ else
46
+ # Separate out the event requirement
47
+ options.delete(:on)
48
+ options.delete(:except_on)
49
+
50
+ # Implicit from/to requirements specified
51
+ @state_requirements = options.collect do |from, to|
52
+ from = WhitelistMatcher.new(from) unless from.is_a?(Matcher)
53
+ to = WhitelistMatcher.new(to) unless to.is_a?(Matcher)
54
+ {:from => from, :to => to}
55
+ end
56
+ end
57
+
58
+ # Track known states. The order that requirements are iterated is based
59
+ # on the priority in which tracked states should be added.
60
+ @known_states = []
61
+ @state_requirements.each do |state_requirement|
62
+ [:from, :to].each {|option| @known_states |= state_requirement[option].values}
63
+ end
64
+ end
65
+
66
+ # Determines whether the given object / query matches the requirements
67
+ # configured for this branch. In addition to matching the event, from state,
68
+ # and to state, this will also check whether the configured :if/:unless
69
+ # conditions pass on the given object.
70
+ #
71
+ # == Examples
72
+ #
73
+ # branch = StateMachine::Branch.new(:parked => :idling, :on => :ignite)
74
+ #
75
+ # # Successful
76
+ # branch.matches?(object, :on => :ignite) # => true
77
+ # branch.matches?(object, :from => nil) # => true
78
+ # branch.matches?(object, :from => :parked) # => true
79
+ # branch.matches?(object, :to => :idling) # => true
80
+ # branch.matches?(object, :from => :parked, :to => :idling) # => true
81
+ # branch.matches?(object, :on => :ignite, :from => :parked, :to => :idling) # => true
82
+ #
83
+ # # Unsuccessful
84
+ # branch.matches?(object, :on => :park) # => false
85
+ # branch.matches?(object, :from => :idling) # => false
86
+ # branch.matches?(object, :to => :first_gear) # => false
87
+ # branch.matches?(object, :from => :parked, :to => :first_gear) # => false
88
+ # branch.matches?(object, :on => :park, :from => :parked, :to => :idling) # => false
89
+ def matches?(object, query = {})
90
+ !match(object, query).nil?
91
+ end
92
+
93
+ # Attempts to match the given object / query against the set of requirements
94
+ # configured for this branch. In addition to matching the event, from state,
95
+ # and to state, this will also check whether the configured :if/:unless
96
+ # conditions pass on the given object.
97
+ #
98
+ # If a match is found, then the event/state requirements that the query
99
+ # passed successfully will be returned. Otherwise, nil is returned if there
100
+ # was no match.
101
+ #
102
+ # Query options:
103
+ # * <tt>:from</tt> - One or more states being transitioned from. If none
104
+ # are specified, then this will always match.
105
+ # * <tt>:to</tt> - One or more states being transitioned to. If none are
106
+ # specified, then this will always match.
107
+ # * <tt>:on</tt> - One or more events that fired the transition. If none
108
+ # are specified, then this will always match.
109
+ # * <tt>:guard</tt> - Whether to guard matches with the if/unless
110
+ # conditionals defined for this branch. Default is true.
111
+ #
112
+ # == Examples
113
+ #
114
+ # branch = StateMachine::Branch.new(:parked => :idling, :on => :ignite)
115
+ #
116
+ # branch.match(object, :on => :ignite) # => {:to => ..., :from => ..., :on => ...}
117
+ # branch.match(object, :on => :park) # => nil
118
+ def match(object, query = {})
119
+ assert_valid_keys(query, :from, :to, :on, :guard)
120
+
121
+ if (match = match_query(query)) && matches_conditions?(object, query)
122
+ match
123
+ end
124
+ end
125
+
126
+ # Draws a representation of this branch on the given graph. This will draw
127
+ # an edge between every state this branch matches *from* to either the
128
+ # configured to state or, if none specified, then a loopback to the from
129
+ # state.
130
+ #
131
+ # For example, if the following from states are configured:
132
+ # * +idling+
133
+ # * +first_gear+
134
+ # * +backing_up+
135
+ #
136
+ # ...and the to state is +parked+, then the following edges will be created:
137
+ # * +idling+ -> +parked+
138
+ # * +first_gear+ -> +parked+
139
+ # * +backing_up+ -> +parked+
140
+ #
141
+ # Each edge will be labeled with the name of the event that would cause the
142
+ # transition.
143
+ def draw(graph, event, valid_states)
144
+ state_requirements.each do |state_requirement|
145
+ # From states determined based on the known valid states
146
+ from_states = state_requirement[:from].filter(valid_states)
147
+
148
+ # If a to state is not specified, then it's a loopback and each from
149
+ # state maps back to itself
150
+ if state_requirement[:to].values.empty?
151
+ loopback = true
152
+ else
153
+ to_state = state_requirement[:to].values.first
154
+ to_state = to_state ? to_state.to_s : 'nil'
155
+ loopback = false
156
+ end
157
+
158
+ # Generate an edge between each from and to state
159
+ from_states.each do |from_state|
160
+ from_state = from_state ? from_state.to_s : 'nil'
161
+ graph.add_edges(from_state, loopback ? from_state : to_state, :label => event.to_s)
162
+ end
163
+ end
164
+
165
+ true
166
+ end
167
+
168
+ protected
169
+ # Builds a matcher strategy to use for the given options. If neither a
170
+ # whitelist nor a blacklist option is specified, then an AllMatcher is
171
+ # built.
172
+ def build_matcher(options, whitelist_option, blacklist_option)
173
+ assert_exclusive_keys(options, whitelist_option, blacklist_option)
174
+
175
+ if options.include?(whitelist_option)
176
+ value = options[whitelist_option]
177
+ value.is_a?(Matcher) ? value : WhitelistMatcher.new(options[whitelist_option])
178
+ elsif options.include?(blacklist_option)
179
+ value = options[blacklist_option]
180
+ raise ArgumentError, ":#{blacklist_option} option cannot use matchers; use :#{whitelist_option} instead" if value.is_a?(Matcher)
181
+ BlacklistMatcher.new(value)
182
+ else
183
+ AllMatcher.instance
184
+ end
185
+ end
186
+
187
+ # Verifies that all configured requirements (event and state) match the
188
+ # given query. If a match is found, then a hash containing the
189
+ # event/state requirements that passed will be returned; otherwise, nil.
190
+ def match_query(query)
191
+ query ||= {}
192
+
193
+ if match_event(query) && (state_requirement = match_states(query))
194
+ state_requirement.merge(:on => event_requirement)
195
+ end
196
+ end
197
+
198
+ # Verifies that the event requirement matches the given query
199
+ def match_event(query)
200
+ matches_requirement?(query, :on, event_requirement)
201
+ end
202
+
203
+ # Verifies that the state requirements match the given query. If a
204
+ # matching requirement is found, then it is returned.
205
+ def match_states(query)
206
+ state_requirements.detect do |state_requirement|
207
+ [:from, :to].all? {|option| matches_requirement?(query, option, state_requirement[option])}
208
+ end
209
+ end
210
+
211
+ # Verifies that an option in the given query matches the values required
212
+ # for that option
213
+ def matches_requirement?(query, option, requirement)
214
+ !query.include?(option) || requirement.matches?(query[option], query)
215
+ end
216
+
217
+ # Verifies that the conditionals for this branch evaluate to true for the
218
+ # given object
219
+ def matches_conditions?(object, query)
220
+ query[:guard] == false ||
221
+ Array(if_condition).all? {|condition| evaluate_method(object, condition)} &&
222
+ !Array(unless_condition).any? {|condition| evaluate_method(object, condition)}
223
+ end
224
+ end
225
+ end