undo-storage-redis 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8a882c3f5c0a35076305a12e0ac865a59c69154
4
- data.tar.gz: 75bce602064d04e209fa91b6bbdee752e020b0da
3
+ metadata.gz: 6c4552cc3c216da926a6ff07a2f0955c7cc5fc9a
4
+ data.tar.gz: 8b99208784965fe42e37e14ff27331e03c4cda59
5
5
  SHA512:
6
- metadata.gz: c12060ce18bae507d6559fa1ee796a4a93245fd8cb76348d865711d382810ddd10dbb000f806de21d7e5caa2a1f0d4c5fc38b68030ec19096a8172ef518e9542
7
- data.tar.gz: baaee65da3bf978c953acf6e6431550052002fb49b88540b43737e744ff9eb5ae1286ea21b51823747a9f525be5802aa370ecf64b151e7db5f95a6ef9f310c4e
6
+ metadata.gz: 93001b74756c0ed421c4c4c8a2d933f4c69fa870abd91f6c4ece0197d8a1463b67088dba569f75b88f4720939e8b242c6b182ddabb9635e4f9ca6800e3cd36f3
7
+ data.tar.gz: 4e5c5594cfad0415544451a72287c2cbfa74a538fbe6a529d8a3407dce34d519c0a2ddd04f0837fcc4fa96fec236586437180a4a40609c57e84180f5adffbb1a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.0-p0
1
+ 2.1.1
data/.travis.yml CHANGED
@@ -17,3 +17,6 @@ matrix:
17
17
 
18
18
  script:
19
19
  - "bundle exec rake ci:all"
20
+
21
+ services:
22
+ - redis-server
data/Gemfile CHANGED
@@ -9,3 +9,7 @@ group :test do
9
9
  gem "pry-plus" if "ruby" == RUBY_ENGINE
10
10
  end
11
11
  end
