rory 0.3.16 → 0.3.17
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.
- data/lib/rory/application.rb +22 -1
- data/lib/rory/dispatcher.rb +6 -0
- data/lib/rory/version.rb +1 -1
- data/spec/fixture_app/lib/dummy_middleware.rb +13 -0
- data/spec/lib/rory/application_spec.rb +16 -0
- metadata +2 -1
data/lib/rory/application.rb
CHANGED
@@ -95,8 +95,29 @@ module Rory
|
|
95
95
|
@db.loggers << logger
|
96
96
|
end
|
97
97
|
|
98
|
+
def use_middleware(*args, &block)
|
99
|
+
@middleware << [args, block]
|
100
|
+
end
|
101
|
+
|
102
|
+
def middleware
|
103
|
+
@middleware ||= []
|
104
|
+
end
|
105
|
+
|
106
|
+
def dispatcher
|
107
|
+
Rory::Dispatcher.rack_app(self)
|
108
|
+
end
|
109
|
+
|
110
|
+
def stack
|
111
|
+
builder = Rack::Builder.new
|
112
|
+
middleware.each do |args, block|
|
113
|
+
builder.use *args, &block
|
114
|
+
end
|
115
|
+
builder.run dispatcher
|
116
|
+
builder
|
117
|
+
end
|
118
|
+
|
98
119
|
def call(env)
|
99
|
-
|
120
|
+
stack.call(env)
|
100
121
|
end
|
101
122
|
|
102
123
|
def logger
|
data/lib/rory/dispatcher.rb
CHANGED
data/lib/rory/version.rb
CHANGED
@@ -111,4 +111,20 @@ describe Rory::Application do
|
|
111
111
|
Fixture::Application.require_all_files
|
112
112
|
end
|
113
113
|
end
|
114
|
+
|
115
|
+
describe '.use_middleware' do
|
116
|
+
it 'adds the given middleware to the stack, retaining args and block' do
|
117
|
+
require Fixture::Application.root.join('lib', 'dummy_middleware')
|
118
|
+
Fixture::Application.use_middleware DummyMiddleware, :puppy do |dm|
|
119
|
+
dm.prefix = 'a salubrious'
|
120
|
+
end
|
121
|
+
|
122
|
+
expect(Fixture::Application.instance).to receive(:dispatcher).
|
123
|
+
and_return(dispatch_stack_mock = double)
|
124
|
+
expect(dispatch_stack_mock).to receive(:call).
|
125
|
+
with('a salubrious puppy')
|
126
|
+
Fixture::Application.call({})
|
127
|
+
Fixture::Application.middleware.clear
|
128
|
+
end
|
129
|
+
end
|
114
130
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- spec/fixture_app/controllers/goose/lumpies_controller.rb
|
212
212
|
- spec/fixture_app/controllers/goose/wombat/rabbits_controller.rb
|
213
213
|
- spec/fixture_app/controllers/stub_controller.rb
|
214
|
+
- spec/fixture_app/lib/dummy_middleware.rb
|
214
215
|
- spec/fixture_app/views/for_reals/but_wait.html.erb
|
215
216
|
- spec/fixture_app/views/for_reals/srsly.html.erb
|
216
217
|
- spec/fixture_app/views/layouts/surround.html.erb
|