excursion 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/excursion/datastores/active_record.rb +6 -0
- data/lib/excursion/datastores/active_record_with_memcache.rb +8 -0
- data/lib/excursion/datastores/datastore.rb +8 -0
- data/lib/excursion/datastores/file.rb +4 -0
- data/lib/excursion/datastores/memcache.rb +20 -3
- data/lib/excursion/datastores/test.rb +11 -0
- data/lib/excursion/helpers/javascript_helper.rb +12 -0
- data/lib/excursion/helpers/url_helper.rb +8 -4
- data/lib/excursion/helpers.rb +1 -0
- data/lib/excursion/pool.rb +4 -0
- data/lib/excursion/railtie.rb +5 -0
- data/lib/excursion/version.rb +1 -1
- data/spec/excursion/datastores/active_record_spec.rb +24 -12
- data/spec/excursion/datastores/active_record_with_memcache_spec.rb +10 -1
- data/spec/excursion/datastores/file_spec.rb +23 -11
- data/spec/excursion/datastores/memcache_spec.rb +24 -11
- data/spec/excursion/datastores/test_spec.rb +23 -12
- metadata +3 -4
- data/spec/dummy/log/development.log +0 -141403
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee64e15f8d7724efbe4740ea2df2536c720a2865
|
4
|
+
data.tar.gz: 45927cde8ec41918fca4bcc1144075d0e40d0c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 039ba40d1e6aa5f66f262a751f64b65a04f03eed7a0f3237d020850e942790826644d2d6d2453b20aa839e4c85a210e35f4016497b5c24ea7ce30052b6166955
|
7
|
+
data.tar.gz: 0d2ba1e113445f529f6c86e1a78b014eed8554987b524cb4142e08de997968caf20f13d4fb2401f59d2af978fe6b6045e5f6dc39874a2ac1ef83702a80bcc325
|
@@ -28,6 +28,14 @@ module Excursion
|
|
28
28
|
end
|
29
29
|
alias_method :unset, :delete
|
30
30
|
|
31
|
+
def all
|
32
|
+
hash = @cache.all
|
33
|
+
return hash unless hash.nil? || hash.empty?
|
34
|
+
@model.all
|
35
|
+
rescue Dalli::RingError => e
|
36
|
+
rescue_from_dalli_ring_error(e) && retry
|
37
|
+
end
|
38
|
+
|
31
39
|
protected
|
32
40
|
|
33
41
|
def initialize(server)
|
@@ -7,12 +7,20 @@ module Excursion
|
|
7
7
|
Excursion::Pool::Application.from_cache(read(key))
|
8
8
|
end
|
9
9
|
|
10
|
+
def all_apps
|
11
|
+
app_hash = HashWithIndifferentAccess.new
|
12
|
+
all.each do |k,v|
|
13
|
+
app_hash[k.to_sym] = Excursion::Pool::Application.from_cache(v)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
10
17
|
def read(key); end
|
11
18
|
alias_method :get, :read
|
12
19
|
def write(key, value); end
|
13
20
|
alias_method :set, :write
|
14
21
|
def delete(key); end
|
15
22
|
alias_method :unset, :delete
|
23
|
+
def all; end
|
16
24
|
|
17
25
|
end
|
18
26
|
end
|
@@ -5,6 +5,7 @@ require 'excursion/exceptions/memcache'
|
|
5
5
|
module Excursion
|
6
6
|
module Datastores
|
7
7
|
class Memcache < Datastore
|
8
|
+
REGISTERED_KEYS = 'registered_keys'
|
8
9
|
|
9
10
|
def read(key)
|
10
11
|
@client.get(key.to_s)
|
@@ -14,20 +15,30 @@ module Excursion
|
|
14
15
|
alias_method :get, :read
|
15
16
|
|
16
17
|
def write(key, value)
|
17
|
-
value if @client.set(key.to_s, value)
|
18
|
+
value if @client.set(key.to_s, value) && @client.set(REGISTERED_KEYS, (registered_keys << key.to_s).join(','))
|
18
19
|
rescue Dalli::RingError => e
|
19
20
|
rescue_from_dalli_ring_error(e) && retry
|
20
21
|
end
|
21
22
|
alias_method :set, :write
|
22
23
|
|
23
24
|
def delete(key)
|
24
|
-
|
25
|
-
|
25
|
+
regd_keys = registered_keys
|
26
|
+
regd_keys.delete(key.to_s)
|
27
|
+
value = @client.get(key.to_s)
|
28
|
+
value if @client.delete(key.to_s) && @client.set(REGISTERED_KEYS, regd_keys.join(','))
|
26
29
|
rescue Dalli::RingError => e
|
27
30
|
rescue_from_dalli_ring_error(e) && retry
|
28
31
|
end
|
29
32
|
alias_method :unset, :delete
|
30
33
|
|
34
|
+
def all
|
35
|
+
hash = HashWithIndifferentAccess.new
|
36
|
+
registered_keys.each { |key| hash[key.to_s] = @client.get(key.to_s) }
|
37
|
+
hash
|
38
|
+
rescue Dalli::RingError => e
|
39
|
+
rescue_from_dalli_ring_error(e) && retry
|
40
|
+
end
|
41
|
+
|
31
42
|
protected
|
32
43
|
|
33
44
|
def initialize(server)
|
@@ -35,6 +46,12 @@ module Excursion
|
|
35
46
|
@client = Dalli::Client.new(server, {namespace: "excursion"})
|
36
47
|
end
|
37
48
|
|
49
|
+
def registered_keys
|
50
|
+
@client.get(REGISTERED_KEYS).split(',')
|
51
|
+
rescue
|
52
|
+
[]
|
53
|
+
end
|
54
|
+
|
38
55
|
# TODO if we're using memcache, and the server goes away, it might be a good idea
|
39
56
|
# to make sure to re-register this app in the pool when it comes back, just in case
|
40
57
|
# the server crashed and the pool is lost.
|
@@ -10,6 +10,13 @@ module Excursion
|
|
10
10
|
def app(key)
|
11
11
|
Excursion::Pool::DummyApplication.from_cache(read(key))
|
12
12
|
end
|
13
|
+
|
14
|
+
def all_apps
|
15
|
+
app_hash = HashWithIndifferentAccess.new
|
16
|
+
all.each do |k,v|
|
17
|
+
app_hash[k.to_sym] = Excursion::Pool::DummyApplication.from_cache(v)
|
18
|
+
end
|
19
|
+
end
|
13
20
|
|
14
21
|
def read(key)
|
15
22
|
return unless Excursion.configuration.test_providers.nil? || Excursion.configuration.test_providers.map(&:to_sym).include?(key.to_sym)
|
@@ -27,6 +34,10 @@ module Excursion
|
|
27
34
|
end
|
28
35
|
alias_method :unset, :delete
|
29
36
|
|
37
|
+
def all
|
38
|
+
HashWithIndifferentAccess.new(@pool)
|
39
|
+
end
|
40
|
+
|
30
41
|
protected
|
31
42
|
|
32
43
|
def initialize(pool=nil)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Excursion
|
2
|
+
module Helpers
|
3
|
+
module JavascriptHelper
|
4
|
+
def render_excursion_javascript_helpers
|
5
|
+
content_tag :script, raw("Excursion.loadPool(#{raw Excursion::Pool.datastore.all.to_json});"), type: "text/javascript"
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActionController::Base.send :helper, Excursion::Helpers::JavascriptHelper
|
@@ -12,10 +12,14 @@ module Excursion
|
|
12
12
|
if route.nil?
|
13
13
|
super
|
14
14
|
else
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
if meth.to_s.match(/_url\Z/)
|
16
|
+
url_opts = (@application.default_url_options || {}).clone
|
17
|
+
url_opts.merge!(args.slice!(args.length-1)) if args.last.is_a?(Hash) #&& args.last.has_key?(:host)
|
18
|
+
|
19
|
+
ActionDispatch::Http::URL.url_for(url_opts.merge({path: replaced_path(route, args)}))
|
20
|
+
elsif meth.to_s.match(/_path\Z/)
|
21
|
+
replaced_path(route, args)
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
data/lib/excursion/helpers.rb
CHANGED
data/lib/excursion/pool.rb
CHANGED
data/lib/excursion/railtie.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module Excursion
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
# automatically registers excursion as an engine and allows
|
4
|
+
# using the javascript helpers
|
5
|
+
end
|
6
|
+
|
2
7
|
class Railtie < Rails::Railtie
|
3
8
|
config.after_initialize do |app|
|
4
9
|
if Excursion.configuration.register_app == true && !Excursion.configuration.datastore.nil? && !defined?(Rails::Generators::Base) # HACK is there a better way to attempt to check if we're running a generator?
|
data/lib/excursion/version.rb
CHANGED
@@ -80,26 +80,38 @@ describe 'Excursion::Datastores::ActiveRecord' do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
describe '#delete' do
|
84
84
|
describe 'key' do
|
85
85
|
it 'should be required' do
|
86
86
|
expect { subject.delete }.to raise_exception(ArgumentError)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
90
|
-
it 'should remove the key from the datastore' do
|
91
|
-
subject.read('key1').should_not eql(nil)
|
92
|
-
subject.delete('key1')
|
93
|
-
subject.read('key1').should be(nil)
|
94
|
-
end
|
95
89
|
|
96
|
-
|
97
|
-
|
98
|
-
|
90
|
+
context 'when the key exists' do
|
91
|
+
it 'should remove the key from the datastore' do
|
92
|
+
subject.read('key1').should_not eql(nil)
|
93
|
+
subject.delete('key1')
|
94
|
+
subject.read('key1').should be(nil)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should return the value of the deleted key' do
|
98
|
+
keyval = subject.read('key1')
|
99
|
+
subject.delete('key1').should eql(keyval)
|
100
|
+
end
|
99
101
|
end
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
+
context 'when the key does not exist' do
|
104
|
+
it 'should return nil' do
|
105
|
+
subject.delete('non_existent_key').should eql(nil)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#all' do
|
111
|
+
it 'should return a hash of all the registered keys and their values' do
|
112
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |k,v|
|
113
|
+
expect(subject.all[k.to_sym]).to eql(v)
|
114
|
+
end
|
103
115
|
end
|
104
116
|
end
|
105
117
|
|
@@ -18,6 +18,7 @@ describe 'Excursion::Datastores::ActiveRecordWithMemcache' do
|
|
18
18
|
dalli_client.set(key, val)
|
19
19
|
Excursion::RoutePool.create key: key, value: val
|
20
20
|
end
|
21
|
+
dalli_client.set(Excursion::Datastores::Memcache::REGISTERED_KEYS, Excursion::Specs::Mocks::SIMPLE_VALUES.keys.map(&:to_s).join(','))
|
21
22
|
end
|
22
23
|
|
23
24
|
subject do
|
@@ -114,7 +115,7 @@ describe 'Excursion::Datastores::ActiveRecordWithMemcache' do
|
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
|
-
|
118
|
+
describe '#delete' do
|
118
119
|
before(:each) do
|
119
120
|
fill_pool
|
120
121
|
end
|
@@ -154,5 +155,13 @@ describe 'Excursion::Datastores::ActiveRecordWithMemcache' do
|
|
154
155
|
subject.delete('non_existent_key').should eql(nil)
|
155
156
|
end
|
156
157
|
end
|
158
|
+
|
159
|
+
describe '#all' do
|
160
|
+
it 'should return a hash of all the registered keys and their values' do
|
161
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |k,v|
|
162
|
+
expect(subject.all[k.to_sym]).to eql(v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
157
166
|
|
158
167
|
end
|
@@ -93,26 +93,38 @@ describe 'Excursion::Datastores::File' do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
|
96
|
+
describe '#delete' do
|
97
97
|
describe 'key' do
|
98
98
|
it 'should be required' do
|
99
99
|
expect { subject.delete }.to raise_exception(ArgumentError)
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
|
103
|
+
context 'when the key exists' do
|
104
|
+
it 'should remove the key from the datastore' do
|
105
|
+
subject.read('key1').should_not eql(nil)
|
106
|
+
subject.delete('key1')
|
107
|
+
subject.read('key1').should be(nil)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should return the value of the deleted key' do
|
111
|
+
keyval = subject.read('key1')
|
112
|
+
subject.delete('key1').should eql(keyval)
|
113
|
+
end
|
107
114
|
end
|
108
115
|
|
109
|
-
|
110
|
-
|
111
|
-
|
116
|
+
context 'when the key does not exist' do
|
117
|
+
it 'should return nil' do
|
118
|
+
subject.delete('non_existent_key').should eql(nil)
|
119
|
+
end
|
112
120
|
end
|
121
|
+
end
|
113
122
|
|
114
|
-
|
115
|
-
|
123
|
+
describe '#all' do
|
124
|
+
it 'should return a hash of all the registered keys and their values' do
|
125
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |k,v|
|
126
|
+
expect(subject.all[k.to_sym]).to eql(v)
|
127
|
+
end
|
116
128
|
end
|
117
129
|
end
|
118
130
|
|
@@ -13,6 +13,7 @@ describe 'Excursion::Datastores::Memcache' do
|
|
13
13
|
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |key,val|
|
14
14
|
dc.set(key,val)
|
15
15
|
end
|
16
|
+
dc.set(Excursion::Datastores::Memcache::REGISTERED_KEYS, Excursion::Specs::Mocks::SIMPLE_VALUES.keys.map(&:to_s).join(','))
|
16
17
|
end
|
17
18
|
|
18
19
|
subject do
|
@@ -94,26 +95,38 @@ describe 'Excursion::Datastores::Memcache' do
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
97
|
-
|
98
|
+
describe '#delete' do
|
98
99
|
describe 'key' do
|
99
100
|
it 'should be required' do
|
100
101
|
expect { subject.delete }.to raise_exception(ArgumentError)
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
context 'when the key exists' do
|
106
|
+
it 'should remove the key from the datastore' do
|
107
|
+
subject.read('key1').should_not eql(nil)
|
108
|
+
subject.delete('key1')
|
109
|
+
subject.read('key1').should be(nil)
|
110
|
+
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
it 'should return the value of the deleted key' do
|
113
|
+
keyval = subject.read('key1')
|
114
|
+
subject.delete('key1').should eql(keyval)
|
115
|
+
end
|
113
116
|
end
|
114
117
|
|
115
|
-
|
116
|
-
|
118
|
+
context 'when the key does not exist' do
|
119
|
+
it 'should return nil' do
|
120
|
+
subject.delete('non_existent_key').should eql(nil)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#all' do
|
126
|
+
it 'should return a hash of all the registered keys and their values' do
|
127
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each do |k,v|
|
128
|
+
expect(subject.all[k.to_sym]).to eql(v)
|
129
|
+
end
|
117
130
|
end
|
118
131
|
end
|
119
132
|
|
@@ -85,27 +85,38 @@ describe 'Excursion::Datastores::Test' do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
|
88
|
+
describe '#delete' do
|
89
89
|
describe 'key' do
|
90
90
|
it 'should be required' do
|
91
91
|
expect { subject.delete }.to raise_exception(ArgumentError)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
95
|
+
context 'when the key exists' do
|
96
|
+
it 'should remove the key from the datastore' do
|
97
|
+
subject.write('key1', Excursion::Specs::Mocks::SIMPLE_VALUES['key1'])
|
98
|
+
subject.read('key1').should eql(Excursion::Specs::Mocks::SIMPLE_VALUES['key1'])
|
99
|
+
subject.delete('key1')
|
100
|
+
subject.read('key1').should_not eql(Excursion::Specs::Mocks::SIMPLE_VALUES['key1'])
|
101
|
+
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
it 'should return the value of the deleted' do
|
104
|
+
keyval = subject.read('key1')
|
105
|
+
subject.delete('key1').should eql(keyval)
|
106
|
+
end
|
105
107
|
end
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
+
context 'when the key does not exist' do
|
110
|
+
it 'should return nil' do
|
111
|
+
subject.delete('non_existent_key').should eql(nil)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#all' do
|
117
|
+
it 'should return a hash of all the registered keys and their values' do
|
118
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each { |k,v| subject.write(k.to_sym, v) }
|
119
|
+
Excursion::Specs::Mocks::SIMPLE_VALUES.each { |k,v| expect(subject.all[k.to_sym]).to eql(v) }
|
109
120
|
end
|
110
121
|
end
|
111
122
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excursion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/excursion/railtie.rb
|
86
86
|
- lib/excursion/configuration.rb
|
87
87
|
- lib/excursion/helpers/url_helper.rb
|
88
|
+
- lib/excursion/helpers/javascript_helper.rb
|
88
89
|
- lib/excursion/helpers/application_helper.rb
|
89
90
|
- lib/excursion/exceptions.rb
|
90
91
|
- lib/excursion/datastores/datastore.rb
|
@@ -129,7 +130,6 @@ files:
|
|
129
130
|
- spec/dummy/db/schema.rb
|
130
131
|
- spec/dummy/config.ru
|
131
132
|
- spec/dummy/README.rdoc
|
132
|
-
- spec/dummy/log/development.log
|
133
133
|
- spec/dummy/script/rails
|
134
134
|
- spec/dummy/doc/README_FOR_APP
|
135
135
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -208,7 +208,6 @@ test_files:
|
|
208
208
|
- spec/dummy/db/schema.rb
|
209
209
|
- spec/dummy/config.ru
|
210
210
|
- spec/dummy/README.rdoc
|
211
|
-
- spec/dummy/log/development.log
|
212
211
|
- spec/dummy/script/rails
|
213
212
|
- spec/dummy/doc/README_FOR_APP
|
214
213
|
- spec/dummy/app/views/layouts/application.html.erb
|