aasm_history 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/aasm_history.gemspec +4 -4
- data/lib/aasm_history.rb +7 -0
- data/lib/aasm_history/aasm_ext/base.rb +28 -8
- data/lib/aasm_history/aasm_ext/configuration.rb +6 -0
- data/lib/aasm_history/version.rb +1 -1
- data/spec/aasm_history_spec.rb +34 -0
- data/spec/support/active_record/models.rb +4 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb0db21a3554b04441443e5c89f047e498d4dc0
|
4
|
+
data.tar.gz: 1e28227d0d95e9b93ea21126502bbff4454dd849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b39cd5c6b03be420f8f13172659cf5bfdf6d50557d1db759f7948577e701ab6c0ba5644ad2276f0b50173e1dc9357cc57de2bc4398ab7e9caab2b2f1aa56bcf
|
7
|
+
data.tar.gz: 7aff72b3c13fe2166eacb6d40e266a9d4d45adb073789fc26a93f6d9a7727f28c32826b75a5c95df62e55677e8ce83987cb1ea4223dfa8516619efbbeeecdaa5
|
data/README.md
CHANGED
@@ -68,6 +68,11 @@ You can also call `has_state_history` in your model to create `state_histories`
|
|
68
68
|
#> Order.last.state_histories
|
69
69
|
[#<StateHistory id: 2, state: "in_production", previous_state: "new", stateable_id: 2, stateable_type: "Order", created_at: "2014-09-27 22:34:00", updated_at: "2014-09-27 22:34:00">]
|
70
70
|
|
71
|
+
## Configuration
|
72
|
+
|
73
|
+
In initializer you can set `AasmHistory.enabled_by_default = true` to make all AASM instances have history support by default (in other words no need to call `has_history`).
|
74
|
+
To make exception call `has_history(false)` in `aasm` block.
|
75
|
+
|
71
76
|
## Extending
|
72
77
|
|
73
78
|
Gem is highly extendable and configurable.
|
data/aasm_history.gemspec
CHANGED
@@ -6,10 +6,10 @@ require 'aasm_history/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'aasm_history'
|
8
8
|
spec.version = AasmHistory::VERSION
|
9
|
-
spec.authors = ['Jan Jedrychowski']
|
10
|
-
spec.email = ['
|
9
|
+
spec.authors = ['Jan Jedrychowski', 'brogoz']
|
10
|
+
spec.email = ['hello@infiniteloop.eu']
|
11
11
|
spec.summary = %q{Track and persist AASM state history}
|
12
|
-
spec.homepage = 'https://github.com/
|
12
|
+
spec.homepage = 'https://github.com/infiniteloopeu/aasm_history'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
spec.required_ruby_version = '>= 2.0.0' # due to Module#prepend
|
19
19
|
|
20
|
-
spec.add_dependency 'aasm', '~>
|
20
|
+
spec.add_dependency 'aasm', '~> 4.2'
|
21
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
data/lib/aasm_history.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'aasm'
|
2
2
|
|
3
3
|
module AasmHistory
|
4
|
+
class << self
|
5
|
+
attr_accessor :enabled_by_default
|
6
|
+
end
|
7
|
+
|
8
|
+
self.enabled_by_default = false
|
9
|
+
|
4
10
|
autoload :PersistanceDeterminator, 'aasm_history/persistance_determinator'
|
5
11
|
autoload :UnknownPersistanceLayer, 'aasm_history/persistance_determinator'
|
6
12
|
|
@@ -17,4 +23,5 @@ end
|
|
17
23
|
|
18
24
|
require 'aasm_history/version'
|
19
25
|
require 'aasm_history/aasm_ext/base'
|
26
|
+
require 'aasm_history/aasm_ext/configuration'
|
20
27
|
require 'aasm_history/load_extensions'
|
@@ -1,14 +1,34 @@
|
|
1
1
|
module AASM
|
2
2
|
class Base
|
3
|
-
def has_history
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
def has_history enabled = true
|
4
|
+
@options[:history_enabled] = enabled
|
5
|
+
if enabled
|
6
|
+
case AasmHistory::PersistanceDeterminator.determine(@klass)
|
7
|
+
when :active_record
|
8
|
+
configure :history_class, 'StateHistory'
|
9
|
+
configure :creator_class, 'AasmHistory::Persistance::ActiveRecordCreator'
|
10
|
+
@klass.send :prepend, AasmHistory::Persistance::ActiveRecord
|
11
|
+
else
|
12
|
+
raise AasmHistory::UnknownPersistanceLayer
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
16
|
+
|
17
|
+
def history_enabled?
|
18
|
+
@options[:history_enabled]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
def aasm(options={}, &block)
|
24
|
+
@aasm ||= AASM::Base.new(self, options)
|
25
|
+
if block
|
26
|
+
@aasm.instance_eval(&block)
|
27
|
+
if AasmHistory.enabled_by_default && @aasm.history_enabled? == nil
|
28
|
+
@aasm.has_history
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@aasm
|
32
|
+
end
|
13
33
|
end
|
14
34
|
end
|
data/lib/aasm_history/version.rb
CHANGED
data/spec/aasm_history_spec.rb
CHANGED
@@ -14,6 +14,40 @@ describe 'determining persistance layer' do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
describe 'configuration' do
|
18
|
+
context 'default' do
|
19
|
+
it 'has enabled_by_default set to false by default' do
|
20
|
+
expect(AasmHistory.enabled_by_default).to eq false
|
21
|
+
aasm = DummyNotConfigured.aasm
|
22
|
+
allow(aasm).to receive(:has_history)
|
23
|
+
DummyNotConfigured.aasm {}
|
24
|
+
expect(aasm).not_to have_received(:has_history)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'enabled_by_default set to true' do
|
29
|
+
after do
|
30
|
+
AasmHistory.enabled_by_default = false # change back to default
|
31
|
+
end
|
32
|
+
it 'adds history to class with aasm' do
|
33
|
+
AasmHistory.enabled_by_default = true
|
34
|
+
aasm = DummyNotConfigured.aasm
|
35
|
+
allow(aasm).to receive(:has_history)
|
36
|
+
DummyNotConfigured.aasm {}
|
37
|
+
expect(aasm).to have_received(:has_history)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can be disabled' do
|
41
|
+
AasmHistory.enabled_by_default = true
|
42
|
+
aasm = DummyNotConfigured.aasm
|
43
|
+
DummyNotConfigured.aasm {
|
44
|
+
has_history false
|
45
|
+
}
|
46
|
+
expect(aasm.history_enabled?).to eq false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
17
51
|
describe 'saving history' do
|
18
52
|
describe 'active record' do
|
19
53
|
subject! do
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aasm_history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Jedrychowski
|
8
|
+
- brogoz
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: aasm
|
@@ -16,14 +17,14 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '4.2'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '4.2'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: rake
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +103,7 @@ dependencies:
|
|
102
103
|
version: 1.3.9
|
103
104
|
description:
|
104
105
|
email:
|
105
|
-
-
|
106
|
+
- hello@infiniteloop.eu
|
106
107
|
executables: []
|
107
108
|
extensions: []
|
108
109
|
extra_rdoc_files: []
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- aasm_history.gemspec
|
117
118
|
- lib/aasm_history.rb
|
118
119
|
- lib/aasm_history/aasm_ext/base.rb
|
120
|
+
- lib/aasm_history/aasm_ext/configuration.rb
|
119
121
|
- lib/aasm_history/ext/active_record.rb
|
120
122
|
- lib/aasm_history/load_extensions.rb
|
121
123
|
- lib/aasm_history/persistance/active_record.rb
|
@@ -126,7 +128,7 @@ files:
|
|
126
128
|
- spec/spec_helper.rb
|
127
129
|
- spec/support/active_record/models.rb
|
128
130
|
- spec/support/active_record/schema.rb
|
129
|
-
homepage: https://github.com/
|
131
|
+
homepage: https://github.com/infiniteloopeu/aasm_history
|
130
132
|
licenses:
|
131
133
|
- MIT
|
132
134
|
metadata: {}
|
@@ -146,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
148
|
version: '0'
|
147
149
|
requirements: []
|
148
150
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.6.14
|
150
152
|
signing_key:
|
151
153
|
specification_version: 4
|
152
154
|
summary: Track and persist AASM state history
|