literal_enums 1.0.0 → 1.1.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
2
  SHA256:
3
- metadata.gz: 5032b916232ac6faa5494185fcf1fd84914e3e7781f791a0466e9b7617d136b9
4
- data.tar.gz: b7ab5c1a471672329cbd2f23707d206cd214c4bdb1b066ba908124750acd4e50
3
+ metadata.gz: 5966057536538f9691058988d2ead560f4c0827325d5334db07326f3d61ce73a
4
+ data.tar.gz: 76be2563d5184035fffb3df734c3578a140daf222e1c53f39d581f25db7dcfb1
5
5
  SHA512:
6
- metadata.gz: 609cbdcfa378843a507deb5d01b9da8a66e5d91a5e3b96b723a57af19e1cb3cb056fa4c9eac7bee96edec89544ce3e8d290c3da3cc664c30d09b9796a0fe4577
7
- data.tar.gz: 7f58231fbdad7bd52c717a0a05922661945fee6b0db62604bb85ee05d52fc62d9bc77071f11e7a8466cf84acc1f9911bca2e03481dad2e215b8d801dd25da432
6
+ metadata.gz: 570244eab14a91efd59a10267cbd05d0b41c2fbb5709486476a483e9877844e73658a99813b20e41f0912d91f4964e93bbac4832f810fd8fc9fd4e560c9495da
7
+ data.tar.gz: c2cecc679d71e18fcc14443ded0d082b9fc6ef051f9d325a0e7e89fdf149d554c7bc3e34cec9dfc20e363d89b3996ea34012a138d92e75e527fb9ae9c4681d6e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- literal_enums (1.0.0)
4
+ literal_enums (1.1.0)
5
5
  activesupport (~> 7.0.2.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -90,50 +90,50 @@ It is also possible to define a more complex state machine by defining `transiti
90
90
 
91
91
  ```ruby
92
92
  class State < Enum
93
- Unprocessed do
93
+ Pending do
94
94
  def transitions_to
95
- [Validated, Errored]
95
+ [Approved, Rejected]
96
96
  end
97
97
  end
98
98
 
99
- Validated do
99
+ Approved do
100
100
  def transitions_to
101
- [Published, Errored]
101
+ Published
102
102
  end
103
103
  end
104
104
 
105
- Published do
105
+ Rejected do
106
106
  def transitions_to
107
- [Processed, Errored]
107
+ Deleted
108
108
  end
109
109
  end
110
110
 
111
- Processed()
112
- Errored()
111
+ Deleted()
112
+ Published()
113
113
  end
114
114
  ```
115
115
 
116
116
  Given the above definition, we can transition from one state to another by calling `transition_to` with the newly desired state. This will raise a `LiteralEnums::TransitionError` if the transition is invalid.
117
117
 
118
118
  ```ruby
119
- State::Unprocessed.transition_to(State::Validated) # returns State::Validated.
120
- State::Unprocessed.transition_to(State::Processed) # raises a LiteralEnums::TransitionError.
119
+ State::Pending.transition_to(State::Approved) # returns State::Approved.
120
+ State::Pending.transition_to(State::Published) # raises a LiteralEnums::TransitionError.
121
121
  ```
122
122
 
123
123
  Alternatively, we can call the new state as a method on the old state.
124
124
 
125
125
  ```ruby
126
- State::Unprocessed.validated # returns State::Validated.
126
+ State::Pending.approved # returns State::Approved.
127
127
  ```
128
128
 
129
- An invalid transition will return a `NoMethodErorr` in this case as the method is not defined.
129
+ An invalid transition would return a `NoMethodErorr` in this case as the method is not defined.
130
130
 
131
131
  The advantage of using method calls to transition from one state to anotehr is the method calls can be chained.
132
132
 
133
133
  ```ruby
134
- State::Unprocessed.validated.processed # returns State::Processed, since it's valid to
135
- # move to State::Processed from State::Validated and it's
136
- # valid to move to State::Validated from State::Unprocessed.
134
+ State::Pending.approved.published # returns State::Published, since it's valid to
135
+ # move to State::Published from State::Approved and it's
136
+ # valid to move to State::Approved from State::Pending.
137
137
  ```
138
138
 
139
139
  ## Installation
data/lib/enum.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  class Enum
2
+ extend Enumerable
2
3
  include LiteralEnums::Transitions
3
4
 
4
5
  attr_reader :name, :value
5
6
 
6
- alias_method :to_s, :value
7
7
  alias_method :inspect, :name
8
8
 
9
9
  def initialize(name, value)
@@ -22,7 +22,7 @@ class Enum
22
22
  end
23
23
 
24
24
  def values
25
- members.map(&:value).to_set
25
+ map(&:value).to_set
26
26
  end
27
27
 
28
28
  def each(&block)
@@ -1,3 +1,3 @@
1
1
  module LiteralEnums
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: literal_enums
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper