big_machine 1.1.0 → 1.1.1

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,32 +1,32 @@
1
- module BigMachine
2
- module ActiveRecord
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- class_attribute :state_attribute
7
- after_initialize :set_current_state_from_db
8
- end
9
-
10
- module ClassMethods
11
- def big_machine(options = {})
12
- super options
13
- self.state_attribute = options[:state_attribute] || 'state'
14
- end
15
- end
16
-
17
- def set_current_state_from_db
18
- attribute = send state_attribute
19
- if attribute
20
- set_current_state(attribute.constantize)
21
- else
22
- self.class.set_initial_state_class
23
- end
24
- end
25
-
26
- def set_current_state(new_state_class)
27
- super(new_state_class)
28
- send "#{state_attribute}=", new_state_class.name
29
- end
30
-
31
- end
32
- end
1
+ module BigMachine
2
+ module ActiveRecord
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class_attribute :state_attribute
7
+ after_initialize :set_current_state_from_db
8
+ end
9
+
10
+ module ClassMethods
11
+ def big_machine(options = {})
12
+ super options
13
+ self.state_attribute = options[:state_attribute] || 'state'
14
+ end
15
+ end
16
+
17
+ def set_current_state_from_db
18
+ return unless self.class.initial_state_class
19
+
20
+ attribute = send state_attribute
21
+
22
+ state_class = attribute ? attribute.constantize : self.class.initial_state_class
23
+ set_current_state(state_class)
24
+ end
25
+
26
+ def set_current_state(new_state_class)
27
+ super(new_state_class)
28
+ send "#{state_attribute}=", new_state_class.name
29
+ end
30
+
31
+ end
32
+ end
@@ -1,26 +1,32 @@
1
- module BigMachine
2
- module Lock
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- end
7
-
8
- def locked?
9
- @locked
10
- end
11
-
12
- def enter
13
- @locked = true
14
- end
15
-
16
- def unlock
17
- @locked = false
18
- end
19
-
20
- def transition_to(state_class)
21
- return if @locked
22
-
23
- super
24
- end
25
- end
26
- end
1
+ module BigMachine
2
+ module Lock
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def transition_methods
10
+ public_instance_methods - State.public_instance_methods - [:unlock, :locked?]
11
+ end
12
+ end
13
+
14
+ def locked?
15
+ @locked
16
+ end
17
+
18
+ def enter(*args)
19
+ @locked = true
20
+ end
21
+
22
+ def unlock(*args)
23
+ @locked = false
24
+ end
25
+
26
+ def transition_to(state_class, *args, &block)
27
+ return if @locked
28
+
29
+ super(state_class, *args, &block)
30
+ end
31
+ end
32
+ end
@@ -11,6 +11,14 @@ module BigMachine
11
11
  public_instance_methods - State.public_instance_methods
12
12
  end
13
13
 
14
+ def self.human_name
15
+ self.to_s.split('::').last.underscore
16
+ end
17
+
18
+ def human_name
19
+ self.class.human_name
20
+ end
21
+
14
22
  def transition_to(state_class, *args, &block)
15
23
  @stateful.transition_to(state_class, *args, &block)
16
24
  end
@@ -1,3 +1,3 @@
1
1
  module BigMachine
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -130,11 +130,11 @@ class BigMachineTest < ActiveSupport::TestCase
130
130
 
131
131
  test "big machine can lock state" do
132
132
  @dummy.lock
133
- assert @dummy.locked?
133
+ assert @dummy.current_state.locked?
134
134
  @dummy.back_to_draft
135
135
  assert_equal 'LockState', @dummy.current_state.class.name
136
136
  assert @dummy.current_state.locked?
137
- @dummy.unlock
137
+ @dummy.current_state.unlock
138
138
  assert !@dummy.current_state.locked?
139
139
  assert_equal 'LockState', @dummy.current_state.class.name
140
140
  @dummy.back_to_draft
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: