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.
- checksums.yaml +4 -4
- data/README.md +43 -1
- data/lib/simplestate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b3153ff78f8f75d2989bfe78b54a90d61f0ee94
|
|
4
|
+
data.tar.gz: 734c4d1ec55579e707a7a5ce6a1a51afd25ab72f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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/
|
|
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
|
data/lib/simplestate/version.rb
CHANGED