strict_states 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/strict_states.rb +162 -0
- data/lib/strict_states/checker.rb +79 -0
- data/lib/strict_states/strict_hash.rb +7 -0
- data/lib/strict_states/version.rb +3 -0
- data/strict_states.gemspec +27 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7eb56411c3e039689e4f965c5a51f28cb66cb51
|
4
|
+
data.tar.gz: b57483f164ce151be42609b08cb9da6edcd62a4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21eb00e217b2c5d2d4e238bd1c064bb52ad53452a7abd04ae314ac2aaea26a6735671c6036959a12474d34ed71e0592068da7ec423c6d04a88cabbaa66537d6b
|
7
|
+
data.tar.gz: 10ed7ed0e33d050fec0d7da660276fbc34174359868f3b355e4656996db8654ceab2ddddd46a46f836c62db4c330f0ea5f69ddb572e3dba6825449ae94f6fc38
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Peter Boling
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# StrictStates
|
2
|
+
|
3
|
+
Provides utility lookup methods to be used to access the states of your state machine to ensure you never typo them.
|
4
|
+
Will raise errors on state machine state typos immediately, so if the code runs you know it is correct.
|
5
|
+
|
6
|
+
Expected to be compatible with, and support multiple state machines per model, for:
|
7
|
+
|
8
|
+
* The venerable [state_machine](https://github.com/pluginaweek/state_machine) gem (Rails 3 max)
|
9
|
+
* The [@seuros](https://github.com/seuros) forked [state_machine](https://github.com/seuros/state_machine) repo (Rails 4 compat!)
|
10
|
+
* The community-driven rewrite [state_machines](https://github.com/state-machines/state_machines) gem (Rails 4 & 5 compat!)
|
11
|
+
* The venerable [aasm](https://github.com/aasm/aasm) gem (formerly "acts_as_state_machine") (Rails 3 & 4)
|
12
|
+
* Both pre and post version 4.3.0 when multiple state machines per model was added.
|
13
|
+
|
14
|
+
Please file a bug if compatibility is missing for your state machine.
|
15
|
+
|
16
|
+
`:machine_name` as `:state` is so universally common that it has been made the default when not provided.
|
17
|
+
|
18
|
+
Most apps only use one state machine implementation, like aasm, or state_machines, however, apps can (and do) use multiple state machine implementations at the same time. This gem supports that, and keeps all the states per-model, per-machine, per-engine separate!
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'strict_states'
|
26
|
+
```
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
$ bundle
|
31
|
+
|
32
|
+
Or install it yourself as:
|
33
|
+
|
34
|
+
$ gem install strict_states
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class MyModel < ActiveRecord::Base
|
40
|
+
# ...
|
41
|
+
# <<<===--- AFTER STATE MACHINE DEFINITION ---===>>>
|
42
|
+
# ...
|
43
|
+
include StrictStates.checker(
|
44
|
+
klass: self,
|
45
|
+
machines: {
|
46
|
+
state: :pluginaweek,
|
47
|
+
awesome_level: :pluginaweek,
|
48
|
+
bogus_level: ->(context, machine_name) {
|
49
|
+
context.state_machines[machine_name.to_sym].states.map(&:name)
|
50
|
+
}
|
51
|
+
}
|
52
|
+
)
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
### strict_state
|
57
|
+
|
58
|
+
Given a state return the same state if they are valid for the given state machine,
|
59
|
+
otherwise raise an error
|
60
|
+
|
61
|
+
Example:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
MyModel.strict_state(:good, machine_name: :state)
|
65
|
+
=> "good"
|
66
|
+
```
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
MyModel.strict_state(:not_actually_a_thing, machine_name: :drive_status)
|
70
|
+
=> KeyError: key not found: :not_actually_a_thing
|
71
|
+
```
|
72
|
+
|
73
|
+
This is better than creating discrete constants for each potential state string in a state machine,
|
74
|
+
because this checks, at app boot, to ensure the states are correct.
|
75
|
+
(e.g. "gift card", vs "gift_card").
|
76
|
+
|
77
|
+
### strict_state_array
|
78
|
+
|
79
|
+
Given an array of states return the same array of states if they are valid for the given state machine,
|
80
|
+
otherwise raise an error.
|
81
|
+
|
82
|
+
Example:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
MyModel.strict_state_array(:good, :bad, :on_hold, machine_name: :state)
|
86
|
+
=> ["good", "bad", "on_hold"]
|
87
|
+
```
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
MyModel.strict_state_array(:good, :bad, :steve_martin, machine_name: :drive_status)
|
91
|
+
=> KeyError: key not found: :steve_martin
|
92
|
+
```
|
93
|
+
|
94
|
+
This is better than creating discrete constants for each potential set of states in a state machine,
|
95
|
+
because this checks, at app boot, to ensure the states are correct.
|
96
|
+
Raw strings in scopes and queries, not created via this method,
|
97
|
+
will not be bound to the state machine's implementation, so they will fail silently.
|
98
|
+
e.g. typos like "gift card" vs "gift_card" and no error raised
|
99
|
+
|
100
|
+
### strict_all_state_names
|
101
|
+
|
102
|
+
Given the name of a state machine, returns all states defined by the state machine, as an array of strings.
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
MyModel.strict_all_state_names(machine_name: :state)
|
106
|
+
=> ["good", "bad", "on_hold"]
|
107
|
+
```
|
108
|
+
|
109
|
+
### state_lookup
|
110
|
+
|
111
|
+
Given a machine name return the StrictStates::StrictHash used to lookup valid states.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
MyModel.state_lookup(machine_name: :state)
|
115
|
+
=> { :new => "new", :pending => "pending", :goofy => "goofy" }
|
116
|
+
```
|
117
|
+
|
118
|
+
### strict_state_lookup
|
119
|
+
|
120
|
+
Returns a StrictStates::StrictHash representation of all the state machine state definitions in the class. A class can have more than one state machine.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
MyModel.strict_state_lookup
|
124
|
+
=> {
|
125
|
+
:awesome_level =>
|
126
|
+
{ :not_awesome => "not_awesome", :awesome_11 => "awesome_11", :bad => "bad", :good => "good" },
|
127
|
+
:bogus_level =>
|
128
|
+
{ :new => "new", :pending => "pending", :goofy => "goofy" }
|
129
|
+
}
|
130
|
+
```
|
131
|
+
|
132
|
+
## Development
|
133
|
+
|
134
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
135
|
+
|
136
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
137
|
+
|
138
|
+
## Contributing
|
139
|
+
|
140
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/strict_states. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
141
|
+
|
142
|
+
|
143
|
+
## License
|
144
|
+
|
145
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
146
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "strict_states"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
require "strict_states/version"
|
2
|
+
require "strict_states/strict_hash"
|
3
|
+
require "strict_states/checker"
|
4
|
+
|
5
|
+
# The *STRICT* paradigm:
|
6
|
+
#
|
7
|
+
# * Will raise an error if states are spelled wrong when lookups happen through this paradigm.
|
8
|
+
# * Typos will be noisy, and many of them will error at app-load, so impossible to miss.
|
9
|
+
#
|
10
|
+
# Uses the StrictHash to accomplish this. See lib/strict_states/strict_hash.rb
|
11
|
+
#
|
12
|
+
# The *INCLUDE WITH ARGUMENTS* paradigm:
|
13
|
+
#
|
14
|
+
# * future-proof support for any/all state machines
|
15
|
+
# * easily integrate with any state machine engine not already supported by this gem
|
16
|
+
#
|
17
|
+
# Uses a method (StrictStates.checker) that returns a module (StrictStates::Checker) to accomplish this.
|
18
|
+
module StrictStates
|
19
|
+
# Usage:
|
20
|
+
#
|
21
|
+
# class MyModel < ActiveRecord::Base
|
22
|
+
# # ...
|
23
|
+
# # <<<===--- AFTER STATE MACHINE DEFINITION ---===>>>
|
24
|
+
# # ...
|
25
|
+
# include StrictStates.checker(
|
26
|
+
# klass: self,
|
27
|
+
# machines: {
|
28
|
+
# state: :pluginaweek,
|
29
|
+
# awesome_level: :pluginaweek,
|
30
|
+
# bogus_level: ->(context, machine_name) {
|
31
|
+
# context.state_machines[machine_name.to_sym].states.map(&:name)
|
32
|
+
# }
|
33
|
+
# }
|
34
|
+
# )
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
def self.checker(**config)
|
38
|
+
validate_config(config)
|
39
|
+
config[:machines] = states_for_machines(config[:klass], config[:machines])
|
40
|
+
set_strict_state_lookup(config)
|
41
|
+
::StrictStates::Checker
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# Supported engines:
|
47
|
+
#
|
48
|
+
# :pluginaweek - for pluginaweek/state_machine
|
49
|
+
# :seuros - for seuros/state_machine
|
50
|
+
# :state_machines - for state-machines/state_machines
|
51
|
+
# :aasm - for aasm/aasm version < 4.3.0
|
52
|
+
# :aasm_multiple - for aasm/aasm version >= 4.3.0
|
53
|
+
#
|
54
|
+
def self.engine_name_apis
|
55
|
+
{
|
56
|
+
pluginaweek: ->(context, machine_name) { context.state_machines[machine_name.to_sym].states.map(&:name) },
|
57
|
+
seuros: ->(context, machine_name) { context.state_machines[machine_name.to_sym].states.map(&:name) },
|
58
|
+
state_machines: ->(context, machine_name) { context.state_machines[machine_name.to_sym].states.map(&:name) },
|
59
|
+
aasm: ->(context, _) { context.aasm.states.map(&:name) }, # aasm gem version < 4.3.0
|
60
|
+
aasm_multiple: ->(context, machine_name) { context.aasm(machine_name).states.map(&:name) } # aasm gem version >= 4.3.0
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.strict_states_to_stings(states)
|
65
|
+
states.map {|state| state.to_s }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.create_strict_state_lookup(names)
|
69
|
+
default_strict_hash = names.each_with_object({}) do |state, memo|
|
70
|
+
memo[state.to_sym] = state
|
71
|
+
end
|
72
|
+
StrictHash[**default_strict_hash]
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.validate_config(**config)
|
76
|
+
raise ArgumentError, "config must have a :machines key with Hash value but was #{config[:machines]}" unless config[:machines] && config[:machines].is_a?(Hash)
|
77
|
+
raise ArgumentError, ":machines Hash must have values either from #{engine_name_apis.keys} or as Procs but was #{config[:machines]}" unless test_machines(config[:machines])
|
78
|
+
raise ArgumentError, "config must have a :klass key with a Class value but was #{config[:klass]}" unless config[:klass] && config[:klass].class == Class
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.test_machines(machines)
|
83
|
+
machines.values.all? do |engine|
|
84
|
+
engine_name_apis.keys.include?(engine) ||
|
85
|
+
engine.respond_to?(:call)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# params:
|
90
|
+
# klass - any Class object with a state machine
|
91
|
+
# machines -
|
92
|
+
# {
|
93
|
+
# state: :pluginaweek,
|
94
|
+
# awesome_level: :pluginaweek,
|
95
|
+
# bogus_level: ->(context, machine_name) {
|
96
|
+
# context.state_machines[machine_name.to_sym].states.map(&:name)}
|
97
|
+
# }
|
98
|
+
#
|
99
|
+
# Example result
|
100
|
+
#
|
101
|
+
# {
|
102
|
+
# state: ["one", "two", "three"],
|
103
|
+
# awesome_level: ["not_awesome", "awesome_11", "bad", "good"],
|
104
|
+
# bogus_level: ["new", "pending", "goofy"]
|
105
|
+
# }
|
106
|
+
#
|
107
|
+
def self.states_for_machines(klass, machines)
|
108
|
+
machines.inject({}) do |memo, (machine_name, engine)|
|
109
|
+
proc = get_proc_for_engine(engine)
|
110
|
+
memo[machine_name] =
|
111
|
+
strict_states_to_stings(
|
112
|
+
proc.call(klass, machine_name)
|
113
|
+
)
|
114
|
+
memo
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.get_proc_for_engine(engine)
|
119
|
+
if (proc = engine_name_apis[engine])
|
120
|
+
# Predefined Engine within this gem
|
121
|
+
proc
|
122
|
+
else
|
123
|
+
# Custom state machine name extraction Proc provided by caller
|
124
|
+
engine
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# params:
|
129
|
+
# config -
|
130
|
+
# {
|
131
|
+
# klass: Car, # any Class object with a state machine
|
132
|
+
# machines: { # the machine names, and states defined within each
|
133
|
+
# state: ["one", "two", "three"],
|
134
|
+
# awesome_level: ["not_awesome", "awesome_11", "bad", "good"],
|
135
|
+
# bogus_level: ["new", "pending", "goofy"]
|
136
|
+
# }
|
137
|
+
# }
|
138
|
+
#
|
139
|
+
# Result:
|
140
|
+
#
|
141
|
+
# MyModel.strict_state_lookup
|
142
|
+
# => {
|
143
|
+
# :state =>
|
144
|
+
# { :one => "one", :two => "two", :three => "three" }
|
145
|
+
# :awesome_level =>
|
146
|
+
# { :not_awesome => "not_awesome", :awesome_11 => "awesome_11", :bad => "bad", :good => "good" },
|
147
|
+
# :bogus_level =>
|
148
|
+
# { :new => "new", :pending => "pending", :goofy => "goofy" }
|
149
|
+
# }
|
150
|
+
def self.set_strict_state_lookup(config)
|
151
|
+
klass = config[:klass]
|
152
|
+
machines = config[:machines]
|
153
|
+
class << klass
|
154
|
+
attr_reader :strict_state_lookup
|
155
|
+
end
|
156
|
+
klass.instance_variable_set(:@strict_state_lookup, StrictStates::StrictHash.new)
|
157
|
+
machines.each do |machine_name, state_array|
|
158
|
+
klass.strict_state_lookup[machine_name.to_sym] = StrictStates.create_strict_state_lookup(state_array).freeze
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module StrictStates
|
2
|
+
module Checker
|
3
|
+
# Usage:
|
4
|
+
#
|
5
|
+
# class MyModel < ActiveRecord::Base
|
6
|
+
# # ...
|
7
|
+
# # <<<===--- AFTER STATE MACHINE DEFINITION ---===>>>
|
8
|
+
# # ...
|
9
|
+
# include StrictStates.checker(
|
10
|
+
# klass: self,
|
11
|
+
# machines: {
|
12
|
+
# state: :pluginaweek,
|
13
|
+
# awesome_level: :pluginaweek,
|
14
|
+
# bogus_level: ->(context, machine_name) {
|
15
|
+
# context.state_machines[machine_name.to_sym].states.map(&:name)
|
16
|
+
# }
|
17
|
+
# }
|
18
|
+
# )
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
def self.included(base)
|
22
|
+
base.send(:extend, ClassMethods)
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
# Given a state return the same state if they are valid for the given state machine,
|
27
|
+
#
|
28
|
+
# MyModel.state_lookup(machine_name: machine_name)
|
29
|
+
# => { :new => "new", :pending => "pending", :goofy => "goofy" }
|
30
|
+
#
|
31
|
+
def state_lookup(machine_name: :state)
|
32
|
+
strict_state_lookup[machine_name.to_sym]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Given a state return the same state if they are valid for the given state machine,
|
36
|
+
# otherwise raise an error
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
#
|
40
|
+
# MyModel.strict_state(:good, machine_name: :state)
|
41
|
+
# => "good"
|
42
|
+
# MyModel.strict_state(:not_actually_a_thing, machine_name: :drive_status) # Can support multiple state machines per model
|
43
|
+
# => KeyError: key not found: :not_actually_a_thing
|
44
|
+
#
|
45
|
+
# This is better than creating discrete constants for each potential state string in a state machine,
|
46
|
+
# because this checks, at app boot, to ensure the states are correct.
|
47
|
+
# (e.g. "gift card", vs "gift_card").
|
48
|
+
#
|
49
|
+
def strict_state(state, machine_name: :state)
|
50
|
+
state_lookup(machine_name: machine_name)[state.to_sym] # This will raise an error if the state key is not a valid state
|
51
|
+
end
|
52
|
+
|
53
|
+
# Given an array of states return the same array of states if they are valid for the given state machine,
|
54
|
+
# otherwise raise an error
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
#
|
58
|
+
# MyModel.strict_state_array(:good, :bad, :on_hold, machine_name: :state)
|
59
|
+
# => ["good", "bad", "on_hold"]
|
60
|
+
# MyModel.strict_state_array(:good, :bad, :steve_martin, machine_name: :drive_status) # Can support multiple state machines per model
|
61
|
+
# => KeyError: key not found: :steve_martin
|
62
|
+
#
|
63
|
+
# This is better than creating discrete constants for each potential set of states in a state machine,
|
64
|
+
# because this checks, at app boot, to ensure the states are correct.
|
65
|
+
# Raw strings in scopes and queries, not created via this method,
|
66
|
+
# will not be bound to the state machine's implementation, so they will fail silently.
|
67
|
+
# e.g. typos like "gift card" vs "gift_card" and no error raised
|
68
|
+
#
|
69
|
+
def strict_state_array(*names, machine_name: :state)
|
70
|
+
names.map {|state| strict_state(state, machine_name: machine_name) }
|
71
|
+
end
|
72
|
+
|
73
|
+
# Given the name of a state machine, returns all states defined by the state machine, as an array of strings.
|
74
|
+
def strict_all_state_names(machine_name: :state)
|
75
|
+
state_lookup(machine_name: machine_name).values # keys would be symbols!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'strict_states/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "strict_states"
|
8
|
+
spec.version = StrictStates::VERSION
|
9
|
+
spec.authors = ["Peter Boling"]
|
10
|
+
spec.email = ["peter.boling@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Safely access state machine states with guarantee that there are no typos.}
|
13
|
+
spec.description = %q{Safely access state machine states with guarantee that there are no typos. Compatible with all Ruby state machine libraries.}
|
14
|
+
spec.homepage = "https://github.com/pboling/strict_states"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "hashie", ">= 3.4.3"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strict_states
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Boling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.4.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Safely access state machine states with guarantee that there are no typos. Compatible
|
70
|
+
with all Ruby state machine libraries.
|
71
|
+
email:
|
72
|
+
- peter.boling@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/strict_states.rb
|
88
|
+
- lib/strict_states/checker.rb
|
89
|
+
- lib/strict_states/strict_hash.rb
|
90
|
+
- lib/strict_states/version.rb
|
91
|
+
- strict_states.gemspec
|
92
|
+
homepage: https://github.com/pboling/strict_states
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.8
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Safely access state machine states with guarantee that there are no typos.
|
116
|
+
test_files: []
|