curator 0.6.0 → 0.7.0
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.
- data/lib/curator/memory/data_store.rb +15 -4
- data/lib/curator/riak/data_store.rb +10 -2
- metadata +2 -2
@@ -14,15 +14,18 @@ module Curator
|
|
14
14
|
bucket = _bucket_name(options[:collection_name])
|
15
15
|
object = options[:value]
|
16
16
|
key = options[:key]
|
17
|
-
|
17
|
+
indexes = options.fetch(:index, {})
|
18
18
|
|
19
19
|
key = _generate_key(bucket) unless key
|
20
20
|
|
21
21
|
_records(bucket).store(key, object)
|
22
|
-
|
22
|
+
indexes.each do |index_name, index_data|
|
23
23
|
index = _index(bucket, index_name)
|
24
|
-
|
25
|
-
|
24
|
+
|
25
|
+
_normalized_index_values(index_data).each do |index_value|
|
26
|
+
index[index_value] ||= []
|
27
|
+
index[index_value] << key unless index[index_value].include?(key)
|
28
|
+
end
|
26
29
|
end
|
27
30
|
|
28
31
|
key
|
@@ -86,6 +89,14 @@ module Curator
|
|
86
89
|
_indices(bucket)[index_name] ||= {}
|
87
90
|
end
|
88
91
|
|
92
|
+
def self._normalized_index_values(indexed_data)
|
93
|
+
if indexed_data.is_a?(Array)
|
94
|
+
indexed_data
|
95
|
+
else
|
96
|
+
[indexed_data]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
89
100
|
def self._generate_key(bucket)
|
90
101
|
keys = _records(bucket).keys
|
91
102
|
keys = [0] if keys.empty?
|
@@ -25,8 +25,8 @@ module Curator
|
|
25
25
|
object = ::Riak::RObject.new(bucket, options[:key])
|
26
26
|
object.content_type = options.fetch(:content_type, "application/json")
|
27
27
|
object.data = options[:value]
|
28
|
-
options.fetch(:index, {}).each do |index_name,
|
29
|
-
object.indexes["#{index_name}_bin"] <<
|
28
|
+
options.fetch(:index, {}).each do |index_name, index_data|
|
29
|
+
object.indexes["#{index_name}_bin"] << _normalized_index_data(index_data)
|
30
30
|
end
|
31
31
|
result = object.store
|
32
32
|
result.key
|
@@ -69,6 +69,14 @@ module Curator
|
|
69
69
|
def self._find_key_by_index(bucket, index_name, query)
|
70
70
|
bucket.get_index("#{index_name}_bin", query)
|
71
71
|
end
|
72
|
+
|
73
|
+
def self._normalized_index_data(index_data)
|
74
|
+
if index_data.is_a?(Array)
|
75
|
+
index_data.join(", ")
|
76
|
+
else
|
77
|
+
index_data
|
78
|
+
end
|
79
|
+
end
|
72
80
|
end
|
73
81
|
end
|
74
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|