enum_state_machine 0.4.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3ae151dc70ba36b4e8fe6269c557282d7651c302
4
- data.tar.gz: a03562029134f816981feddf364bc0d45807ced7
2
+ SHA256:
3
+ metadata.gz: b789f253ef713a0650807bc1d06439252411fca86b15c7c9947dfa466edb104b
4
+ data.tar.gz: dd54f68b6bd0ff062c98ab75bcfd4444e4879820a831a5def374845fcfec8380
5
5
  SHA512:
6
- metadata.gz: 4529e8a2615e81a8a8e3639de6db2b2856b70fe325315efee427cc08627e0c49d3cb97a8fa4b9fd7e6ea937b656a455e06b53081cad3326ed53bc7c7456466ae
7
- data.tar.gz: e3027199f6a2a345016d4f59f9c9aae5960b5717044f986cc0e782caea6ba0816e7a0f0c1654c1c2bdbe8363a01f1b3459ccd0cf5165ab6c94f194a1600a34a1
6
+ metadata.gz: 3d35efc93d0045b153105ddb01499a4b09db5d70acf740ab3ac1ac9b106d5f917042491604c2702b40137acdd317e0b0d4bc4c8c1670146010c6c5915ea9f3ad
7
+ data.tar.gz: 73389b3df7fe1d451e81321e4eee3e0c4714fcf89270ac1afd10094aca807df6543d8785f79884869f3f6b807d16b61edf0cd3763e1e897c83bb040cf7ea8117
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.6.5
data/README.md CHANGED
@@ -1,4 +1,75 @@
1
- ##enum_state_machine
1
+ ## enum_state_machine
2
2
  ==================
3
3
 
