state_machine 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.yardopts +0 -1
  2. data/CHANGELOG.md +7 -0
  3. data/LICENSE +1 -1
  4. data/README.md +97 -5
  5. data/gemfiles/active_model-3.0.0.gemfile.lock +1 -1
  6. data/gemfiles/active_model-3.0.5.gemfile.lock +1 -1
  7. data/gemfiles/active_model-3.1.1.gemfile.lock +1 -1
  8. data/gemfiles/active_record-2.0.0.gemfile.lock +1 -1
  9. data/gemfiles/active_record-2.0.5.gemfile.lock +1 -1
  10. data/gemfiles/active_record-2.1.0.gemfile.lock +1 -1
  11. data/gemfiles/active_record-2.1.2.gemfile.lock +1 -1
  12. data/gemfiles/active_record-2.2.3.gemfile.lock +1 -1
  13. data/gemfiles/active_record-2.3.12.gemfile.lock +1 -1
  14. data/gemfiles/active_record-3.0.0.gemfile.lock +1 -1
  15. data/gemfiles/active_record-3.0.5.gemfile.lock +1 -1
  16. data/gemfiles/active_record-3.1.1.gemfile.lock +1 -1
  17. data/gemfiles/data_mapper-0.10.2.gemfile.lock +1 -1
  18. data/gemfiles/data_mapper-0.9.11.gemfile.lock +1 -1
  19. data/gemfiles/data_mapper-0.9.4.gemfile.lock +1 -1
  20. data/gemfiles/data_mapper-0.9.7.gemfile.lock +1 -1
  21. data/gemfiles/data_mapper-1.0.0.gemfile.lock +1 -1
  22. data/gemfiles/data_mapper-1.0.1.gemfile.lock +1 -1
  23. data/gemfiles/data_mapper-1.0.2.gemfile.lock +1 -1
  24. data/gemfiles/data_mapper-1.1.0.gemfile.lock +1 -1
  25. data/gemfiles/data_mapper-1.2.0.gemfile.lock +1 -1
  26. data/gemfiles/default.gemfile.lock +1 -1
  27. data/gemfiles/graphviz-0.9.0.gemfile.lock +1 -1
  28. data/gemfiles/graphviz-0.9.21.gemfile.lock +1 -1
  29. data/gemfiles/graphviz-1.0.0.gemfile.lock +1 -1
  30. data/gemfiles/mongo_mapper-0.10.0.gemfile.lock +1 -1
  31. data/gemfiles/mongo_mapper-0.5.5.gemfile.lock +1 -1
  32. data/gemfiles/mongo_mapper-0.5.8.gemfile.lock +1 -1
  33. data/gemfiles/mongo_mapper-0.6.0.gemfile.lock +1 -1
  34. data/gemfiles/mongo_mapper-0.6.10.gemfile.lock +1 -1
  35. data/gemfiles/mongo_mapper-0.7.0.gemfile.lock +1 -1
  36. data/gemfiles/mongo_mapper-0.7.5.gemfile.lock +1 -1
  37. data/gemfiles/mongo_mapper-0.8.0.gemfile.lock +1 -1
  38. data/gemfiles/mongo_mapper-0.8.3.gemfile.lock +1 -1
  39. data/gemfiles/mongo_mapper-0.8.4.gemfile.lock +1 -1
  40. data/gemfiles/mongo_mapper-0.8.6.gemfile.lock +1 -1
  41. data/gemfiles/mongo_mapper-0.9.0.gemfile.lock +1 -1
  42. data/gemfiles/mongoid-2.0.0.gemfile.lock +1 -1
  43. data/gemfiles/mongoid-2.1.4.gemfile.lock +1 -1
  44. data/gemfiles/mongoid-2.2.4.gemfile.lock +1 -1
  45. data/gemfiles/mongoid-2.3.3.gemfile.lock +1 -1
  46. data/gemfiles/sequel-2.11.0.gemfile.lock +1 -1
  47. data/gemfiles/sequel-2.12.0.gemfile.lock +1 -1
  48. data/gemfiles/sequel-2.8.0.gemfile.lock +1 -1
  49. data/gemfiles/sequel-3.0.0.gemfile.lock +1 -1
  50. data/gemfiles/sequel-3.13.0.gemfile.lock +1 -1
  51. data/gemfiles/sequel-3.14.0.gemfile.lock +1 -1
  52. data/gemfiles/sequel-3.23.0.gemfile.lock +1 -1
  53. data/gemfiles/sequel-3.24.0.gemfile.lock +1 -1
  54. data/gemfiles/sequel-3.29.0.gemfile.lock +1 -1
  55. data/lib/state_machine.rb +2 -499
  56. data/lib/state_machine/core.rb +2 -0
  57. data/lib/state_machine/core_ext.rb +1 -0
  58. data/lib/state_machine/core_ext/class/state_machine.rb +5 -0
  59. data/lib/state_machine/event.rb +0 -5
  60. data/lib/state_machine/event_collection.rb +1 -1
  61. data/lib/state_machine/integrations/mongo_mapper.rb +1 -1
  62. data/lib/state_machine/integrations/mongoid.rb +1 -1
  63. data/lib/state_machine/machine.rb +12 -0
  64. data/lib/state_machine/macro_methods.rb +493 -0
  65. data/lib/state_machine/node_collection.rb +50 -18
  66. data/lib/state_machine/state.rb +0 -5
  67. data/lib/state_machine/state_collection.rb +1 -1
  68. data/lib/state_machine/version.rb +1 -1
  69. data/test/unit/event_collection_test.rb +34 -0
  70. data/test/unit/integrations/data_mapper_test.rb +38 -0
  71. data/test/unit/integrations/mongo_mapper_test.rb +28 -0
  72. data/test/unit/integrations/mongoid_test.rb +28 -0
  73. data/test/unit/machine_test.rb +15 -0
  74. data/test/unit/node_collection_test.rb +37 -9
  75. data/test/unit/state_collection_test.rb +38 -0
  76. data/test/unit/state_test.rb +1 -1
  77. metadata +11 -6
