Class: Curator::ResettableRiak::DataStore

Inherits:
Curator::Riak::DataStore show all
Defined in:
lib/curator/resettable_riak/data_store.rb

Class Method Summary collapse

Methods inherited from Curator::Riak::DataStore

_bucket, _bucket_name, _find_key_by_index, client, delete, find_by_index, find_by_key, ping

Class Method Details

.bucket_prefixObject



6
7
8
9
# File 'lib/curator/resettable_riak/data_store.rb', line 6

def self.bucket_prefix
  job = "#{ENV['JOB_NAME'].gsub(/[^[:alnum:]]/, '_')}" if ENV['JOB_NAME'].present?
  [Curator.config.bucket_prefix, job, Curator.config.environment].compact.join(':')
end

.exclude_from_resetObject



11
12
13
14
15
# File 'lib/curator/resettable_riak/data_store.rb', line 11

def self.exclude_from_reset
  @exclude_from_reset = true
  yield
  @exclude_from_reset = false
end

.remove_all_keysObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/curator/resettable_riak/data_store.rb', line 17

def self.remove_all_keys
  silence_warnings do
    buckets = client.buckets.select { |bucket| bucket.name.start_with?(DataStore.bucket_prefix) }
    buckets.each do |bucket|
      bucket.keys do |keys|
        keys.each { |key| bucket.delete(key) }
      end
    end
  end
end

.reset!Object



28
29
30
31
32
33
34
35
# File 'lib/curator/resettable_riak/data_store.rb', line 28

def self.reset!
  @bucket_names ||= {}
  deletable_buckets = @bucket_names.each do |bucket_name, keys|
    bucket = _bucket(bucket_name)
    keys.each {|key| bucket.delete(key)}
  end
  @bucket_names = {}
end

.save(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/curator/resettable_riak/data_store.rb', line 37

def self.save(options)
  key = super

  unless @exclude_from_reset
    @bucket_names ||= {}
    @bucket_names[options[:collection_name]] ||= []
    @bucket_names[options[:collection_name]] << key
  end

  key
end