mustermann-grape 1.0.1 → 1.1.0

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: 55697b38c24285593dccd82d84d78475a68e9f85c097215dd34361755a532c0d
4
- data.tar.gz: 10c154f103a904e122a996423225981f3f00e3ec831737b7c34ef9db85ed8d23
3
+ metadata.gz: 6ccb4995f214f92cb170ebaaf19eb1eb25936ab3d578020cf08a36a0adf50101
4
+ data.tar.gz: fb6d1a61a8ab987fba38e6b356c4ff6dffb59961de9767a03cde70f0b41b3b95
5
5
  SHA512:
6
- metadata.gz: f62d87d318ea717f8da907fd77be82b80ec4332c8912f4a6b28ac771b9c83fe35a2f70503c99c224a5e661d6e5ca8d5bd3b8b2d5ce2d74e028bafef220089d81
7
- data.tar.gz: 72de2d4f7012efa3f5054065d1585f5aca004c60f7567353959bb0d380f8f4f2fb11a25f02155eb6cec247d10bc9253e9050aba66602af76d1d8df0c1d2c02cb
6
+ metadata.gz: da5216e8f3905d70bf4f42893c67519171cf538f13c380fc4e1ea07ba516ba2b5b5e1ac728d76da7a5abdc72449ee6c2fcebea708a15346e70d4492dab150175
7
+ data.tar.gz: 34259f47c0ac7accb57e222cd47290bb8a45981a169ed4399ab321321e65c90f27a878475d25f57fd50aa6c952c373b10a40b212df3eb07d5a11486d5da2ae65
@@ -0,0 +1,22 @@
1
+ name: tests
2
+ on:
3
+ [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ matrix:
12
+ ruby-version: ['2.6', '2.7', '3.0']
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby ${{ matrix.ruby-version }}
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby-version }}
20
+ bundler-cache: true
21
+ - name: Run tests
22
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ### 1.1.0 (2023/11/24)
2
+
3
+ #### Fixes
4
+
5
+ * [#21](https://github.com/ruby-grape/mustermann-grape/pull/21): Introducing the `params` option to `Mustermann::Grape` to enhance matching by offering detailed information regarding the parameter types. - [@jcagarcia](https://github.com/jcagarcia).
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Mustermann-Grape Contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,17 +2,22 @@
2
2
 
3
3
  This gem implements the `grape` pattern type for Mustermann.
4
4
 
5
- [![Build Status](https://travis-ci.org/ruby-grape/mustermann-grape.svg?branch=master)](https://travis-ci.org/ruby-grape/mustermann-grape)
5
+ [![tests](https://github.com/ruby-grape/mustermann-grape/workflows/tests/badge.svg)](https://github.com/ruby-grape/mustermann-grape/actions?query=workflow%3Atests)
6
6
 
7
7
  ## Overview
8
8
 
9
9
  **Supported options:**
10
- `capture`, `except`, `greedy`, `space_matches_plus`, `uri_decode`, `converters` and `ignore_unknown_options`
10
+ `capture`, `converters`, `except`, `greedy`, `ignore_unknown_options`, `params`, `space_matches_plus` and `uri_decode`
11
11
 
12
12
  ``` ruby
13
13
  require 'mustermann/grape'
14
14
 
15
15
  Mustermann.new('/:id', type: :grape).params('/foo') # => { id: 'foo' }
16
+
17
+ # Providing params option
18
+ Mustermann.new('/:id', type: :grape, params: {"id"=>{:type=>"Integer"}}).params('/1') # => { id: '1'}
19
+ Mustermann.new('/:id', type: :grape, params: {"id"=>{:type=>"Integer"}}).params('/foo') # => nil
20
+ Mustermann.new('/:id', type: :grape, params: {"id"=>{:type=>"String"}}).params('/foo') # => { id: 'foo'}
16
21
  ```
17
22
 
18
23
  ## Syntax
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MustermannGrape
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -13,11 +13,28 @@ module Mustermann
13
13
  # @see file:README.md#grape Syntax description in the README
14
14
  class Grape < AST::Pattern
15
15
  register :grape
16
+ supported_options :params
16
17
 
17
18
  on(nil, '?', ')') { |c| unexpected(c) }
18
19
 
19
20
  on('*') { |_c| scan(/\w+/) ? node(:named_splat, buffer.matched) : node(:splat) }
20
- on(':') { |_c| node(:capture, constraint: "[^/\\?#\.]") { scan(/\w+/) } }
21
+ on(':') do |_c|
22
+ param_name = scan(/\w+/)
23
+ return node(:capture, param_name, constraint: "[^/\\?#\.]") { scan(/\w+/) } unless pattern
24
+
25
+ params_opt = pattern.options[:params]
26
+ if params_opt && params_opt[param_name] && params_opt[param_name][:type]
27
+ param_type = params_opt[param_name][:type]
28
+ case(param_type)
29
+ when "Integer"
30
+ node(:capture, param_name, constraint: /\d/) { scan(/\w+/) }
31
+ else
32
+ node(:capture, param_name, constraint: "[^/\\?#\.]") { scan(/\w+/) }
33
+ end
34
+ else
35
+ node(:capture, param_name, constraint: "[^/\\?#\.]") { scan(/\w+/) }
36
+ end
37
+ end
21
38
  on('\\') { |_c| node(:char, expect(/./)) }
22
39
  on('(') { |_c| node(:optional, node(:group) { read unless scan(')') }) }
23
40
  on('|') { |_c| node(:or) }
data/spec/grape_spec.rb CHANGED
@@ -751,4 +751,33 @@ describe Mustermann::Grape do
751
751
  example { pattern.peek_params('/foo bar') .should be_nil }
752
752
  end
753
753
  end
754
+
755
+ context 'when params option is provided' do
756
+ context 'and they contain parameters information' do
757
+ pattern '/foo/:id', params: {"id"=>{:type=>"Integer"}} do
758
+ it { should match('/foo/1') }
759
+ it { should_not match('/foo/bar') }
760
+ end
761
+
762
+ context 'and inherit routes are present' do
763
+ pattern '/foo/:id/bar/:reference', params: {"id"=>{:type=>"Integer"}, "reference"=>{:type=>"String"}} do
764
+ it { should match('/foo/1/bar/wadus') }
765
+ it { should_not match('/foo/bar/bar/wadus') }
766
+ end
767
+
768
+ pattern '/foo/:id/bar/:reference', params: {"id"=>{:type=>"Integer"}, "reference"=>{:type=>"Integer"}} do
769
+ it { should match('/foo/1/bar/1') }
770
+ it { should_not match('/foo/1/bar/wadus') }
771
+ it { should_not match('/foo/bar/bar/1') }
772
+ end
773
+ end
774
+ end
775
+
776
+ context 'and they do NOT contain parameters information' do
777
+ pattern '/foo/:id' do
778
+ it { should match('/foo/1') }
779
+ it { should match('/foo/bar') }
780
+ end
781
+ end
782
+ end
754
783
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustermann-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - namusyaka
8
8
  - Konstantin Haase
9
9
  - Daniel Doubrovkine
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-01-09 00:00:00.000000000 Z
13
+ date: 2023-11-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mustermann
@@ -32,9 +32,12 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".travis.yml"
35
+ - ".github/workflows/tests.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - CHANGELOG.md
36
39
  - Gemfile
37
- - Gemfile.lock
40
+ - LICENSE
38
41
  - README.md
39
42
  - Rakefile
40
43
  - lib/mustermann/grape.rb
@@ -46,7 +49,7 @@ homepage: https://github.com/ruby-grape/mustermann-grape
46
49
  licenses:
47
50
  - MIT
48
51
  metadata: {}
49
- post_install_message:
52
+ post_install_message:
50
53
  rdoc_options: []
51
54
  require_paths:
52
55
  - lib
@@ -61,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
64
  - !ruby/object:Gem::Version
62
65
  version: '0'
63
66
  requirements: []
64
- rubygems_version: 3.0.4
65
- signing_key:
67
+ rubygems_version: 3.3.7
68
+ signing_key:
66
69
  specification_version: 4
67
70
  summary: Grape syntax for Mustermann
68
71
  test_files:
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.5
5
- - 2.6
6
- - 2.7
7
-
8
- cache: bundler
data/Gemfile.lock DELETED
@@ -1,98 +0,0 @@
1
- GIT
2
- remote: https://github.com/sinatra/mustermann.git
3
- revision: db86e25f786c717dbe937d862a5ba0d35a58797b
4
- specs:
5
- mustermann (1.1.0)
6
- ruby2_keywords (~> 0.0.1)
7
- support (0.0.1)
8
- addressable
9
- coveralls
10
- rack-test
11
- rake
12
- redcarpet
13
- rspec
14
- rspec-its
15
- simplecov
16
- sinatra (~> 1.4)
17
- tool (~> 0.2)
18
- yard
19
-
20
- PATH
21
- remote: .
22
- specs:
23
- mustermann-grape (1.0.1)
24
- mustermann (>= 1.0.0)
25
-
26
- GEM
27
- remote: https://rubygems.org/
28
- specs:
29
- addressable (2.7.0)
30
- public_suffix (>= 2.0.2, < 5.0)
31
- coveralls (0.7.2)
32
- multi_json (~> 1.3)
33
- rest-client (= 1.6.7)
34
- simplecov (>= 0.7)
35
- term-ansicolor (= 1.2.2)
36
- thor (= 0.18.1)
37
- diff-lcs (1.3)
38
- docile (1.3.2)
39
- json (2.3.0)
40
- mime-types (3.3.1)
41
- mime-types-data (~> 3.2015)
42
- mime-types-data (3.2019.1009)
43
- multi_json (1.14.1)
44
- public_suffix (4.0.2)
45
- rack (1.6.12)
46
- rack-protection (1.5.5)
47
- rack
48
- rack-test (1.1.0)
49
- rack (>= 1.0, < 3)
50
- rake (13.0.1)
51
- redcarpet (3.5.0)
52
- rest-client (1.6.7)
53
- mime-types (>= 1.16)
54
- rspec (3.9.0)
55
- rspec-core (~> 3.9.0)
56
- rspec-expectations (~> 3.9.0)
57
- rspec-mocks (~> 3.9.0)
58
- rspec-core (3.9.1)
59
- rspec-support (~> 3.9.1)
60
- rspec-expectations (3.9.0)
61
- diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.9.0)
63
- rspec-its (1.3.0)
64
- rspec-core (>= 3.0.0)
65
- rspec-expectations (>= 3.0.0)
66
- rspec-mocks (3.9.0)
67
- diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.9.0)
69
- rspec-support (3.9.2)
70
- ruby2_keywords (0.0.1)
71
- simplecov (0.17.1)
72
- docile (~> 1.1)
73
- json (>= 1.8, < 3)
74
- simplecov-html (~> 0.10.0)
75
- simplecov-html (0.10.2)
76
- sinatra (1.4.8)
77
- rack (~> 1.5)
78
- rack-protection (~> 1.4)
79
- tilt (>= 1.3, < 3)
80
- term-ansicolor (1.2.2)
81
- tins (~> 0.8)
82
- thor (0.18.1)
83
- tilt (2.0.10)
84
- tins (0.13.2)
85
- tool (0.2.3)
86
- yard (0.9.20)
87
-
88
- PLATFORMS
89
- ruby
90
-
91
- DEPENDENCIES
92
- mustermann-grape!
93
- rake
94
- rspec-core
95
- support!
96
-
97
- BUNDLED WITH
98
- 2.1.2