Class: Curator::Riak::DataStore
- Inherits:
-
Object
- Object
- Curator::Riak::DataStore
show all
- Defined in:
- lib/curator/riak/data_store.rb
Class Method Summary
collapse
Class Method Details
._bucket(name) ⇒ Object
57
58
59
|
# File 'lib/curator/riak/data_store.rb', line 57
def self._bucket(name)
client.bucket(_bucket_name(name))
end
|
._bucket_name(name) ⇒ Object
61
62
63
|
# File 'lib/curator/riak/data_store.rb', line 61
def self._bucket_name(name)
bucket_prefix + ":" + name
end
|
._find_key_by_index(bucket, index_name, query) ⇒ Object
69
70
71
|
# File 'lib/curator/riak/data_store.rb', line 69
def self._find_key_by_index(bucket, index_name, query)
bucket.get_index("#{index_name}_bin", query)
end
|
.bucket_prefix ⇒ Object
65
66
67
|
# File 'lib/curator/riak/data_store.rb', line 65
def self.bucket_prefix
"#{Curator.config.bucket_prefix}:#{Curator.config.environment}"
end
|
.client ⇒ Object
7
8
9
10
11
|
# File 'lib/curator/riak/data_store.rb', line 7
def self.client
return @client if @client
yml_config = YAML.load(File.read(Curator.config.riak_config_file))[Curator.config.environment]
@client = ::Riak::Client.new(yml_config)
end
|
.delete(bucket_name, key) ⇒ Object
13
14
15
16
17
|
# File 'lib/curator/riak/data_store.rb', line 13
def self.delete(bucket_name, key)
bucket = _bucket(bucket_name)
object = bucket.get(key)
object.delete
end
|
.find_by_index(bucket_name, index_name, query) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/curator/riak/data_store.rb', line 45
def self.find_by_index(bucket_name, index_name, query)
return [] if query.nil?
bucket = _bucket(bucket_name)
begin
keys = _find_key_by_index(bucket, index_name.to_s, query)
keys.map { |key| find_by_key(bucket_name, key) }
rescue ::Riak::HTTPFailedRequest => failed_request
raise failed_request unless failed_request.not_found?
end
end
|
.find_by_key(bucket_name, key) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/curator/riak/data_store.rb', line 35
def self.find_by_key(bucket_name, key)
bucket = _bucket(bucket_name)
begin
object = bucket.get(key)
{ :key => object.key, :data => object.data } unless object.data.empty?
rescue ::Riak::HTTPFailedRequest => failed_request
raise failed_request unless failed_request.not_found?
end
end
|
.ping ⇒ Object
19
20
21
|
# File 'lib/curator/riak/data_store.rb', line 19
def self.ping
client.ping
end
|
.save(options) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/curator/riak/data_store.rb', line 23
def self.save(options)
bucket = _bucket(options[:collection_name])
object = ::Riak::RObject.new(bucket, options[:key])
object.content_type = options.fetch(:content_type, "application/json")
object.data = options[:value]
options.fetch(:index, {}).each do |index_name, index_value|
object.indexes["#{index_name}_bin"] << index_value
end
result = object.store
result.key
end
|