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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a75166acdb08099edebb39e02f78ca3bf04af192e3233f71067f1178950e964b
4
- data.tar.gz: f5af8a9a4df6a4c82e61b7bef67ec6beb3bcac6b49db2dbe7ae46ce8385084ef
3
+ metadata.gz: 40e03ddc9cd827e3047661cab129984d98c4feb300a4ba9a61980dfba440a74a
4
+ data.tar.gz: aeff37004a2afb7094f391bb25ffeaa2696979382f6170c28b72a600aaee8cae
5
5
  SHA512:
6
- metadata.gz: 3079ead2000c24c0c6e06156e6e775e56e233c11fe06a851e655d2b2197bb133b855ae901d8749520f9661ff37e89d759e318c2ad1e9516097fd7c14c0a6d125
7
- data.tar.gz: 6612f175de419c560af5e221bbf3f9e074692a5fee2f3907dd800bddc7404db932201ffe69e191fadc87169ae8a6ce7df93700c48510dcbbfc96fc2bdbc28b1f
6
+ metadata.gz: 3cea30f5d6074a7dfd075d6489bbe8cbbbaf4a053a3aa3645d9540f206e526834ef301710306949676917c94c7aef3b519c07ca8b3ed5ac8fe870606b2131108
7
+ data.tar.gz: 8cf2cbd8fdc20cf6c3a24deadbf7f98ebb0cb5dd242c4d013182d264bcd9d482668ba263eb89bb01c8c8245abebc7dc2734941c0d2b32130dbe615f0fce24e67
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.7
3
+ Exclude:
4
+ - 'lib/monkey_patch/*'
3
5
 
4
6
  Style/StringLiterals:
5
7
  Enabled: false
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Natsukantou
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/natsukantou.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'logger'
4
4
  require 'middleware'
5
+ require_relative "monkey_patch/builder"
6
+ require_relative "monkey_patch/runner"
5
7
  require 'oga'
6
8
 
7
9
  require_relative "natsukantou/version"
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.0
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