state_machines-yard 0.1.0 → 0.4.0
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/.github/workflows/ci.yml +12 -4
- data/.github/workflows/release.yml +8 -6
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +38 -0
- data/CHANGELOG.md +54 -0
- data/Gemfile +12 -1
- data/README.md +45 -0
- data/Rakefile +21 -3
- data/lib/state_machines/yard/description.rb +77 -0
- data/lib/state_machines/yard/handlers/actions.rb +113 -0
- data/lib/state_machines/yard/handlers/base.rb +145 -20
- data/lib/state_machines/yard/handlers/callback.rb +56 -0
- data/lib/state_machines/yard/handlers/event.rb +16 -12
- data/lib/state_machines/yard/handlers/machine.rb +258 -253
- data/lib/state_machines/yard/handlers/requirements.rb +92 -0
- data/lib/state_machines/yard/handlers/state.rb +16 -12
- data/lib/state_machines/yard/handlers/transition.rb +59 -30
- data/lib/state_machines/yard/handlers.rb +3 -1
- data/lib/state_machines/yard/renderer.rb +62 -0
- data/lib/state_machines/yard/templates/default/class/html/setup.rb +14 -7
- data/lib/state_machines/yard/templates/default/class/html/state_machines.erb +33 -0
- data/lib/state_machines/yard/templates.rb +2 -0
- data/lib/state_machines/yard/version.rb +3 -1
- data/lib/state_machines/yard.rb +7 -0
- data/release-please-config.json +11 -0
- data/state_machines-yard.gemspec +16 -8
- data/test/description_test.rb +138 -0
- data/test/handlers/base_test.rb +43 -18
- data/test/handlers/callback_test.rb +168 -0
- data/test/handlers/event_test.rb +32 -19
- data/test/handlers/guards_test.rb +180 -0
- data/test/handlers/machine_test.rb +100 -16
- data/test/handlers/review_test.rb +192 -0
- data/test/handlers/state_test.rb +20 -13
- data/test/handlers/transition_test.rb +154 -19
- data/test/integration_test.rb +47 -36
- data/test/templates_test.rb +39 -16
- data/test/test_helper.rb +24 -10
- metadata +103 -20
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StateMachines
|
|
4
|
+
module Yard
|
|
5
|
+
module Handlers
|
|
6
|
+
# Handles and processes the transition callbacks: before_transition,
|
|
7
|
+
# after_transition, around_transition and after_failure. The
|
|
8
|
+
# documented machine gets each callback with the methods it runs, the
|
|
9
|
+
# transitions it runs on (from/to/on and their except_ forms, or
|
|
10
|
+
# implicit from => to pairs) and its own conditions, read as the core
|
|
11
|
+
# reads a transition's.
|
|
12
|
+
class Callback < Base
|
|
13
|
+
include Requirements
|
|
14
|
+
include Actions
|
|
15
|
+
|
|
16
|
+
# The DSL method of each callback kind
|
|
17
|
+
KINDS = %i[before_transition after_transition around_transition after_failure].freeze
|
|
18
|
+
# Options the core takes that change how a callback runs, not when
|
|
19
|
+
BEHAVIOUR = %i[bind_to_object terminator].freeze
|
|
20
|
+
|
|
21
|
+
KINDS.each { handles method_call(it) }
|
|
22
|
+
|
|
23
|
+
# Store the handled method name for testing
|
|
24
|
+
@handles_method = KINDS
|
|
25
|
+
|
|
26
|
+
def process
|
|
27
|
+
return unless owner.is_a?(StateMachines::Machine)
|
|
28
|
+
|
|
29
|
+
owner.public_send(call_node.name, **callback_options)
|
|
30
|
+
rescue Unreadable, ArgumentError => e
|
|
31
|
+
# A callback that cannot be read, or that the core refuses, would be
|
|
32
|
+
# documented as running on other transitions or methods than it does
|
|
33
|
+
skip(call_node.name.to_s, e)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def callback_options
|
|
39
|
+
methods = positional_arguments.map { action(it) }
|
|
40
|
+
options = option_pairs.each_with_object({}) do |(key, value), read|
|
|
41
|
+
name = requirement(key)
|
|
42
|
+
next if BEHAVIOUR.include?(name)
|
|
43
|
+
|
|
44
|
+
if name == :do
|
|
45
|
+
methods.concat(action_list(value))
|
|
46
|
+
else
|
|
47
|
+
read[name] = option_value(name, value)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
methods.concat(block_actions(call_node.block)) if call_node.block
|
|
51
|
+
options.merge(do: methods)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -1,28 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module StateMachines
|
|
2
4
|
module Yard
|
|
3
5
|
module Handlers
|
|
4
6
|
# Handles and processes #event
|
|
5
7
|
class Event < Base
|
|
6
8
|
handles method_call(:event)
|
|
7
|
-
|
|
9
|
+
|
|
8
10
|
# Store the handled method name for testing
|
|
9
11
|
@handles_method = :event
|
|
10
12
|
|
|
11
13
|
def process
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
return unless owner.is_a?(StateMachines::Machine)
|
|
15
|
+
|
|
16
|
+
handler = self
|
|
17
|
+
block = statement.block
|
|
18
|
+
names = positional_arguments.flat_map { names_in(it) }
|
|
19
|
+
options = literal_options(%i[human_name], code: %i[human_name])
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if statement.block
|
|
21
|
-
handler.parse_block(statement.block.last, owner: self)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
21
|
+
names.each do |name|
|
|
22
|
+
owner.event(name, **options) do
|
|
23
|
+
handler.parse_block(block.last, owner: self) if block
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
+
rescue Unreadable, ArgumentError => e
|
|
27
|
+
# One the core refuses (a name of another type than the others) is
|
|
28
|
+
# not documented as something else
|
|
29
|
+
skip('event', e)
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
end
|