Skip to content
Browse files

Create gh-pages branch via GitHub

  • Loading branch information...
1 parent c3a2c47 commit b09a1f525759a240273a601396569974df299059 @jnunemaker committed Apr 11, 2013
Showing with 22 additions and 31 deletions.
  1. +21 −30 index.html
  2. +1 −1 params.json
View
51 index.html
@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Adapter by jnunemaker</title>
-
+
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
@@ -17,68 +17,59 @@
<header>
<h1>Adapter</h1>
<p>A simple interface to anything.</p>
+
<p class="view"><a href="https://github.com/jnunemaker/adapter">View the Project on GitHub <small>jnunemaker/adapter</small></a></p>
+
+
<ul>
<li><a href="https://github.com/jnunemaker/adapter/zipball/master">Download <strong>ZIP File</strong></a></li>
<li><a href="https://github.com/jnunemaker/adapter/tarball/master">Download <strong>TAR Ball</strong></a></li>
- <li><a href="https://github.com/jnunemaker/adapter">Fork On <strong>GitHub</strong></a></li>
+ <li><a href="https://github.com/jnunemaker/adapter">View On <strong>GitHub</strong></a></li>
</ul>
</header>
<section>
- <h2>Install</h2>
+ <h1>Adapter</h1>
-<pre><code>gem install adapter
-</code></pre>
+<p>A simple interface to anything.</p>
<h2>Defining an Adapter</h2>
<p>An adapter requires 4 methods to work: read, write, delete and clear.</p>
-<div class="highlight">
-<pre><span class="no">Adapter</span><span class="o">.</span><span class="n">define</span><span class="p">(</span><span class="ss">:memory</span><span class="p">)</span> <span class="k">do</span>
- <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
- <span class="n">decode</span><span class="p">(</span><span class="n">client</span><span class="o">[</span><span class="n">key_for</span><span class="p">(</span><span class="n">key</span><span class="p">)</span><span class="o">]</span><span class="p">)</span>
+<div class="highlight"><pre><span class="no">Adapter</span><span class="o">.</span><span class="n">define</span><span class="p">(</span><span class="ss">:memory</span><span class="p">)</span> <span class="k">do</span>
+ <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">options</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
+ <span class="n">client</span><span class="o">[</span><span class="n">key</span><span class="o">]</span>
<span class="k">end</span>
- <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="n">client</span><span class="o">[</span><span class="n">key_for</span><span class="p">(</span><span class="n">key</span><span class="p">)</span><span class="o">]</span> <span class="o">=</span> <span class="n">encode</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
+ <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">attributes</span><span class="p">,</span> <span class="n">options</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
+ <span class="n">client</span><span class="o">[</span><span class="n">key</span><span class="o">]</span> <span class="o">=</span> <span class="n">attributes</span>
<span class="k">end</span>
- <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
- <span class="n">client</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">key_for</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
+ <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">options</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
+ <span class="n">client</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">end</span>
- <span class="k">def</span> <span class="nf">clear</span>
+ <span class="k">def</span> <span class="nf">clear</span><span class="p">(</span><span class="n">options</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
<span class="n">client</span><span class="o">.</span><span class="n">clear</span>
<span class="k">end</span>
<span class="k">end</span>
-</pre>
-</div>
-
+</pre></div>
<p>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.</p>
<p>Once you have defined an adapter, you can get a class of that adapter like this:</p>
-<div class="highlight">
-<pre><span class="no">Adapter</span><span class="o">[</span><span class="ss">:memory</span><span class="o">]</span>
-</pre>
-</div>
-
+<div class="highlight"><pre><span class="no">Adapter</span><span class="o">[</span><span class="ss">:memory</span><span class="o">]</span>
+</pre></div>
<p>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):</p>
-<div class="highlight">
-<pre><span class="n">adapter</span> <span class="o">=</span> <span class="no">Adapter</span><span class="o">[</span><span class="ss">:memory</span><span class="o">].</span><span class="n">new</span><span class="p">({})</span> <span class="c1"># sets {} to client</span>
+<div class="highlight"><pre><span class="n">adapter</span> <span class="o">=</span> <span class="no">Adapter</span><span class="o">[</span><span class="ss">:memory</span><span class="o">].</span><span class="n">new</span><span class="p">({})</span> <span class="c1"># sets {} to client</span>
<span class="n">adapter</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">)</span>
<span class="n">adapter</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="c1"># 'bar'</span>
<span class="n">adapter</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span>
<span class="n">adapter</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">)</span> <span class="c1"># returns bar and sets foo to bar</span>
-</pre>
-</div>
-
-
-<p><code>get</code> and <code>[]</code> are aliased to read. <code>set</code> and <code>[]=</code> are aliased to write.</p>
+</pre></div>
<p>Note: You can also optionally provide a lock method. <a href="https://github.com/jnunemaker/adapter/wiki/Locking">Read More</a></p>
@@ -94,7 +85,7 @@
<p><a href="https://groups.google.com/forum/#!forum/toystoreadapter">https://groups.google.com/forum/#!forum/toystoreadapter</a></p>
-<h2>Contributing</h2>
+<h2>Note on Patches/Pull Requests</h2>
<ul>
<li>Fork the project.</li>
View
2 params.json
@@ -1 +1 @@
-{"note":"Don't delete this file! It's used internally to help with page regeneration.","body":"## Install\r\n\r\n```\r\ngem install adapter\r\n```\r\n\r\n## Defining an Adapter\r\n\r\nAn adapter requires 4 methods to work: read, write, delete and clear.\r\n\r\n```ruby\r\nAdapter.define(:memory) do\r\n def read(key)\r\n decode(client[key_for(key)])\r\n end\r\n\r\n def write(key, value)\r\n client[key_for(key)] = encode(value)\r\n end\r\n\r\n def delete(key)\r\n client.delete(key_for(key))\r\n end\r\n\r\n def clear\r\n client.clear\r\n end\r\nend\r\n```\r\n\r\nNote: 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.\r\n\r\nOnce you have defined an adapter, you can get a class of that adapter like this:\r\n\r\n```ruby\r\nAdapter[:memory]\r\n```\r\n\r\nThis 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):\r\n\r\n```ruby\r\nadapter = Adapter[:memory].new({}) # sets {} to client\r\nadapter.write('foo', 'bar')\r\nadapter.read('foo') # 'bar'\r\nadapter.delete('foo')\r\nadapter.fetch('foo', 'bar') # returns bar and sets foo to bar\r\n```\r\n\r\n`get` and `[]` are aliased to read. `set` and `[]=` are aliased to write.\r\n\r\nNote: You can also optionally provide a lock method. [Read More](https://github.com/jnunemaker/adapter/wiki/Locking)\r\n\r\n## Adapter Power User Guides\r\n\r\n* [Wiki Home](https://github.com/jnunemaker/adapter/wiki)\r\n* [Creating an Adapter](https://github.com/jnunemaker/adapter/wiki/Creating-an-Adapter)\r\n* [Overriding an Adapter](https://github.com/jnunemaker/adapter/wiki/Overriding-an-Adapter)\r\n* [Allowing for Options](https://github.com/jnunemaker/adapter/wiki/Allowing-for-Options)\r\n* [Adapter defaults](https://github.com/jnunemaker/adapter/wiki/Adapter-defaults)\r\n\r\n## Mailing List\r\n\r\nhttps://groups.google.com/forum/#!forum/toystoreadapter\r\n\r\n## Contributing\r\n\r\n* Fork the project.\r\n* Make your feature addition or bug fix in a topic branch.\r\n* Add tests for it. This is important so we don't break it in a future version unintentionally.\r\n* 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)\r\n* Send a pull request.\r\n","tagline":"A simple interface to anything.","name":"Adapter","google":""}
+{"name":"Adapter","tagline":"A simple interface to anything.","body":"# Adapter\r\n\r\nA simple interface to anything.\r\n\r\n## Defining an Adapter\r\n\r\nAn adapter requires 4 methods to work: read, write, delete and clear.\r\n\r\n```ruby\r\nAdapter.define(:memory) do\r\n def read(key, options = nil)\r\n client[key]\r\n end\r\n\r\n def write(key, attributes, options = nil)\r\n client[key] = attributes\r\n end\r\n\r\n def delete(key, options = nil)\r\n client.delete(key)\r\n end\r\n\r\n def clear(options = nil)\r\n client.clear\r\n end\r\nend\r\n```\r\n\r\nNote: 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.\r\n\r\nOnce you have defined an adapter, you can get a class of that adapter like this:\r\n\r\n```ruby\r\nAdapter[:memory]\r\n```\r\n\r\nThis 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):\r\n\r\n```ruby\r\nadapter = Adapter[:memory].new({}) # sets {} to client\r\nadapter.write('foo', 'bar')\r\nadapter.read('foo') # 'bar'\r\nadapter.delete('foo')\r\nadapter.fetch('foo', 'bar') # returns bar and sets foo to bar\r\n```\r\n\r\nNote: You can also optionally provide a lock method. [Read More](https://github.com/jnunemaker/adapter/wiki/Locking)\r\n\r\n## Adapter Power User Guides\r\n\r\n* [Wiki Home](https://github.com/jnunemaker/adapter/wiki)\r\n* [Creating an Adapter](https://github.com/jnunemaker/adapter/wiki/Creating-an-Adapter)\r\n* [Overriding an Adapter](https://github.com/jnunemaker/adapter/wiki/Overriding-an-Adapter)\r\n* [Allowing for Options](https://github.com/jnunemaker/adapter/wiki/Allowing-for-Options)\r\n* [Adapter defaults](https://github.com/jnunemaker/adapter/wiki/Adapter-defaults)\r\n\r\n## Mailing List\r\n\r\nhttps://groups.google.com/forum/#!forum/toystoreadapter\r\n\r\n## Note on Patches/Pull Requests\r\n\r\n* Fork the project.\r\n* Make your feature addition or bug fix in a topic branch.\r\n* Add tests for it. This is important so we don't break it in a future version unintentionally.\r\n* 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)\r\n* Send a pull request.\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}

0 comments on commit b09a1f5

Please sign in to comment.
Something went wrong with that request. Please try again.