data/.yardopts CHANGED
@@ -1,6 +1,5 @@
1
1
  --title "state_machine"
2
2
  --readme README.md
3
- --markup-provider redcarpet
4
3
  -
5
4
  CHANGELOG.md
6
5
  LICENSE
@@ -1,5 +1,12 @@
1
1
  # master
2
2
 
3
+ ## 1.1.1 / 2011-12-31
4
+
5
+ * Fix fields being defined for Mongoid / MongoMapper state attributes even if they're already defined in the model
6
+ * Raise error when states / events are referenced in a definition with different types (e.g. both Strings and Symbols)
7
+ * Allow all states / events to be looked up by their string / symbol equivalent
8
+ * Allow state_machine to be loaded without extensions to the Ruby core
9
+
3
10
  ## 1.1.0 / 2011-11-13
4
11
 
5
12
  * Allow the transitions / known states for an event to be reset
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2011 Aaron Pfefier
1
+ Copyright (c) 2006-2012 Aaron Pfeifer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -632,14 +632,73 @@ end
632
632
  For more information about the various behaviors added for Sequel state
633
633
  machines, see `StateMachine::Integrations::Sequel`.
634
634
 
635
- ## Syntax flexibility
635
+ ## Additional Topics
636
+
637
+ ### Symbols vs. Strings
638
+
639
+ In all of the examples used throughout the documentation, you'll notice that
640
+ states and events are almost always referenced as symbols. This isn't a
641
+ requirement, but rather a suggested best practice.
642
+
643
+ You can very well define your state machine with Strings like so:
644
+
645
+ ```ruby
646
+ class Vehicle
647
+ state_machine :initial => 'parked' do
648
+ event 'ignite' do
649
+ transition 'parked' => 'idling'
650
+ end
651
+
652
+ # ...
653
+ end
654
+ end
655
+ ```
656
+
657
+ You could even use numbers as your state / event names. The **important** thing
658
+ to keep in mind is that the type being used for referencing states / events in
659
+ your machine definition must be **consistent**. If you're using Symbols, then
660
+ all states / events must use Symbols. Otherwise you'll encounter the following
661
+ error:
662
+
663
+ ```ruby
664
+ class Vehicle
665
+ state_machine do
666
+ event :ignite do
667
+ transition :parked => 'idling'
668
+ end
669
+ end
670
+ end
671
+
672
+ # => ArgumentError: "idling" state defined as String, :parked defined as Symbol; all states must be consistent
673
+ ```
674
+
675
+ There **is** an exception to this rule. The consistency is only required within
676
+ the definition itself. However, when the machine's helper methods are called
677
+ with input from external sources, such as a web form, state_machine will map
678
+ that input to a String / Symbol. For example:
679
+
680
+ ```ruby
681
+ class Vehicle
682
+ state_machine :initial => :parked do
683
+ event :ignite do
684
+ transition :parked => :idling
685
+ end
686
+ end
687
+ end
688
+
689
+ v = Vehicle.new # => #<Vehicle:0xb71da5f8 @state="parked">
690
+ v.state?('parked') # => true
691
+ v.state?(:parked) # => true
692
+ ```
693
+
694
+ ### Syntax flexibility
636
695
 
