Skip to content
Browse files

More clear variable names.

attributes is more specific than value.
  • Loading branch information...
1 parent 13a5de9 commit 4cbb1d5d9da0bfe4502696382cfefe6f73efdd08 @jnunemaker committed
Showing with 37 additions and 37 deletions.
  1. +2 −2 README.md
  2. +4 −4 examples/overriding_serialization.rb
  3. +6 −6 lib/adapter/defaults.rb
  4. +2 −2 lib/adapter/memory.rb
  5. +23 −23 lib/adapter/spec/an_adapter.rb
View
4 README.md
@@ -12,8 +12,8 @@ Adapter.define(:memory) do
decode(client[key_for(key)])
end
- def write(key, value)
- client[key_for(key)] = encode(value)
+ def write(key, attributes)
+ client[key_for(key)] = encode(attributes)
end
def delete(key)
View
8 examples/overriding_serialization.rb
@@ -19,12 +19,12 @@
# Marshal.load/dump. Also, important to note that this does not affect
# the memory adapter which still uses Marshal.
Adapter.define(:memory_json, Adapter::Memory) do
- def encode(value)
- ActiveSupport::JSON.encode(value)
+ def encode(attributes)
+ ActiveSupport::JSON.encode(attributes)
end
- def decode(value)
- ActiveSupport::JSON.decode(value)
+ def decode(attributes)
+ ActiveSupport::JSON.decode(attributes)
end
end
View
12 lib/adapter/defaults.rb
@@ -1,11 +1,11 @@
module Adapter
module Defaults
- def fetch(key, value=nil)
+ def fetch(key, attributes=nil)
read(key) || begin
if block_given?
yield(key)
else
- value
+ attributes
end
end
end
@@ -24,12 +24,12 @@ def key_for(key)
key
end
- def encode(value)
- value
+ def encode(attributes)
+ attributes
end
- def decode(value)
- value
+ def decode(attributes)
+ attributes
end
end
end
View
4 lib/adapter/memory.rb
@@ -6,8 +6,8 @@ def read(key)
decode(client[key_for(key)])
end
- def write(key, value)
- client[key_for(key)] = encode(value)
+ def write(key, attributes)
+ client[key_for(key)] = encode(attributes)
end
def delete(key)
View
46 lib/adapter/spec/an_adapter.rb
@@ -25,11 +25,11 @@
adapter.read(key).should be_nil
end
- it "returns value if key available" do
+ it "returns attributes if key available" do
adapter.write(key, attributes)
result = adapter.read(key)
- attributes.each do |key, value|
- result[key].should eq(value)
+ attributes.each do |column, value|
+ result[column].should eq(value)
end
end
end
@@ -39,11 +39,11 @@
adapter.get(key).should be_nil
end
- it "returns value if key available" do
+ it "returns attributes if key available" do
adapter.write(key, attributes)
result = adapter.get(key)
- attributes.each do |key, value|
- result[key].should eq(value)
+ attributes.each do |column, value|
+ result[column].should eq(value)
end
end
end
@@ -53,11 +53,11 @@
adapter[key].should be_nil
end
- it "returns value if key available" do
+ it "returns attributes if key available" do
adapter.write(key, attributes)
result = adapter[key]
- attributes.each do |key, value|
- result[key].should eq(value)
+ attributes.each do |column, value|
+ result[column].should eq(value)
end
end
end
@@ -68,7 +68,7 @@
adapter.write(key2, attributes2)
end
- it "returns Hash of keys and values" do
+ it "returns Hash of keys and attributes" do
result = adapter.read_multiple(key, key2)
attributes.each do |column, value|
@@ -81,7 +81,7 @@
end
context "with mix of keys that are and are not available" do
- it "returns Hash of keys and values where unavailable keys are nil" do
+ it "returns Hash of keys and attributes where unavailable keys are nil" do
result = adapter.read_multiple(key, key2, 'foo', 'bar')
attributes.each do |column, value|
@@ -104,7 +104,7 @@
adapter.write(key2, attributes2)
end
- it "returns Hash of keys and values" do
+ it "returns Hash of keys and attributes" do
result = adapter.get_multiple(key, key2)
attributes.each do |column, value|
@@ -117,7 +117,7 @@
end
context "with mix of keys that are and are not available" do
- it "returns Hash of keys and values where unavailable keys are nil" do
+ it "returns Hash of keys and attributes where unavailable keys are nil" do
result = adapter.get_multiple(key, key2, 'foo', 'bar')
attributes.each do |column, value|
@@ -146,9 +146,9 @@
end
describe "#fetch" do
- context "with key not stored" do
- context "with default value" do
- it "returns default value" do
+ context "with key not available" do
+ context "with default attributes" do
+ it "returns default" do
adapter.fetch(key, {}).should eq({})
end
end
@@ -160,9 +160,9 @@
end
end
- context "with key that is stored" do
- context "with default value" do
- it "returns key value instead of default" do
+ context "with key that is available" do
+ context "with default attributes" do
+ it "returns result of read instead of default" do
adapter.write(key, attributes2)
result = adapter.fetch(key, attributes)
attributes2.each do |column, value|
@@ -183,7 +183,7 @@
end
describe "#write" do
- it "sets key to value" do
+ it "sets key to attributes" do
adapter.write(key, attributes)
result = adapter.read(key)
attributes.each do |column, value|
@@ -193,7 +193,7 @@
end
describe "#set" do
- it "sets key to value" do
+ it "sets key to attributes" do
adapter.set(key, attributes)
result = adapter.read(key)
attributes.each do |column, value|
@@ -203,7 +203,7 @@
end
describe "#[]=" do
- it "sets key to value" do
+ it "sets key to attributes" do
adapter[key] = attributes
result = adapter.read(key)
attributes.each do |column, value|
@@ -232,7 +232,7 @@
end
describe "#clear" do
- it "removes all stored keys" do
+ it "removes all available keys" do
adapter.write(key, attributes)
adapter.write(key2, attributes2)
adapter.key?(key).should be_true

0 comments on commit 4cbb1d5

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