unidom-action 1.0 → 1.1
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 +5 -3
- data/app/models/unidom/action/acting.rb +5 -0
- data/app/models/unidom/action/concerns/as_state_subject.rb +16 -0
- data/app/models/unidom/action/obsolescing.rb +5 -0
- data/app/models/unidom/action/state_transition.rb +5 -0
- data/lib/unidom/action/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87b412b4d3977bfe6aecef7b9c8b27ac899954b5
|
|
4
|
+
data.tar.gz: d839f30d586c5f32cab8bb71427710fb4876b433
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8afc0fed64acea96ba1c8b38bbc7a2f982423846505f5da9df5a83030a436d3ba6c2d8dd840b3ea0d9c0696cfc085707a3a60d0095afec1d10f432c69c6ab832
|
|
7
|
+
data.tar.gz: 249df032859f87e078db5875f4e9350393dc52f3205d783ac07b2b10211a8a48102d58244b995c0e26d7471de94d9ef7b879460e56b1cccaf39f2e15ebec6fe6
|
data/README.md
CHANGED
|
@@ -44,6 +44,7 @@ user = Unidom::Visitor::User.create!
|
|
|
44
44
|
# Create/Update/Delete the person
|
|
45
45
|
person = Unidom::Party::Person.create! name: 'Tim'
|
|
46
46
|
acting = Unidom::Action::Acting.create! actor_visitor: user, actor_party: person, reason: reason, acted: person, from_value: {}, thru_value: { name: 'Time' }
|
|
47
|
+
actings = Unidom::Action::Acting.acted_via(user).acted_by(person).acted_is(person).caused_by(reason)
|
|
47
48
|
|
|
48
49
|
# Update the state of the person
|
|
49
50
|
person.state = 'R'
|
|
@@ -53,15 +54,16 @@ transition = Unidom::Action::StateTransition.create! transitor_visitor: user, tr
|
|
|
53
54
|
# The following source code also create a state transition to record the above change
|
|
54
55
|
transition = Unidom::Action::StateTransition.transit! transitor_visitor: user, transitor_party: person, reason: reason, subject: person, from_state: 'C', thru_state: 'R', opened_at: Time.now
|
|
55
56
|
# The reason could be nil.
|
|
57
|
+
transitions = Unidom::Action::StateTransition.transited_via(user).transited_by(person).subject_is(subject).caused_by(reason).from_transited_to('C').thru_transited_to('R')
|
|
56
58
|
|
|
57
59
|
# Soft destroy the person
|
|
58
60
|
person.soft_destroy
|
|
59
61
|
# Create an obsolescing to record the above change
|
|
60
|
-
|
|
62
|
+
obsolescing = Unidom::Action::Obsolescing.create! obsolescer_visitor: user, obsolescer_party: person, reason: reason, obsolesced: person, obsolescence_code: 'OBSL'
|
|
61
63
|
# The following source code also create an obsolescing to record the above change
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
obsolescing = Unidom::Action::Obsolescing.obsolesce! obsolesced: person, obsolescer_visitor: user, obsolescer_party: person, reason: reason, obsolescence_code: 'OBSL', opened_at: Time.now
|
|
64
65
|
# The reason could be nil.
|
|
66
|
+
obsolescings = Unidom::Action::Obsolescing.obsolesced_via(user).obsolesced_by(person).obsolesced_is(person).caused_by(reason).obsolescence_coded_as('OBSL')
|
|
65
67
|
```
|
|
66
68
|
|
|
67
69
|
|
|
@@ -14,4 +14,9 @@ class Unidom::Action::Acting < Unidom::Action::ApplicationRecord
|
|
|
14
14
|
belongs_to :acted, polymorphic: true
|
|
15
15
|
belongs_to :reason, class_name: 'Unidom::Action::Reason'
|
|
16
16
|
|
|
17
|
+
scope :acted_via, ->(actor_visitor) { where actor_visitor: actor_visitor }
|
|
18
|
+
scope :acted_by, ->(actor_party) { where actor_party: actor_party }
|
|
19
|
+
scope :acted_is, ->(acted) { where acted: acted }
|
|
20
|
+
scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
|
|
21
|
+
|
|
17
22
|
end
|
|
@@ -6,6 +6,22 @@ module Unidom::Action::Concerns::AsStateSubject
|
|
|
6
6
|
|
|
7
7
|
has_many :state_transitions, class_name: 'Unidom::Action::StateTransition', as: :subject
|
|
8
8
|
|
|
9
|
+
=begin
|
|
10
|
+
def is_transited!(from: nil, thru: nil, due_to: nil, via: nil, by: nil, at: Time.now)
|
|
11
|
+
state_transitions.create! from_state: from, thru_state: thru, transitor_visitor: via, transitor_party: by, reason: due_to, opened_at: at
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def is_transited?(from: nil, thru: nil, due_to: nil, via: nil, by: nil, at: Time.now)
|
|
15
|
+
query = state_transitions
|
|
16
|
+
query = query.from_transited_to from if from.present?
|
|
17
|
+
query = query.thru_transited_to from if thru.present?
|
|
18
|
+
query = query.transited_by by if by.present?
|
|
19
|
+
query = query.transited_via via if via.present?
|
|
20
|
+
query = query.caused_by due_to if due_to.present?
|
|
21
|
+
query = query.valid_at now: at if at.present?
|
|
22
|
+
query.exists?
|
|
23
|
+
end
|
|
24
|
+
=end
|
|
9
25
|
end
|
|
10
26
|
|
|
11
27
|
module ClassMethods
|
|
@@ -14,6 +14,11 @@ class Unidom::Action::Obsolescing < Unidom::Action::ApplicationRecord
|
|
|
14
14
|
belongs_to :obsolesced, polymorphic: true
|
|
15
15
|
belongs_to :reason, class_name: 'Unidom::Action::Reason'
|
|
16
16
|
|
|
17
|
+
scope :obsolesced_via, ->(obsolescer_visitor) { where obsolescer_visitor: obsolescer_visitor }
|
|
18
|
+
scope :obsolesced_by, ->(obsolescer_party) { where obsolescer_party: obsolescer_party }
|
|
19
|
+
scope :obsolesced_is, ->(obsolesced) { where obsolesced: obsolesced }
|
|
20
|
+
scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
|
|
21
|
+
|
|
17
22
|
def self.obsolesce!(obsolesced: nil, obsolescer_visitor: nil, obsolescer_party: nil, reason: nil, obsolescence_code: 'OBSL', opened_at: Time.now)
|
|
18
23
|
create! obsolesced: obsolesced, obsolescer_visitor: obsolescer_visitor, obsolescer_party: obsolescer_party, reason: reason, obsolescence_code: obsolescence_code, opened_at: opened_at
|
|
19
24
|
end
|
|
@@ -13,6 +13,11 @@ class Unidom::Action::StateTransition < Unidom::Action::ApplicationRecord
|
|
|
13
13
|
belongs_to :subject, polymorphic: true
|
|
14
14
|
belongs_to :reason, class_name: 'Unidom::Action::Reason'
|
|
15
15
|
|
|
16
|
+
scope :transited_via, ->(transitor_visitor) { where transitor_visitor: transitor_visitor }
|
|
17
|
+
scope :transited_by, ->(transitor_party) { where transitor_party: transitor_party }
|
|
18
|
+
scope :subject_is, ->(subject) { where subject: subject }
|
|
19
|
+
scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
|
|
20
|
+
|
|
16
21
|
def self.transit!(subject: nil, from_state: nil, thru_state: nil, transitor_visitor: nil, transitor_party: nil, reason: nil, opened_at: Time.now)
|
|
17
22
|
create! transitor_visitor: transitor_visitor, transitor_party: transitor_party, subject: subject, reason: reason, from_state: from_state, thru_state: thru_state, opened_at: opened_at
|
|
18
23
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unidom-action
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.1'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-10-
|
|
11
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|