activerecord-fsm 0.1.1 → 0.1.2
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/Gemfile.lock +1 -1
- data/README.md +18 -4
- data/lib/activerecord/fsm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 351276a49e27c515507b1e7857e9a67f554014b0d104f3044b7564ef3c8f1b60
|
4
|
+
data.tar.gz: b6820092158ca95745e4d4286539b1bb3a2b89995a639415a753cb2815bfedad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16bb26cfdd1bea69b4f740e575b7d7c3319e1acce307650fdc999ae1dea86b9477d07b9e3352ec61e7abc13a3b6e688a7ce9f9c7435e691901c5f2cba05c4d25
|
7
|
+
data.tar.gz: ac6f2bd60084ac177923c03afa8934d90cc7a12709c77b402237f6f3b8e8a19699cbdbdcffaf5af643c6bca95fdfcfc7e70828ccec03dfb2cf2e992d35bbfb6b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,15 +42,25 @@ Maybe you need to do migration, add one column named `status`:
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
```
|
45
|
-
**Model without using `fsm_define` will only act as the same with `
|
46
|
-
In other words, using `fsm_define` will make `
|
45
|
+
**Model without using `fsm_define` will only act as the same with `NormalModel` which doesn't has fsm mechanic.**
|
46
|
+
In other words, using `fsm_define` will make `NormalModel` become `FsmModel`.
|
47
47
|
|
48
|
-
3. Use `FsmModel.fsm_graph.
|
49
|
-
4. Use `
|
48
|
+
3. Use `FsmModel.fsm_graph.transitions` to get all permit_transition you defined.
|
49
|
+
4. Use `FsmModel.fsm_graph.states` to get all permit_status you defined.
|
50
|
+
5. Use `FsmModel.fsm_graph.final_states.include?(fsm_instance.status)` to judge FsmModel instance `fsm_instance` terminate?.
|
51
|
+
6. Use `ActiveRecord::Fsm::Graph.defined_klasses` to get all the models which really used `ActiveRecord::Fsm`.
|
50
52
|
|
51
53
|
e.g.
|
52
54
|
|
53
55
|
```ruby
|
56
|
+
class ApplicationRecord < ActiveRecord::Base
|
57
|
+
include ActiveRecord::Fsm
|
58
|
+
|
59
|
+
self.abstract_class = true
|
60
|
+
# blabalbla......
|
61
|
+
end
|
62
|
+
|
63
|
+
# FsmModel need call fsm_define
|
54
64
|
class FsmModel < ApplicationRecord
|
55
65
|
STATE_1 = 1
|
56
66
|
STATE_2 = 2
|
@@ -65,12 +75,16 @@ class FsmModel < ApplicationRecord
|
|
65
75
|
fsm_define(PERMIT_TRANSITIONS)
|
66
76
|
end
|
67
77
|
|
78
|
+
# FsmModel can be shown having used ActiveRecord::Fsm
|
68
79
|
ActiveRecord::Fsm::Graph.defined_klasses
|
69
80
|
# => [FsmModel]
|
70
81
|
|
82
|
+
# NormalModel doesn't call fsm_define
|
83
|
+
# although inherited from ApplicationRecord
|
71
84
|
class NormalModel < ApplicationRecord
|
72
85
|
end
|
73
86
|
|
87
|
+
# NormalModel is not included
|
74
88
|
ActiveRecord::Fsm::Graph.defined_klasses
|
75
89
|
# => [FsmModel]
|
76
90
|
```
|