637
696
  Although state_machine introduces a simplified syntax, it still remains
638
697
  backwards compatible with previous versions and other state-related libraries by
639
698
  providing some flexibility around how transitions are defined. See below for an
640
699
  overview of these syntaxes.
641
700
 
642
- ### Verbose syntax
701
+ #### Verbose syntax
643
702
 
644
703
  In general, it's recommended that state machines use the implicit syntax for
645
704
  transitions. However, you can be a little more explicit and verbose about
@@ -663,7 +722,7 @@ class Vehicle
663
722
  end
664
723
  ```
665
724
 
666
- ### Transition context
725
+ #### Transition context
667
726
 
668
727
  Some flexibility is provided around the context in which transitions can be
669
728
  defined. In almost all examples throughout the documentation, transitions are
@@ -699,7 +758,7 @@ class Vehicle
699
758
  end
700
759
  ```
701
760
 
702
- In the above example, there's no need to specify the +from+ state for each
761
+ In the above example, there's no need to specify the `from` state for each
703
762
  transition since it's inferred from the context.
704
763
 
705
764
  You can also define transitions completely outside the context of a particular
@@ -727,7 +786,7 @@ Notice that in these alternative syntaxes:
727
786
  * You can continue to define `from` states (when in the machine context) using
728
787
  the `all`, `any`, and `same` helper methods
729
788
 
730
- ## Static / Dynamic definitions
789
+ ### Static / Dynamic definitions
731
790
 
732
791
  In most cases, the definition of a state machine is **static**. That is to say,
733
792
  the states, events and possible transitions are known ahead of time even though
@@ -816,6 +875,39 @@ As you can see, state_machine provides enough flexibility for you to be able
816
875
  to create new machine definitions on the fly based on an external source of
817
876
  transitions.
818
877
 
878
+ ### Core Extensions
879
+
880
+ By default, state_machine extends the Ruby core with a `state_machine` method on
881
+ `Class`. All other parts of the library are confined within the `StateMachine`
882
+ namespace. While this isn't wholly necessary, it also doesn't have any performance
883
+ impact and makes it truly feel like an extension to the language. This is very
884
+ similar to the way that you'll find `yaml`, `json`, or other libraries adding a
885
+ simple method to all objects just by loading the library.
886
+
887
+ However, if you'd like to avoid having state_machine add this extension to the
888
+ Ruby core, you can do so like so:
889
+
890
+ ```ruby
891
+ require 'state_machine/core'
892
+
893
+ class Vehicle
894
+ extend StateMachine::MacroMethods
895
+
896
+ state_machine do
897
+ # ...
898
+ end
899
+ end
900
+ ```
901
+
902
+ If you're using a gem loader like Bundler, you can explicitly indicate which
903
+ file to load:
904
+
905
+ ```ruby
906
+ # In Gemfile
907
+ ...
908
+ gem 'state_machine', :require => 'state_machine/core'
909
+ ```
910
+
819
911
  ## Tools
820
912
 
821
913
  ### Generating graphs
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /home/aaron/Projects/Personal/pluginaweek/state_machine
3
3
  specs:
4
- state_machine (1.0.3)
4
+ state_machine (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://www.rubygems.org/