raki 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab3397c01504c3d1377e3677fd9ab6e96bd008483439b67d5aec2470d148d8a7
4
- data.tar.gz: 1c9785b4be9430e556cc5493864c9e8147fa161122275a11c3f37805f335e12f
3
+ metadata.gz: b9fd5bc673e5339421fabb11056856de910aaeadc073f90b90e0dfcdc1e55b2e
4
+ data.tar.gz: e4d2408df565ffcbb84f628dc5c2363d037d6975ec0519cfa080a0130c04d492
5
5
  SHA512:
6
- metadata.gz: be5079c7ae71b350f7e46190153bbe6b2f75c00d998dfa8ed87e80be9c28f908ea8da0aa161ee6ec1666ae0ba840ab3243d693c23aafe63e88fd4bae03a0d445
7
- data.tar.gz: ffe994cb549ef1edc9456afa5e3017d886118a0a95bd90ff6db678a0a112c6902d8abd7009953a5bbb3585368ad2a95393fc114a948a822e5fb72790360d8b86
6
+ metadata.gz: 2e5bb4e3770618c9fac8c25f6f9376d2acfde1003a8963ad1fcdb4271fb8cead7ff61ed1a15cc6492eac25a68ac51cde6091cee3bde33699268929c1f571371d
7
+ data.tar.gz: 94ebb8db09a7f187130902b0715a04814336bb3388adb174fb61fb735bceffea763b4ed8ae7d24b7a25fedbea319b0b0cef07514e9d7e122794fde373f558eb8
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dittmar Krall - www.matique.com
3
+ Copyright (c) 2020-2021 Dittmar Krall - www.matique.com
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,3 +1,153 @@
1
- # raki
1
+ # Raki
2
+ [![Gem Version](https://badge.fury.io/rb/raki.png)](http://badge.fury.io/rb/raki)
2
3
 
3
- Under heavy construction
4
+ The Raki specification enables a kind of piping objects.
5
+
6
+ The composing is done by Raki::Chain and Raki::Builder.
7
+
8
+ ## Specification
9
+
10
+ A Raki is a Ruby object (not a class) that responds to "call".
11
+ It takes exactly one argument, a Hash, and returns a result, again a Hash.
12
+
13
+ Rakis are stackable due to the generality of its argument and result.
14
+
15
+ Sometimes it is expected that a Raki delivers an array of strings as
16
+ part of the result.
17
+ The convention is that this array is accessed as "result[:body]".
18
+
19
+ ## Simple Raki
20
+
21
+ A simple Raki (a proc/lambda can be a Raki):
22
+
23
+ ~~~
24
+ raki = ->(hsh) { {body: ["Hello World!"]} }
25
+ ~~~
26
+
27
+ and a little more complex:
28
+
29
+ ~~~
30
+ raki = ->(hsh) { {body: ["Hi #{hsh[:name]!", "Nice to meet you."] } }
31
+ ~~~
32
+
33
+ ## Middleware
34
+
35
+ A Raki::Middleware is a Raki that calls another Raki enabling
36
+ "before" and "after" code, i.e. operations around the second Raki.
37
+
38
+ A Raki middleware is ready to be stacked.
39
+
40
+ A sample for a Raki middleware:
41
+
42
+ ~~~~
43
+ # already included in "gem raki"
44
+ module Raki
45
+ class Middleware
46
+ def initialize(app)
47
+ @app = app
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ # your sample
54
+ class SampleMiddleware < Raki::Middleware
55
+ def call(env)
56
+ # do something before
57
+ result = @app.call(env) # if @app
58
+ # do something after
59
+ result[:body] << "My grain of salt."
60
+ result
61
+ end
62
+ end
63
+ ~~~~
64
+
65
+ ## Composing
66
+
67
+ ### Raki::Chain
68
+
69
+ Raki::Chain chains Rakis.
70
+ In particular, it will forward the result of a previous Raki
71
+ as the argument of the next one.
72
+ The argument for the first Raki is the arguent of the "call".
73
+ The return value is the result of the last Raki.
74
+
75
+ A sample:
76
+
77
+ ~~~
78
+ class Cl < Raki::Base
79
+ def call(env)
80
+ env + @args.first
81
+ end
82
+ end
83
+
84
+ proca = ->(env) { env + "a" }
85
+ app = Raki::Chain.new do
86
+ add Cl, "C"
87
+ add proca
88
+ add { |env| env + "b" }
89
+ add ->(env) { env + "c" }
90
+ end
91
+
92
+ app.call("") # --> "Cabc"
93
+ ~~~
94
+
95
+ ### Raki::Builder
96
+
97
+ Raki::Builder chains Raki::Middleware.
98
+ In particular, the "@app" is initialized for each middleware.
99
+ The last middleware "@app" is initialized to "nil".
100
+
101
+ It is expected that each middleware takes care to call the next one.
102
+
103
+ A sample:
104
+
105
+ ~~~
106
+ class MW < Raki::Middleware
107
+ def call(env)
108
+ result = env + @args.first
109
+ return result unless @app
110
+
111
+ @app.call(result)
112
+ end
113
+ end
114
+
115
+ app = Raki::Builder.new do
116
+ add MW, "a"
117
+ add MW, "b"
118
+ end
119
+
120
+ app.call("") # --> "ab"
121
+
122
+ ~~~
123
+
124
+ ### Recommendations
125
+
126
+ Implement a Raki as idempotent, i.e. same arguments delivers same results.
127
+
128
+ It is always a good idea to avoid side-effects.
129
+
130
+ Frozen arguments may avoid some strange behaviour.
131
+
132
+ ## Installation
133
+
134
+ Install the gem:
135
+
136
+ ~~~
137
+ gem install raki
138
+ ~~~
139
+
140
+ Or in your Gemfile:
141
+
142
+ ~~~
143
+ # Gemfile
144
+ gem 'raki'
145
+ ~~~
146
+
147
+ ## Miscellaneous
148
+
149
+ Heavily inspired by Rack.
150
+
151
+ Raki is released under the MIT License.
152
+
153
+ [Code of Conduct](https://github.com/matique/matique/blob/main/CODE_OF_CONDUCT.md)
data/lib/raki/builder.rb CHANGED
@@ -1,59 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # see also
4
- # cat ~/test/rack/lib/rack/builder.rb
5
-
6
- # inspired by Rack::Builder
7
3
  module Raki
8
- class Builder
9
- def initialize(default_app = nil, &block)
10
- @added = []
11
- @runs = [default_app].compact
12
- instance_eval(&block) if block_given?
13
- end
4
+ class Builder < Raki::Base
5
+ # attr_accessor :stack
14
6
 
15
- # Create a new Raki::Builder instance and return the Raki application
16
- # generated from it.
17
- def self.app(default_app = nil, &block)
18
- new(default_app, &block).to_app
7
+ def initialize(&block)
8
+ @stack = []
9
+ instance_eval(&block) if block
10
+ chain
19
11
  end
20
12
 
21
13
  def add(middleware, *args, &block)
22
- raise 'No add allowed after a run' if @runs.size.positive?
23
-
24
- @added <<
14
+ @stack <<
25
15
  if middleware.instance_of?(Class)
26
- proc { |app| middleware.new(app, *args, &block) }
16
+ middleware.new(*args, &block)
27
17
  else
28
- proc { |_app| middleware }
18
+ middleware
29
19
  end
30
20
  end
31
- ruby2_keywords(:add) if respond_to?(:ruby2_keywords, true)
32
21
 
33
- def run(app)
34
- @runs << app
22
+ def chain
23
+ previous = nil
24
+ @stack.each do |app|
25
+ previous.app = app if previous
26
+ previous = app
27
+ end
35
28
  end
36
29
 
37
- def to_app
38
- app = fake_parallel(@runs)
39
- @added.reverse.inject(app) { |a, e| e[a] }
30
+ def call(hsh = {})
31
+ @stack.first&.call(hsh)
40
32
  end
41
33
 
42
- private
43
- def fake_parallel(runs)
44
- return runs.first if runs.size < 2
45
-
46
- app = lambda do |env|
47
- status, hsh, body = [200, {}, []]
48
- runs.shuffle.each { |run|
49
- s, h, b = run.call(env)
50
- status = s unless s == 200
51
- hsh.merge! h
52
- body << b unless b.empty?
53
- }
54
-
55
- [status, hsh, body.flatten]
56
- end
57
- end
34
+ # def to_s(pre = "")
35
+ # next_pre = pre + " "
36
+ # res = []
37
+ # res << "#{pre}#{self.class.name} #{object_id}"
38
+ # res << "#{pre}@stack.length #{@stack.length}"
39
+ # @stack.each_with_index { |mv, idx|
40
+ # res << "#{pre}[#{idx}] #{mv.to_s(next_pre)}"
41
+ # }
42
+ # res.flatten.join("\n")
43
+ # end
58
44
  end
59
45
  end
data/lib/raki/chain.rb ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Raki
4
+ class Chain < Base
5
+ def initialize(*args, &block)
6
+ super
7
+ @stack = []
8
+ instance_eval(&block) if block
9
+ end
10
+
11
+ def add(middleware = nil, *args, &block)
12
+ middleware ||= block
13
+ @stack <<
14
+ if middleware.instance_of?(Class)
15
+ middleware.new(*args, &block)
16
+ else
17
+ middleware
18
+ end
19
+ end
20
+
21
+ def call(hsh)
22
+ my_hsh = hsh
23
+ @stack.each { |app| my_hsh = app.call(my_hsh) }
24
+ my_hsh
25
+ end
26
+
27
+ # def to_s(pre = "")
28
+ # next_pre = pre + " "
29
+ # res = []
30
+ # res << "#{pre}#{self.class.name} #{object_id}"
31
+ # res << "#{pre}args #{@args}"
32
+ # # res << @app.to_s(next_pre) if @app
33
+ # res << "#{pre}@app #{@app.object_id}" if @app
34
+ # @stack.each_with_index { |mv, idx|
35
+ # res << "#{pre}[#{idx}] #{mv.to_s(next_pre)}"
36
+ # }
37
+ # res.flatten.join("\n")
38
+ # end
39
+ end
40
+ end
data/lib/raki/idem.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Middleware just passing over or returning the params.
3
+ # Rreturns "env" (doing nothing)
4
4
  module Raki
5
- class Idem < Raki::MiddlewareBase
5
+ class Idem < Raki::Middleware
6
6
  def call(env)
7
- return env unless @app
8
-
9
- @block&.call(env)
10
- @app.call(env)
7
+ env
11
8
  end
12
9
  end
13
10
  end
data/lib/raki/lint.rb CHANGED
@@ -1,31 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Raki::AssertRequest validates your requests according to Raki spec.
4
-
5
- # see also:
6
- # cat ~/test/rack/lib/rack/lint.rb
7
- # cat ~/test/rack/SPEC.rdoc
3
+ # validates according to Raki definition.
8
4
  module Raki
9
5
  class LintError < RuntimeError; end
10
6
 
11
- class Lint < Raki::MiddlewareBase
7
+ class Lint < Raki::Middleware
12
8
  def call(env)
13
- assert('No env given') { env }
14
- assert('Block complained') { @block.call(env) } if @block
15
-
16
- @block&.call(env)
17
- response = @app.call(env)
9
+ assert("No env given") { env }
10
+ # assert("Run complained") { @block.call(env) } if @block
18
11
 
19
- assert('Expected array') { response.class == Array }
20
- assert('Expected array of 3 items') { response.size == 3 }
21
- assert('First item must be an Integer') { response[0].class == Integer }
22
- assert('Second item must be a Hash') { response[1].class == Hash }
23
- assert('Third item must be an Array') { response[2].class == Array }
24
-
25
- response
12
+ result = @app&.call(env)
13
+ assert("Expected hash") { result.instance_of?(Hash) }
14
+ result
26
15
  end
27
16
 
28
- private
17
+ private
18
+
29
19
  def assert(message)
30
20
  return if yield
31
21
 
data/lib/raki/merge.rb CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  # Middleware Merge.
4
4
  module Raki
5
- class Merge < Raki::MiddlewareBase
5
+ class Merge < Raki::Middleware
6
6
  def call(env)
7
7
  my_env = env.merge(*@args)
8
- @block&.call(my_env)
9
- @app.call(my_env)
8
+ app = @block || @app
9
+ app.call(my_env)
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Base for middleware
4
+ module Raki
5
+ class Middleware
6
+ attr_accessor :app
7
+
8
+ def initialize(*args, &block)
9
+ @app = nil
10
+ @args = args
11
+ @block = block
12
+ end
13
+
14
+ def call(env)
15
+ my_env = env
16
+ result = ZERO
17
+ app = @block || @app
18
+ return result unless app
19
+
20
+ app.call(my_env)
21
+ end
22
+
23
+ # def to_s(pre = "")
24
+ # # next_pre = pre + " "
25
+ # res = []
26
+ # res << "#{pre}#{self.class.name} #{object_id}"
27
+ # res << "#{pre}args #{@args}"
28
+ # # res << @app.to_s(next_pre) if @app
29
+ # res << "#{pre}@app #{@app.object_id}" if @app
30
+ # res.flatten.join("\n")
31
+ # end
32
+ end
33
+ end
data/lib/raki/require.rb CHANGED
@@ -4,14 +4,13 @@
4
4
  module Raki
5
5
  class RequireError < RuntimeError; end
6
6
 
7
- class Require < Raki::MiddlewareBase
7
+ class Require < Raki::Middleware
8
8
  def call(env)
9
9
  expected = @args.flatten.sort
10
10
  bool = env.keys.sort == expected
11
11
  raise(RequireError, "Expected <#{expected.join}>") unless bool
12
12
 
13
- @block&.call(env)
14
- @app.call(env)
13
+ @app&.call(env)
15
14
  end
16
15
  end
17
16
  end
data/lib/raki/slice.rb CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  # Middleware Slice.
4
4
  module Raki
5
- class Slice < Raki::MiddlewareBase
5
+ class Slice < Raki::Middleware
6
6
  def call(env)
7
7
  my_env = env.slice(*@args.flatten)
8
- @block&.call(my_env)
9
- @app.call(my_env)
8
+ app = @block || @app
9
+ app.call(my_env)
10
10
  end
11
11
  end
12
12
  end
data/lib/raki/version.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raki
4
- VERSION = '0.0.3' # 2020-07-14
5
- # VERSION = '0.0.2'
4
+ VERSION = "0.1.0" # 2021-11-03
5
+ # VERSION = "0.0.5" # 2021-07-01
6
+ # VERSION = '0.0.4' # 2021-06-25
7
+ # VERSION = '0.0.3' # 2020-07-14
8
+ # VERSION = '0.0.2'
6
9
  end
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Raki is freely distributable under the terms of an MIT-style license.
4
- # See MIT-LICENSE or https://opensource.org/licenses/MIT.
5
-
6
- # The Raki main module, serving as a namespace for all core Raki
7
- # modules and classes.
8
- #
9
- # All modules meant for use in your application are <tt>autoload</tt>ed here,
10
- # so it should be enough just to <tt>require 'rack'</tt> in your code.
11
-
12
3
  module Raki
13
- VERSION = '0.0.2'
4
+ VERSION = "0.0.5" # 2021-07-01
5
+ # VERSION = '0.0.4' # 2021-06-25
6
+ # VERSION = '0.0.3' # 2020-07-14
7
+ # VERSION = '0.0.2'
14
8
  end
data/lib/raki.rb CHANGED
@@ -1,15 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raki
4
- autoload :Block, 'raki/block'
5
- autoload :Builder, 'raki/builder'
6
- autoload :Cache, 'raki/cache'
7
- autoload :Idem, 'raki/idem'
8
- autoload :Lint, 'raki/lint'
9
- autoload :Merge, 'raki/merge'
10
- autoload :MiddlewareBase, 'raki/middleware_base'
11
- autoload :Nil, 'raki/nil'
12
- autoload :Params, 'raki/params'
13
- autoload :Require, 'raki/require'
14
- autoload :Slice, 'raki/slice'
4
+ autoload :Builder, "raki/builder"
5
+ autoload :Chain, "raki/chain"
6
+ autoload :Idem, "raki/idem"
7
+ autoload :Lint, "raki/lint"
8
+ autoload :Merge, "raki/merge"
9
+ autoload :Middleware, "raki/middleware"
10
+ autoload :Params, "raki/params"
11
+ autoload :Require, "raki/require"
12
+ autoload :Slice, "raki/slice"
13
+
14
+ ZERO = {body: []}
15
+
16
+ class Base
17
+ def initialize(*args)
18
+ @args = args
19
+ end
20
+
21
+ def call(env)
22
+ ZERO
23
+ end
24
+ end
15
25
  end
data/lib/raki.rb.bak ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Raki
4
+ autoload :Builder, "raki/builder"
5
+ autoload :Chain, "raki/chain"
6
+ autoload :Idem, "raki/idem"
7
+ autoload :Lint, "raki/lint"
8
+ autoload :Merge, "raki/merge"
9
+ autoload :Middleware, "raki/middleware"
10
+ autoload :Params, "raki/params"
11
+ autoload :Require, "raki/require"
12
+ autoload :Slice, "raki/slice"
13
+
14
+ ZERO = {body: []}
15
+
16
+ class Base
17
+ def initialize(*args)
18
+ @args = args
19
+ end
20
+
21
+ def call(env)
22
+ ZERO
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,74 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-14 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '13'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '13'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest-global_expectations
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1'
69
- description: 'Raki is under construction
68
+ version: '0'
69
+ description: |
70
+ Raki enables chaining of objects.
71
+ It is based on the definition of an interface and
72
+ some builders.
70
73
 
71
- '
74
+ Chained Rakis must conforms to the Raki definition.
72
75
  email: dittmar.krall@matique.de
73
76
  executables: []
74
77
  extensions: []
@@ -77,14 +80,13 @@ files:
77
80
  - LICENSE
78
81
  - README.md
79
82
  - lib/raki.rb
80
- - lib/raki/block.rb
83
+ - lib/raki.rb.bak
81
84
  - lib/raki/builder.rb
82
- - lib/raki/cache.rb
85
+ - lib/raki/chain.rb
83
86
  - lib/raki/idem.rb
84
87
  - lib/raki/lint.rb
85
88
  - lib/raki/merge.rb
86
- - lib/raki/middleware_base.rb
87
- - lib/raki/nil.rb
89
+ - lib/raki/middleware.rb
88
90
  - lib/raki/require.rb
89
91
  - lib/raki/slice.rb
90
92
  - lib/raki/version.rb
@@ -92,7 +94,8 @@ files:
92
94
  homepage: https://matique.com
93
95
  licenses:
94
96
  - MIT
95
- metadata: {}
97
+ metadata:
98
+ source_code_uri: https://github.com/matique/raki
96
99
  post_install_message:
97
100
  rdoc_options: []
98
101
  require_paths:
@@ -101,15 +104,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
104
  requirements:
102
105
  - - ">="
103
106
  - !ruby/object:Gem::Version
104
- version: '2.6'
107
+ version: '0'
105
108
  required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  requirements:
107
110
  - - ">="
108
111
  - !ruby/object:Gem::Version
109
112
  version: '0'
110
113
  requirements: []
111
- rubygems_version: 3.0.8
114
+ rubygems_version: 3.2.22
112
115
  signing_key:
113
116
  specification_version: 4
114
- summary: A modular hash interface.
117
+ summary: Kind of chaining objects
115
118
  test_files: []
data/lib/raki/block.rb DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Middleware to execute a Block.
4
- module Raki
5
- class Block < Raki::MiddlewareBase
6
- def call(env)
7
- my_env = env
8
- @block.call(my_env)
9
- @app.call(my_env)
10
- end
11
- end
12
- end
data/lib/raki/cache.rb DELETED
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'crimp'
4
-
5
- # not yet finished
6
- # requires a Rails environment! (see Rails below)
7
- # middleware for caching.
8
-
9
- module Raki
10
- class Cache < Raki::MiddlewareBase
11
- def call(env)
12
- @block&.call(env)
13
- kache(Crimp.signature(env)) {
14
- @app.call(env)
15
- }
16
- end
17
-
18
- private
19
- def kache(key)
20
- # raise 'Missing Rails environment' unless defined?(Rails.cache)
21
- return yield unless defined?(Rails.cache)
22
-
23
- Rails.cache.fetch(key, expires_in: 1.hour) {
24
- yield
25
- }
26
- end
27
- end
28
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Middleware just passing over or returning the params.
4
- module Raki
5
- class MiddlewareBase
6
- def initialize(app = nil, *args, &block)
7
- @app = app
8
- @args = args
9
- @block = block
10
- end
11
-
12
- def call(_env)
13
- raise '#call must be overwritten by a middleware raki'
14
- end
15
- end
16
- end
data/lib/raki/nil.rb DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Returns a Raki zero.
4
- module Raki
5
- class Nil < Raki::MiddlewareBase
6
- def call(_env)
7
- @block&.call(env)
8
- @app&.call(env)
9
-
10
- [200, {}, []]
11
- end
12
- end
13
- end