12
+
13
+ group :test, :development do
14
+ gem 'redis'
15
+ end
data/README.md CHANGED
@@ -5,7 +5,7 @@ Undo
5
5
  [![Coverage Status](https://coveralls.io/repos/AlexParamonov/undo-storage-redis/badge.png?branch=master)](https://coveralls.io/r/AlexParamonov/undo-storage-redis?branch=master)
6
6
  [![Gem Version](https://badge.fury.io/rb/undo-storage-redis.png)](http://badge.fury.io/rb/undo-storage-redis)
7
7
 
8
- Redis storage adapter for Undo gem.
8
+ Redis storage adapter for [Undo gem](https://github.com/AlexParamonov/undo).
9
9
 
10
10
  Contents
11
11
  ---------
@@ -34,6 +34,7 @@ Or install it yourself as:
34
34
  Requirements
35
35
  ------------
36
36
  1. Ruby 1.9 or above
37
+ 1. Undo gem
37
38
 
38
39
  Contacts
39
40
  -------------
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -1,33 +1,31 @@
1
1
  require 'json'
2
+ require 'undo/storage/adapter'
2
3
 
3
4
  module Undo
4
5
  module Storage
5
- class Redis
6
- VERSION = "0.0.4"
7
-
6
+ class Redis < Adapter
8
7
  def initialize(redis, options = {})
9
8
  @redis = redis
10
- @options = options
9
+ super options
11
10
  end
12
11
 
13
- def put(uuid, object)
14
- redis.set uuid, serialize(object), options
12
+ def store(uuid, object, options = {})
13
+ redis.set uuid,
14
+ pack(object),
15
+ adapter_options(options)
15
16
  end
16
17
 
17
- def fetch(uuid)
18
- deserialize redis.get uuid, options
18
+ def fetch(uuid, options = {})
19
+ data = redis.get(uuid) or raise KeyError, "key #{uuid} not found"
20
+ unpack data
19
21
  end
20
22
 
21
- private
22
- attr_reader :redis, :options
23
-
24
- def serialize(object)
25
- object.to_json
23
+ def delete(uuid, options = {})
24
+ redis.del uuid
26
25
  end
27
26
 
28
- def deserialize(data)
29
- JSON.load data
30
- end
27
+ private
28
+ attr_reader :redis
31
29
  end
32
30
  end
33
31
  end
@@ -0,0 +1,12 @@
1
+ require "spec_helper_lite"
2
+ require "undo"
3
+ require "redis"
4
+ require 'undo/integration/shared_undo_integration_examples.rb'
5
+
6
+ Undo.configure do |config|
7
+ config.storage = Undo::Storage::Redis.new Redis.new
8
+ end
9
+
10
+ describe Undo do
11
+ include_examples "undo integration"
12
+ end
@@ -1,11 +1,5 @@
1
- if !!ENV['CI']
2
- require 'coveralls'
3
- Coveralls.wear!
4
- else
5
- require 'pry'
6
- end
7
-
8
- ENV['RAILS_ENV'] ||= 'test'
9
1
  require 'rspec'
2
+ require_relative "support/ci_helper"
3
+ require 'undo/storage/redis'
10
4
 
11
5
  $: << File.expand_path('../lib', File.dirname(__FILE__))
@@ -0,0 +1,16 @@
1
+ if !!ENV["CI"]
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ add_filter '/vendor/'
12
+ minimum_coverage(90)
13
+ end
14
+ else
15
+ require "pry"
16
+ end
@@ -1,37 +1,65 @@
1
1
  require "spec_helper_lite"
2
- require 'undo/storage/redis'
3
2
 
4
3
  describe Undo::Storage::Redis do
5
- let(:adapter) { described_class.new redis }
4
+ subject { described_class.new redis }
6
5
  let(:redis) { double :redis }
7
6
 
8
- it "writes hash to redis" do
7
+ it "uses provided storage" do
8
+ subject = described_class.new redis
9
+
10
+ expect(redis).to receive :set
11
+ subject.store "foo", "bar"
12
+ end
13
+
14
+ it "writes hash as json" do
9
15
  expect(redis).to receive(:set).with "123", '{"hello":"world"}', anything
10
- adapter.put "123", "hello" => "world"
16
+ subject.store "123", "hello" => "world"
11
17
  end
12
18
 
13
- it "reads hash from redis" do
14
- expect(redis).to receive(:get).with("123", anything) { '{"hello":"world"}' }
15
- expect(adapter.fetch "123").to eq "hello" => "world"
19
+ it "reads hash" do
20
+ expect(redis).to receive(:get).with("123") { '{"hello":"world"}' }
21
+ expect(subject.fetch "123").to eq "hello" => "world"
16
22
  end
17
23
 
18
- describe "options" do
19
- let(:adapter) { described_class.new redis, options }
20
- let(:options) { { :additional => :option } }
24
+ describe "default options" do
25
+ subject { described_class.new redis, options }
26
+ let(:options) { { additional: :option } }
21
27
 
22
- it "sends provided options to redis.get" do
23
- expect(redis).to receive(:get).with anything, options
24
- adapter.fetch "foo"
28
+ it "does not send options to redis.get" do
29
+ expect(redis).to receive(:get).with("foo") { "bar".to_json }
30
+ subject.fetch "foo"
31
+ end
32
+
33
+ it "does not send options to redis.del" do
34
+ expect(redis).to receive(:del).with "foo"
35
+ subject.delete "foo"
25
36
  end
26
37
 
27
38
  it "sends provided options to redis.set" do
28
39
  expect(redis).to receive(:set).with anything, anything, options
29
- adapter.put "foo", "bar"
40
+ subject.store "foo", "bar"
41
+ end
42
+ end
43
+
44
+ describe "options" do
45
+ let(:object) { double :object }
46
+ let(:options) { { foo: :bar } }
47
+
48
+ it "accepts options per method" do
49
+ redis.as_null_object
50
+
51
+ expect do
52
+ subject.store 123, object, options
53
+ subject.fetch 123, options
54
+ subject.delete 123, options
55
+ end.not_to raise_error
30
56
  end
31
57
 
32
- before do
33
- # JSON.load behaves differently in 1.9
34
- allow(redis).to receive(:get).with(any_args) { { :foo => :bar }.to_json }
35
- end if RUBY_VERSION < "2.0"
58
+ it "has higher priority than default options" do
59
+ subject = described_class.new redis, ex: 10
60
+
61
+ expect(redis).to receive(:set).with anything, anything, ex: 1
62
+ subject.store 123, object, ex: 1
63
+ end
36
64
  end
37
65
  end
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'undo/storage/redis'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "undo-storage-redis"
8
- spec.version = Undo::Storage::Redis::VERSION
7
+ spec.version = IO.read("VERSION")
9
8
  spec.authors = ["Alexander Paramonov"]
10
9
  spec.email = ["alexander.n.paramonov@gmail.com"]
11
10
  spec.summary = %q{Redis storage adapter for Undo}
@@ -18,7 +17,8 @@ Gem::Specification.new do |spec|
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_dependency "undo", "~> 1.0"
21
+ spec.add_development_dependency "bundler", "~> 1.0"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", ">= 3.0.0.beta1"
24
24
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: undo-storage-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Paramonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: undo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.5'
33
+ version: '1.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.5'
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -69,8 +83,11 @@ files:
69
83
  - LICENSE.txt
70
84
  - README.md
71
85
  - Rakefile
86
+ - VERSION
72
87
  - lib/undo/storage/redis.rb
88
+ - spec/integration/undo_spec.rb
73
89
  - spec/spec_helper_lite.rb
90
+ - spec/support/ci_helper.rb
74
91
  - spec/undo/storage/redis_spec.rb
75
92
  - undo-storage-redis.gemspec
76
93
  homepage: http://github.com/AlexParamonov/undo-storage-redis
@@ -93,11 +110,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
110
  version: '0'
94
111
  requirements: []
95
112
  rubyforge_project:
96
- rubygems_version: 2.2.2
113
+ rubygems_version: 2.1.11
97
114
  signing_key:
98
115
  specification_version: 4
99
116
  summary: Redis storage adapter for Undo
100
117
  test_files:
118
+ - spec/integration/undo_spec.rb
101
119
  - spec/spec_helper_lite.rb
120
+ - spec/support/ci_helper.rb
102
121
  - spec/undo/storage/redis_spec.rb
103
122
  has_rdoc: