Class: Curator::ResettableRiak::DataStore

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

Instance Method Summary collapse

Methods inherited from Curator::Riak::DataStore

#_bucket, #_bucket_name, #_deserialize, #_find_key_by_index, #client, #delete, #find_all, #find_by_attribute, #find_by_key, #ping, #settings, #update_settings!

Instance Method Details

#bucket_prefixObject



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

def 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_reset(&block) ⇒ Object



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

def exclude_from_reset(&block)
  @exclude_from_reset = true
  yield
ensure
  @exclude_from_reset = false
end

#remove_all_keysObject



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

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

#reset!Object



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

def 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



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

def save(options)
  key = super

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

  key
end