natsukantou 0.1.0 → 0.1.1
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 +4 -4
- data/.rubocop.yml +2 -0
- data/lib/monkey_patch/builder.rb +14 -0
- data/lib/monkey_patch/runner.rb +32 -0
- data/lib/natsukantou/version.rb +1 -1
- data/lib/natsukantou.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40e03ddc9cd827e3047661cab129984d98c4feb300a4ba9a61980dfba440a74a
|
4
|
+
data.tar.gz: aeff37004a2afb7094f391bb25ffeaa2696979382f6170c28b72a600aaee8cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cea30f5d6074a7dfd075d6489bbe8cbbbaf4a053a3aa3645d9540f206e526834ef301710306949676917c94c7aef3b519c07ca8b3ed5ac8fe870606b2131108
|
7
|
+
data.tar.gz: 8cf2cbd8fdc20cf6c3a24deadbf7f98ebb0cb5dd242c4d013182d264bcd9d482668ba263eb89bb01c8c8245abebc7dc2734941c0d2b32130dbe615f0fce24e67
|
data/.rubocop.yml
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Middleware
|
2
|
+
class Builder
|
3
|
+
def use(middleware, *args, **kwargs, &block)
|
4
|
+
if middleware.kind_of?(Builder)
|
5
|
+
# Merge in the other builder's stack into our own
|
6
|
+
self.stack.concat(middleware.stack)
|
7
|
+
else
|
8
|
+
self.stack << [middleware, args, kwargs, block]
|
9
|
+
end
|
10
|
+
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Middleware
|
2
|
+
class Runner
|
3
|
+
protected
|
4
|
+
|
5
|
+
def build_call_chain(stack)
|
6
|
+
stack.reverse.inject(EMPTY_MIDDLEWARE) do |next_middleware, current_middleware|
|
7
|
+
# Unpack the actual item
|
8
|
+
klass, args, kwargs, block = current_middleware
|
9
|
+
|
10
|
+
# Default the arguments to an empty array. Otherwise in Ruby 1.8
|
11
|
+
# a `nil` args will actually pass `nil` into the class. Not what
|
12
|
+
# we want!
|
13
|
+
args ||= []
|
14
|
+
|
15
|
+
if klass.is_a?(Class)
|
16
|
+
# If the klass actually is a class, then instantiate it with
|
17
|
+
# the app and any other arguments given.
|
18
|
+
klass.new(next_middleware, *args, **kwargs, &block)
|
19
|
+
elsif klass.respond_to?(:call)
|
20
|
+
# Make it a lambda which calls the item then forwards up
|
21
|
+
# the chain.
|
22
|
+
lambda do |env|
|
23
|
+
klass.call(env)
|
24
|
+
next_middleware.call(env)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise "Invalid middleware, doesn't respond to `call`: #{klass.inspect}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/natsukantou/version.rb
CHANGED
data/lib/natsukantou.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natsukantou
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lulalala
|
@@ -124,6 +124,8 @@ files:
|
|
124
124
|
- README.md
|
125
125
|
- Rakefile
|
126
126
|
- exe/natsukantou
|
127
|
+
- lib/monkey_patch/builder.rb
|
128
|
+
- lib/monkey_patch/runner.rb
|
127
129
|
- lib/natsukantou.rb
|
128
130
|
- lib/natsukantou/deep_l.rb
|
129
131
|
- lib/natsukantou/handle_ruby_markup.rb
|