has_state_machine 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +33 -4
- data/lib/has_state_machine/state_helpers.rb +4 -2
- data/lib/has_state_machine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45eda1d8fea5dc52d88061386c86631f2af4b38651b4b8ea7051ea6e1873f034
|
4
|
+
data.tar.gz: ba0de1f1e78ee90f85f4753d888cf8dbe040d6993b748091626284a7a18a84d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd70251e921b0cc6efd5eb822a1cc015de54d081bd8cff2b9bdddf0e99e4301c7067639c7e2dc68be70b7f6dc40cfff8551b210494543d846ad00c12db6270ed
|
7
|
+
data.tar.gz: 71855b126675bff3a7799f5bb1c8e6d3f19d9df9884d3b06198fd2178fdf6ddc0a3e19302df3e0131ff59a1ab4126effef633b25f62228db20d43f9a8fdc3011
|
data/README.md
CHANGED
@@ -5,6 +5,14 @@
|
|
5
5
|
|
6
6
|
HasStateMachine uses ruby classes to make creating a finite state machine for your ActiveRecord models a breeze.
|
7
7
|
|
8
|
+
## Contents
|
9
|
+
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Usage](#usage)
|
12
|
+
- [Changelog](https://github.com/encampment/has_state_machine/blob/master/CHANGELOG.md)
|
13
|
+
- [Contributing](#contributing)
|
14
|
+
- [License](#license)
|
15
|
+
|
8
16
|
## Installation
|
9
17
|
Add this line to your application's Gemfile:
|
10
18
|
|
@@ -70,15 +78,15 @@ module Workflow
|
|
70
78
|
# There are callbacks for running logic before and after
|
71
79
|
# a transition occurs.
|
72
80
|
before_transition do
|
73
|
-
Rails.logger.info "Post is being archived
|
81
|
+
Rails.logger.info "== Post is being archived ==\n"
|
74
82
|
end
|
75
83
|
|
76
84
|
after_transition do
|
77
|
-
Rails.logger.info "Post has been archived
|
85
|
+
Rails.logger.info "== Post has been archived ==\n"
|
78
86
|
|
79
87
|
# You can access the previous state of the object in
|
80
88
|
# after_transition callbacks as well.
|
81
|
-
Rails.logger.info "Transitioned from #{previous_state}
|
89
|
+
Rails.logger.info "== Transitioned from #{previous_state} ==\n"
|
82
90
|
end
|
83
91
|
end
|
84
92
|
end
|
@@ -95,10 +103,31 @@ post.status # => "draft"
|
|
95
103
|
post.title = "Foobar"
|
96
104
|
post.status.transition_to(:published) # => true
|
97
105
|
post.status # => "published"
|
106
|
+
|
107
|
+
post.status.transition_to(:archived)
|
108
|
+
# == Post is being archived ==
|
109
|
+
# == Post has been archived ==
|
110
|
+
# == Transitioned from published ==
|
111
|
+
# => true
|
98
112
|
```
|
99
113
|
|
100
114
|
## Contributing
|
101
|
-
|
115
|
+
|
116
|
+
Anyone is encouraged to help improve this project. Here are a few ways you can help:
|
117
|
+
|
118
|
+
- [Report bugs](https://github.com/encampment/has_state_machine/issues)
|
119
|
+
- Fix bugs and [submit pull requests](https://github.com/encampment/has_state_machine/pulls)
|
120
|
+
- Write, clarify, or fix documentation
|
121
|
+
- Suggest or add new features
|
122
|
+
|
123
|
+
To get started with development:
|
124
|
+
|
125
|
+
```
|
126
|
+
git clone https://github.com/encampment/has_state_machine.git
|
127
|
+
cd has_state_machine
|
128
|
+
bundle install
|
129
|
+
bundle exec rake test
|
130
|
+
```
|
102
131
|
|
103
132
|
## License
|
104
133
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -55,7 +55,9 @@ module HasStateMachine
|
|
55
55
|
# @example Retreiving a users published posts
|
56
56
|
# > Post.published.where(user: user)
|
57
57
|
# #=> [#<Post>]
|
58
|
-
|
58
|
+
if defined?(ActiveRecord) && (self < ActiveRecord::Base)
|
59
|
+
scope state, -> { where("#{state_attribute} = ?", state) }
|
60
|
+
end
|
59
61
|
|
60
62
|
##
|
61
63
|
# Defines boolean helpers to determine if the active state matches
|
@@ -76,7 +78,7 @@ module HasStateMachine
|
|
76
78
|
# Getter for the current state of the model based on the configured state
|
77
79
|
# attribute.
|
78
80
|
def current_state
|
79
|
-
|
81
|
+
attributes.with_indifferent_access[state_attribute]
|
80
82
|
end
|
81
83
|
|
82
84
|
##
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Hargett
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-11-
|
12
|
+
date: 2020-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|