Skip to content

Commit

Permalink
Edit readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmd committed Nov 14, 2015
1 parent ee60446 commit 0ab8e06
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -16,15 +14,56 @@ gem 'collectr'

And then execute:

$ bundle
$ bundle install

Or install it yourself as:

$ gem install collectr

## 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

Expand Down
2 changes: 1 addition & 1 deletion lib/collectr/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Collectr
VERSION = "0.0.7"
VERSION = "1.0.0"
end
20 changes: 4 additions & 16 deletions spec/hash_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down Expand Up @@ -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

0 comments on commit 0ab8e06

Please sign in to comment.