rory 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rory/application.rb +36 -16
- data/lib/rory/initializers.rb +81 -0
- data/lib/rory/middleware_stack.rb +85 -0
- data/lib/rory/request_id.rb +1 -1
- data/lib/rory/version.rb +1 -1
- data/lib/tasks/rory.rake +12 -1
- data/rory.gemspec +2 -2
- data/spec/lib/rory/application_spec.rb +65 -6
- data/spec/lib/rory/initializers_spec.rb +77 -0
- data/spec/lib/rory/middleware_stack_spec.rb +86 -0
- data/spec/lib/rory/request_id_spec.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74194a9762b2ac9e360fc706885bc17bfb1820d5
|
4
|
+
data.tar.gz: 7343f3b2aa9ae9c24620bc786fefb7931b763d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ec94f1abf69f20d707edaf075014bf9fc3e8dae628d57d0d95ed1262d2a4fd1d5a15599590abf911b3a1f221d99797526db54cac266ae8c4f5d7768424b9c10
|
7
|
+
data.tar.gz: c8bcbdac1f51336f161a8a0e0f74460f647cfa57eaf00bfe8f2d9fe05097b195882534b7473963f948fd53e56999d1075a2327a902364f3e15ae53cf5c2c9a9a
|
data/lib/rory/application.rb
CHANGED
@@ -2,9 +2,10 @@ require 'pathname'
|
|
2
2
|
require 'rory/logger'
|
3
3
|
require 'rory/request_id'
|
4
4
|
require 'rory/route_mapper'
|
5
|
+
require 'rory/middleware_stack'
|
6
|
+
require 'rory/initializers'
|
5
7
|
require 'rack/commonlogger'
|
6
|
-
|
7
|
-
|
8
|
+
require 'rory/request_parameter_logger'
|
8
9
|
|
9
10
|
module Rory
|
10
11
|
# Main application superclass. Applications should subclass this class,
|
@@ -30,7 +31,12 @@ module Rory
|
|
30
31
|
instance.send(*args, &block)
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
+
# @return [Rory::Initializers]
|
35
|
+
def initializers
|
36
|
+
@initializers ||= Initializers.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def respond_to?(method, private=false)
|
34
40
|
return true if instance.respond_to?(method)
|
35
41
|
super
|
36
42
|
end
|
@@ -42,8 +48,16 @@ module Rory
|
|
42
48
|
def root=(root_path)
|
43
49
|
$:.unshift @root = Pathname.new(root_path).realpath
|
44
50
|
end
|
51
|
+
|
52
|
+
def initializer_default_middleware
|
53
|
+
Rory::Application.initializers.add "rory.request_middleware" do |app|
|
54
|
+
app.request_middleware
|
55
|
+
end
|
56
|
+
end
|
45
57
|
end
|
46
58
|
|
59
|
+
initializer_default_middleware
|
60
|
+
|
47
61
|
def auto_require_paths
|
48
62
|
@auto_require_paths ||= %w(models controllers helpers)
|
49
63
|
end
|
@@ -102,12 +116,11 @@ module Rory
|
|
102
116
|
end
|
103
117
|
|
104
118
|
def use_middleware(*args, &block)
|
105
|
-
|
106
|
-
middleware << [args, block]
|
119
|
+
middleware.use *args, &block
|
107
120
|
end
|
108
121
|
|
109
122
|
def middleware
|
110
|
-
@middleware ||=
|
123
|
+
@middleware ||= MiddlewareStack.new
|
111
124
|
end
|
112
125
|
|
113
126
|
def dispatcher
|
@@ -136,20 +149,27 @@ module Rory
|
|
136
149
|
@stack = nil
|
137
150
|
end
|
138
151
|
|
139
|
-
def
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
152
|
+
def uuid_prefix
|
153
|
+
Support.tokenize(self.class.name.gsub("::Application", ""))
|
154
|
+
end
|
155
|
+
|
156
|
+
def request_middleware
|
157
|
+
return unless request_logging_on?
|
158
|
+
use_middleware Rory::RequestId, :uuid_prefix => uuid_prefix
|
159
|
+
use_middleware Rack::PostBodyContentTypeParser
|
160
|
+
use_middleware Rack::CommonLogger, logger
|
161
|
+
use_middleware Rory::RequestParameterLogger, logger, :filters => parameters_to_filter
|
162
|
+
end
|
163
|
+
|
164
|
+
def run_initializers
|
165
|
+
Rory::Application.initializers.run(self)
|
146
166
|
end
|
147
167
|
|
148
168
|
def stack
|
149
169
|
@stack ||= Rack::Builder.new.tap { |builder|
|
150
|
-
|
151
|
-
middleware.each do |
|
152
|
-
builder.use *args, &block
|
170
|
+
run_initializers
|
171
|
+
middleware.each do |m|
|
172
|
+
builder.use m.klass, *m.args, &m.block
|
153
173
|
end
|
154
174
|
builder.run dispatcher
|
155
175
|
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Rory
|
2
|
+
class Initializers
|
3
|
+
class Initializer
|
4
|
+
attr_reader :name, :block
|
5
|
+
|
6
|
+
def initialize(name, block)
|
7
|
+
@name = name
|
8
|
+
@block = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def ==(initializer)
|
12
|
+
name == initializer.name
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
"<Initializer '#{name}'>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(app)
|
20
|
+
block.call(app)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
include Enumerable
|
25
|
+
extend Forwardable
|
26
|
+
attr_accessor :initializers
|
27
|
+
def_delegators :initializers, :each, :clear, :size, :last, :first, :[]
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@initializers = []
|
31
|
+
yield(self) if block_given?
|
32
|
+
end
|
33
|
+
|
34
|
+
def unshift(name, &block)
|
35
|
+
initializers.unshift(build_initializer(name, block))
|
36
|
+
end
|
37
|
+
|
38
|
+
def insert(index, name, &block)
|
39
|
+
index = assert_index(index, :before)
|
40
|
+
initializers.insert(index, build_initializer(name, block))
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :insert_before, :insert
|
44
|
+
|
45
|
+
def insert_after(index, name, &block)
|
46
|
+
index = assert_index(index, :after)
|
47
|
+
insert(index + 1, name, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete(target)
|
51
|
+
initializers.delete_if { |m| m.name == target }
|
52
|
+
end
|
53
|
+
|
54
|
+
def add(name, &block)
|
55
|
+
initializers.push(build_initializer(name, block))
|
56
|
+
end
|
57
|
+
|
58
|
+
def run(app)
|
59
|
+
initializers.map{|i| i.call(app)}
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def assert_index(index, where)
|
65
|
+
i = index.is_a?(Integer) ? index : initializers.index { |m| m.name == index }
|
66
|
+
raise "No such initializer to insert #{where}: #{index.inspect}" unless i
|
67
|
+
i
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_initializer(name, block)
|
71
|
+
Initializer.new(name, block).tap{ |i| assert_unique_name(i) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def assert_unique_name(i)
|
75
|
+
unless (conflict = @initializers.select{|ii| ii == i}).empty?
|
76
|
+
raise "Initializer name: '#{i.name}' is already used. #{conflict.first.block}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Rory
|
2
|
+
class MiddlewareStack
|
3
|
+
class Middleware
|
4
|
+
attr_reader :args, :block, :klass
|
5
|
+
|
6
|
+
def initialize(klass, args, block)
|
7
|
+
@klass = klass
|
8
|
+
@args = args
|
9
|
+
@block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def name;
|
13
|
+
klass.name;
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(middleware)
|
17
|
+
case middleware
|
18
|
+
when Middleware
|
19
|
+
klass == middleware.klass
|
20
|
+
when Class
|
21
|
+
klass == middleware
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
if klass.is_a?(Class)
|
27
|
+
klass.to_s
|
28
|
+
else
|
29
|
+
klass.class.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def build(app)
|
34
|
+
klass.new(app, *args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
include Enumerable
|
39
|
+
extend Forwardable
|
40
|
+
attr_accessor :middlewares
|
41
|
+
def_delegators :middlewares, :each, :clear, :size, :last, :first, :[]
|
42
|
+
|
43
|
+
def initialize(on_change: -> {})
|
44
|
+
|
45
|
+
@middlewares = []
|
46
|
+
yield(self) if block_given?
|
47
|
+
end
|
48
|
+
|
49
|
+
def unshift(klass, *args, &block)
|
50
|
+
middlewares.unshift(build_middleware(klass, args, block))
|
51
|
+
end
|
52
|
+
|
53
|
+
def insert(index, klass, *args, &block)
|
54
|
+
index = assert_index(index, :before)
|
55
|
+
middlewares.insert(index, build_middleware(klass, args, block))
|
56
|
+
end
|
57
|
+
|
58
|
+
alias_method :insert_before, :insert
|
59
|
+
|
60
|
+
def insert_after(index, *args, &block)
|
61
|
+
index = assert_index(index, :after)
|
62
|
+
insert(index + 1, *args, &block)
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete(target)
|
66
|
+
middlewares.delete_if { |m| m.klass == target }
|
67
|
+
end
|
68
|
+
|
69
|
+
def use(klass, *args, &block)
|
70
|
+
middlewares.push(build_middleware(klass, args.compact, block))
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def assert_index(index, where)
|
76
|
+
i = index.is_a?(Integer) ? index : middlewares.index { |m| m.klass == index }
|
77
|
+
raise "No such middleware to insert #{where}: #{index.inspect}" unless i
|
78
|
+
i
|
79
|
+
end
|
80
|
+
|
81
|
+
def build_middleware(klass, args, block)
|
82
|
+
Middleware.new(klass, args, block)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/rory/request_id.rb
CHANGED
data/lib/rory/version.rb
CHANGED
data/lib/tasks/rory.rake
CHANGED
@@ -6,6 +6,17 @@ namespace :rory do
|
|
6
6
|
command = ARGV.shift
|
7
7
|
IRB.start
|
8
8
|
end
|
9
|
+
|
10
|
+
desc "List out middleware stack in load order"
|
11
|
+
task :middleware => :environment do
|
12
|
+
Rory.application.run_initializers
|
13
|
+
puts Rory.application.middleware.map(&:klass).map(&:to_s).join("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "List out initializers in load order"
|
17
|
+
task :initializers => :environment do
|
18
|
+
puts Rory::Application.initializers.map(&:name).join("\n")
|
19
|
+
end
|
9
20
|
end
|
10
21
|
|
11
22
|
namespace :log do
|
@@ -23,4 +34,4 @@ task :tasks do
|
|
23
34
|
{ 'name' => t.name, 'location' => t.locations }
|
24
35
|
}
|
25
36
|
puts tasks
|
26
|
-
end
|
37
|
+
end
|
data/rory.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.name = "rory"
|
9
9
|
s.version = Rory::VERSION
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.authors = ["Ravi Gadad", "Michael Irey", "David Begin"]
|
11
|
+
s.authors = ["Ravi Gadad", "Michael Irey", "David Begin", "Dustin Zeisler"]
|
12
12
|
s.email = ["ravi@screamingmuse.com"]
|
13
13
|
s.homepage = "http://github.com/screamingmuse/rory"
|
14
14
|
s.summary = "Another Ruby web framework. Just what the world needs."
|
@@ -19,7 +19,7 @@ Rails design decisions.
|
|
19
19
|
|
20
20
|
See http://github.com/screamingmuse/rory for more info.
|
21
21
|
EOF
|
22
|
-
s.required_ruby_version = ">= 1.
|
22
|
+
s.required_ruby_version = ">= 2.1.5"
|
23
23
|
s.required_rubygems_version = ">= 1.3.6"
|
24
24
|
|
25
25
|
s.extra_rdoc_files = ["LICENSE.txt", "README.md"]
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative '../../fixture_app/lib/dummy_middleware'
|
2
|
+
|
3
|
+
RSpec.describe Rory::Application do
|
2
4
|
let(:subject) {
|
3
5
|
Object.const_set(test_rory_app_name, Class.new(Rory::Application).tap { |app|
|
4
6
|
app.root = root
|
@@ -12,6 +14,11 @@ describe Rory::Application do
|
|
12
14
|
}
|
13
15
|
let(:root){"spec/fixture_app"}
|
14
16
|
|
17
|
+
before do
|
18
|
+
Rory::Application.initializers.clear
|
19
|
+
Rory::Application.initializer_default_middleware
|
20
|
+
end
|
21
|
+
|
15
22
|
describe ".root=" do
|
16
23
|
let(:root) { "current_app" }
|
17
24
|
before { `ln -s spec/fixture_app current_app` }
|
@@ -165,7 +172,7 @@ describe Rory::Application do
|
|
165
172
|
and_return(:the_dispatcher)
|
166
173
|
allow(Rack::Builder).to receive(:new).and_return(builder)
|
167
174
|
subject.use_middleware :horse
|
168
|
-
expect(subject.instance).to receive(:
|
175
|
+
expect(subject.instance).to receive(:request_middleware).with(no_args)
|
169
176
|
expect(builder).to receive(:use).with(:horse)
|
170
177
|
expect(builder).to receive(:run).with(:the_dispatcher)
|
171
178
|
expect(subject.stack).to eq(builder)
|
@@ -183,17 +190,17 @@ describe Rory::Application do
|
|
183
190
|
allow(subject.instance).to receive(:request_logging_on?).and_return(true)
|
184
191
|
allow(subject.instance).to receive(:parameters_to_filter).and_return([:horses])
|
185
192
|
allow(subject.instance).to receive(:logger).and_return(:the_logger)
|
186
|
-
expect(subject.instance).to receive(:use_middleware).with(Rory::RequestId, :uuid_prefix => test_rory_app_name)
|
193
|
+
expect(subject.instance).to receive(:use_middleware).with(Rory::RequestId, :uuid_prefix => Rory::Support.tokenize(test_rory_app_name))
|
187
194
|
expect(subject.instance).to receive(:use_middleware).with(Rack::PostBodyContentTypeParser)
|
188
195
|
expect(subject.instance).to receive(:use_middleware).with(Rack::CommonLogger, :the_logger)
|
189
196
|
expect(subject.instance).to receive(:use_middleware).with(Rory::RequestParameterLogger, :the_logger, :filters => [:horses])
|
190
|
-
subject.
|
197
|
+
subject.request_middleware
|
191
198
|
end
|
192
199
|
|
193
200
|
it "does not add middleware when request logging is off" do
|
194
201
|
allow(subject.instance).to receive(:request_logging_on?).and_return(false)
|
195
202
|
expect(subject.instance).to receive(:use_middleware).never
|
196
|
-
subject.
|
203
|
+
subject.request_middleware
|
197
204
|
end
|
198
205
|
end
|
199
206
|
|
@@ -254,7 +261,7 @@ describe Rory::Application do
|
|
254
261
|
|
255
262
|
describe '.use_middleware' do
|
256
263
|
it 'adds the given middleware to the stack, retaining args and block' do
|
257
|
-
|
264
|
+
|
258
265
|
subject.use_middleware DummyMiddleware, :puppy do |dm|
|
259
266
|
dm.prefix = 'a salubrious'
|
260
267
|
end
|
@@ -291,4 +298,56 @@ describe Rory::Application do
|
|
291
298
|
end
|
292
299
|
end
|
293
300
|
end
|
301
|
+
|
302
|
+
describe ".initializers" do
|
303
|
+
describe ".insert_after" do
|
304
|
+
it "inserts initializer before another" do
|
305
|
+
probe = []
|
306
|
+
Rory::Application.initializers.add("insert_after.A") { probe << "insert_after.A" }
|
307
|
+
Rory::Application.initializers.add("insert_after.B") { probe << "insert_after.B" }
|
308
|
+
Rory::Application.initializers.insert_after("insert_after.A", "insert_after.C") { probe << "insert_after.C" }
|
309
|
+
|
310
|
+
expect { subject.run_initializers }.to change { probe }.from([]).
|
311
|
+
to(%w(insert_after.A insert_after.C insert_after.B))
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe ".add" do
|
316
|
+
it "runs the code inside any initializer block" do
|
317
|
+
probe = :initializers_not_run
|
318
|
+
Rory::Application.initializers.add "add.test" do
|
319
|
+
probe = :was_run
|
320
|
+
end
|
321
|
+
expect { subject.run_initializers }.to change { probe }.from(:initializers_not_run).to(:was_run)
|
322
|
+
end
|
323
|
+
|
324
|
+
it "passes the app instance to the block" do
|
325
|
+
probe = :block_not_called
|
326
|
+
Rory::Application.initializers.add "add.test_passes_app" do |app|
|
327
|
+
probe = :block_called
|
328
|
+
expect(app.class.superclass).to eq Rory::Application
|
329
|
+
end
|
330
|
+
expect { subject.run_initializers }.to change { probe }.from(:block_not_called).to(:block_called)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "#middleware" do
|
336
|
+
before { subject.middleware.clear }
|
337
|
+
|
338
|
+
describe "#insert_before" do
|
339
|
+
it "places the middleware order right after the given class" do
|
340
|
+
subject.instance.instance_variable_set(:@request_logging, :true)
|
341
|
+
Rory::Application.initializers.add "insert_before.dummy_middleware" do |app|
|
342
|
+
app.middleware.insert_before Rory::RequestId, DummyMiddleware, :puppy
|
343
|
+
end
|
344
|
+
subject.run_initializers
|
345
|
+
expect(subject.middleware.map(&:klass)).to eq [DummyMiddleware,
|
346
|
+
Rory::RequestId,
|
347
|
+
Rack::PostBodyContentTypeParser,
|
348
|
+
Rack::CommonLogger,
|
349
|
+
Rory::RequestParameterLogger]
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
294
353
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
RSpec.describe Rory::Initializers do
|
2
|
+
|
3
|
+
describe "#unshift" do
|
4
|
+
it "adds an item to the front" do
|
5
|
+
subject.unshift("test.1unshift") {}
|
6
|
+
subject.unshift("test.2unshift") {}
|
7
|
+
expect(subject.initializers.map(&:name)).to eq %w(test.2unshift test.1unshift)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#insert" do
|
12
|
+
it "adds an item before another" do
|
13
|
+
subject.add("test.1insert") {}
|
14
|
+
subject.insert("test.1insert", "test.2insert") {}
|
15
|
+
expect(subject.initializers.map(&:name)).to eq %w(test.2insert test.1insert)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#insert_before" do
|
20
|
+
it "adds an item before another" do
|
21
|
+
subject.add("test.1insert_before") {}
|
22
|
+
subject.insert_before("test.1insert_before", "test.2insert_before") {}
|
23
|
+
expect(subject.initializers.map(&:name)).to eq %w(test.2insert_before test.1insert_before)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#insert_after" do
|
28
|
+
it "adds an item at certain point after a given initializer" do
|
29
|
+
subject.add("test.1insert_after") {}
|
30
|
+
subject.add("test.2insert_after") {}
|
31
|
+
subject.insert_after("test.1insert_after", "test.3insert_after") {}
|
32
|
+
expect(subject.initializers.map(&:name)).to eq %w(test.1insert_after test.3insert_after test.2insert_after)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#delete" do
|
37
|
+
it "removes a given initializer from loading" do
|
38
|
+
subject.add("test.delete") {}
|
39
|
+
subject.delete("test.delete")
|
40
|
+
expect(subject.initializers.map(&:name)).to eq []
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#add" do
|
45
|
+
it "push an item on the list to be loaded" do
|
46
|
+
subject.add("test.1add") {}
|
47
|
+
subject.add("test.2add") {}
|
48
|
+
expect(subject.initializers.map(&:name)).to eq %w(test.1add test.2add)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when two initializers have the same name" do
|
52
|
+
it "raises an error" do
|
53
|
+
subject.add("same_name_test") {}
|
54
|
+
expect{subject.add("same_name_test") {}}.to raise_error(/Initializer name: 'same_name_test' is already used./)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#run" do
|
60
|
+
it "runs the initializers when given an app" do
|
61
|
+
probe = :block_not_run
|
62
|
+
subject.add("test.1add") { |app| probe = app }
|
63
|
+
subject.run(:this_is_the_app)
|
64
|
+
expect(probe).to eq :this_is_the_app
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "delegated array methods" do
|
69
|
+
[:each, :clear, :size, :last, :first].each do |meth|
|
70
|
+
it "##{meth}" do
|
71
|
+
expect(subject.initializers).to receive(meth)
|
72
|
+
subject.public_send(meth)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
RSpec.describe Rory::MiddlewareStack do
|
2
|
+
|
3
|
+
let(:middleware_order) { subject.middlewares.map(&:klass).map(&:name) }
|
4
|
+
|
5
|
+
describe "#unshift" do
|
6
|
+
it "adds an item to the front" do
|
7
|
+
subject.unshift(double(name: "unshift1")) {}
|
8
|
+
subject.unshift(double(name: "unshift2"), 1, 2)
|
9
|
+
|
10
|
+
expect(middleware_order).to eq %w(unshift2 unshift1)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#insert" do
|
15
|
+
it "adds an item to the end" do
|
16
|
+
insert1 = (double(name: "insert1"))
|
17
|
+
subject.use(insert1) {}
|
18
|
+
subject.insert(insert1, double(name: "insert2"), 1, 2)
|
19
|
+
|
20
|
+
expect(middleware_order).to eq %w(insert2 insert1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#insert_before" do
|
25
|
+
it "adds an item to the end" do
|
26
|
+
insert1 = (double(name: "insert_before1"))
|
27
|
+
subject.use(insert1) {}
|
28
|
+
subject.insert(insert1, double(name: "insert_before2"), 1, 2)
|
29
|
+
|
30
|
+
expect(middleware_order).to eq %w(insert_before2 insert_before1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#insert_after" do
|
35
|
+
it "adds an item at certain point after a given middleware" do
|
36
|
+
insert_after1 = double(name: "test.1insert_after")
|
37
|
+
subject.use(insert_after1) {}
|
38
|
+
subject.use(double(name: "test.2insert_after")) {}
|
39
|
+
subject.insert_after(insert_after1, double(name: "test.3insert_after")) {}
|
40
|
+
expect(middleware_order).to eq %w(test.1insert_after test.3insert_after test.2insert_after)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#delete" do
|
45
|
+
it "removes a given middleware from loading" do
|
46
|
+
test_delete = double(name: "delete")
|
47
|
+
subject.use(test_delete)
|
48
|
+
subject.delete(test_delete)
|
49
|
+
expect(middleware_order).to eq []
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#use" do
|
54
|
+
it "push an item on the list to be loaded" do
|
55
|
+
subject.use(double(name: "use1")) {}
|
56
|
+
subject.use(double(name: "use2"), 1, 2)
|
57
|
+
|
58
|
+
expect(middleware_order).to eq %w(use1 use2)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "arguments will be saved" do
|
62
|
+
subject.use(double(name: "use1")) {}
|
63
|
+
subject.use(double(name: "use2"), 1, 2)
|
64
|
+
|
65
|
+
expect(subject.middlewares.map(&:args)).to eq [[], [1, 2]]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "blocks will be saved" do
|
69
|
+
probe = :block_not_called
|
70
|
+
subject.use(double(name: "use1")) {probe = :block_called}
|
71
|
+
subject.use(double(name: "use2"), 1, 2)
|
72
|
+
subject.middlewares.map(&:block).compact.map(&:call)
|
73
|
+
expect(probe).to eq :block_called
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "delegated array methods" do
|
78
|
+
[:each, :clear, :size, :last, :first].each do |meth|
|
79
|
+
it "##{meth}" do
|
80
|
+
expect(subject.middlewares).to receive(meth)
|
81
|
+
subject.public_send(meth)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -23,7 +23,7 @@ RSpec.describe Rory::RequestId do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
context "the uuid can be given a prefixed to know where it was created" do
|
26
|
-
let(:uuid_prefix) { "
|
26
|
+
let(:uuid_prefix) { "app_name" }
|
27
27
|
it { expect(Thread.current.get_inheritable_attribute(:rory_request_id)).to eq "app_name-1234" }
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ravi Gadad
|
8
8
|
- Michael Irey
|
9
9
|
- David Begin
|
10
|
+
- Dustin Zeisler
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2016-
|
14
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rack
|
@@ -229,7 +230,9 @@ files:
|
|
229
230
|
- lib/rory/application.rb
|
230
231
|
- lib/rory/controller.rb
|
231
232
|
- lib/rory/dispatcher.rb
|
233
|
+
- lib/rory/initializers.rb
|
232
234
|
- lib/rory/logger.rb
|
235
|
+
- lib/rory/middleware_stack.rb
|
233
236
|
- lib/rory/parameter_filter.rb
|
234
237
|
- lib/rory/path_generation.rb
|
235
238
|
- lib/rory/renderer.rb
|
@@ -268,7 +271,9 @@ files:
|
|
268
271
|
- spec/lib/rory/application_spec.rb
|
269
272
|
- spec/lib/rory/controller_spec.rb
|
270
273
|
- spec/lib/rory/dispatcher_spec.rb
|
274
|
+
- spec/lib/rory/initializers_spec.rb
|
271
275
|
- spec/lib/rory/logger_spec.rb
|
276
|
+
- spec/lib/rory/middleware_stack_spec.rb
|
272
277
|
- spec/lib/rory/parameter_filter_spec.rb
|
273
278
|
- spec/lib/rory/renderer/context_spec.rb
|
274
279
|
- spec/lib/rory/renderer_spec.rb
|
@@ -293,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
298
|
requirements:
|
294
299
|
- - ">="
|
295
300
|
- !ruby/object:Gem::Version
|
296
|
-
version: 1.
|
301
|
+
version: 2.1.5
|
297
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
303
|
requirements:
|
299
304
|
- - ">="
|