statesman_mongoid 0.4.0 → 0.4.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/Gemfile.lock +1 -1
- data/lib/statesman/adapters/mongoid_queries.rb +29 -0
- data/lib/statesman_mongoid/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: e026f69df2640019768b793fbbf588052ee15fca01cc1062d805ccaf0601bb35
|
4
|
+
data.tar.gz: 5ae0bea5ecc9b360244784191863a7003d974ac1f46d44f859ee860269d1f440
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 858083c254432838c46df2c32f1bd0421e6aa1cf7c9172bee49b7fda1abd87fef5cab3b3bec7ffcf5cc042b8b5706ad06a4f7eb26c46f60ee2b4facc81069f91
|
7
|
+
data.tar.gz: 9759390d1a84d8b898504f74dfd461eafde888e4accd6117bc5e9f939c53398e72616acbec32e4a1d44591262b56d4fc02161d701c854467d1d9ef2acd514e24
|
data/Gemfile.lock
CHANGED
@@ -94,14 +94,43 @@ module Statesman
|
|
94
94
|
|
95
95
|
def states_where(states)
|
96
96
|
ids = aggregate_ids_for_most_recent(states, inclusive_match: true)
|
97
|
+
|
98
|
+
if initial_state.to_s.in?(states.map(&:to_s))
|
99
|
+
all_ids = aggregate_ids_for_all_state(states)
|
100
|
+
ids += model.where(_id: { '$nin' => all_ids }).pluck(:id)
|
101
|
+
end
|
102
|
+
|
97
103
|
model.where(_id: { '$in' => ids })
|
98
104
|
end
|
99
105
|
|
100
106
|
def states_where_not(states)
|
101
107
|
ids = aggregate_ids_for_most_recent(states, inclusive_match: false)
|
108
|
+
|
109
|
+
unless initial_state.to_s.in?(states.map(&:to_s))
|
110
|
+
all_ids = aggregate_ids_for_all_state(states)
|
111
|
+
ids += model.where(_id: { '$nin' => all_ids }).pluck(:id)
|
112
|
+
end
|
113
|
+
|
102
114
|
model.where(_id: { '$in' => ids })
|
103
115
|
end
|
104
116
|
|
117
|
+
def aggregate_ids_for_all_state(states)
|
118
|
+
aggregation = [
|
119
|
+
# Group by foreign key
|
120
|
+
{
|
121
|
+
'$group': {
|
122
|
+
_id: "$#{model_foreign_key}",
|
123
|
+
model_foreign_key => { '$first': "$#{model_foreign_key}" },
|
124
|
+
},
|
125
|
+
},
|
126
|
+
# Trim response to only the foreign key
|
127
|
+
{ '$project': { _id: 0 } },
|
128
|
+
]
|
129
|
+
|
130
|
+
# Hit the database and return a flat array of ids
|
131
|
+
transition_class.collection.aggregate(aggregation).pluck(model_foreign_key)
|
132
|
+
end
|
133
|
+
|
105
134
|
def aggregate_ids_for_most_recent(states, inclusive_match: true)
|
106
135
|
aggregation = [
|
107
136
|
# Sort most recent
|