Skip to content

Instantly share code, notes, and snippets.

@alco alco/riak_backend.ex
Last active Aug 29, 2015

Embed
What would you like to do?
defmodule Beamie.Store.RiakHTTP do
def put(bucket, key, value) do
IO.puts "storing value #{inspect value} with key #{key} in bucket '#{bucket}'"
put_req(bucket, key, value)
end
def get(bucket, key) do
IO.puts "retrieving value for key #{key} from bucket '#{bucket}'"
get_req(bucket, key)
end
#...
end
defp prepare_code_store_backend() do
{:ok, backend} = :application.get_env(:beamie, :code_store_backend)
Beamie.Store.Generator.gen_module(backend)
end
# ...
defmodule Beamie.Store.Generator do
# create a module at runtime that will dispatch to the chosen backend
def gen_module(backend) do
Module.create(Beamie.Store, quote do
@backend unquote(backend)
def put(bucket, key, value) do
apply(@backend, :put, [bucket, key, value])
end
def get(bucket, key) do
apply(@backend, :get, [bucket, key])
end
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.