51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'foobara-0.0.110/projects/state_machine/src/callbacks.rb', line 51
def create_register_callback_methods
if register_callback_methods
raise "Do not create register callback methods twice"
end
callback_methods = @register_callback_methods = []
tos = Set.new
transitions = Set.new
froms = Set.new
froms_to_tos = Set.new
transitions_to_tos = Set.new
froms_to_transitions = Set.new
froms_transitions_tos = Set.new
transition_map.each_pair do |from, to_map|
froms << from
to_map.each_pair do |transition, to|
transitions << transition
tos << to
froms_to_tos << [from, to]
transitions_to_tos << [transition, to]
froms_to_transitions << [from, transition]
froms_transitions_tos << [from, transition, to]
end
end
Foobara::Callback::Block.types.each do |type|
method_name = "#{type}_any_transition"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, &block)
end
froms.each do |from|
method_name = "#{type}_transition_from_#{from}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, from:, &block)
end
end
transitions.each do |transition|
method_name = "#{type}_#{transition}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, transition:, &block)
end
end
tos.each do |to|
method_name = "#{type}_transition_to_#{to}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, to:, &block)
end
end
froms_to_tos.each do |(from, to)|
method_name = "#{type}_transition_from_#{from}_to_#{to}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, to:, from:, &block)
end
end
transitions_to_tos.each do |(transition, to)|
method_name = "#{type}_#{transition}_to_#{to}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, transition:, to:, &block)
end
end
froms_to_transitions.each do |(from, transition)|
method_name = "#{type}_#{transition}_from_#{from}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, transition:, from:, &block)
end
end
froms_transitions_tos.each do |(from, transition, to)|
method_name = "#{type}_#{transition}_from_#{from}_to_#{to}"
callback_methods << method_name
define_method method_name do |&block|
register_transition_callback(type, transition:, from:, to:, &block)
end
end
end
end
|