Last active
August 29, 2015 14:01
-
-
Save alco/c08256ae72d31c76e767 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
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 |
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
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