stockpile 1.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,14 @@
1
1
  .autotest
2
2
  .gemtest
3
3
  .minitest.rb
4
+ .rubocop.yml
5
+ .simplecov-prelude.rb
4
6
  .travis.yml
7
+ .workenv
8
+ Code-of-Conduct.md
5
9
  Contributing.rdoc
6
10
  Gemfile
7
- History.rdoc
11
+ History.md
8
12
  Licence.rdoc
9
13
  Manifest.txt
10
14
  README.rdoc
@@ -2,7 +2,7 @@
2
2
 
3
3
  code :: https://github.com/halostatue/stockpile/
4
4
  bugs :: https://github.com/halostatue/stockpile/issues
5
- continuous integration :: {<img src="https://travis-ci.org/halostatue/stockpile.png" />}[https://travis-ci.org/halostatue/stockpile]
5
+ continuous integration :: {<img src="https://travis-ci.org/halostatue/stockpile.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/halostatue/stockpile]
6
6
 
7
7
  == Description
8
8
 
@@ -14,11 +14,10 @@ implemented connection managers. So far, only Redis has been implemented
14
14
  Stockpile also provides an adapter so that its functionality can be accessed
15
15
  from within a module.
16
16
 
17
- Release 1.1 fixes an issue with early initialization of an injected Stockpile
18
- instance during adaptation
19
- ({stockpile#2}[https://githbub.com/halostatue/stockpile/issues/2]). Several
20
- small improvements to Stockpile.new, Stockpile#connect, and
21
- Stockpile#connection_for have been documented.
17
+ Release 2.0 fixes an issue when Stockpile options are provided with an
18
+ OpenStruct, originally reported as
19
+ {stockpile-redis#1}[https://github.com/halostatue/stockpile-redis/issues/1].
20
+ Support for Ruby 1.9 has been dropped.
22
21
 
23
22
  == Features
24
23
 
data/Rakefile CHANGED
@@ -1,53 +1,61 @@
1
1
  # -*- ruby -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems'
4
5
  require 'hoe'
5
6
  require 'rake/clean'
6
7
 
7
8
  Hoe.plugin :doofus
9
+ Hoe.plugin :email unless ENV['CI'] || ENV['TRAVIS']
8
10
  Hoe.plugin :gemspec2
9
11
  Hoe.plugin :git
10
12
  Hoe.plugin :minitest
11
13
  Hoe.plugin :travis
12
- Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS']
13
14
 
14
15
  spec = Hoe.spec 'stockpile' do
15
16
  developer('Austin Ziegler', 'halostatue@gmail.com')
16
17
 
17
- self.history_file = 'History.rdoc'
18
+ self.history_file = 'History.md'
18
19
  self.readme_file = 'README.rdoc'
19
- self.extra_rdoc_files = FileList["*.rdoc"].to_a
20
-
21
- license "MIT"
22
-
23
- self.need_tar = true
24
- self.require_ruby_version '>= 1.9.2'
25
-
26
- self.extra_dev_deps << ['hoe-doofus', '~> 1.0']
27
- self.extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
28
- self.extra_dev_deps << ['hoe-git', '~> 1.5']
29
- self.extra_dev_deps << ['hoe-travis', '~> 1.2']
30
- self.extra_dev_deps << ['minitest', '~> 5.4']
31
- self.extra_dev_deps << ['minitest-around', '~> 0.3']
32
- self.extra_dev_deps << ['minitest-autotest', '~> 1.0']
33
- self.extra_dev_deps << ['minitest-bisect', '~> 1.2']
34
- self.extra_dev_deps << ['minitest-focus', '~> 1.1']
35
- self.extra_dev_deps << ['minitest-moar', '~> 0.0']
36
- self.extra_dev_deps << ['minitest-pretty_diff', '~> 0.1']
37
- self.extra_dev_deps << ['rake', '>= 10.0']
38
- self.extra_dev_deps << ['simplecov', '~> 0.7']
20
+
21
+ license 'MIT'
22
+
23
+ require_ruby_version '>= 2.0'
24
+
25
+ extra_dev_deps << ['hoe-doofus', '~> 1.0']
26
+ extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
27
+ extra_dev_deps << ['hoe-git', '~> 1.5']
28
+ extra_dev_deps << ['hoe-travis', '~> 1.2']
29
+ extra_dev_deps << ['minitest', '~> 5.4']
30
+ extra_dev_deps << ['minitest-autotest', '~> 1.0']
31
+ extra_dev_deps << ['minitest-bisect', '~> 1.2']
32
+ extra_dev_deps << ['minitest-bonus-assertions', '~> 2.0']
33
+ extra_dev_deps << ['minitest-focus', '~> 1.1']
34
+ extra_dev_deps << ['minitest-moar', '~> 0.0']
35
+ extra_dev_deps << ['minitest-pretty_diff', '~> 0.1']
36
+ extra_dev_deps << ['rake', '>= 10.0']
37
+ extra_dev_deps << ['simplecov', '~> 0.7']
38
+ end
39
+
40
+ module Hoe::Publish
41
+ alias_method :original_make_rdoc_cmd, :make_rdoc_cmd
42
+
43
+ def make_rdoc_cmd(*extra_args) # :nodoc:
44
+ spec.extra_rdoc_files.reject! { |f| f == 'Manifest.txt' }
45
+ original_make_rdoc_cmd(*extra_args)
46
+ end
39
47
  end
40
48
 
41
49
  namespace :test do
42
50
  task :coverage do
43
- spec.test_prelude = [
44
- 'require "simplecov"',
45
- 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
46
- 'gem "minitest"'
47
- ].join('; ')
51
+ spec.test_prelude = %q(load ".simplecov-prelude.rb")
52
+
48
53
  Rake::Task['test'].execute
49
54
  end
55
+
50
56
  CLOBBER << 'coverage'
51
57
  end
52
58
 
59
+ CLOBBER << 'tmp'
60
+
53
61
  # vim: syntax=ruby
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
4
 
@@ -14,7 +14,7 @@ require 'forwardable'
14
14
  class Stockpile
15
15
  extend Forwardable
16
16
 
17
- VERSION = "1.1" # :nodoc:
17
+ VERSION = '2.0' # :nodoc:
18
18
 
19
19
  @default_manager = nil
20
20
 
@@ -75,7 +75,7 @@ class Stockpile
75
75
  # LastRunTime.last_run_time('adaptable_application')
76
76
  def inject!(mod, options = {})
77
77
  unless mod.kind_of?(Module)
78
- raise ArgumentError, "#{mod} is not a class or module"
78
+ fail ArgumentError, "#{mod} is not a class or module"
79
79
  end
80
80
 
81
81
  name = options.fetch(:method, :cache).to_sym
@@ -174,7 +174,7 @@ class Stockpile
174
174
  default = options.delete(:default_manager) || self.class.default_manager
175
175
 
176
176
  unless manager || default
177
- raise ArgumentError, "No connection manager provided or set as default."
177
+ fail ArgumentError, 'No connection manager provided or set as default.'
178
178
  end
179
179
 
180
180
  manager ||= default
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'stockpile'
4
4
 
@@ -28,6 +28,7 @@ class Stockpile
28
28
  # manager.
29
29
  def initialize(options = {})
30
30
  @options = options.dup
31
+ @options = options.to_h unless @options.kind_of?(Hash)
31
32
  @narrow = !!@options.fetch(:narrow, ::Stockpile.narrow?)
32
33
  @connection = nil
33
34
  @clients = {}
@@ -121,6 +122,7 @@ class Stockpile
121
122
  end
122
123
 
123
124
  private
125
+
124
126
  # Converts +client_names+ into a hash of client names to options.
125
127
  #
126
128
  # * A Hash object, mapping client names to client options.
@@ -169,18 +171,18 @@ class Stockpile
169
171
  end
170
172
 
171
173
  # Performs a client connect action. Must be implemented by a client.
172
- def client_connect(name = nil, options = {})
173
- raise NotImplementedError
174
+ def client_connect(_name = nil, _options = {})
175
+ fail NotImplementedError
174
176
  end
175
177
 
176
178
  # Performs a client reconnect action. Must be implemented by a client.
177
- def client_reconnect(client = connect())
178
- raise NotImplementedError
179
+ def client_reconnect(_client = connect)
180
+ fail NotImplementedError
179
181
  end
180
182
 
181
183
  # Performs a client disconnect action. Must be implemented by a client.
182
- def client_disconnect(client = connect())
183
- raise NotImplementedError
184
+ def client_disconnect(_client = connect)
185
+ fail NotImplementedError
184
186
  end
185
187
  end
186
188
  end
@@ -1,4 +1,4 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'stockpile/base'
4
4
 
@@ -49,18 +49,19 @@ class Stockpile
49
49
  end
50
50
 
51
51
  def hget(key, field)
52
- raise unless connected?
52
+ fail unless connected?
53
53
  valid_hkey!(key)[field]
54
54
  end
55
55
 
56
56
  def hset(key, field, value)
57
- raise unless connected?
57
+ fail unless connected?
58
58
  valid_hkey!(key)[field] = value
59
59
  end
60
60
 
61
61
  private
62
+
62
63
  def check_valid!
63
- raise unless connected?
64
+ fail unless connected?
64
65
  end
65
66
 
66
67
  def valid_hkey!(key)
@@ -71,7 +72,7 @@ class Stockpile
71
72
  when Hash
72
73
  nil
73
74
  else
74
- raise
75
+ fail
75
76
  end
76
77
  h
77
78
  end
@@ -153,17 +154,19 @@ class Stockpile
153
154
  # which disconnects all connections implicitly.
154
155
 
155
156
  ##
157
+
156
158
  private
157
- def client_connect(name = nil, options = {})
159
+
160
+ def client_connect(_name = nil, options = {})
158
161
  return connection if connection && narrow?
159
162
  Data.new(@options.merge(options))
160
163
  end
161
164
 
162
- def client_reconnect(client = connection())
165
+ def client_reconnect(client = connection)
163
166
  client.reconnect if client
164
167
  end
165
168
 
166
- def client_disconnect(client = connection())
169
+ def client_disconnect(client = connection)
167
170
  client.disconnect if client
168
171
  end
169
172
  end
@@ -1,4 +1,4 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  gem 'minitest'
4
4
  require 'minitest/autorun'
@@ -18,11 +18,7 @@ module Minitest::ENVStub
18
18
  def stub_env env, options = {}, *block_args, &block
19
19
  mock = lambda { |key|
20
20
  env.fetch(key) { |k|
21
- if options[:passthrough]
22
- ENV.send(:"__minitest_stub__[]", k)
23
- else
24
- nil
25
- end
21
+ ENV.send(:"__minitest_stub__[]", k) if options[:passthrough]
26
22
  }
27
23
  }
28
24
 
@@ -1,22 +1,23 @@
1
+ # frozen_string_literal: true
1
2
  require 'minitest_config'
2
3
  require 'time'
3
4
 
4
5
  describe Stockpile do
5
- describe ".narrow?" do
6
- it "is wide by default" do
6
+ describe '.narrow?' do
7
+ it 'is wide by default' do
7
8
  stub_env({}) do
8
9
  refute Stockpile.narrow?
9
10
  end
10
11
  end
11
12
 
12
- it "is narrow when $STOCKPILE_CONNECTION_WIDTH = 'narrow'" do
13
- stub_env({ 'STOCKPILE_CONNECTION_WIDTH' => 'narrow' }) do
13
+ it %q(is narrow when $STOCKPILE_CONNECTION_WIDTH = 'narrow') do
14
+ stub_env('STOCKPILE_CONNECTION_WIDTH' => 'narrow') do
14
15
  assert Stockpile.narrow?
15
16
  end
16
17
  end
17
18
  end
18
19
 
19
- describe ".inject!" do
20
+ describe '.inject!' do
20
21
  let(:cls) { Class.new }
21
22
  let(:mod) { Module.new }
22
23
  let(:lrt) {
@@ -40,86 +41,86 @@ describe Stockpile do
40
41
  end
41
42
  }
42
43
 
43
- it "throws an ArgumentError unless it's a class or module" do
44
+ it %q(throws an ArgumentError unless it's a class or module) do
44
45
  assert_raises ArgumentError do
45
46
  ::Stockpile.inject!(Object.new)
46
47
  end
47
48
  end
48
49
 
49
- describe "Stockpile.inject!(Module):" do
50
+ describe 'Stockpile.inject!(Module):' do
50
51
  before { ::Stockpile.inject!(mod) }
51
52
 
52
- it "defines Mod.cache" do
53
+ it 'defines Mod.cache' do
53
54
  assert_respond_to mod, :cache
54
55
  end
55
56
 
56
- it "defines Mod.cache_adapter" do
57
+ it 'defines Mod.cache_adapter' do
57
58
  assert_respond_to mod, :cache_adapter
58
59
  end
59
60
 
60
- it "defines Mod.cache_adapter!" do
61
+ it 'defines Mod.cache_adapter!' do
61
62
  assert_respond_to mod, :cache_adapter!
62
63
  end
63
64
 
64
- it "Fails cache initialization" do
65
+ it 'Fails cache initialization' do
65
66
  assert_raises ArgumentError do
66
67
  mod.cache
67
68
  end
68
69
  end
69
70
  end
70
71
 
71
- describe "Stockpile.inject!(Mod, adaptable: false)" do
72
+ describe 'Stockpile.inject!(Mod, adaptable: false)' do
72
73
  before { ::Stockpile.inject!(mod, adaptable: false) }
73
74
 
74
- it "defines Mod.cache" do
75
+ it 'defines Mod.cache' do
75
76
  assert_respond_to mod, :cache
76
77
  end
77
78
 
78
- it "does not define Mod.cache_adapter or Mod.cache_adapter!" do
79
+ it 'does not define Mod.cache_adapter or Mod.cache_adapter!' do
79
80
  refute_respond_to mod, :cache_adapter
80
81
  refute_respond_to mod, :cache_adapter!
81
82
  end
82
83
  end
83
84
 
84
- describe "Stockpile.inject!(Mod, method: stockpile)" do
85
+ describe 'Stockpile.inject!(Mod, method: stockpile)' do
85
86
  before { ::Stockpile.inject!(mod, method: :stockpile) }
86
87
 
87
- it "defines Mod.stockpile" do
88
+ it 'defines Mod.stockpile' do
88
89
  assert_respond_to mod, :stockpile
89
90
  end
90
91
 
91
- it "defines Mod.stockpile_adapter" do
92
+ it 'defines Mod.stockpile_adapter' do
92
93
  assert_respond_to mod, :stockpile_adapter
93
94
  end
94
95
 
95
- it "defines Mod.stockpile_adapter!" do
96
+ it 'defines Mod.stockpile_adapter!' do
96
97
  assert_respond_to mod, :stockpile_adapter!
97
98
  end
98
99
  end
99
100
 
100
- describe "Stockpile.inject!(Mod, method: :stockpile, adaptable: false)" do
101
+ describe 'Stockpile.inject!(Mod, method: :stockpile, adaptable: false)' do
101
102
  before do
102
103
  ::Stockpile.inject!(mod, method: :stockpile, adaptable: false)
103
104
  end
104
105
 
105
- it "defines Mod.stockpile" do
106
+ it 'defines Mod.stockpile' do
106
107
  assert_respond_to mod, :stockpile
107
108
  end
108
109
 
109
- it "does not define Mod.stockpile_adapter or Mod.stockpile_adapter!" do
110
+ it 'does not define Mod.stockpile_adapter or Mod.stockpile_adapter!' do
110
111
  refute_respond_to mod, :stockpile_adapter
111
112
  refute_respond_to mod, :stockpile_adapter!
112
113
  end
113
114
  end
114
115
 
115
- describe "Mod.cache_adapter" do
116
+ describe 'Mod.cache_adapter' do
116
117
  let(:now) { Time.now }
117
118
  let(:iso) { now.utc.iso8601 }
118
119
  before do
119
120
  ::Stockpile.inject!(mod, default_manager: Stockpile::Memory)
120
121
  end
121
122
 
122
- it "queues adaptation until Stockpile has been initialized" do
123
+ it 'queues adaptation until Stockpile has been initialized' do
123
124
  stub Stockpile, :new do
124
125
  mod.cache_adapter(lrt)
125
126
  refute_called Stockpile, :new
@@ -127,13 +128,12 @@ describe Stockpile do
127
128
  refute_empty mod.instance_variable_get(:@__stockpile_triggers__)
128
129
  end
129
130
 
130
- assert_equal({ namespace: 'n' },
131
- mod.cache(namespace: 'n').connection.options)
131
+ assert_equal({ namespace: 'n' }, mod.cache(namespace: 'n').connection.options)
132
132
  assert_respond_to mod.cache, :last_run_time
133
133
  assert_respond_to mod.cache, :job_ran
134
134
  end
135
135
 
136
- it "adapts an initialized Stockpile immediately" do
136
+ it 'adapts an initialized Stockpile immediately' do
137
137
  mod.cache
138
138
  mod.cache_adapter(lrt)
139
139
  assert_respond_to mod.cache, :last_run_time
@@ -141,42 +141,42 @@ describe Stockpile do
141
141
  assert_empty mod.instance_variable_get(:@__stockpile_triggers__)
142
142
  end
143
143
 
144
- it "adapts the cache with last_run_time" do
144
+ it 'adapts the cache with last_run_time' do
145
145
  mod.cache_adapter(lrt)
146
146
  assert_nil mod.cache.last_run_time('foo')
147
147
  assert_equal iso, mod.cache.last_run_time('foo', now)
148
148
  assert_equal now.to_i, mod.cache.last_run_time('foo').to_i
149
149
  end
150
150
 
151
- it "adapts the module with last_run_time" do
151
+ it 'adapts the module with last_run_time' do
152
152
  mod.cache_adapter(lrt, mod)
153
153
  assert_nil mod.last_run_time('foo')
154
154
  assert_equal iso, mod.last_run_time('foo', now)
155
155
  assert_equal now.to_i, mod.last_run_time('foo').to_i
156
156
  end
157
157
 
158
- it "adapts the lrt module with last_run_time" do
158
+ it 'adapts the lrt module with last_run_time' do
159
159
  mod.cache_adapter!(lrt)
160
160
  assert_nil lrt.last_run_time('foo')
161
161
  assert_equal iso, lrt.last_run_time('foo', now)
162
162
  assert_equal now.to_i, lrt.last_run_time('foo').to_i
163
163
  end
164
164
 
165
- it "adapts the cache with job_ran" do
165
+ it 'adapts the cache with job_ran' do
166
166
  mod.cache_adapter(lrt)
167
167
  refute mod.cache.job_ran('foo')
168
168
  assert mod.cache.job_ran('foo', true)
169
169
  assert mod.cache.job_ran('foo')
170
170
  end
171
171
 
172
- it "adapts the module with last_run_time" do
172
+ it 'adapts the module with last_run_time' do
173
173
  mod.cache_adapter(lrt, mod)
174
174
  refute mod.job_ran('foo')
175
175
  assert mod.job_ran('foo', true)
176
176
  assert mod.job_ran('foo')
177
177
  end
178
178
 
179
- it "adapts the lrt module with last_run_time" do
179
+ it 'adapts the lrt module with last_run_time' do
180
180
  mod.cache_adapter!(lrt)
181
181
  refute lrt.job_ran('foo')
182
182
  assert lrt.job_ran('foo', true)
@@ -184,22 +184,22 @@ describe Stockpile do
184
184
  end
185
185
  end
186
186
 
187
- describe "Stockpile.inject!(Class):" do
187
+ describe 'Stockpile.inject!(Class):' do
188
188
  before { ::Stockpile.inject!(cls) }
189
189
 
190
- it "defines cls.cache" do
190
+ it 'defines cls.cache' do
191
191
  assert_respond_to cls, :cache
192
192
  end
193
193
 
194
- it "defines cls.cache_adapter" do
194
+ it 'defines cls.cache_adapter' do
195
195
  assert_respond_to cls, :cache_adapter
196
196
  end
197
197
 
198
- it "defines cls.cache_adapter!" do
198
+ it 'defines cls.cache_adapter!' do
199
199
  assert_respond_to cls, :cache_adapter!
200
200
  end
201
201
 
202
- it "Fails cache initialization" do
202
+ it 'Fails cache initialization' do
203
203
  assert_raises ArgumentError do
204
204
  cls.cache
205
205
  end