undo-storage-rails_cache 0.0.1 → 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 +5 -13
- data/.ruby-version +1 -1
- data/Gemfile +2 -7
- data/README.md +28 -4
- data/VERSION +1 -0
- data/lib/undo/storage/rails_cache.rb +15 -17
- data/spec/integration/undo_spec.rb +11 -0
- data/spec/spec_helper_lite.rb +1 -8
- data/spec/spec_helper_rails.rb +1 -9
- data/spec/support/ci_helper.rb +16 -0
- data/spec/undo/storage/rails_cache_integration_spec.rb +19 -10
- data/spec/undo/storage/rails_cache_spec.rb +35 -16
- data/undo-storage-rails_cache.gemspec +7 -4
- metadata +40 -20
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NzIzMTMxODY0ODA1MGU5NjM4Y2UyMGJjMTdjNGRlYWE2ZTJhNmJiOQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 402dfa78018e83220e282c74986babe501261407
|
4
|
+
data.tar.gz: febbba1204c31d2604f25e68034d69759c62937c
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MjAzNDlmMzY1MzQ2NzFmZDAwZWZmODdmZTdhYzhhZDNkZDE3YzRjMGRlZDJi
|
11
|
-
OGExMjhhY2E0NWVhN2Y1OTQ2NTU1OGY1NTlhMjg4NzE3OGJlYjE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NTVhZmNkYzNiN2RiMGU0OGFmNGY2YjE3NmJhMTRlY2M0MDA1MjE2MDlhNjM4
|
14
|
-
M2Y3ODkxNDliMjgxYThjMzg4MDEyZmY3N2YzMTdmMzlkN2EyNWUyZWZmZTAw
|
15
|
-
YmI4NDk4MDdlNmIxNTg1OGQyZjZmNDJkNDM3ZjMxOWM0YmNlNjk=
|
6
|
+
metadata.gz: a07b94576f504783b2e6efaa1fce4c80241aa04f9923634f4489cbffd47231d2635d78bdd32fe8bdf27b0d0121b5c2cfa9309ef79f285fddcfe641ca5b0a885b
|
7
|
+
data.tar.gz: 7b8749b26ea40931c2e21a357b5eb046471e5ca686316d4caf82f30dbd381954f3f2eb2331f8f5653c30d7cd1b6a19b67f957db4a3aed75a34c12d8283105551
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.1
|
data/Gemfile
CHANGED
@@ -2,7 +2,8 @@ source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :test do
|
5
|
-
gem 'rails', '4.0.2'
|
5
|
+
gem 'rails', '>= 4.0.2'
|
6
|
+
|
6
7
|
if !!ENV['CI']
|
7
8
|
gem "coveralls"
|
8
9
|
else
|
@@ -10,9 +11,3 @@ group :test do
|
|
10
11
|
gem "pry-plus" if "ruby" == RUBY_ENGINE
|
11
12
|
end
|
12
13
|
end
|
13
|
-
|
14
|
-
platforms :rbx do
|
15
|
-
gem 'racc'
|
16
|
-
gem 'rubysl', '~> 2.0'
|
17
|
-
gem 'psych'
|
18
|
-
end
|
data/README.md
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
Undo
|
2
2
|
==========
|
3
3
|
[](https://travis-ci.org/AlexParamonov/undo-storage-rails_cache)
|
4
|
-
[](http://gemnasium.com/AlexParamonov/undo-storage-rails_cache)
|
5
4
|
[](https://coveralls.io/r/AlexParamonov/undo-storage-rails_cache?branch=master)
|
5
|
+
[](https://codeclimate.com/github/AlexParamonov/undo-storage-rails_cache)
|
6
|
+
[](http://gemnasium.com/AlexParamonov/undo-storage-rails_cache)
|
6
7
|
[](http://badge.fury.io/rb/undo-storage-rails_cache)
|
7
8
|
|
8
|
-
Rails.cache adapter for Undo gem.
|
9
|
+
Rails.cache adapter for [Undo gem](https://github.com/AlexParamonov/undo).
|
10
|
+
Designed to be used with Rails cache, but it can be used with any
|
11
|
+
similarly quaking cache store. Rails constant may not even be defined.
|
9
12
|
|
10
13
|
Contents
|
11
14
|
---------
|
12
15
|
1. Installation
|
16
|
+
1. Usage
|
13
17
|
1. Requirements
|
14
18
|
1. Contacts
|
15
19
|
1. Compatibility
|
@@ -31,12 +35,32 @@ Or install it yourself as:
|
|
31
35
|
|
32
36
|
$ gem install undo-storage-rails_cache
|
33
37
|
|
38
|
+
|
39
|
+
Usage
|
40
|
+
-----
|
41
|
+
|
42
|
+
Undo.configure do |config|
|
43
|
+
config.storage = Undo::Storage::RailsCache.new
|
44
|
+
end
|
45
|
+
|
46
|
+
Default options will applied on each call to cache storage:
|
47
|
+
|
48
|
+
Undo.configure do |config|
|
49
|
+
config.storage = Undo::Storage::RailsCache.new(expires_in: 1.hour)
|
50
|
+
end
|
51
|
+
|
52
|
+
As any Undo storage it gets argument bypassed from #store, #restore and #wrap:
|
53
|
+
|
54
|
+
Undo.store object, expires_in: 1.minute
|
55
|
+
|
56
|
+
|
34
57
|
Requirements
|
35
58
|
------------
|
36
59
|
1. Ruby 1.9 or above
|
60
|
+
1. [The Undo](https://github.com/AlexParamonov/undo).
|
37
61
|
|
38
62
|
Contacts
|
39
|
-
|
63
|
+
--------
|
40
64
|
Have questions or recommendations? Contact me via `alexander.n.paramonov@gmail.com`
|
41
65
|
Found a bug or have enhancement request? You are welcome at [Github bugtracker](https://github.com/AlexParamonov/undo-storage-rails_cache/issues)
|
42
66
|
|
@@ -58,7 +82,7 @@ See [build history](http://travis-ci.org/#!/AlexParamonov/undo-storage-rails_cac
|
|
58
82
|
|
59
83
|
## Contributing
|
60
84
|
|
61
|
-
1. Fork repository
|
85
|
+
1. [Fork repository](http://github.com/AlexParamonov/undo-storage-rails_cache/fork)
|
62
86
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
87
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
88
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -1,34 +1,32 @@
|
|
1
|
-
require '
|
1
|
+
require 'undo/storage/adapter'
|
2
2
|
|
3
3
|
module Undo
|
4
4
|
module Storage
|
5
|
-
class RailsCache
|
6
|
-
VERSION = "0.0.1"
|
7
|
-
|
5
|
+
class RailsCache < Adapter
|
8
6
|
def initialize(cache = nil, options = {})
|
9
7
|
@cache = cache
|
10
8
|
@cache ||= Rails.cache if defined? Rails
|
11
|
-
@options = options
|
12
|
-
end
|
13
9
|
|
14
|
-
|
15
|
-
cache.write uuid, serialize(object), options
|
10
|
+
super options
|
16
11
|
end
|
17
12
|
|
18
|
-
def
|
19
|
-
|
13
|
+
def store(uuid, object, options = {})
|
14
|
+
cache.write uuid,
|
15
|
+
pack(object),
|
16
|
+
adapter_options(options)
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def serialize(object)
|
26
|
-
object.to_json
|
19
|
+
def fetch(uuid, options = {})
|
20
|
+
raise KeyError, "key #{uuid} not found" unless cache.exist? uuid
|
21
|
+
unpack cache.read uuid, adapter_options(options)
|
27
22
|
end
|
28
23
|
|
29
|
-
def
|
30
|
-
|
24
|
+
def delete(uuid, options = {})
|
25
|
+
cache.delete uuid, adapter_options(options)
|
31
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
attr_reader :cache
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper_rails"
|
2
|
+
require "undo"
|
3
|
+
require 'undo/integration/shared_undo_integration_examples.rb'
|
4
|
+
|
5
|
+
Undo.configure do |config|
|
6
|
+
config.storage = Undo::Storage::RailsCache.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Undo do
|
10
|
+
include_examples "undo integration"
|
11
|
+
end
|
data/spec/spec_helper_lite.rb
CHANGED
data/spec/spec_helper_rails.rb
CHANGED
@@ -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,20 +1,29 @@
|
|
1
1
|
require "spec_helper_rails"
|
2
2
|
|
3
3
|
describe Undo::Storage::RailsCache do
|
4
|
+
it "stores and fetches object" do
|
5
|
+
subject.store 123, "hello" => "world"
|
6
|
+
expect(subject.fetch 123).to eq "hello" => "world"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "deletes stored data" do
|
10
|
+
subject.store 123, "hello" => "world"
|
11
|
+
subject.delete 123
|
12
|
+
expect { subject.fetch 123 }.to raise_error(KeyError)
|
13
|
+
end
|
14
|
+
|
4
15
|
it "uses Rails.cache by default" do
|
5
|
-
adapter = described_class.new
|
6
16
|
expect(Rails.cache).to receive :write
|
7
|
-
|
17
|
+
subject.store "foo", "bar"
|
8
18
|
end
|
9
19
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
20
|
+
describe "options" do
|
21
|
+
it "accepts known options" do
|
22
|
+
expect { subject.store "foo", "bar", expires_in: 1.minute }.not_to raise_error
|
23
|
+
end
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
25
|
+
it "silently ignores unknown options" do
|
26
|
+
expect { subject.store "foo", "bar", unknown: [:something] }.not_to raise_error
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|
@@ -2,35 +2,32 @@ require "spec_helper_lite"
|
|
2
2
|
require 'undo/storage/rails_cache'
|
3
3
|
|
4
4
|
describe Undo::Storage::RailsCache do
|
5
|
-
|
6
|
-
let(:cache) { double :cache }
|
5
|
+
subject { described_class.new cache }
|
6
|
+
let(:cache) { double :cache, exist?: true }
|
7
7
|
|
8
|
-
it "
|
9
|
-
|
10
|
-
adapter.put "123", "hello" => "world"
|
11
|
-
end
|
8
|
+
it "uses provided cache storage" do
|
9
|
+
subject = described_class.new cache
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
expect(adapter.fetch "123").to eq "hello" => "world"
|
11
|
+
expect(cache).to receive :write
|
12
|
+
subject.store "foo", "bar"
|
16
13
|
end
|
17
14
|
|
18
15
|
it "does not raise when created without arguments" do
|
19
16
|
expect { described_class.new }.not_to raise_error
|
20
17
|
end
|
21
18
|
|
22
|
-
describe "options" do
|
23
|
-
|
24
|
-
let(:options) {
|
19
|
+
describe "default options" do
|
20
|
+
subject { described_class.new cache, options }
|
21
|
+
let(:options) { { additional: :option } }
|
25
22
|
|
26
23
|
it "sends provided options to cache.read" do
|
27
|
-
expect(cache).to receive(:read).with
|
28
|
-
|
24
|
+
expect(cache).to receive(:read).with anything, options
|
25
|
+
subject.fetch "foo"
|
29
26
|
end
|
30
27
|
|
31
28
|
it "sends provided options to cache.write" do
|
32
|
-
expect(cache).to receive(:write).with
|
33
|
-
|
29
|
+
expect(cache).to receive(:write).with anything, anything, options
|
30
|
+
subject.store "foo", "bar"
|
34
31
|
end
|
35
32
|
|
36
33
|
before do
|
@@ -38,4 +35,26 @@ describe Undo::Storage::RailsCache do
|
|
38
35
|
allow(cache).to receive(:read).with(any_args) { { :foo => :bar }.to_json }
|
39
36
|
end if RUBY_VERSION < "2.0"
|
40
37
|
end
|
38
|
+
|
39
|
+
describe "options" do
|
40
|
+
let(:object) { double :object }
|
41
|
+
let(:options) { { foo: :bar } }
|
42
|
+
|
43
|
+
it "accepts options per method" do
|
44
|
+
cache.as_null_object
|
45
|
+
|
46
|
+
expect do
|
47
|
+
subject.store 123, object, options
|
48
|
+
subject.fetch 123, options
|
49
|
+
subject.delete 123, options
|
50
|
+
end.not_to raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has higher priority than default options" do
|
54
|
+
subject = described_class.new cache, expires_in: 10
|
55
|
+
|
56
|
+
expect(cache).to receive(:write).with anything, anything, expires_in: 1
|
57
|
+
subject.store 123, object, expires_in: 1
|
58
|
+
end
|
59
|
+
end
|
41
60
|
end
|
@@ -1,15 +1,17 @@
|
|
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/rails_cache'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "undo-storage-rails_cache"
|
8
|
-
spec.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{Rails.cache storage adapter for Undo}
|
12
|
-
spec.description = %q{
|
11
|
+
spec.description = %q{
|
12
|
+
Rails.cache storage adapter for Undo. Does not depend on Rails and can
|
13
|
+
be used with any similarly quaking storage.
|
14
|
+
}
|
13
15
|
spec.homepage = "http://github.com/AlexParamonov/undo-storage-rails_cache"
|
14
16
|
spec.license = "MIT"
|
15
17
|
|
@@ -18,7 +20,8 @@ Gem::Specification.new do |spec|
|
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
21
|
spec.require_paths = ["lib"]
|
20
22
|
|
21
|
-
spec.
|
23
|
+
spec.add_dependency "undo", "~> 1.0"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.0"
|
22
25
|
spec.add_development_dependency "rake"
|
23
26
|
spec.add_development_dependency "rspec", ">= 3.0.0.beta1"
|
24
27
|
end
|
metadata
CHANGED
@@ -1,75 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: undo-storage-rails_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
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-
|
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.
|
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.
|
40
|
+
version: '1.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: 3.0.0.beta1
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 3.0.0.beta1
|
55
|
-
description:
|
69
|
+
description: "\nRails.cache storage adapter for Undo. Does not depend on Rails and
|
70
|
+
can\nbe used with any similarly quaking storage.\n "
|
56
71
|
email:
|
57
72
|
- alexander.n.paramonov@gmail.com
|
58
73
|
executables: []
|
59
74
|
extensions: []
|
60
75
|
extra_rdoc_files: []
|
61
76
|
files:
|
62
|
-
- .coveralls.yml
|
63
|
-
- .gitignore
|
64
|
-
- .rspec
|
65
|
-
- .ruby-gemset
|
66
|
-
- .ruby-version
|
67
|
-
- .travis.yml
|
77
|
+
- ".coveralls.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".ruby-gemset"
|
81
|
+
- ".ruby-version"
|
82
|
+
- ".travis.yml"
|
68
83
|
- Gemfile
|
69
84
|
- LICENSE.txt
|
70
85
|
- README.md
|
71
86
|
- Rakefile
|
87
|
+
- VERSION
|
72
88
|
- lib/undo/storage/rails_cache.rb
|
89
|
+
- spec/integration/undo_spec.rb
|
73
90
|
- spec/rails_app/.gitignore
|
74
91
|
- spec/rails_app/Rakefile
|
75
92
|
- spec/rails_app/config.ru
|
@@ -80,6 +97,7 @@ files:
|
|
80
97
|
- spec/rails_app/script/rails
|
81
98
|
- spec/spec_helper_lite.rb
|
82
99
|
- spec/spec_helper_rails.rb
|
100
|
+
- spec/support/ci_helper.rb
|
83
101
|
- spec/undo/storage/rails_cache_integration_spec.rb
|
84
102
|
- spec/undo/storage/rails_cache_spec.rb
|
85
103
|
- undo-storage-rails_cache.gemspec
|
@@ -93,21 +111,22 @@ require_paths:
|
|
93
111
|
- lib
|
94
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
113
|
requirements:
|
96
|
-
- -
|
114
|
+
- - ">="
|
97
115
|
- !ruby/object:Gem::Version
|
98
116
|
version: '0'
|
99
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
118
|
requirements:
|
101
|
-
- -
|
119
|
+
- - ">="
|
102
120
|
- !ruby/object:Gem::Version
|
103
121
|
version: '0'
|
104
122
|
requirements: []
|
105
123
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.1.11
|
107
125
|
signing_key:
|
108
126
|
specification_version: 4
|
109
127
|
summary: Rails.cache storage adapter for Undo
|
110
128
|
test_files:
|
129
|
+
- spec/integration/undo_spec.rb
|
111
130
|
- spec/rails_app/.gitignore
|
112
131
|
- spec/rails_app/Rakefile
|
113
132
|
- spec/rails_app/config.ru
|
@@ -118,6 +137,7 @@ test_files:
|
|
118
137
|
- spec/rails_app/script/rails
|
119
138
|
- spec/spec_helper_lite.rb
|
120
139
|
- spec/spec_helper_rails.rb
|
140
|
+
- spec/support/ci_helper.rb
|
121
141
|
- spec/undo/storage/rails_cache_integration_spec.rb
|
122
142
|
- spec/undo/storage/rails_cache_spec.rb
|
123
143
|
has_rdoc:
|