Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rdoc to md for readme.

  • Loading branch information...
commit 2ecc3df37e93a8e8a1e6dbce1c96b132bc6d25d0 1 parent 0a0d612
@jnunemaker authored
Showing with 68 additions and 55 deletions.
  1. +68 −0 README.md
  2. +0 −55 README.rdoc
View
68 README.md
@@ -0,0 +1,68 @@
+# Adapter
+
+A simple interface to anything.
+
+## Defining an Adapter
+
+An adapter requires 4 methods to work: read, write, delete and clear.
+
+```ruby
+Adapter.define(:memory) do
+ def read(key)
+ decode(client[key_for(key)])
+ end
+
+ def write(key, value)
+ client[key_for(key)] = encode(value)
+ end
+
+ def delete(key)
+ client.delete(key_for(key))
+ end
+
+ def clear
+ 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:
+
+```ruby
+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):
+
+```ruby
+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
+```
+
+`get` and `[]` are aliased to read. `set` and `[]=` are aliased to write.
+
+Note: You can also optionally provide a lock method. [Read More](https://github.com/jnunemaker/adapter/wiki/Locking)
+
+## Adapter Power User Guides
+
+* [Creating an Adapter](https://github.com/jnunemaker/adapter/wiki/Creating-an-Adapter)
+* [Overriding an Adapter](https://github.com/jnunemaker/adapter/wiki/Overriding-an-Adapter)
+* [Allowing for Options](https://github.com/jnunemaker/adapter/wiki/Allowing-for-Options)
+* [Adapter defaults](https://github.com/jnunemaker/adapter/wiki/Adapter-defaults)
+
+## Mailing List
+
+https://groups.google.com/forum/#!forum/toystoreadapter
+
+## Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* 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 us a pull request. Bonus points for topic branches.
View
55 README.rdoc
@@ -1,55 +0,0 @@
-= 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)
- decode(client[key_for(key)])
- end
-
- def write(key, value)
- client[key_for(key)] = encode(value)
- end
-
- def delete(key)
- client.delete(key_for(key))
- end
-
- def clear
- 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
-
-get and [] are aliased to read. set and []= are aliased to write.
-
-Note: You can also optionally provide a lock method. See the memcached and redis adapters for more on locking.
-
-== Extending Adapters
-
-Adapters can be defined using a block, a module, or a module and a block. This allows very flexibly overriding specific things in an adapter to create a new adapter, without having to redo all of the work. See examples/overriding_serialization.rb for an example of this.
-
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* 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 us a pull request. Bonus points for topic branches.
Please sign in to comment.
Something went wrong with that request. Please try again.