microfsm 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +10 -8
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/Gemfile +5 -4
- data/Gemfile.lock +20 -16
- data/LICENSE +3 -1
- data/README.md +30 -33
- data/Rakefile +6 -6
- data/examples/advanced.rb +5 -5
- data/examples/basic.rb +4 -4
- data/examples/callbacks.rb +6 -6
- data/lib/microfsm.rb +2 -1
- data/lib/version.rb +5 -4
- data/microfsm.gemspec +12 -11
- data/test/callbacks_test.rb +4 -4
- data/test/introspection_test.rb +5 -5
- data/test/microfsm_test.rb +5 -5
- data/test/test_helper.rb +5 -5
- metadata +5 -7
- data/.rubocop.yml +0 -20
- data/.watchr +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afc1b721660dde4225b57491fc30f99a4776473d918c7bb75fe59c103b6da37d
|
4
|
+
data.tar.gz: 575c2c67815e3ee7250c4aa49ab4a19a952c59bad6bf006cd9cb5b8d09066796
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 146a4d85345da08f2030767fb4a203d6e4516004da3ee55e8b115d17f5ef297824d72bfbc828e49369f82ae0cb71853415464f881bc6a32654de96218d465778
|
7
|
+
data.tar.gz: 407ccf0c6a370b65f7802256bcf588e73f85b604f005e2980ec2e7f223348d6934e43ef1dd371fa82f2085cd2fbb606e73a659bf117528c795a028f954d58bec
|
data/.github/workflows/rake.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
1
2
|
name: Rake
|
2
3
|
|
3
|
-
#on: [push, pull_request]
|
4
4
|
on: [push]
|
5
5
|
|
6
6
|
jobs:
|
@@ -8,17 +8,19 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
# os: [ubuntu-latest, macos-latest]
|
12
11
|
os: [ubuntu-latest]
|
13
|
-
|
14
|
-
|
15
|
-
ruby: [2.7]
|
12
|
+
ruby: ["2.7", "3.0", "3.1", head]
|
13
|
+
test_command: ["bundle exec rake test"]
|
16
14
|
runs-on: ${{ matrix.os }}
|
17
15
|
|
18
16
|
steps:
|
19
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v3
|
20
18
|
- uses: ruby/setup-ruby@v1
|
21
19
|
with:
|
22
20
|
ruby-version: ${{ matrix.ruby }}
|
23
|
-
|
24
|
-
|
21
|
+
- name: Bundle install
|
22
|
+
run: |
|
23
|
+
bundle config path /home/runner/bundle
|
24
|
+
bundle install
|
25
|
+
bundle update
|
26
|
+
- run: ${{ matrix.test_command }}
|
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rails-
|
1
|
+
rails-7.0
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-
|
1
|
+
ruby-3.1.3
|
data/Gemfile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :test do
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
5
|
+
gem "observr"
|
6
|
+
gem "ricecream"
|
7
|
+
gem "rubocop", require: false
|
8
|
+
gem "simplecov", require: false
|
8
9
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
microfsm (0.1.
|
4
|
+
microfsm (0.1.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
10
|
docile (1.4.0)
|
11
|
-
|
11
|
+
json (2.6.3)
|
12
|
+
minitest (5.16.3)
|
12
13
|
observr (1.0.5)
|
13
|
-
parallel (1.
|
14
|
-
parser (3.
|
14
|
+
parallel (1.22.1)
|
15
|
+
parser (3.1.3.0)
|
15
16
|
ast (~> 2.4.1)
|
16
|
-
rainbow (3.
|
17
|
-
rake (13.0.
|
18
|
-
regexp_parser (2.
|
17
|
+
rainbow (3.1.1)
|
18
|
+
rake (13.0.6)
|
19
|
+
regexp_parser (2.6.1)
|
19
20
|
rexml (3.2.5)
|
20
|
-
|
21
|
+
ricecream (0.2.1)
|
22
|
+
rubocop (1.41.1)
|
23
|
+
json (~> 2.3)
|
21
24
|
parallel (~> 1.10)
|
22
|
-
parser (>= 3.
|
25
|
+
parser (>= 3.1.2.1)
|
23
26
|
rainbow (>= 2.2.2, < 4.0)
|
24
27
|
regexp_parser (>= 1.8, < 3.0)
|
25
|
-
rexml
|
26
|
-
rubocop-ast (>= 1.
|
28
|
+
rexml (>= 3.2.5, < 4.0)
|
29
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
27
30
|
ruby-progressbar (~> 1.7)
|
28
31
|
unicode-display_width (>= 1.4.0, < 3.0)
|
29
|
-
rubocop-ast (1.
|
30
|
-
parser (>= 3.
|
32
|
+
rubocop-ast (1.24.0)
|
33
|
+
parser (>= 3.1.1.0)
|
31
34
|
ruby-progressbar (1.11.0)
|
32
35
|
simplecov (0.21.2)
|
33
36
|
docile (~> 1.1)
|
34
37
|
simplecov-html (~> 0.11)
|
35
38
|
simplecov_json_formatter (~> 0.1)
|
36
39
|
simplecov-html (0.12.3)
|
37
|
-
simplecov_json_formatter (0.1.
|
38
|
-
unicode-display_width (2.
|
40
|
+
simplecov_json_formatter (0.1.4)
|
41
|
+
unicode-display_width (2.3.0)
|
39
42
|
|
40
43
|
PLATFORMS
|
41
44
|
x86_64-linux
|
@@ -46,8 +49,9 @@ DEPENDENCIES
|
|
46
49
|
minitest
|
47
50
|
observr
|
48
51
|
rake
|
52
|
+
ricecream
|
49
53
|
rubocop
|
50
54
|
simplecov
|
51
55
|
|
52
56
|
BUNDLED WITH
|
53
|
-
2.
|
57
|
+
2.3.26
|
data/LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021-2022 Dittmar Krall (www.matiq.com)
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
MicroFSM
|
2
|
-
========
|
1
|
+
# MicroFSM
|
3
2
|
|
4
3
|
[![Gem Version](https://badge.fury.io/rb/microfsm.svg)](https://badge.fury.io/rb/microfsm)
|
5
4
|
|
@@ -15,33 +14,27 @@ Please feel free to use any of them if they fit better to your work.
|
|
15
14
|
The MicroFSM code consists of less than 100 locs.
|
16
15
|
No magic, no niceties, just an implementation using Ruby hashes.
|
17
16
|
|
18
|
-
Installation
|
19
|
-
------------
|
17
|
+
## Installation
|
20
18
|
|
21
|
-
|
19
|
+
As usual:
|
20
|
+
```ruby
|
22
21
|
# Gemfile
|
23
22
|
gem "microfsm"
|
23
|
+
```
|
24
|
+
and run "bundle install".
|
24
25
|
|
25
|
-
|
26
|
+
## Usage
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
$ [sudo] gem install microfsm
|
30
|
-
~~~~
|
31
|
-
|
32
|
-
Usage
|
33
|
-
-----
|
34
|
-
|
35
|
-
~~~~
|
28
|
+
```ruby
|
36
29
|
require 'microfsm'
|
37
30
|
|
38
31
|
fsm = MicroFSM.new(:new) # Initial state.
|
39
32
|
|
40
33
|
# Define the possible transitions for each event.
|
41
34
|
# Template: fsm.when(<event>, <from> => <to>)
|
42
|
-
fsm.when(:confirm, :
|
43
|
-
fsm.when(:ignore, :
|
44
|
-
fsm.when(:reset, :
|
35
|
+
fsm.when(:confirm, new: :confirmed)
|
36
|
+
fsm.when(:ignore, new: :ignored)
|
37
|
+
fsm.when(:reset, confirmed: :new, ignored: :new)
|
45
38
|
|
46
39
|
fsm.trigger(:confirm) #=> true
|
47
40
|
fsm.state #=> :confirmed
|
@@ -54,12 +47,12 @@ fsm.state #=> :new
|
|
54
47
|
|
55
48
|
fsm.trigger(:ignore) #=> true
|
56
49
|
fsm.state #=> :ignored
|
57
|
-
|
50
|
+
```
|
58
51
|
|
59
52
|
You can also ask if an event will trigger a change in state.
|
60
53
|
Following the example above:
|
61
54
|
|
62
|
-
|
55
|
+
```ruby
|
63
56
|
fsm.state #=> :ignored
|
64
57
|
|
65
58
|
fsm.trigger?(:ignore) #=> false
|
@@ -67,27 +60,25 @@ fsm.trigger?(:reset) #=> true
|
|
67
60
|
|
68
61
|
# And the state is preserved, because you were only asking.
|
69
62
|
fsm.state #=> :ignored
|
70
|
-
|
63
|
+
```
|
71
64
|
|
72
|
-
Actions
|
73
|
-
-------
|
65
|
+
## Actions
|
74
66
|
|
75
67
|
Adding actions to a transition is trivial:
|
76
68
|
|
77
|
-
|
69
|
+
```ruby
|
78
70
|
fsm.when(:confirm, new: :confirmed) { |event| count += 1 }
|
79
71
|
fsm.when(:confirm, new: :confirmed) { |event| foo(event) }
|
80
|
-
|
72
|
+
```
|
81
73
|
|
82
74
|
Two actions/callbacks are triggered in the previous example.
|
83
75
|
|
84
76
|
|
85
|
-
Miscellaneous
|
86
|
-
-------------
|
77
|
+
## Miscellaneous
|
87
78
|
|
88
79
|
Finally, you can list possible events or states:
|
89
80
|
|
90
|
-
|
81
|
+
```ruby
|
91
82
|
# All possible events
|
92
83
|
fsm.events #=> [:confirm, :ignore, :reset]
|
93
84
|
|
@@ -96,19 +87,25 @@ fsm.triggerable_events #=> [:confirm, :ignore]
|
|
96
87
|
|
97
88
|
# All possible states
|
98
89
|
fsm.states #=> [:new, :confirmed, :ignored]
|
99
|
-
|
90
|
+
```
|
100
91
|
|
101
92
|
And, the state can be set (which may be useful for testing purposes):
|
102
93
|
|
103
|
-
|
94
|
+
```ruby
|
104
95
|
fsm.state = :new
|
105
96
|
fsm.state #=> :new
|
106
|
-
|
97
|
+
```
|
107
98
|
|
108
99
|
Check the examples directory for more information.
|
109
100
|
|
110
|
-
Links
|
111
|
-
-----
|
101
|
+
## Links
|
112
102
|
|
113
103
|
- [Wikipedia](https://en.wikipedia.org/wiki/Finite-state_machine)
|
114
104
|
- [micromachine](https://github.com/soveran/micromachine)
|
105
|
+
|
106
|
+
## Miscellaneous
|
107
|
+
|
108
|
+
Copyright (c) 2021-2022 Dittmar Krall (www.matiq.com),
|
109
|
+
released under the MIT license:
|
110
|
+
|
111
|
+
* https://opensource.org/licenses/MIT
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
4
|
Rake::TestTask.new do |t|
|
5
|
-
t.libs.push
|
6
|
-
t.pattern =
|
5
|
+
t.libs.push "test"
|
6
|
+
t.pattern = "test/*_test.rb"
|
7
7
|
end
|
8
8
|
|
9
|
-
desc
|
10
|
-
task :
|
9
|
+
desc "Default: run unit tests."
|
10
|
+
task default: :test
|
data/examples/advanced.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "microfsm"
|
2
2
|
|
3
3
|
# This example can be run with ruby -I lib/ ./examples/advanced.rb
|
4
4
|
|
5
5
|
fsm = MicroFSM.new(:pending)
|
6
|
-
proc = ->
|
7
|
-
fsm.when(:confirm, :
|
8
|
-
|
9
|
-
|
6
|
+
proc = ->(event) { puts fsm.state.capitalize }
|
7
|
+
fsm.when(:confirm, pending: :confirmed, &proc)
|
8
|
+
.when(:ignore, pending: :ignored, &proc)
|
9
|
+
.when(:reset, confirmed: :pending, ignored: :pending, &proc)
|
10
10
|
|
11
11
|
puts "Should print Confirmed, Pending and Ignored:"
|
12
12
|
fsm.trigger(:confirm)
|
data/examples/basic.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "microfsm"
|
2
2
|
|
3
3
|
# This example can be run with ruby -I lib/ ./examples/basic.rb
|
4
4
|
|
5
5
|
fsm = MicroFSM.new(:pending)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
.when(:confirm, pending: :confirmed)
|
7
|
+
.when(:ignore, pending: :ignored)
|
8
|
+
.when(:reset, confirmed: :pending, ignored: :pending)
|
9
9
|
|
10
10
|
puts "Should print Confirmed, Reset and Ignored:"
|
11
11
|
|
data/examples/callbacks.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "microfsm"
|
2
2
|
|
3
3
|
# This example can be run with ruby -I lib/ ./examples/callbacks.rb
|
4
4
|
|
5
5
|
fsm = MicroFSM.new(:pending)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
.when(:confirm, pending: :confirmed) { puts "Confirmed" }
|
7
|
+
.when(:ignore, pending: :ignored) { puts "Ignored" }
|
8
|
+
.when(:reset, confirmed: :pending, ignored: :pending) {
|
9
|
+
puts "Reset"
|
10
|
+
}
|
11
11
|
|
12
12
|
puts "Should print Confirmed, Reset and Ignored:"
|
13
13
|
fsm.trigger(:confirm)
|
data/lib/microfsm.rb
CHANGED
data/lib/version.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class MicroFSM
|
4
|
-
VERSION =
|
5
|
-
# VERSION =
|
6
|
-
# VERSION =
|
7
|
-
# VERSION =
|
4
|
+
VERSION = "0.1.4" # 2022-12-22
|
5
|
+
# VERSION = "0.1.3" # 2021-06-22
|
6
|
+
# VERSION = "0.1.2" # 2021-02-10
|
7
|
+
# VERSION = "0.1.1" # 2021-02-08
|
8
|
+
# VERSION = "0.0.1" # 2021-01-24
|
8
9
|
end
|
data/microfsm.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path(
|
2
|
-
require
|
1
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
2
|
+
require "version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "microfsm"
|
6
6
|
s.version = MicroFSM::VERSION
|
7
|
-
s.summary = %
|
8
|
-
s.description = %
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.homepage =
|
7
|
+
s.summary = %(Minimal Finite State Machine.)
|
8
|
+
s.description = %{MicroFSM implements a minimal/simple Finite-State Machine (FSM). Transitions are triggered by events. Actions for a transition can be added as callbacks.}
|
9
|
+
s.authors = ["Dittmar Krall"]
|
10
|
+
s.email = "dittmar.krall@matiq.com"
|
11
|
+
s.homepage = "https://matiq.com"
|
12
12
|
s.license = "MIT"
|
13
|
+
s.platform = Gem::Platform::RUBY
|
13
14
|
|
14
|
-
s.metadata[
|
15
|
+
s.metadata["source_code_uri"] = "https://github.com/matique/microfsm"
|
15
16
|
|
16
17
|
s.files = `git ls-files`.split("\n")
|
17
18
|
|
18
|
-
s.add_development_dependency
|
19
|
-
s.add_development_dependency
|
19
|
+
s.add_development_dependency "bundler"
|
20
|
+
s.add_development_dependency "rake"
|
20
21
|
|
21
|
-
s.add_development_dependency
|
22
|
+
s.add_development_dependency "minitest"
|
22
23
|
end
|
data/test/callbacks_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
describe MicroFSM do
|
4
|
-
let
|
4
|
+
let(:fsm) {
|
5
5
|
MicroFSM.new(:pending)
|
6
|
-
|
7
|
-
|
6
|
+
.when(:confirm, pending: :confirmed) { @state = "Confirmed" }
|
7
|
+
.when(:reset, confirmed: :pending) { @state = "Pending" }
|
8
8
|
}
|
9
9
|
|
10
10
|
def test_executes_callbacks_during_transition
|
data/test/introspection_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
describe MicroFSM do
|
4
|
-
let
|
4
|
+
let(:fsm) {
|
5
5
|
MicroFSM.new(:pending)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
.when(:confirm, pending: :confirmed)
|
7
|
+
.when(:ignore, pending: :ignored)
|
8
|
+
.when(:reset, confirmed: :pending, ignored: :pending)
|
9
9
|
}
|
10
10
|
|
11
11
|
def test_returns_an_array_with_the_defined_events
|
data/test/microfsm_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
describe MicroFSM do
|
4
|
-
let
|
4
|
+
let(:fsm) {
|
5
5
|
MicroFSM.new(:pending)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
.when(:confirm, pending: :confirmed)
|
7
|
+
.when(:ignore, pending: :ignored)
|
8
|
+
.when(:reset, confirmed: :pending, ignored: :pending)
|
9
9
|
}
|
10
10
|
|
11
11
|
def test_class
|
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
if ENV[
|
2
|
-
require
|
1
|
+
if ENV["COVERAGE"]
|
2
|
+
require "simplecov"
|
3
3
|
SimpleCov.start do
|
4
|
-
add_filter
|
4
|
+
add_filter "/test/"
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
require
|
8
|
+
require "minitest/autorun"
|
9
9
|
|
10
|
-
require
|
10
|
+
require "microfsm"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microfsm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,16 +54,14 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
description: MicroFSM implements a minimal/simple Finite-State Machine (FSM). Transitions
|
56
56
|
are triggered by events. Actions for a transition can be added as callbacks.
|
57
|
-
email: dittmar.krall@
|
57
|
+
email: dittmar.krall@matiq.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".github/workflows/rake.yml"
|
63
|
-
- ".rubocop.yml"
|
64
63
|
- ".ruby-gemset"
|
65
64
|
- ".ruby-version"
|
66
|
-
- ".watchr"
|
67
65
|
- Gemfile
|
68
66
|
- Gemfile.lock
|
69
67
|
- LICENSE
|
@@ -79,7 +77,7 @@ files:
|
|
79
77
|
- test/introspection_test.rb
|
80
78
|
- test/microfsm_test.rb
|
81
79
|
- test/test_helper.rb
|
82
|
-
homepage: https://
|
80
|
+
homepage: https://matiq.com
|
83
81
|
licenses:
|
84
82
|
- MIT
|
85
83
|
metadata:
|
@@ -99,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
97
|
- !ruby/object:Gem::Version
|
100
98
|
version: '0'
|
101
99
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
100
|
+
rubygems_version: 3.3.26
|
103
101
|
signing_key:
|
104
102
|
specification_version: 4
|
105
103
|
summary: Minimal Finite State Machine.
|
data/.rubocop.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
inherit_from:
|
2
|
-
- '~/configs/.rubocop.yml'
|
3
|
-
|
4
|
-
AllCops:
|
5
|
-
NewCops: enable
|
6
|
-
Include:
|
7
|
-
- 'lib/**/*.rb'
|
8
|
-
|
9
|
-
Exclude:
|
10
|
-
- 'bin/**/*'
|
11
|
-
- 'test/**/*'
|
12
|
-
SuggestExtensions: false
|
13
|
-
|
14
|
-
Layout/AccessModifierIndentation:
|
15
|
-
Enabled: false
|
16
|
-
Layout/EmptyLinesAroundAccessModifier:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Metrics/AbcSize:
|
20
|
-
Enabled: false
|
data/.watchr
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
TESTING = %w[test]
|
2
|
-
HH = '#' * 22 unless defined?(HH)
|
3
|
-
H = '#' * 5 unless defined?(H)
|
4
|
-
|
5
|
-
def usage
|
6
|
-
puts <<-EOS
|
7
|
-
Ctrl-\\ or ctrl-4 Running all tests
|
8
|
-
Ctrl-C Exit
|
9
|
-
EOS
|
10
|
-
end
|
11
|
-
|
12
|
-
def run(cmd)
|
13
|
-
puts "#{HH} #{Time.now} #{HH}"
|
14
|
-
puts "#{H} #{cmd}"
|
15
|
-
system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def run_it(type, file)
|
19
|
-
case type
|
20
|
-
when 'test'; run %(bundle exec ruby -I test #{file})
|
21
|
-
# when 'spec'; run %(rspec -X #{file})
|
22
|
-
else; puts "#{H} unknown type: #{type}, file: #{file}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def run_all_tests
|
27
|
-
puts "\n#{HH} Running all tests #{HH}\n"
|
28
|
-
TESTING.each { |dir| run "bundle exec rake #{dir}" if File.exist?(dir) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def run_matching_files(base)
|
32
|
-
base = base.split('_').first
|
33
|
-
TESTING.each { |type|
|
34
|
-
files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
|
35
|
-
run_it type, files.join(' ') unless files.empty?
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
TESTING.each { |type|
|
40
|
-
watch("#{type}/#{type}_helper\.rb") { run_all_tests }
|
41
|
-
watch('lib/.*\.rb') { run_all_tests }
|
42
|
-
watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
|
43
|
-
watch("#{type}/data/(.*)\.rb") { |match|
|
44
|
-
m1 = match[1]
|
45
|
-
run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
%w[rb erb haml slim].each { |type|
|
50
|
-
watch(".*/(.*)\.#{type}") { |match|
|
51
|
-
run_matching_files(match[1])
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
# Ctrl-\ or ctrl-4
|
56
|
-
Signal.trap('QUIT') { run_all_tests }
|
57
|
-
# Ctrl-C
|
58
|
-
Signal.trap('INT') { abort("Interrupted\n") }
|
59
|
-
usage
|