grape-path-helpers 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cce4a208f0d1e34b8a35da84f34d2ffa02bc7e4
4
+ data.tar.gz: c7363febba8def48120a68779cf9d097fec7b8e2
5
+ SHA512:
6
+ metadata.gz: e8e1650bc433de578ef57e8d91fcdf31e94542545a12fccb69040d6094b9b1188404b9b6ed8956d59f4f6b26274434b71795176024d4bf99b82c1cf3f155bd03
7
+ data.tar.gz: 1b65db4108966fee07ccaf91931672e1c6fb01ae918a8a52c3057e2f34da3d25725408ad97376f9b268fd7e7c46c5e4551dadf44239902df79f5245bacf6979e
@@ -0,0 +1,3 @@
1
+ *.swp
2
+ *.gem
3
+ .ruby-version
@@ -0,0 +1,18 @@
1
+ image: "ruby:2.4-alpine"
2
+
3
+ cache:
4
+ paths:
5
+ - vendor/ruby
6
+
7
+ before_script:
8
+ - apk add --update git
9
+ - gem install bundler
10
+ - bundle install
11
+
12
+ rubocop:
13
+ script:
14
+ - rubocop
15
+
16
+ rspec:
17
+ script:
18
+ - bundle exec rspec spec
@@ -0,0 +1,10 @@
1
+ Metrics/ClassLength:
2
+ Max: 104
3
+ Enabled: false
4
+
5
+ Metrics/MethodLength:
6
+ Max: 21
7
+ Enabled: false
8
+
9
+ Style/FileName:
10
+ Enabled: false
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+
3
+ cache: bundler
4
+
5
+ rvm:
6
+ - ruby-head
7
+ - 2.3.0
8
+ - 2.2.0
9
+ - 2.1.0
10
+ - 2.0.0
11
+ - 1.9.3
12
+ - jruby-19mode
13
+ - jruby-head
14
+
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ - rvm: jruby-head
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+
3
+ ## December 17 2016
4
+
5
+ * Bump to 2.1.0
6
+ * Fix bug that caused POST routes to be ignored if more than one was defined
7
+ * Many thanks to @njd5475 for the bug report and pull request that helped me write this
8
+
9
+ ## April 28 2016
10
+
11
+ * Release 2.0.0
12
+ * Fix incompatibility between grape-route-helpers and grape 0.16.0
13
+
14
+ ## April 11 2016
15
+
16
+ * Release 1.2.2
17
+ * Fixed incompatibility between grape-route-helpers and Ruby 2.3 by merging PR #8 from phallguy
18
+
19
+ ## October 11 2015
20
+
21
+ * Release 1.2.1
22
+ * Fixed issue #4
23
+
24
+ ## September 27 2015
25
+
26
+ * Release 1.2.0
27
+
28
+ * You can now assign custom helper names to Grape routes
29
+ * Fixed a bug where routes would be listed more than once in the rake task if they are mounted to another API
30
+ * Added the HTTP verb to rake task output
31
+
32
+ ## July 5 2015
33
+
34
+ * You can now pass query parameters to helper functions in order to generate your own query string (Issue #1)
35
+
36
+ ## June 28 2015
37
+
38
+ Release 1.0.1
39
+
40
+ * Rename rake task from `grape:routes` to `grape:route_helpers`
41
+
42
+ * If a Grape::Route has a specific format (json, etc.) in its route_path attribute, the helper will return a path with this extension at the end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grape-path-helpers (1.0.0)
5
+ activesupport
6
+ grape (~> 1.0)
7
+ rake
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.0)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.4.0)
18
+ axiom-types (0.1.1)
19
+ descendants_tracker (~> 0.0.4)
20
+ ice_nine (~> 0.11.0)
21
+ thread_safe (~> 0.3, >= 0.3.1)
22
+ builder (3.2.3)
23
+ coderay (1.1.2)
24
+ coercible (1.0.0)
25
+ descendants_tracker (~> 0.0.1)
26
+ concurrent-ruby (1.0.5)
27
+ descendants_tracker (0.0.4)
28
+ thread_safe (~> 0.3, >= 0.3.1)
29
+ diff-lcs (1.3)
30
+ equalizer (0.0.11)
31
+ grape (1.0.2)
32
+ activesupport
33
+ builder
34
+ mustermann-grape (~> 1.0.0)
35
+ rack (>= 1.3.0)
36
+ rack-accept
37
+ virtus (>= 1.0.0)
38
+ i18n (1.0.1)
39
+ concurrent-ruby (~> 1.0)
40
+ ice_nine (0.11.2)
41
+ method_source (0.9.0)
42
+ minitest (5.11.3)
43
+ mustermann (1.0.2)
44
+ mustermann-grape (1.0.0)
45
+ mustermann (~> 1.0.0)
46
+ parallel (1.12.1)
47
+ parser (2.5.1.0)
48
+ ast (~> 2.4.0)
49
+ powerpack (0.1.1)
50
+ pry (0.11.3)
51
+ coderay (~> 1.1.0)
52
+ method_source (~> 0.9.0)
53
+ rack (2.0.5)
54
+ rack-accept (0.4.5)
55
+ rack (>= 0.4)
56
+ rainbow (3.0.0)
57
+ rake (12.3.1)
58
+ rspec (3.7.0)
59
+ rspec-core (~> 3.7.0)
60
+ rspec-expectations (~> 3.7.0)
61
+ rspec-mocks (~> 3.7.0)
62
+ rspec-core (3.7.1)
63
+ rspec-support (~> 3.7.0)
64
+ rspec-expectations (3.7.0)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.7.0)
67
+ rspec-mocks (3.7.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.7.0)
70
+ rspec-support (3.7.1)
71
+ rubocop (0.55.0)
72
+ parallel (~> 1.10)
73
+ parser (>= 2.5)
74
+ powerpack (~> 0.1)
75
+ rainbow (>= 2.2.2, < 4.0)
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (~> 1.0, >= 1.0.1)
78
+ ruby-progressbar (1.9.0)
79
+ thread_safe (0.3.6)
80
+ tzinfo (1.2.5)
81
+ thread_safe (~> 0.1)
82
+ unicode-display_width (1.3.2)
83
+ virtus (1.0.5)
84
+ axiom-types (~> 0.1)
85
+ coercible (~> 1.0)
86
+ descendants_tracker (~> 0.0, >= 0.0.3)
87
+ equalizer (~> 0.0, >= 0.0.9)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ grape-path-helpers!
94
+ pry
95
+ rspec
96
+ rubocop
97
+
98
+ BUNDLED WITH
99
+ 1.16.2
@@ -0,0 +1,22 @@
1
+ MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Harper Henn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
@@ -0,0 +1,172 @@
1
+ # grape-route-helpers
2
+
3
+ [![Build Status](https://travis-ci.org/reprah/grape-route-helpers.svg)](https://travis-ci.org/reprah/grape-route-helpers)
4
+
5
+ Provides named route helpers for Grape APIs, similar to [Rails' route helpers](http://edgeguides.rubyonrails.org/routing.html#path-and-url-helpers).
6
+
7
+ ### Installation
8
+
9
+ #### Compatibility with Grape
10
+
11
+ If you're using grape 0.16.0 or higher, you'll need version 2.0.0 or higher of grape-route-helpers.
12
+
13
+ #### Rails
14
+
15
+ 1.) Add the gem to your Gemfile.
16
+
17
+ ```bash
18
+ $ bundle install grape-route-helpers
19
+ ```
20
+
21
+ #### Sinatra/Rack
22
+
23
+ 1.) Add the gem to your Gemfile if you're using Bundler.
24
+
25
+ If you're not using Bundler to install/manage dependencies:
26
+
27
+ ```bash
28
+ $ gem install grape-route-helpers
29
+ ```
30
+
31
+ ```ruby
32
+ # environment setup file
33
+ require 'grape'
34
+ require 'grape/route_helpers'
35
+ ```
36
+
37
+ 2.) Write a rake task called `:environment` that loads the application's environment first. This gem's tasks are dependent on it. You could put this in the root of your project directory:
38
+
39
+ ```ruby
40
+ # Rakefile
41
+
42
+ require 'rake'
43
+ require 'bundler'
44
+ Bundler.setup
45
+ require 'grape-route-helpers'
46
+ require 'grape-route-helpers/tasks'
47
+
48
+ desc 'load the Sinatra environment.'
49
+ task :environment do
50
+ require File.expand_path('your_app_file', File.dirname(__FILE__))
51
+ end
52
+ ```
53
+
54
+ ### Usage
55
+
56
+ #### List All Helper Names
57
+
58
+ To see which methods correspond to which paths, and which options you can pass them:
59
+
60
+ ```bash
61
+ # In your API root directory, at the command line
62
+ $ rake grape:route_helpers
63
+ ```
64
+
65
+ #### Use Helpers in IRB/Pry
66
+
67
+ You can use helper methods in your REPL session by including a module:
68
+
69
+ ```ruby
70
+ [1] pry(main)> include GrapeRouteHelpers::NamedRouteMatcher
71
+ ```
72
+ #### Use Helpers in Your API
73
+
74
+ Use the methods inside your Grape API actions. Given this example API:
75
+
76
+ ```ruby
77
+ class ExampleAPI < Grape::API
78
+ version 'v1'
79
+ prefix 'api'
80
+ format 'json'
81
+
82
+ get 'ping' do
83
+ 'pong'
84
+ end
85
+
86
+ resource :cats do
87
+ get '/' do
88
+ %w(cats cats cats)
89
+ end
90
+
91
+ route_param :id do
92
+ get do
93
+ 'cat'
94
+ end
95
+ end
96
+ end
97
+
98
+ route :any, '*anything' do
99
+ redirect api_v1_cats_path
100
+ end
101
+ end
102
+ ```
103
+
104
+ You'd have the following methods available inside your Grape API actions:
105
+
106
+ ```ruby
107
+ # specifying the version when using Grape's "path" versioning strategy
108
+ api_v1_ping_path # => '/api/v1/ping.json'
109
+
110
+ # specifying the format
111
+ api_v1_cats_path(format: '.xml') # => '/api/v1/cats.xml'
112
+
113
+ # adding a query string
114
+ api_v1_cats_path(params: { sort_by: :age }) # => '/api/v1/cats?sort_by=age'
115
+
116
+ # passing in values required to build a path
117
+ api_v1_cats_path(id: 1) # => '/api/v1/cats/1.json'
118
+
119
+ # catch-all paths have helpers
120
+ api_v1_anything_path # => '/api/v1/*anything'
121
+ ```
122
+
123
+ #### Custom Helper Names
124
+
125
+ If you want to assign a custom helper name to a route, pass the `:as` option when creating your route in your API:
126
+
127
+ ```ruby
128
+ class Base < Grape::API
129
+ get 'ping', as: 'is_the_server_running'
130
+ 'pong'
131
+ end
132
+ end
133
+ ```
134
+
135
+ This results in creating a helper called `is_the_server_running_path`.
136
+
137
+ #### Testing
138
+
139
+ You can use route helpers in your API tests by including the `GrapeRouteHelpers::NamedRouteMatcher` module inside your specs. Here's an example:
140
+
141
+ ```ruby
142
+ require 'spec_helper'
143
+
144
+ describe Api::Base do
145
+ include GrapeRouteHelpers::NamedRouteMatcher
146
+
147
+ describe 'GET /ping' do
148
+ it 'returns a 200 OK' do
149
+ get api_v2_ping_path
150
+ expect(response.status).to be(200)
151
+ end
152
+ end
153
+ end
154
+ ```
155
+
156
+ ### Contributing
157
+
158
+ 1.) Fork it
159
+
160
+ 2.) Create your feature branch `(git checkout -b my-new-feature)`
161
+
162
+ 3.) Write specs for your feature
163
+
164
+ 4.) Commit your changes `(git commit -am 'Add some feature')`
165
+
166
+ 5.) Push to the branch `(git push origin my-new-feature)`
167
+
168
+ 6.) Create a new pull request
169
+
170
+ ### License
171
+
172
+ See LICENSE
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup :default, :test, :development
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ task :spec
14
+
15
+ require 'rainbow/ext/string' unless String.respond_to?(:color)
16
+
17
+ task default: [:spec]
@@ -0,0 +1,21 @@
1
+ require File.join(Dir.pwd, 'lib', 'grape-path-helpers', 'version')
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'grape-path-helpers'
5
+ gem.version = GrapePathHelpers::VERSION
6
+ gem.licenses = ['MIT']
7
+ gem.summary = 'Route path helpers for Grape'
8
+ gem.description = 'Route path helpers for Grape'
9
+ gem.authors = ['Drew Blessing', 'Harper Henn']
10
+ gem.email = ''
11
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
12
+ gem.homepage = 'https://github.com/gitlab/grape-path-helpers'
13
+
14
+ gem.add_runtime_dependency 'activesupport'
15
+ gem.add_runtime_dependency 'grape', '~> 1.0'
16
+ gem.add_runtime_dependency 'rake'
17
+
18
+ gem.add_development_dependency 'pry'
19
+ gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'rubocop'
21
+ end