micromachine 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1e4cf4c889a6b914e2b7f2e6e94e14b6ca5e97f
4
- data.tar.gz: 7c27986b29e696f35424ae9c31a4dbf1307bf63b
3
+ metadata.gz: 82b235594232cccbcac8ea901232262324cd7748
4
+ data.tar.gz: 3c6c8d2b2cbcbdc5d435a30e30bf6ed2f078bddf
5
5
  SHA512:
6
- metadata.gz: be3ccf1c76220287fe4897368d10d1bfaead7adbe62b966912b54ff8660f2cc63d96536978c66358de841d2a7a8c16fdbac71cd01f69e4a4f941547128972c0c
7
- data.tar.gz: eae3a5f96d87b1075b30c4de5c59d6c205ca39a066e7449b88791c14b1edc53526a87340b8c3b908a10fd4c38fc3e4861bd273ab1882c05c9119b56acfc4214f
6
+ metadata.gz: 0c15ea016bf6bec45f30cc52e17369476be9503361bc935b85b3c4b7999bd980b9b8fd60f36dd6c5d7a5d2cda85fc68b9cd6166055c268ae9f74b84aee23e7da
7
+ data.tar.gz: fbdf2e41392c293b9afd9433dad03d672aa196cd97a4efcd286801d8b8c92ffac611efc46031de3e6dafde83f7588f665df39cd7f53299b1a6691cfd1c138616
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [2.1.0] - 2017-07-07
8
+
9
+ ### Added
10
+ - `triggerable_events` method lists events that can be called from the current state
11
+
12
+ ### Changed
13
+ - (nothing)
14
+
15
+ ## [2.0.0] - 2015-11-03
16
+
17
+ (These and previous changes were not documented)
@@ -0,0 +1,24 @@
1
+ This code tries to solve a particular problem with a very simple
2
+ implementation. We try to keep the code to a minimum while making
3
+ it as clear as possible. The design is very likely finished, and
4
+ if some feature is missing it is possible that it was left out on
5
+ purpose. That said, new usage patterns may arise, and when that
6
+ happens we are ready to adapt if necessary.
7
+
8
+ A good first step for contributing is to meet us on IRC and discuss
9
+ ideas. We spend a lot of time on #lesscode at freenode, always ready
10
+ to talk about code and simplicity. If connecting to IRC is not an
11
+ option, you can create an issue explaining the proposed change and
12
+ a use case. We pay a lot of attention to use cases, because our
13
+ goal is to keep the code base simple. Usually the result of a
14
+ conversation is the creation of a different tool.
15
+
16
+ Please don't start the conversation with a pull request. The code
17
+ should come at last, and even though it may help to convey an idea,
18
+ more often than not it draws the attention to a particular
19
+ implementation.
20
+
21
+ # Running the Tests
22
+
23
+ - `gem install cutest`
24
+ - `make`
data/README.md CHANGED
@@ -89,6 +89,19 @@ end
89
89
  Note that `:any` is a special key. Using it as a state when declaring
90
90
  transitions will give you unexpected results.
91
91
 
92
+ Finally, you can list possible events or states:
93
+
94
+ ``` ruby
95
+ # All possible events
96
+ machine.events #=> [:confirm, :ignore, :reset]
97
+
98
+ # All events triggerable from the current state
99
+ machine.triggerable_events #=> [:confirm, :ignore]
100
+
101
+ # All possible states
102
+ machine.states #=> [:new, :confirmed, :ignored]
103
+ ```
104
+
92
105
  Check the examples directory for more information.
93
106
 
94
107
  Adding MicroMachine to your models
@@ -37,6 +37,10 @@ class MicroMachine
37
37
  transitions_for.keys
38
38
  end
39
39
 
40
+ def triggerable_events
41
+ events.select { |event| trigger?(event) }
42
+ end
43
+
40
44
  def states
41
45
  transitions_for.values.map(&:to_a).flatten.uniq
42
46
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "micromachine"
3
- s.version = "2.0.0"
3
+ s.version = "2.1.0"
4
4
  s.summary = %{Minimal Finite State Machine.}
5
5
  s.description = %Q{There are many finite state machine implementations for Ruby, and they all provide a nice DSL for declaring events, exceptions, callbacks, and all kinds of niceties in general.\n\nBut if all you want is a finite state machine, look no further: this has less than 50 lines of code and provides everything a finite state machine must have, and nothing more.}
6
6
  s.author = ["Michel Martens"]
@@ -14,6 +14,10 @@ test "returns an array with the defined events" do |machine|
14
14
  assert_equal [:confirm, :ignore, :reset], machine.events
15
15
  end
16
16
 
17
+ test "list the available events for the current state" do |machine|
18
+ assert_equal [:confirm, :ignore], machine.triggerable_events
19
+ end
20
+
17
21
  test "returns an array with the defined states" do |machine|
18
22
  assert_equal [:pending, :confirmed, :ignored], machine.states
19
23
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micromachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: |-
@@ -34,7 +34,9 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
- - .gems
37
+ - ".gems"
38
+ - CHANGELOG.md
39
+ - CONTRIBUTING
38
40
  - LICENSE
39
41
  - README.md
40
42
  - examples/advanced.rb
@@ -57,17 +59,17 @@ require_paths:
57
59
  - lib
58
60
  required_ruby_version: !ruby/object:Gem::Requirement
59
61
  requirements:
60
- - - '>='
62
+ - - ">="
61
63
  - !ruby/object:Gem::Version
62
64
  version: '0'
63
65
  required_rubygems_version: !ruby/object:Gem::Requirement
64
66
  requirements:
65
- - - '>='
67
+ - - ">="
66
68
  - !ruby/object:Gem::Version
67
69
  version: '0'
68
70
  requirements: []
69
71
  rubyforge_project:
70
- rubygems_version: 2.0.14
72
+ rubygems_version: 2.6.11
71
73
  signing_key:
72
74
  specification_version: 4
73
75
  summary: Minimal Finite State Machine.