sinatra-rake-routes 0.0.1 → 0.0.3

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
  SHA1:
3
- metadata.gz: 1d5ce5982072c93d1f8ea2a3f091e1a0dab7effd
4
- data.tar.gz: 455143d3f9b4908901fe57bb8bcc12d4e36b1960
3
+ metadata.gz: 407b7955269b5c168134db5d9281869200d38d11
4
+ data.tar.gz: d5e39656762c0dede87e9589aa7cfe0fb76164e1
5
5
  SHA512:
6
- metadata.gz: 15bb3d4f668108a439caa03d78edde3f515085595f9960cb649c9d8f866919c5e841debbaf6859aca19495ebbd4484005e1414378c65496d026188559792da35
7
- data.tar.gz: 099ee3bfed991ead6f90a05e5d17c1eec290577182ac2e64428b3d6ad5022c811bdec214df20661b0c47696405833b5cf55f965762a7ce08e4a4e428c5f54d16
6
+ metadata.gz: a1a174a8a372d2bbae676ea191e2c5e3d74d8cd8a063c5c5552958eb893ebab0c5c6bbb85a32162da3c32659d4e4973915972370a5ecc197e447ff054738a512
7
+ data.tar.gz: 3294f3f0b7be56e948258183e5ef34c7432d1621faca77493173adf02738e022677bd6d34a770ea694661f1c697d1c2d8dcd3882d4b8dcefc81b5e2c73591fe5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sinatra-rake-routes [![Circle CI](https://circleci.com/gh/wealthsimple/sinatra-rake-routes.svg?style=svg)](https://circleci.com/gh/wealthsimple/sinatra-rake-routes)
2
2
 
3
- `rake routes` command for Sinatra applications
3
+ `rake routes` command for Sinatra applications for printing out all defined routes.
4
4
 
5
5
  ## Usage
6
6
 
@@ -31,23 +31,23 @@ require "sinatra-rake-routes/tasks"
31
31
  bundle exec rake routes
32
32
 
33
33
  POST
34
- A/users/:user_id/messages\
35
- A/users\
34
+ /users
35
+ /users/:user_id/messages
36
36
 
37
37
  GET
38
- A/users/:user_id/messages/:message_id\
39
- A/users/:user_id/messages\
40
- A/users/:user_id\
38
+ /users/:user_id
39
+ /users/:user_id/messages
40
+ /users/:user_id/messages/:message_id
41
41
 
42
42
  HEAD
43
- A/users/:user_id/messages/:message_id\
44
- A/users/:user_id/messages\
45
- A/users/:user_id\
43
+ /users/:user_id
44
+ /users/:user_id/messages
45
+ /users/:user_id/messages/:message_id
46
46
 
47
47
  PUT
48
- A/users/:user_id/messages/:message_id\
49
- A/users/:user_id\
48
+ /users/:user_id
49
+ /users/:user_id/messages/:message_id
50
50
 
51
51
  DELETE
52
- A/users/:user_id\
52
+ /users/:user_id
53
53
  ```
data/circle.yml ADDED
@@ -0,0 +1,9 @@
1
+ dependencies:
2
+ override:
3
+ - 'rvm-exec 1.9.3-p551 bundle install'
4
+ - 'rvm-exec 2.3.0 bundle install'
5
+
6
+ test:
7
+ override:
8
+ - 'rvm-exec 1.9.3-p551 bundle exec rspec'
9
+ - 'rvm-exec 2.3.0 bundle exec rspec'
@@ -1,6 +1,6 @@
1
1
  desc "Print out all defined routes"
2
2
  task :routes do
3
- puts SinatraRakeRoutes.output
3
+ puts SinatraRakeRoutes.new.to_s
4
4
  end
5
5
 
6
6
  if Rake::Task.task_defined?("configure_routes")
@@ -1,3 +1,3 @@
1
1
  class SinatraRakeRoutes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -16,21 +24,28 @@ class SinatraRakeRoutes
16
24
  @@app_class
17
25
  end
18
26
 
19
- def self.output
27
+ def to_s
20
28
  str = []
21
- app_routes = app_class.routes
22
- app_routes.each_with_index do |(http_method, routes_list), i|
29
+ self.class.app_class.routes.each do |http_method, routes|
23
30
  str << http_method
24
- routes = []
25
- routes_list.each do |item|
26
- source = item[0].source
27
- item[1].each do |s|
28
- source.sub!(/\(.+?\)/, ':'+s)
29
- end
30
- routes << source[1...-1]
31
- end
31
+ routes = routes.map { |route| decompile_route(route) }
32
32
  str << routes.sort.join("\n") + "\n"
33
33
  end
34
34
  str.join("\n")
35
35
  end
36
+
37
+ private
38
+
39
+ def decompile_route(route)
40
+ source = route[0].source
41
+ params = route[1]
42
+ source.gsub!(HYPHEN_REGEX.source, "-")
43
+ source.gsub!(PERIOD_REGEX.source, ".")
44
+ source.gsub!(SPLAT_REGEX.source, "*")
45
+ params.each do |param|
46
+ source.sub!(NAMED_PARAM_REGEX_SOURCE, ":#{param}")
47
+ end
48
+ # Remove leading "\A" and trailing "\z"
49
+ source[2...-2]
50
+ end
36
51
  end
@@ -9,18 +9,18 @@ Gem::Specification.new do |gem|
9
9
  gem.author = "Peter Graham"
10
10
  gem.summary = %q{`rake routes` command for Sinatra applications}
11
11
  gem.email = %q{peter@wealthsimple.com}
12
- gem.description = %q{Rails' `rake routes` command for Sinatra applications}
13
- gem.homepage = %q{https://github.com/wealthsimple}
12
+ gem.description = %q{Rake command for printing out all defined routes in Sinatra applications}
13
+ gem.homepage = %q{https://github.com/wealthsimple/sinatra-rake-routes}
14
14
  gem.files = `git ls-files`.split("\n")
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
18
  gem.licenses = ["MIT"]
19
19
 
20
- gem.add_dependency "rake"
20
+ gem.required_ruby_version = ">= 1.9.3"
21
+ gem.add_dependency "rake", ">= 0"
21
22
 
22
- gem.add_development_dependency "rspec"
23
- gem.add_development_dependency "rspec-collection_matchers"
24
- gem.add_development_dependency "rspec-its"
25
- gem.add_development_dependency "sinatra"
23
+ gem.add_development_dependency "rspec", "~> 3.4"
24
+ gem.add_development_dependency "sinatra", "~> 1.4"
25
+ gem.add_development_dependency "rspec_junit_formatter", "~> 0.2"
26
26
  end
@@ -1,20 +1,24 @@
1
1
  POST
2
- A/users/:user_id/messages\
3
- A/users\
2
+ /test-hyphenated/:test_id/something
3
+ /users
4
+ /users/*/splat/*
5
+ /users/:user_id/messages
4
6
 
5
7
  GET
6
- A/users/:user_id/messages/:message_id\
7
- A/users/:user_id/messages\
8
- A/users/:user_id\
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
- A/users/:user_id/messages/:message_id\
12
- A/users/:user_id/messages\
13
- A/users/:user_id\
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
- A/users/:user_id/messages/:message_id\
17
- A/users/:user_id\
20
+ /users/:user_id
21
+ /users/:user_id/messages/:message_id
18
22
 
19
23
  DELETE
20
- A/users/:user_id\
24
+ /users/:user_id
@@ -17,10 +17,10 @@ describe SinatraRakeRoutes do
17
17
  end
18
18
  end
19
19
 
20
- describe ".output" do
20
+ describe "#to_s" do
21
21
  it "outputs routes" do
22
22
  described_class.set_app_class(SampleApp)
23
- expect(described_class.output).to eq(File.read('./spec/fixtures/sample_app_output.txt'))
23
+ expect(described_class.new.to_s).to eq(File.read('./spec/fixtures/sample_app_output.txt'))
24
24
  end
25
25
  end
26
26
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'rspec'
2
- require 'rspec/collection_matchers'
3
- require 'rspec/its'
4
2
 
5
3
  Dir["./spec/support/**/*.rb"].each { |f| require f }
6
4
 
@@ -9,12 +7,4 @@ require './lib/sinatra-rake-routes'
9
7
  RSpec.configure do |config|
10
8
  config.filter_run :focus
11
9
  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
10
  end
@@ -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.1
4
+ version: 0.0.3
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-10 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -28,59 +28,45 @@ dependencies:
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec-collection_matchers
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '3.4'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '3.4'
55
41
  - !ruby/object:Gem::Dependency
56
- name: rspec-its
42
+ name: sinatra
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: '1.4'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: '1.4'
69
55
  - !ruby/object:Gem::Dependency
70
- name: sinatra
56
+ name: rspec_junit_formatter
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: '0.2'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: Rails' `rake routes` command for Sinatra applications
68
+ version: '0.2'
69
+ description: Rake command for printing out all defined routes in Sinatra applications
84
70
  email: peter@wealthsimple.com
85
71
  executables: []
86
72
  extensions: []
@@ -91,6 +77,7 @@ files:
91
77
  - Gemfile
92
78
  - LICENSE
93
79
  - README.md
80
+ - circle.yml
94
81
  - lib/sinatra-rake-routes.rb
95
82
  - lib/sinatra-rake-routes/tasks.rb
96
83
  - lib/sinatra-rake-routes/version.rb
@@ -100,7 +87,7 @@ files:
100
87
  - spec/spec_helper.rb
101
88
  - spec/support/sample_app.rb
102
89
  - spec/version_spec.rb
103
- homepage: https://github.com/wealthsimple
90
+ homepage: https://github.com/wealthsimple/sinatra-rake-routes
104
91
  licenses:
105
92
  - MIT
106
93
  metadata: {}
@@ -112,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
99
  requirements:
113
100
  - - ">="
114
101
  - !ruby/object:Gem::Version
115
- version: '0'
102
+ version: 1.9.3
116
103
  required_rubygems_version: !ruby/object:Gem::Requirement
117
104
  requirements:
118
105
  - - ">="