From 0ab8e06b2dd87caf0026eae08c52661949424ef4 Mon Sep 17 00:00:00 2001 From: Brian Murphy-Dye Date: Fri, 13 Nov 2015 19:46:00 -0700 Subject: [PATCH] Edit readme. --- README.md | 49 ++++++++++++++++++++++++++++++++++++---- lib/collectr/version.rb | 2 +- spec/hash_spec_helper.rb | 20 ++++------------ 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c7895c2..427f435 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ -[![Build Status](https://api.travis-ci.org/brianmd/collectr.png?branch=master)](https://travis-ci.org/brianmd/collectr) [![Gem Version](https://badge.fury.io/rb/collectr.png)](http://badge.fury.io/rb/collectr) [![Coverage Status](https://coveralls.io/repos/brianmd/collectr/badge.png?branch=master&service=github)](https://coveralls.io/github/brianmd/collectr?branch=master) +[![Build Status](https://api.travis-ci.org/brianmd/collectr.png?branch=master)](https://travis-ci.org/brianmd/collectr) [![Gem Version](https://badge.fury.io/rb/collectr.png)](http://badge.fury.io/rb/collectr) [![Coverage Status](https://coveralls.io/repos/brianmd/collectr/badge.svg?branch=master&service=github)](https://coveralls.io/github/brianmd/collectr?branch=master) # Collectr Abstraction for thread-safe collections (array, hash, set, bag). -Once it is fleshed out, will include complete abstractions for redis and memory. - ## Installation Add this line to your application's Gemfile: @@ -16,7 +14,7 @@ gem 'collectr' And then execute: - $ bundle + $ bundle install Or install it yourself as: @@ -24,7 +22,48 @@ Or install it yourself as: ## Usage -TODO: Write usage instructions here +```ruby +require 'collectr/redis/redis_hash' +x = Collectr::RedisHash.new('example') +x[3] = 7 +x[3] + => 7 +x.fetch(3) { 88 } + => 7 +x.fetch(:not_found) { 88 } + => 88 +``` + +```ruby +require 'collectr/redis/redis_hash_expiry' +x = Collectr::RedisHashExpiry.new('example', expires_in: 60) +x['purple'] = :blue +x['purple'] + => "blue" +sleep 61 +x['purple'] + => nil +x.write('nine', 9, expires_in: 2) +x['nine'] +``` + +```ruby +require 'collectr/memory/memory_hash' +x = Collectr::MemoryHash.new('example') +x[:a] = 'abc' +x[:a] + => "abc" +``` + +```ruby +require 'collectr/redis/redis_array' +array = Collectr::RedisArray.new('arr', max_size: 3) +array.clear +array << 'a' +array << 'b' +array.to_a + => ["a", "b"] +``` ## Contributing diff --git a/lib/collectr/version.rb b/lib/collectr/version.rb index 83e0b3a..5437682 100644 --- a/lib/collectr/version.rb +++ b/lib/collectr/version.rb @@ -1,3 +1,3 @@ module Collectr - VERSION = "0.0.7" + VERSION = "1.0.0" end diff --git a/spec/hash_spec_helper.rb b/spec/hash_spec_helper.rb index 9d228bf..e3c4d61 100644 --- a/spec/hash_spec_helper.rb +++ b/spec/hash_spec_helper.rb @@ -1,6 +1,10 @@ require 'json' require 'spec_helper' +if redis_exists? + warn Redis.current.flushall +end + shared_examples 'a hash' do context 'when keys and/or values may be other than strings' do subject(:collection) { described_class.new 'example' } @@ -56,21 +60,5 @@ # it 'string key is distinct from symbol key' do expect(collection.fetch('x')).to eq(7) end it 'new value is retained' do collection['x'] = 9 ; expect(collection.fetch('x')).to eq(9) end end - - # context 'when expires' do - # it 'expires on time' - # end end -if redis_exists? and false - describe Collectr::RedisHash do - it_behaves_like 'a hash' - end - - describe Collectr::RedisHashExpiry do - it_behaves_like 'a hash' - end -end - -# warn Redis.current.flushall -