grape_routes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/grape_routes.gemspec +25 -0
- data/lib/grape_routes.rb +72 -0
- data/lib/grape_routes/grape_routes.rb +0 -0
- data/lib/grape_routes/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27a0638e7f29ecfc8c551136283b4926ee2cc0da
|
4
|
+
data.tar.gz: 1031e17e301362be706c612cf311a1438a265e0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8fbc4ca8aaa4d199617e6bce4d4158688092358d7565885d5899eb084016804b9b51e0627f2aadddc187547d8959337e3d441b49e990b00aabf8d44eb24fd1e1
|
7
|
+
data.tar.gz: a3909a36c9e7f33122ec95cc59ed2a095c14986a4b48fe8a5886e37185a3875e4f11b0c5f4daf5e5ee154396b04bc2f7bfed79974904d764c1cd3ba908b6148e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Adam Pahlevi
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Grape::Routes
|
2
|
+
|
3
|
+
Allow you to refer to your Grape API routes as a function call.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
class UseAPI < Grape::API
|
7
|
+
prefix 'v1'
|
8
|
+
format :json
|
9
|
+
version 'v1', using: :header, vendor: 'myapi'
|
10
|
+
|
11
|
+
resources :user do
|
12
|
+
desc "create user"
|
13
|
+
params do
|
14
|
+
optional :fullname, type: String
|
15
|
+
end
|
16
|
+
post :create do
|
17
|
+
# your code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
You can refer to your API path as follow:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Grape::Routes.v1_user_create_post_path
|
27
|
+
```
|
28
|
+
|
29
|
+
You can refer to list of all available routes:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Grape::Routes.all_routes.keys
|
33
|
+
```
|
34
|
+
|
35
|
+
You can re-parse, only if you add routes on the fly, probably?
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Grape::Routes.parse!
|
39
|
+
```
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'grape_routes'
|
47
|
+
```
|
48
|
+
|
49
|
+
And then execute:
|
50
|
+
|
51
|
+
$ bundle
|
52
|
+
|
53
|
+
Or install it yourself as:
|
54
|
+
|
55
|
+
$ gem install grape_routes
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is proudly available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
60
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "grape_routes"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grape_routes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "grape_routes"
|
8
|
+
spec.version = GrapeRoutes::VERSION
|
9
|
+
spec.authors = ["Adam Pahlevi"]
|
10
|
+
spec.email = ["adam.pahlevi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provide referable routing mechanism for your Grape API}
|
13
|
+
spec.description = %q{Provide referable routing mechanism for your Grape API}
|
14
|
+
spec.homepage = 'https://github.com/saveav/grape_routes'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
data/lib/grape_routes.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "grape_routes/version"
|
2
|
+
require "singleton"
|
3
|
+
|
4
|
+
module GrapeRoutes
|
5
|
+
end
|
6
|
+
|
7
|
+
module Grape::Routes
|
8
|
+
class << self
|
9
|
+
attr_accessor :all_routes
|
10
|
+
attr_accessor :endpoints
|
11
|
+
|
12
|
+
def all_routes
|
13
|
+
parse!
|
14
|
+
@all_routes
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# reparse everything
|
19
|
+
def self.parse!
|
20
|
+
self.endpoints = []
|
21
|
+
Grape::API.descendants.each { |endpoint| self.endpoints << endpoint }
|
22
|
+
self.endpoints.each { |endpoint| parse_endpoint(endpoint) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_endpoint(grape_api_class)
|
26
|
+
parsable_routes = {}
|
27
|
+
grape_api_class.routes.each do |route|
|
28
|
+
route_path_name = route.route_path
|
29
|
+
route_path_name = route_path_name.gsub(%r{^\/}, '')
|
30
|
+
route_path_name = route_path_name.tr('/', '_')
|
31
|
+
route_path_name = route_path_name.gsub(/(\(.+\))+/, '')
|
32
|
+
route_path_name = 'index' if route_path_name.empty?
|
33
|
+
route_path_name << '_' + route.route_method.to_s.downcase
|
34
|
+
route_path_name << '_path'
|
35
|
+
parsable_routes[route_path_name] = route
|
36
|
+
end
|
37
|
+
|
38
|
+
@all_routes = {} if @all_routes.nil?
|
39
|
+
|
40
|
+
self.class_eval do
|
41
|
+
parsable_routes.each do |route_path_name, route_object|
|
42
|
+
next if @all_routes[route_path_name]
|
43
|
+
|
44
|
+
route_path = route_object.route_path.gsub(/(\(.+\))+/, '')
|
45
|
+
if route_path_name =~ /:version_/i
|
46
|
+
route_path_name = route_path_name.gsub(/:version_/i, '')
|
47
|
+
@all_routes[route_path_name] = route_object
|
48
|
+
define_singleton_method route_path_name do |*args|
|
49
|
+
fail 'Pass in version' if args.length != 1
|
50
|
+
version = args[0]
|
51
|
+
route_path.gsub(':version', version)
|
52
|
+
end # define_singleton_method
|
53
|
+
else
|
54
|
+
@all_routes[route_path_name] = route_object
|
55
|
+
define_singleton_method route_path_name do
|
56
|
+
route_path
|
57
|
+
end
|
58
|
+
end # if check
|
59
|
+
end # each parsable_routes
|
60
|
+
end # class_eval
|
61
|
+
end # parse_endpoint
|
62
|
+
|
63
|
+
def self.method_missing(method_name, *args, &block)
|
64
|
+
self.parse!
|
65
|
+
if self.respond_to?(method_name)
|
66
|
+
self.send(method_name)
|
67
|
+
else
|
68
|
+
super.method_missing(method_name, *args, &block)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grape_routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Pahlevi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Provide referable routing mechanism for your Grape API
|
56
|
+
email:
|
57
|
+
- adam.pahlevi@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".README.md.swp"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- grape_routes.gemspec
|
74
|
+
- lib/.grape_routes.rb.swp
|
75
|
+
- lib/grape_routes.rb
|
76
|
+
- lib/grape_routes/grape_routes.rb
|
77
|
+
- lib/grape_routes/version.rb
|
78
|
+
homepage: https://github.com/saveav/grape_routes
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Provide referable routing mechanism for your Grape API
|
102
|
+
test_files: []
|
103
|
+
has_rdoc:
|