sinatra-rake-routes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -11
- data/circle.yml +9 -0
- data/lib/sinatra-rake-routes.rb +14 -3
- data/lib/sinatra-rake-routes/version.rb +1 -1
- data/sinatra-rake-routes.gemspec +1 -0
- data/spec/fixtures/sample_app_output.txt +15 -11
- data/spec/spec_helper.rb +0 -8
- data/spec/support/sample_app.rb +6 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20a8a6eb82256cc8d036ce1ed352f4d8594f047e
|
4
|
+
data.tar.gz: d59ebfe726be080845da89cb1836018e9bc082fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36cfdde45a9cdc8eb31f07a90c39105d8e799ba30a723aabd66ebe13d7159c9d6c390479a9378adfc5175f95649dbe7bb992d0beb46bb35cc5a96d794d4eaedb
|
7
|
+
data.tar.gz: 04a45094da7de351568798efc787d150a484d4fd2a7ecc9e9e207353ccfa5ad9c9b1845c7ca4da462ecab74bd9e67618eac8f2644f0a94ed06d687a647f9f384
|
data/README.md
CHANGED
@@ -31,23 +31,23 @@ require "sinatra-rake-routes/tasks"
|
|
31
31
|
bundle exec rake routes
|
32
32
|
|
33
33
|
POST
|
34
|
-
|
35
|
-
|
34
|
+
/users
|
35
|
+
/users/:user_id/messages
|
36
36
|
|
37
37
|
GET
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
/users/:user_id
|
39
|
+
/users/:user_id/messages
|
40
|
+
/users/:user_id/messages/:message_id
|
41
41
|
|
42
42
|
HEAD
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
/users/:user_id
|
44
|
+
/users/:user_id/messages
|
45
|
+
/users/:user_id/messages/:message_id
|
46
46
|
|
47
47
|
PUT
|
48
|
-
|
49
|
-
|
48
|
+
/users/:user_id
|
49
|
+
/users/:user_id/messages/:message_id
|
50
50
|
|
51
51
|
DELETE
|
52
|
-
|
52
|
+
/users/:user_id
|
53
53
|
```
|
data/circle.yml
ADDED
data/lib/sinatra-rake-routes.rb
CHANGED
@@ -4,6 +4,14 @@ require 'sinatra-rake-routes/version'
|
|
4
4
|
class SinatraRakeRoutes
|
5
5
|
@@app_class = nil
|
6
6
|
|
7
|
+
# Sinatra compiles routes into regexes. See below link for how this works:
|
8
|
+
# https://github.com/sinatra/sinatra/blob/4c7d38eb1b2cc02ce51029f28e0c3c34ca12ccfd/lib/sinatra/base.rb#L1618
|
9
|
+
# The below regexes cover some of the common cases.
|
10
|
+
HYPHEN_REGEX = /(?:\-|%2[Dd])/
|
11
|
+
NAMED_PARAM_REGEX_SOURCE = "([^\/?#]+)"
|
12
|
+
PERIOD_REGEX = /(?:\.|%2[Ee])/
|
13
|
+
SPLAT_REGEX = /(.*?)/
|
14
|
+
|
7
15
|
def self.set_app_class(klass)
|
8
16
|
if klass.respond_to?(:routes) && klass.routes.is_a?(Hash)
|
9
17
|
@@app_class = klass
|
@@ -19,15 +27,18 @@ class SinatraRakeRoutes
|
|
19
27
|
def self.output
|
20
28
|
str = []
|
21
29
|
app_routes = app_class.routes
|
22
|
-
app_routes.
|
30
|
+
app_routes.each do |http_method, routes_list|
|
23
31
|
str << http_method
|
24
32
|
routes = []
|
25
33
|
routes_list.each do |item|
|
26
34
|
source = item[0].source
|
35
|
+
source.gsub!(HYPHEN_REGEX.source, "-")
|
36
|
+
source.gsub!(PERIOD_REGEX.source, ".")
|
37
|
+
source.gsub!(SPLAT_REGEX.source, "*")
|
27
38
|
item[1].each do |s|
|
28
|
-
source.sub!(
|
39
|
+
source.sub!(NAMED_PARAM_REGEX_SOURCE, ":#{s}")
|
29
40
|
end
|
30
|
-
routes << source[
|
41
|
+
routes << source[2...-2]
|
31
42
|
end
|
32
43
|
str << routes.sort.join("\n") + "\n"
|
33
44
|
end
|
data/sinatra-rake-routes.gemspec
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
POST
|
2
|
-
|
3
|
-
|
2
|
+
/test-hyphenated/:test_id/something
|
3
|
+
/users
|
4
|
+
/users/*/splat/*
|
5
|
+
/users/:user_id/messages
|
4
6
|
|
5
7
|
GET
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
/users.tar.gz
|
9
|
+
/users/:user_id
|
10
|
+
/users/:user_id/messages
|
11
|
+
/users/:user_id/messages/:message_id
|
9
12
|
|
10
13
|
HEAD
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
/users.tar.gz
|
15
|
+
/users/:user_id
|
16
|
+
/users/:user_id/messages
|
17
|
+
/users/:user_id/messages/:message_id
|
14
18
|
|
15
19
|
PUT
|
16
|
-
|
17
|
-
|
20
|
+
/users/:user_id
|
21
|
+
/users/:user_id/messages/:message_id
|
18
22
|
|
19
23
|
DELETE
|
20
|
-
|
24
|
+
/users/:user_id
|
data/spec/spec_helper.rb
CHANGED
@@ -9,12 +9,4 @@ require './lib/sinatra-rake-routes'
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
config.filter_run :focus
|
11
11
|
config.run_all_when_everything_filtered = true
|
12
|
-
|
13
|
-
config.expect_with :rspec do |expectations|
|
14
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
15
|
-
end
|
16
|
-
|
17
|
-
config.mock_with :rspec do |mocks|
|
18
|
-
mocks.verify_partial_doubles = true
|
19
|
-
end
|
20
12
|
end
|
data/spec/support/sample_app.rb
CHANGED
@@ -3,8 +3,14 @@ require 'sinatra'
|
|
3
3
|
class SampleApp < Sinatra::Base
|
4
4
|
post '/users' do
|
5
5
|
end
|
6
|
+
post '/users/*/splat/*' do
|
7
|
+
end
|
8
|
+
post '/test-hyphenated/:test_id/something' do
|
9
|
+
end
|
6
10
|
post '/users/:user_id/messages' do
|
7
11
|
end
|
12
|
+
get '/users.tar.gz' do
|
13
|
+
end
|
8
14
|
get '/users/:user_id' do
|
9
15
|
end
|
10
16
|
get '/users/:user_id/messages' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rake-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Graham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec_junit_formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Rails' `rake routes` command for Sinatra applications
|
84
98
|
email: peter@wealthsimple.com
|
85
99
|
executables: []
|
@@ -91,6 +105,7 @@ files:
|
|
91
105
|
- Gemfile
|
92
106
|
- LICENSE
|
93
107
|
- README.md
|
108
|
+
- circle.yml
|
94
109
|
- lib/sinatra-rake-routes.rb
|
95
110
|
- lib/sinatra-rake-routes/tasks.rb
|
96
111
|
- lib/sinatra-rake-routes/version.rb
|