aasm 2.4.0 → 3.0.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.
@@ -1,53 +0,0 @@
1
- class AASM::SupportingClasses::State
2
- attr_reader :name, :options
3
-
4
- def initialize(name, options={})
5
- @name = name
6
- update(options)
7
- end
8
-
9
- def ==(state)
10
- if state.is_a? Symbol
11
- name == state
12
- else
13
- name == state.name
14
- end
15
- end
16
-
17
- def call_action(action, record)
18
- action = @options[action]
19
- catch :halt_aasm_chain do
20
- action.is_a?(Array) ?
21
- action.each {|a| _call_action(a, record)} :
22
- _call_action(action, record)
23
- end
24
- end
25
-
26
- def display_name
27
- @display_name ||= name.to_s.gsub(/_/, ' ').capitalize
28
- end
29
-
30
- def for_select
31
- [display_name, name.to_s]
32
- end
33
-
34
- def update(options = {})
35
- if options.key?(:display) then
36
- @display_name = options.delete(:display)
37
- end
38
- @options = options
39
- self
40
- end
41
-
42
- private
43
-
44
- def _call_action(action, record)
45
- case action
46
- when Symbol, String
47
- record.send(action)
48
- when Proc
49
- action.call(record)
50
- end
51
- end
52
-
53
- end
@@ -1,46 +0,0 @@
1
- class AASM::SupportingClasses::StateTransition
2
- attr_reader :from, :to, :opts
3
- alias_method :options, :opts
4
-
5
- def initialize(opts)
6
- @from, @to, @guard, @on_transition = opts[:from], opts[:to], opts[:guard], opts[:on_transition]
7
- @opts = opts
8
- end
9
-
10
- def perform(obj, *args)
11
- case @guard
12
- when Symbol, String
13
- obj.send(@guard, *args)
14
- when Proc
15
- @guard.call(obj, *args)
16
- else
17
- true
18
- end
19
- end
20
-
21
- def execute(obj, *args)
22
- @on_transition.is_a?(Array) ?
23
- @on_transition.each {|ot| _execute(obj, ot, *args)} :
24
- _execute(obj, @on_transition, *args)
25
- end
26
-
27
- def ==(obj)
28
- @from == obj.from && @to == obj.to
29
- end
30
-
31
- def from?(value)
32
- @from == value
33
- end
34
-
35
- private
36
-
37
- def _execute(obj, on_transition, *args)
38
- case on_transition
39
- when Proc
40
- on_transition.arity == 0 ? on_transition.call : on_transition.call(obj, *args)
41
- when Symbol, String
42
- obj.send(:method, on_transition.to_sym).arity == 0 ? obj.send(on_transition) : obj.send(on_transition, *args)
43
- end
44
- end
45
-
46
- end
@@ -1,7 +0,0 @@
1
- module AASM::SupportingClasses
2
- end
3
-
4
- require File.join(File.dirname(__FILE__), 'base')
5
- require File.join(File.dirname(__FILE__), 'state_transition')
6
- require File.join(File.dirname(__FILE__), 'event')
7
- require File.join(File.dirname(__FILE__), 'state')