web_pipe 0.15.0 → 0.15.1

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: 8a8ebc7025774af2e5938efb5c76a0ff120bc386f449900781e3f05d35eb6a15
4
- data.tar.gz: a6e03d72fb7cb3bd384cea1f51369f21a375b4a009b8409ef3a588600adc07b7
3
+ metadata.gz: 8148f2a5701baf60d74d238ed32b6fcdaadaaf5006431322222a081d005caa01
4
+ data.tar.gz: 90a38228ba60cd9637584b85cffd06d0271df5bd2d3d9bc721b3d3cb7de61287
5
5
  SHA512:
6
- metadata.gz: 278d8402ec4ea79266eefd3ee558522af3923bb23232b3fcefd8574d73dc64c8106757f910a1c312ceed57889ee352e5955c19641601dfdcb47bcbbc63673bb8
7
- data.tar.gz: 99ae42906946fbdda913bbf4f0cdd2cc1a6c3951ffb5972b52bb11b5caf882b6b6c286b68aca9d92ce0e6974d6168178860ae164d3d49af7bcb36556202b70dc
6
+ metadata.gz: 4bd1b21978116a5743d53106cc4c2b8f042dba4cbe63804adbc370174bf08a9221f563561b123a10445e5cb3f87b7672d9cf0ef8c1161e53a9b54f83ae3aba13
7
+ data.tar.gz: a0028185e4bfe8858206fc90c8e355891d3e9a14db81fad7076fd8c05960f01abd1418fc05bece3c6fe73585a5732e2f13318a6529e9d6fef75f4e86181da376
data/CHANGELOG.md CHANGED
@@ -4,11 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [0.15.1] - 2021-09-19
8
+ ### Added
9
+ - `:not_found` extension
10
+ [#46](https://github.com/waiting-for-dev/web_pipe/pull/46)
11
+
7
12
  ## [0.15.0] - 2021-09-12
13
+ ### Added
8
14
  - **BREAKING**. Switch `dry_view` extension with `hanami_view`.
9
15
  [#45](https://github.com/waiting-for-dev/web_pipe/pull/45)
10
16
 
11
- ### Added
12
17
  ## [0.14.0] - 2021-04-14
13
18
  ### Added
14
19
  - Inspecting operations
data/README.md CHANGED
@@ -41,6 +41,7 @@ extension](docs/extensions/rails.md).
41
41
  1. [Flash](docs/extensions/flash.md)
42
42
  1. [Dry Schema](docs/extensions/dry_schema.md)
43
43
  1. [Hanami View](docs/extensions/hanami_view.md)
44
+ 1. [Not found](docs/extensions/not_found.md)
44
45
  1. [Params](docs/extensions/params.md)
45
46
  1. [Rails](docs/extensions/rails.md)
46
47
  1. [Redirect](docs/extensions/redirect.md)
@@ -0,0 +1,40 @@
1
+ # Not found
2
+
3
+ This extension helps to build a not-found response in a single method
4
+ invocation. The `WebPipe::Conn#not_found` method will:
5
+
6
+ - Set 404 as response status.
7
+ - Set 'Not found' as the response body, or instead run a step configured in
8
+ `:not_found_body_step` config key.
9
+ - Halt the connection struct.
10
+
11
+ ```ruby
12
+ require 'web_pipe'
13
+ require 'web_pipe/plugs/config'
14
+
15
+ WebPipe.load_extensions(:params, :not_found)
16
+
17
+ class ShowItem
18
+ include 'web_pipe'
19
+
20
+ plug :config, WebPipe::Plugs::Config.(
21
+ not_found_body_step: ->(conn) { conn.set_response_body('Nothing') }
22
+ )
23
+
24
+ plug :fetch_item do |conn|
25
+ conn.add(:item, Item[params['id']])
26
+ end
27
+
28
+ plug :check_item do |conn|
29
+ if conn.fetch(:item)
30
+ conn
31
+ else
32
+ conn.not_found
33
+ end
34
+ end
35
+
36
+ plug :render do |conn|
37
+ conn.set_response_body(conn.fetch(:item).name)
38
+ end
39
+ end
40
+ ```
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ #:nodoc:
4
+ module WebPipe
5
+ # Generates a not-found response
6
+ #
7
+ # This extension helps to build a not-found response in a single method
8
+ # invocation. The {#not_found} method will:
9
+ #
10
+ # - Set 404 as response status.
11
+ # - Set 'Not found' as the response body, or instead run a step configured in
12
+ # a `:not_found_body_step` config key.
13
+ # - Halt the connection struct.
14
+ #
15
+ # @example
16
+ # require 'web_pipe'
17
+ # require 'web_pipe/plugs/config'
18
+ #
19
+ # WebPipe.load_extensions(:params, :not_found)
20
+ #
21
+ # class ShowItem
22
+ # include 'web_pipe'
23
+ #
24
+ # plug :config, WebPipe::Plugs::Config.(
25
+ # not_found_body_step: ->(conn) { conn.set_response_body('Nothing') }
26
+ # )
27
+ #
28
+ # plug :fetch_item do |conn|
29
+ # conn.add(:item, Item[params['id']])
30
+ # end
31
+ #
32
+ # plug :check_item do |conn|
33
+ # if conn.fetch(:item)
34
+ # conn
35
+ # else
36
+ # conn.not_found
37
+ # end
38
+ # end
39
+ #
40
+ # plug :render do |conn|
41
+ # conn.set_response_body(conn.fetch(:item).name)
42
+ # end
43
+ # end
44
+ module NotFound
45
+ # @api private
46
+ RESPONSE_BODY_STEP_CONFIG_KEY = :not_found_body_step
47
+
48
+ # Generates the not-found response
49
+ #
50
+ # @return [WebPipe::Conn::Halted]
51
+ # @see NotFound
52
+ def not_found
53
+ set_status(404)
54
+ .then do |conn|
55
+ response_body_step = conn.fetch_config(RESPONSE_BODY_STEP_CONFIG_KEY,
56
+ ->(c) { c.set_response_body('Not found') })
57
+
58
+ response_body_step.call(conn)
59
+ end.halt
60
+ end
61
+
62
+ Conn.include(NotFound)
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebPipe
4
- VERSION = '0.15.0'
4
+ VERSION = '0.15.1'
5
5
  end
data/lib/web_pipe.rb CHANGED
@@ -62,4 +62,8 @@ module WebPipe
62
62
  register_extension :url do
63
63
  require 'web_pipe/extensions/url/url'
64
64
  end
65
+
66
+ register_extension :not_found do
67
+ require 'web_pipe/extensions/not_found/not_found'
68
+ end
65
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Busqué
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-12 00:00:00.000000000 Z
11
+ date: 2021-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -279,6 +279,7 @@ files:
279
279
  - docs/extensions/dry_schema.md
280
280
  - docs/extensions/flash.md
281
281
  - docs/extensions/hanami_view.md
282
+ - docs/extensions/not_found.md
282
283
  - docs/extensions/params.md
283
284
  - docs/extensions/rails.md
284
285
  - docs/extensions/redirect.md
@@ -320,6 +321,7 @@ files:
320
321
  - lib/web_pipe/extensions/dry_schema/plugs/sanitize_params.rb
321
322
  - lib/web_pipe/extensions/flash/flash.rb
322
323
  - lib/web_pipe/extensions/hanami_view/hanami_view.rb
324
+ - lib/web_pipe/extensions/not_found/not_found.rb
323
325
  - lib/web_pipe/extensions/params/params.rb
324
326
  - lib/web_pipe/extensions/params/params/transf.rb
325
327
  - lib/web_pipe/extensions/rails/rails.rb