swarm 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/swarm/expression.rb +3 -1
- data/lib/swarm/expressions/branch_expression.rb +1 -7
- data/lib/swarm/hive.rb +2 -2
- data/lib/swarm/hive_dweller.rb +22 -5
- data/lib/swarm/process.rb +6 -12
- data/lib/swarm/process_definition.rb +1 -0
- data/lib/swarm/storage/hash_storage.rb +7 -0
- data/lib/swarm/storage/key_value_storage.rb +23 -0
- data/lib/swarm/storage/redis_storage.rb +9 -0
- data/lib/swarm/support.rb +8 -0
- data/lib/swarm/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: e4410067eb9ac5847b4add5e8a31f9c78f3a6f18
|
4
|
+
data.tar.gz: fdf564f1018be4d4ffdd837777c4fd25d1a1664d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02303d2b8f04002bad616eddbd69ecec4e49f33cd44b4b3785802147c4815ad4f52e318c267a4f7f2de5be8451de48567b01a0ccdb277cfac7b88c140b716a94
|
7
|
+
data.tar.gz: ab727019332409f4e5954f8c23c34b62c1b445497b107b60f58d1c12d6fb76e5bc35c1195c0241983dabe9002ef2db007862ebbf24420a87f45dd3cc90fb4b01
|
data/lib/swarm/expression.rb
CHANGED
@@ -13,8 +13,10 @@ module Swarm
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
set_columns :parent_id, :position, :workitem, :
|
16
|
+
set_columns :parent_id, :position, :workitem, :children_ids, :milestones, :process_id
|
17
17
|
many_to_one :process, :class_name => "Swarm::Process"
|
18
|
+
many_to_one :parent, :class_name => "Swarm::Expression", :key => :parent_id
|
19
|
+
one_to_many :children, :class_name => "Swarm::Expression", :foreign_key => :parent_id
|
18
20
|
|
19
21
|
def branch_position
|
20
22
|
@branch_position ||= position.last
|
@@ -4,12 +4,6 @@ module Swarm
|
|
4
4
|
class BranchExpression < Expression
|
5
5
|
class InvalidPositionError < StandardError; end;
|
6
6
|
|
7
|
-
def children
|
8
|
-
(child_ids || []).map { |child_id|
|
9
|
-
Expression.fetch(child_id, hive: hive)
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
7
|
def kick_off_children(at_positions)
|
14
8
|
at_positions.each do |at_position|
|
15
9
|
add_and_apply_child(at_position)
|
@@ -26,7 +20,7 @@ module Swarm
|
|
26
20
|
node = tree[at_position]
|
27
21
|
raise InvalidPositionError unless node
|
28
22
|
expression = create_child_expression(node: node, at_position: at_position)
|
29
|
-
(self.
|
23
|
+
(self.children_ids ||= []) << expression.id
|
30
24
|
expression
|
31
25
|
end
|
32
26
|
|
data/lib/swarm/hive.rb
CHANGED
@@ -40,11 +40,11 @@ module Swarm
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def traced
|
43
|
-
storage
|
43
|
+
storage.trace ||= []
|
44
44
|
end
|
45
45
|
|
46
46
|
def trace(new_element)
|
47
|
-
storage
|
47
|
+
storage.trace = traced + [new_element]
|
48
48
|
end
|
49
49
|
|
50
50
|
def queue(action, object)
|
data/lib/swarm/hive_dweller.rb
CHANGED
@@ -116,14 +116,29 @@ module Swarm
|
|
116
116
|
@columns = @columns | args
|
117
117
|
end
|
118
118
|
|
119
|
-
def
|
119
|
+
def one_to_many(type, class_name: nil, foreign_key: nil)
|
120
120
|
define_method(type) do
|
121
121
|
memo = instance_variable_get(:"@#{type}")
|
122
122
|
memo || begin
|
123
|
-
|
124
|
-
|
123
|
+
associations = hive.storage.load_associations(
|
124
|
+
type, owner: self, type: class_name || type, foreign_key: foreign_key
|
125
|
+
)
|
126
|
+
entities = associations.map { |association| hive.reify_from_hash(association) }
|
127
|
+
instance_variable_set(:"@#{type}", entities)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
@associations << type
|
131
|
+
end
|
132
|
+
|
133
|
+
def many_to_one(type, class_name: nil, key: nil)
|
134
|
+
define_method(type) do
|
135
|
+
memo = instance_variable_get(:"@#{type}")
|
136
|
+
memo || begin
|
137
|
+
key ||= :"#{type}_id"
|
138
|
+
associated_id = self.send(key)
|
139
|
+
return nil unless associated_id
|
125
140
|
klass = Swarm::Support.constantize("#{class_name || type}")
|
126
|
-
instance_variable_set(:"@#{type}", klass.fetch(
|
141
|
+
instance_variable_set(:"@#{type}", klass.fetch(associated_id, :hive => hive))
|
127
142
|
end
|
128
143
|
end
|
129
144
|
@associations << type
|
@@ -172,7 +187,9 @@ module Swarm
|
|
172
187
|
end
|
173
188
|
|
174
189
|
def all(hive: Hive.default, subtypes: true)
|
175
|
-
|
190
|
+
hive.storage.all_of_type(storage_type, subtypes: subtypes).map { |hsh|
|
191
|
+
hive.reify_from_hash(hsh.dup)
|
192
|
+
}
|
176
193
|
end
|
177
194
|
end
|
178
195
|
end
|
data/lib/swarm/process.rb
CHANGED
@@ -5,6 +5,8 @@ module Swarm
|
|
5
5
|
set_columns :process_definition_id, :workitem, :root_expression_id, :parent_expression_id
|
6
6
|
many_to_one :process_definition, :class_name => "Swarm::ProcessDefinition"
|
7
7
|
many_to_one :parent_expression, :class_name => "Swarm::Expression"
|
8
|
+
many_to_one :root_expression, :class_name => "Swarm::Expression"
|
9
|
+
one_to_many :expressions, :class_name => "Swarm::Expression"
|
8
10
|
|
9
11
|
def wait_until_finished(timeout: 5)
|
10
12
|
Swarm::Support.wait_until(timeout: timeout) { finished? }
|
@@ -16,28 +18,20 @@ module Swarm
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def _launch
|
19
|
-
|
21
|
+
new_expression = SequenceExpression.create(
|
20
22
|
:hive => hive,
|
21
23
|
:parent_id => id,
|
22
24
|
:position => [0],
|
23
25
|
:workitem => workitem,
|
24
26
|
:process_id => id
|
25
27
|
)
|
26
|
-
|
27
|
-
self.root_expression_id =
|
28
|
+
new_expression.apply
|
29
|
+
self.root_expression_id = new_expression.id
|
28
30
|
save
|
29
31
|
end
|
30
32
|
|
31
|
-
def root_expression
|
32
|
-
@root_expression ||= begin
|
33
|
-
reload! unless root_expression_id
|
34
|
-
if root_expression_id
|
35
|
-
Expression.fetch(root_expression_id, hive: hive)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
33
|
def finished?
|
34
|
+
reload!
|
41
35
|
root_expression && root_expression.replied?
|
42
36
|
end
|
43
37
|
|
@@ -8,6 +8,13 @@ module Swarm
|
|
8
8
|
keys.map { |key| key.gsub(regex_for_type(type), '\1') }
|
9
9
|
end
|
10
10
|
|
11
|
+
def all_of_type(type, subtypes: true)
|
12
|
+
store.select { |key, value|
|
13
|
+
key.match(regex_for_type(type)) &&
|
14
|
+
(subtypes || value["type"] == type)
|
15
|
+
}.values
|
16
|
+
end
|
17
|
+
|
11
18
|
def delete(key)
|
12
19
|
store.delete(key)
|
13
20
|
end
|
@@ -7,6 +7,14 @@ module Swarm
|
|
7
7
|
@store = store
|
8
8
|
end
|
9
9
|
|
10
|
+
def trace
|
11
|
+
self["trace"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def trace=(traced)
|
15
|
+
self["trace"] = traced
|
16
|
+
end
|
17
|
+
|
10
18
|
def regex_for_type(type)
|
11
19
|
/^#{type}\:(.*)/
|
12
20
|
end
|
@@ -15,6 +23,21 @@ module Swarm
|
|
15
23
|
raise "Not implemented yet!"
|
16
24
|
end
|
17
25
|
|
26
|
+
def all_of_type(type)
|
27
|
+
raise "Not implemented yet!"
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_associations(association_name, owner:, type:, foreign_key: nil)
|
31
|
+
type = type.split("::").last
|
32
|
+
local_association_ids = :"#{association_name}_ids"
|
33
|
+
if owner.respond_to?(local_association_ids)
|
34
|
+
ids = owner.send(local_association_ids) || []
|
35
|
+
ids.map { |id|
|
36
|
+
self["#{type}:#{id}"]
|
37
|
+
}.compact
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
18
41
|
def serialize(value)
|
19
42
|
return nil if value.nil?
|
20
43
|
value.to_json
|
@@ -8,6 +8,15 @@ module Swarm
|
|
8
8
|
store.keys("#{type}:*").map { |key| key.gsub(regex_for_type(type), '\1') }
|
9
9
|
end
|
10
10
|
|
11
|
+
def all_of_type(type, subtypes: true)
|
12
|
+
hsh = store.mapped_mget(*store.keys("#{type}:*"))
|
13
|
+
if subtypes
|
14
|
+
hsh.values
|
15
|
+
else
|
16
|
+
hsh.select { |key, value| value["type"] == type }.values
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
def delete(key)
|
12
21
|
store.del(key)
|
13
22
|
end
|
data/lib/swarm/support.rb
CHANGED
@@ -43,6 +43,14 @@ module Swarm
|
|
43
43
|
"#{Time.now.strftime("%Y%m%d-%H%M%S")}-#{SecureRandom.uuid}"
|
44
44
|
end
|
45
45
|
|
46
|
+
def tokenize(string)
|
47
|
+
return nil if string.nil?
|
48
|
+
string = string.to_s.gsub(/&/, ' and ').
|
49
|
+
gsub(/[ \/]+/, '_').
|
50
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
51
|
+
downcase
|
52
|
+
end
|
53
|
+
|
46
54
|
def camelize(string)
|
47
55
|
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
48
56
|
string = string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
data/lib/swarm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swarm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ravi Gadad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|