enum_state_machine 0.4.0 → 0.4.1

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
2
  SHA1:
3
- metadata.gz: 3ae151dc70ba36b4e8fe6269c557282d7651c302
4
- data.tar.gz: a03562029134f816981feddf364bc0d45807ced7
3
+ metadata.gz: f0fff66d7a0561056a0a44726a3ae5d94d5d9d24
4
+ data.tar.gz: 1ea8c3370bd2d8c15379c4aa898d2f7e9088aed9
5
5
  SHA512:
6
- metadata.gz: 4529e8a2615e81a8a8e3639de6db2b2856b70fe325315efee427cc08627e0c49d3cb97a8fa4b9fd7e6ea937b656a455e06b53081cad3326ed53bc7c7456466ae
7
- data.tar.gz: e3027199f6a2a345016d4f59f9c9aae5960b5717044f986cc0e782caea6ba0816e7a0f0c1654c1c2bdbe8363a01f1b3459ccd0cf5165ab6c94f194a1600a34a1
6
+ metadata.gz: 43c264aa10cd9ad765f69f17509e9412199b48a5246c3887377335bb4dc207a340099639dee6b8d87a569fc3ae5604569644a7e82c6ca38879c29828480c8c16
7
+ data.tar.gz: 4793fdab192b45767e9174a184b28710fc83f9afb291df56dcf44d5bf4a5783a89e2663ce99534bffe96abd084719f7d57e354769eac4a9ce3a498a2f0f31d9f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.4
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
+ ```
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency "activerecord-deprecated_finders", "~> 1.0.3"
23
23
  #s.add_dependency "rails-observers", "~> 0.1.2"
24
- s.add_dependency "power_enum", "~> 2.7"
24
+ s.add_dependency "power_enum", "> 2.8", "< 4.0"
25
25
 
26
26
  s.add_development_dependency "rake"
27
27
  s.add_development_dependency "minitest", "~> 5.1"
@@ -1,3 +1,3 @@
1
1
  module EnumStateMachine
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - The HornsAndHooves Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
11
+ date: 2017-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: power_enum
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.8'
48
+ - - "<"
46
49
  - !ruby/object:Gem::Version
47
- version: '2.7'
50
+ version: '4.0'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.8'
58
+ - - "<"
53
59
  - !ruby/object:Gem::Version
54
- version: '2.7'
60
+ version: '4.0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -270,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
276
  version: '0'
271
277
  requirements: []
272
278
  rubyforge_project:
273
- rubygems_version: 2.2.2
279
+ rubygems_version: 2.6.8
274
280
  signing_key:
275
281
  specification_version: 4
276
282
  summary: Enum State machines for attributes
@@ -309,4 +315,3 @@ test_files:
309
315
  - test/unit/state_test.rb
310
316
  - test/unit/transition_collection_test.rb
311
317
  - test/unit/transition_test.rb
312
- has_rdoc: