simplestate 0.1.2 → 0.1.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -1
  3. data/lib/simplestate/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f051584efb2ecbc68840491289289c4209c3090
4
- data.tar.gz: 4babe09b7cc299b3ce6f3a3cb713b176d65cdf0e
3
+ metadata.gz: 2b3153ff78f8f75d2989bfe78b54a90d61f0ee94
4
+ data.tar.gz: 734c4d1ec55579e707a7a5ce6a1a51afd25ab72f
5
5
  SHA512:
6
- metadata.gz: 8c6f77cb3377f86ef45f283ed34c7d40191be2fe7b39b726e3ae9886bf93adb535c6e1389dc13ebb87f5bca9d2943b9f69ce79a60c84fbc61459ec9c054d5086
7
- data.tar.gz: b8b1db030161492d86c61a0793e811cddf116201175c0e8e32007c9bf103300617fba77c222f686350f884253d507a8d6c1fa834812413eb1b8bb5b284037c9d
6
+ metadata.gz: 041594007f16771c4ae393339aa8d1d29d77be98c375794e0884c73c5e87d8fa74702dc2fad2e8abedf90d10dc634de2c00d75590d57a00828fb82afcc6dadaa
7
+ data.tar.gz: e54fa9fced19ded450401386beedbbc24d6aa5891d99a79bbb91107aa805decc4168eebdfdeb0d14151b4fbd8d22e43e1dab8b2aaccb99e1169546398bef11a8
data/README.md CHANGED
@@ -25,6 +25,48 @@ Or install it yourself as:
25
25
  $ gem install simplestate
26
26
 
27
27
  ## Usage
28
+ Inherit from StateHolder to create the class of objects that will hold states:
29
+
30
+ ```ruby
31
+ class Button < StateHolder
32
+ # button methods here
33
+ end
34
+ ```
35
+ Inherit from State to create a class to provide specific state behaviors:
36
+
37
+ ```ruby
38
+ class Off < State
39
+ def press
40
+ transition_to(On)
41
+ holder.messages << "#{holder.name} is on"
42
+ end
43
+
44
+ def name
45
+ 'Off'
46
+ end
47
+
48
+ private
49
+ def enter
50
+ holder.messages << "Entered the Off state"
51
+ end
52
+
53
+ def exit
54
+ holder.messages << "Exited the Off state"
55
+ end
56
+ end
57
+ ```
58
+ The subclassed state may provide *private* enter and exit methods. Any other state methods intended to be available via a call to that method on the state holder must be public. #enter and #exit will always be called appropriately during state transitions.
59
+
60
+ A state has access to methods on the state holder via #holder:
61
+
62
+ ```ruby
63
+ holder.a_special_holder_method
64
+ ```
65
+ Creation of a holder instance *must* specify the initial state class:
66
+
67
+ ```ruby
68
+ button = Button.new(initial_state_class: Off)
69
+ ```
28
70
 
29
71
  The button module provides an example of the usage of Simplestate. Tests of this are provided in simplestate_test.rb.
30
72
 
@@ -36,7 +78,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
36
78
 
37
79
  ## Contributing
38
80
 
39
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simplestate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dpneumo/simplestate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
82
 
41
83
 
42
84
  ## License
@@ -1,3 +1,3 @@
1
1
  module Simplestate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplestate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell C Kuppinger