Last active
December 25, 2015 21:19
-
-
Save gerep/7042091 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HERE IS HOW I USE RIAKWRAPPER | |
# | |
def destroy_on_riak | |
# DELETING ON RIAK | |
acronym = current_company.acronym | |
wrapper = RiakWrapper.new(walk_server_client) | |
wrapper.delete("#{acronym}_#{self.number}", 'terminals') | |
wrapper.delete("#{acronym}_#{self.number}_params.dat", 'assets') | |
wrapper.delete("#{acronym}_#{self.number}_params.dat", 'files') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THIS IS MY CALLBACK | |
# | |
class RiakCallback | |
def before_destroy(record) | |
raise 'Invalid Riak Client' unless record.walk_server_client.is_a? Riak::Client | |
@client = record.walk_server_client | |
record.riak_keys.each do |key| | |
delete(key[0], key[1]) | |
end | |
end | |
def exists?(key, bucket_name) | |
bucket(bucket_name).exists?(key) | |
end | |
def delete(key, bucket_name) | |
bucket(bucket_name).delete(key) if exists?(key, bucket_name) | |
end | |
def bucket(bucket_name) | |
@client.bucket(bucket_name) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RiakWrapper | |
def initialize(client) | |
raise 'Invalid Riak client' unless client.is_a?(Riak::Client) | |
@client = client | |
end | |
def exists?(key, bucket_name) | |
bucket(bucket_name).exists?(key) | |
end | |
def get(key, bucket_name) | |
bucket(bucket_name).get(key) | |
raise Riak::ProtobuffsFailedRequest => e | |
false | |
end | |
def delete(key, bucket_name) | |
bucket(bucket_name).delete(key) if exists?(key, bucket_name) | |
end | |
def bucket(bucket_name) | |
@client.bucket(bucket_name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment