Skip to content
This repository
branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Changelog.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Guardfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 adapter.gemspec
README.md

Adapter

A simple interface to anything.

Defining an Adapter

An adapter requires 4 methods to work: read, write, delete and clear.

Adapter.define(:memory) do
  def read(key, options = nil)
    client[key]
  end

  def write(key, attributes, options = nil)
    client[key] = attributes
  end

  def delete(key, options = nil)
    client.delete(key)
  end

  def clear(options = nil)
    client.clear
  end
end

Note: in order for things to be most flexible, always wrap key with key_for(key) which will ensure that pretty much anything can be a key. Also, by default encode and decode are included and they Marshal.dump and Marshal.load. Feel free to override these if you prefer JSON serialization or something else.

Once you have defined an adapter, you can get a class of that adapter like this:

Adapter[:memory]

This returns a dynamic class with your adapting methods included and an initialize method that takes a client. This means you can get an instance of the adapter by using new and passing the client (in this instance a boring hash):

adapter = Adapter[:memory].new({}) # sets {} to client
adapter.write('foo', 'bar')
adapter.read('foo') # 'bar'
adapter.delete('foo')
adapter.fetch('foo', 'bar') # returns bar and sets foo to bar

Note: You can also optionally provide a lock method. Read More

Adapter Power User Guides

Mailing List

https://groups.google.com/forum/#!forum/toystoreadapter

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix in a topic branch.
  • Add tests for it. This is important so we don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine, but bump version in a commit by itself so we can ignore when we pull)
  • Send a pull request.
Something went wrong with that request. Please try again.