4
- state_machine patches to use PowerEnum enums for state values.
4
+ `state_machine` patches to use PowerEnum enums for state values.
5
+ It allows you to use an enumerated attribute to track a state machine status.
6
+
7
+ ## Installation:
8
+
9
+ Add the following to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'enum_state_machine'
13
+ ```
14
+
15
+ ## Usage:
16
+
17
+ Before using this you must familiarize yourself with the [PowerEnum](https://github.com/albertosaurus/power_enum_2)
18
+ and [state_machine](https://github.com/pluginaweek/state_machine) gems.
19
+
20
+ Include `EnumStateMachine::StateEnum` in our model. That adds a single method that is used to define an enumerated state attribute:
21
+
22
+ ```ruby
23
+ # state_attr is the name of the state variable
24
+ # enum_attr is the name of the underlying enumerated attribute
25
+ # enum_opts are options to be passed to has_enumerated
26
+ has_state_enum(state_attr, enum_attr, enum_opts = {})
27
+ ```
28
+
29
+ This is best illustrated with an example. Suppose you have a Grenade model that can have four possible states: stored, armed, kaboom, and fizzle.
30
+
31
+ ```ruby
32
+
33
+ # Migration
34
+
35
+ create_enum :grenade_status
36
+
37
+ create_table :grenades do |t|
38
+ t.references :grenade_statuses
39
+ t.boolean :is_defective
40
+
41
+ t.timestamps
42
+ end
43
+
44
+ # Seeds
45
+
46
+ GrenadeStatus.update_enumerations_model do
47
+ [:unarmed, :armed, :kaboom, :fizzle].each { |name| GrenadeStatus.create! name: name }
48
+ end
49
+
50
+ # Models
51
+
52
+ class GrenadeStatus < ActiveRecord::Base
53
+ acts_as_enumerated
54
+ end
55
+
56
+ class Grenade < ActiveRecord::Base
57
+ include EnumStateMachine::StateEnum
58
+ has_state_enum :status, :grenade_status, default: :unarmed
59
+
60
+ state_machine :status, initial: :unarmed do
61
+ event :pulled_pin do
62
+ transition :unarmed => :armed
63
+ end
64
+
65
+ event :thrown do
66
+ # a defective grenade won't explode
67
+ transition :armed => :fizzle, :if => :is_defective?
68
+ # a normal armed one will explode
69
+ transition :armed => :kaboom
70
+ # If you forgot to pull the pin, nothing happens
71
+ transition :unarmed => :unarmed
72
+ end
73
+ end
74
+ end
75
+ ```
@@ -17,11 +17,10 @@ Gem::Specification.new do |s|
17
17
  s.extra_rdoc_files = %w(README.md CHANGELOG.md LICENSE)
18
18
  s.license = 'MIT'
19
19
 
20
- s.add_dependency "rails", "~> 4.0"
21
-
22
- s.add_dependency "activerecord-deprecated_finders", "~> 1.0.3"
23
- #s.add_dependency "rails-observers", "~> 0.1.2"
24
- s.add_dependency "power_enum", "~> 2.7"
20
+ s.add_dependency "rails", "> 4.0", "< 7.0"
21
+ s.add_dependency "activerecord-deprecated_finders", ">= 1.0.3"
22
+ #s.add_dependency "rails-observers", ">= 0.1.2"
23
+ s.add_dependency "power_enum", "> 2.8", "< 4.0"
25
24
 
26
25
  s.add_development_dependency "rake"
27
26
  s.add_development_dependency "minitest", "~> 5.1"
@@ -455,10 +455,17 @@ module EnumStateMachine
455
455
  # attributes passed into #initialize
456
456
  define_helper :class, <<-end_eval, __FILE__, __LINE__ + 1
457
457
  def column_defaults(*) #:nodoc:
458
- result = super
458
+ @column_defaults = super
459
+ return @column_defaults if @column_defaults_are_set
460
+ @column_defaults_are_set = true
461
+
462
+ was_frozen = @column_defaults.frozen?
463
+ @column_defaults = @column_defaults.deep_dup if was_frozen
464
+
459
465
  # No need to pass in an object, since the overrides will be forced
460
- self.state_machines.initialize_states(nil, :static => :force, :dynamic => false, :to => result)
461
- result
466
+ self.state_machines.initialize_states(nil, :static => :force, :dynamic => false, :to => @column_defaults)
467
+
468
+ @column_defaults.tap { |defaults| defaults.freeze if was_frozen }
462
469
  end
463
470
  end_eval
464
471
  end
@@ -1,3 +1,3 @@
1
1
  module EnumStateMachine
2
- VERSION = "0.4.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -247,7 +247,7 @@ class EventWithConflictingHelpersAfterDefinitionTest < MiniTest::Test
247
247
  end
248
248
 
249
249
  assert_equal false, @object.can_ignite?
250
- assert_equal nil, @object.ignite_transition
250
+ assert_nil @object.ignite_transition
251
251
  assert_equal false, @object.ignite
252
252
  assert_raises(EnumStateMachine::InvalidTransition) { @object.ignite! }
253
253
  end
@@ -764,7 +764,7 @@ class EventWithTransitionWithNilToStateTest < MiniTest::Test
764
764
  transition = @event.transition_for(@object)
765
765
  refute_nil transition
766
766
  assert_equal 'idling', transition.from
767
- assert_equal nil, transition.to
767
+ assert_nil transition.to
768
768
  assert_equal :park, transition.event
769
769
  end
770
770
 
@@ -774,7 +774,7 @@ class EventWithTransitionWithNilToStateTest < MiniTest::Test
774
774
 
775
775
  def test_should_not_change_the_current_state
776
776
  @event.fire(@object)
777
- assert_equal nil, @object.state
777
+ assert_nil @object.state
778
778
  end
779
779
  end
780
780
 
@@ -1847,10 +1847,10 @@ class MachineWithConflictingHelpersAfterDefinitionTest < MiniTest::Test
1847
1847
  assert_equal 'parked', @klass.human_state_name(:parked)
1848
1848
  assert_equal 'ignite', @klass.human_state_event_name(:ignite)
1849
1849
 
1850
- assert_equal nil, @object.state
1850
+ assert_nil @object.state
1851
1851
  @object.state = 'idling'
1852
1852
  assert_equal 'idling', @object.state
1853
- assert_equal nil, @object.status
1853
+ assert_nil @object.status
1854
1854
  assert_equal false, @object.state?(:parked)
1855
1855
  assert_equal :idling, @object.state_name
1856
1856
  assert_equal 'idling', @object.human_state_name
@@ -79,7 +79,7 @@ class TransitionCollectionEmptyWithBlockTest < MiniTest::Test
79
79
  end
80
80
 
81
81
  def test_should_use_block_reslut_if_nil
82
- assert_equal nil, @transitions.perform { nil }
82
+ assert_nil @transitions.perform { nil }
83
83
  end
84
84
  end
85
85
 
metadata CHANGED
@@ -1,57 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The HornsAndHooves Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
11
+ date: 2022-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activerecord-deprecated_finders
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: 1.0.3
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - "~>"
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: 1.0.3
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: power_enum
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">"
46
52
  - !ruby/object:Gem::Version
47
- version: '2.7'
53
+ version: '2.8'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '4.0'
48
57
  type: :runtime
49
58
  prerelease: false
50
59
  version_requirements: !ruby/object:Gem::Requirement
51
60
  requirements:
52
- - - "~>"
61
+ - - ">"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.8'
64
+ - - "<"
53
65
  - !ruby/object:Gem::Version
54
- version: '2.7'
66
+ version: '4.0'
55
67
  - !ruby/object:Gem::Dependency
56
68
  name: rake
57
69
  requirement: !ruby/object:Gem::Requirement
@@ -248,7 +260,7 @@ homepage: https://github.com/HornsAndHooves/enum_state_machine
248
260
  licenses:
249
261
  - MIT
250
262
  metadata: {}
251
- post_install_message:
263
+ post_install_message:
252
264
  rdoc_options:
253
265
  - "--line-numbers"
254
266
  - "--inline-source"
@@ -269,9 +281,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
281
  - !ruby/object:Gem::Version
270
282
  version: '0'
271
283
  requirements: []
272
- rubyforge_project:
273
- rubygems_version: 2.2.2
274
- signing_key:
284
+ rubygems_version: 3.0.9
285
+ signing_key:
275
286
  specification_version: 4
276
287
  summary: Enum State machines for attributes
277
288
  test_files:
@@ -309,4 +320,3 @@ test_files:
309
320
  - test/unit/state_test.rb
310
321
  - test/unit/transition_collection_test.rb
311
322
  - test/unit/transition_test.rb
312
- has_rdoc: