roda-route_list 1.0.0 → 2.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.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/Rakefile +7 -29
- data/lib/roda/plugins/route_list.rb +9 -9
- data/spec/roda-route_list_spec.rb +28 -38
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 745db7ba79ed2650b068c20e5665ab0c7b96e78b
|
4
|
+
data.tar.gz: 963dbb5cf8bc7da828ebd287522f7e562e05a4e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec654b9fa1c3e65b62b238870e15b4d3824f4017d35f21d5a034e91cc23a74be5af3ea53a42d8c13e0ef1e4d69fb45b46b0681f37a5c40b4b5827f6b269393a5
|
7
|
+
data.tar.gz: 9c689b0166f9a48b417d3906ae4b15e9da3ba292a94a50ece93289f996532c316d4fe16a524f53846699330169072c62635078b42250f16878bfa1f36b5f4f8e
|
data/CHANGELOG
CHANGED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -49,15 +49,15 @@ get route information:
|
|
49
49
|
route_list # => [{:path=>'/path/to/foo', :methods=>['GET', 'POST']}]
|
50
50
|
|
51
51
|
# path for the route with the given name
|
52
|
-
|
52
|
+
listed_route(:route_name) # => '/path/to/foo'
|
53
53
|
|
54
54
|
# path for the route with the given name, supplying hash for placeholders
|
55
|
-
|
55
|
+
listed_route(:foo, :foo_id=>3) # => '/path/to/foo/3'
|
56
56
|
|
57
57
|
# path for the route with the given name, supplying array for placeholders
|
58
|
-
|
58
|
+
listed_route(:foo, [3]) # => '/path/to/foo/3'
|
59
59
|
|
60
|
-
The +
|
60
|
+
The +listed_route+ method is also available at the instance level to make it
|
61
61
|
easier to use inside the route block.
|
62
62
|
|
63
63
|
=== Automatically Updating the Routes Metadata
|
data/Rakefile
CHANGED
@@ -10,36 +10,14 @@ end
|
|
10
10
|
|
11
11
|
### Specs
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rescue LoadError
|
20
|
-
# RSpec 2
|
21
|
-
require "rspec/core/rake_task"
|
22
|
-
spec_class = RSpec::Core::RakeTask
|
23
|
-
spec_files_meth = :pattern=
|
24
|
-
end
|
25
|
-
|
26
|
-
spec = lambda do |name, files, d|
|
27
|
-
lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'lib')
|
28
|
-
ENV['RUBYLIB'] ? (ENV['RUBYLIB'] += ":#{lib_dir}") : (ENV['RUBYLIB'] = lib_dir)
|
29
|
-
desc d
|
30
|
-
spec_class.new(name) do |t|
|
31
|
-
ENV['RUBY'] = FileUtils::RUBY
|
32
|
-
t.send(spec_files_meth, files)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
task :default => [:spec]
|
37
|
-
spec.call("spec", Dir["spec/*_spec.rb"], "Run specs")
|
38
|
-
rescue LoadError
|
39
|
-
task :default do
|
40
|
-
puts "Must install rspec to run the default task (which runs specs)"
|
41
|
-
end
|
13
|
+
desc "Build roda-route_list gem"
|
14
|
+
task :spec do |p|
|
15
|
+
ENV['RUBY'] = FileUtils::RUBY
|
16
|
+
ENV['RUBYLIB'] = "ENV['RUBYLIB']:lib"
|
17
|
+
ENV['RUBYOPT'] = "-rubygems"
|
18
|
+
sh %{#{FileUtils::RUBY} spec/roda-route_list_spec.rb }
|
42
19
|
end
|
20
|
+
task :default=>:spec
|
43
21
|
|
44
22
|
### RDoc
|
45
23
|
|
@@ -41,15 +41,15 @@ class Roda
|
|
41
41
|
# route_list # => [{:path=>'/path/to/foo', :methods=>['GET', 'POST']}]
|
42
42
|
#
|
43
43
|
# # path for the route with the given name
|
44
|
-
#
|
44
|
+
# listed_route(:route_name) # => '/path/to/foo'
|
45
45
|
#
|
46
46
|
# # path for the route with the given name, supplying hash for placeholders
|
47
|
-
#
|
47
|
+
# listed_route(:foo, :foo_id=>3) # => '/path/to/foo/3'
|
48
48
|
#
|
49
49
|
# # path for the route with the given name, supplying array for placeholders
|
50
|
-
#
|
50
|
+
# listed_route(:foo, [3]) # => '/path/to/foo/3'
|
51
51
|
#
|
52
|
-
# The +
|
52
|
+
# The +listed_route+ method is also available at the instance level to make it
|
53
53
|
# easier to use inside the route block.
|
54
54
|
module RouteList
|
55
55
|
# Set the file to load the routes metadata from. Options:
|
@@ -68,7 +68,7 @@ class Roda
|
|
68
68
|
# values in the path are replaced with the matching values in args.
|
69
69
|
# If args is an array, placeholder values are taken from the array
|
70
70
|
# in order.
|
71
|
-
def
|
71
|
+
def listed_route(name, args=nil)
|
72
72
|
unless path = @route_list_names[name]
|
73
73
|
raise RodaError, "no route exists with the name: #{name.inspect}"
|
74
74
|
end
|
@@ -112,7 +112,7 @@ class Roda
|
|
112
112
|
route = {:path=>path}
|
113
113
|
|
114
114
|
if methods = r['methods']
|
115
|
-
route[:methods] = methods.map
|
115
|
+
route[:methods] = methods.map(&:to_sym)
|
116
116
|
end
|
117
117
|
|
118
118
|
if name = r['name']
|
@@ -131,11 +131,11 @@ class Roda
|
|
131
131
|
end
|
132
132
|
|
133
133
|
module InstanceMethods
|
134
|
-
# Calls the app's
|
134
|
+
# Calls the app's listed_route method. If the app's :add_script_name option
|
135
135
|
# has been setting, prefixes the resulting path with the script name.
|
136
|
-
def
|
136
|
+
def listed_route(name, args=nil)
|
137
137
|
app = self.class
|
138
|
-
path = app.
|
138
|
+
path = app.listed_route(name, args)
|
139
139
|
path = request.script_name.to_s + path if app.opts[:add_script_name]
|
140
140
|
path
|
141
141
|
end
|
@@ -1,16 +1,6 @@
|
|
1
1
|
require 'roda'
|
2
2
|
require 'json'
|
3
|
-
|
4
|
-
if defined?(RSpec)
|
5
|
-
require 'rspec/version'
|
6
|
-
if RSpec::Version::STRING >= '2.11.0'
|
7
|
-
RSpec.configure do |config|
|
8
|
-
config.expect_with :rspec do |c|
|
9
|
-
c.syntax = :should
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
3
|
+
require 'minitest/autorun'
|
14
4
|
|
15
5
|
describe 'roda-route_list plugin' do
|
16
6
|
def req(path='/', env={})
|
@@ -36,7 +26,7 @@ describe 'roda-route_list plugin' do
|
|
36
26
|
@app = Class.new(Roda)
|
37
27
|
@app.plugin :route_list, :file=>'spec/routes.json'
|
38
28
|
@app.route do |r|
|
39
|
-
|
29
|
+
listed_route(env['PATH_INFO'].to_sym)
|
40
30
|
end
|
41
31
|
@app
|
42
32
|
end
|
@@ -46,7 +36,7 @@ describe 'roda-route_list plugin' do
|
|
46
36
|
end
|
47
37
|
|
48
38
|
it "should correctly parse the routes from the json file" do
|
49
|
-
@app.route_list.
|
39
|
+
@app.route_list.must_equal [
|
50
40
|
{:path=>'/foo'},
|
51
41
|
{:path=>'/foo/bar', :name=>:bar},
|
52
42
|
{:path=>'/foo/baz', :methods=>[:GET]},
|
@@ -58,51 +48,51 @@ describe 'roda-route_list plugin' do
|
|
58
48
|
@app = Class.new(Roda)
|
59
49
|
@app.opts[:root] = 'spec'
|
60
50
|
@app.plugin :route_list, :file=>'routes2.json'
|
61
|
-
@app.route_list.
|
51
|
+
@app.route_list.must_equal [{:path=>'/foo'}]
|
62
52
|
end
|
63
53
|
|
64
|
-
it ".
|
65
|
-
@app.
|
66
|
-
@app.
|
54
|
+
it ".listed_route should return path for route" do
|
55
|
+
@app.listed_route(:bar).must_equal '/foo/bar'
|
56
|
+
@app.listed_route(:quux).must_equal '/foo/baz/quux/:quux_id'
|
67
57
|
end
|
68
58
|
|
69
|
-
it ".
|
70
|
-
@app.
|
59
|
+
it ".listed_route should return path for route when given a values hash" do
|
60
|
+
@app.listed_route(:quux, :quux_id=>3).must_equal '/foo/baz/quux/3'
|
71
61
|
end
|
72
62
|
|
73
|
-
it ".
|
74
|
-
@app.
|
63
|
+
it ".listed_route should return path for route when given a values array" do
|
64
|
+
@app.listed_route(:quux, [3]).must_equal '/foo/baz/quux/3'
|
75
65
|
end
|
76
66
|
|
77
|
-
it ".
|
78
|
-
proc{@app.
|
67
|
+
it ".listed_route should raise RodaError if there is no matching route" do
|
68
|
+
proc{@app.listed_route(:foo)}.must_raise(Roda::RodaError)
|
79
69
|
end
|
80
70
|
|
81
|
-
it ".
|
82
|
-
proc{@app.
|
71
|
+
it ".listed_route should raise RodaError if there is no matching value when using a values hash" do
|
72
|
+
proc{@app.listed_route(:quux, {})}.must_raise(Roda::RodaError)
|
83
73
|
end
|
84
74
|
|
85
|
-
it ".
|
86
|
-
proc{@app.
|
75
|
+
it ".listed_route should raise RodaError if there is no matching value when using a values array" do
|
76
|
+
proc{@app.listed_route(:quux, [])}.must_raise(Roda::RodaError)
|
87
77
|
end
|
88
78
|
|
89
|
-
it ".
|
90
|
-
proc{@app.
|
79
|
+
it ".listed_route should raise RodaError if there are too many values when using a values array" do
|
80
|
+
proc{@app.listed_route(:quux, [3, 1])}.must_raise(Roda::RodaError)
|
91
81
|
end
|
92
82
|
|
93
83
|
it "should allow parsing routes from a separate file" do
|
94
84
|
@app.plugin :route_list, :file=>'spec/routes2.json'
|
95
|
-
@app.route_list.
|
85
|
+
@app.route_list.must_equal [{:path=>'/foo'}]
|
96
86
|
end
|
97
87
|
|
98
|
-
it "#
|
99
|
-
body('bar').
|
88
|
+
it "#listed_route should work" do
|
89
|
+
body('bar').must_equal '/foo/bar'
|
100
90
|
end
|
101
91
|
|
102
|
-
it "#
|
92
|
+
it "#listed_route should respect :add_script_name option" do
|
103
93
|
@app.opts[:add_script_name] = true
|
104
|
-
body('bar').
|
105
|
-
body('bar', 'SCRIPT_NAME'=>'/a').
|
94
|
+
body('bar').must_equal '/foo/bar'
|
95
|
+
body('bar', 'SCRIPT_NAME'=>'/a').must_equal '/a/foo/bar'
|
106
96
|
end
|
107
97
|
end
|
108
98
|
|
@@ -112,8 +102,8 @@ describe 'roda-route_parser executable' do
|
|
112
102
|
end
|
113
103
|
|
114
104
|
it "should correctly parse the routes" do
|
115
|
-
system(ENV['RUBY'], "bin/roda-parse_routes", "-f", "spec/routes-example.json", "spec/routes.example")
|
116
|
-
File.file?("spec/routes-example.json").
|
117
|
-
JSON.parse(File.read('spec/routes-example.json')).
|
105
|
+
system(ENV['RUBY'] || 'ruby', "bin/roda-parse_routes", "-f", "spec/routes-example.json", "spec/routes.example")
|
106
|
+
File.file?("spec/routes-example.json").must_equal true
|
107
|
+
JSON.parse(File.read('spec/routes-example.json')).must_equal JSON.parse(File.read('spec/routes.json'))
|
118
108
|
end
|
119
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda-route_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roda
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
description: |
|
42
42
|
Roda, like other routing tree web frameworks, doesn't have the ability
|
43
43
|
to introspect routes. roda-route_list offers a way to specify a json
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.5.1
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: List routes when using Roda
|