described_routes 0.3.4 → 0.3.5

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.
data/History.txt CHANGED
@@ -1,52 +1,48 @@
1
+
2
+ * Framework-neutral metadata describing Rails routes in JSON, YAML, XML and plain text formats.
3
+ * Please comment on the roadmap at http://positiveincline.com/?p=213
4
+
5
+ == 0.3.5 2009-05-06
6
+
7
+ * make it possible to customise the data collected from Rails
8
+
1
9
  == 0.3.4 2009-05-06
2
10
 
3
- * Please comment on roadmap at http://positiveincline.com/?p=213 !
4
- * 2 minor enhancements:
5
- * optional BASE parameter: rake described_routes:<format> BASE=http://...
6
- * added test_rails_app subproject, included in main project's tests
11
+ * optional BASE parameter: rake described_routes:<format> BASE=http://...
12
+ * added test_rails_app subproject, included in main project's tests
7
13
 
8
14
  == 0.3.3 2009-05-05
9
15
 
10
- * Please comment on roadmap at http://positiveincline.com/?p=213 !
11
- * 1 minor fix:
12
- * fix controller for YAML output
16
+ * fix controller for YAML output
13
17
 
14
18
  == 0.3.0 2009-05-03
15
19
 
16
- * 1 major enhancement:
17
- * text output:
18
- * rake described_routes:text
19
- * curl <app>/described_routes.txt
20
+ * text output:
21
+ * rake described_routes:text
22
+ * curl <app>/described_routes.txt
20
23
 
21
24
  == 0.2.1 2009-04-29
22
25
 
23
- * 1 minor fix:
24
- * fix uri_template export, update test fixiture
26
+ * fix uri_template export, update test fixiture
25
27
 
26
28
  == 0.2.1 2009-04-29
27
29
 
28
- * 1 minor fix:
29
- * reinstate params in json and yaml formats
30
+ * reinstate params in json and yaml formats
30
31
 
31
32
  == 0.2.0 2009-04-29
32
33
 
33
- * 1 minor enhancement:
34
- * add show method to controller
35
- * other:
36
- * add tests
37
- * refactoring
34
+ * add show method to controller
35
+ * add tests
36
+ * refactoring
38
37
 
39
38
  == 0.1.1 2009-04-28
40
39
 
41
- * 1 minor enhancement:
42
- * include uri_template elements in XML
40
+ * include uri_template elements in XML
43
41
 
44
42
  == 0.1.0 2009-04-24
45
43
 
46
- * 1 major enhancement:
47
- * added Rails controller
44
+ * added Rails controller
48
45
 
49
46
  == 0.0.1 2009-04-24
50
47
 
51
- * 1 major enhancement:
52
- * Initial release
48
+ * Initial release
data/Manifest.txt CHANGED
@@ -39,6 +39,7 @@ test_rails_app/test/fixtures/build_time/described_routes.text
39
39
  test_rails_app/test/fixtures/build_time/described_routes.xml
40
40
  test_rails_app/test/fixtures/build_time/described_routes.yaml
41
41
  test_rails_app/test/fixtures/build_time/described_routes.yaml_short
42
+ test_rails_app/test/fixtures/build_time/described_routes.yaml_short_no_admin
42
43
  test_rails_app/test/fixtures/run_time/described_routes.json
43
44
  test_rails_app/test/fixtures/run_time/described_routes.text
44
45
  test_rails_app/test/fixtures/run_time/described_routes.xml
data/README.rdoc CHANGED
@@ -1,6 +1,8 @@
1
1
  = described_routes README
2
2
 
3
- Note to reader: Please comment on the roadmap at http://positiveincline.com/?p=213
3
+ Framework-neutral descriptions of Rails routes in JSON, YAML, XML and plain text formats.
4
+
5
+ Please comment on the roadmap at http://positiveincline.com/?p=213
4
6
 
5
7
  == DESCRIPTION:
6
8
 
@@ -25,8 +27,7 @@ Then:
25
27
 
26
28
  The text output looks like this:
27
29
 
28
- $ rake described_routes:text
29
- (in /Users/asplake/railsapps/testapp)
30
+ $ rake --silent described_routes:text
30
31
  root root /
31
32
  admin_products admin_products GET, POST /admin/products{-prefix|.|format}
32
33
  new_admin_product new_admin_product GET /admin/products/new{-prefix|.|format}
@@ -136,6 +137,14 @@ This follows the natural structure but with the following modifications:
136
137
 
137
138
  Calls to parse_xml will at present result in NoMethodError exceptions being raised.
138
139
 
140
+ == CUSTOMISATION
141
+
142
+ It is possible to customise the data collected from Rails, for example to hide sensitive routes:
143
+
144
+ DescribedRoutes::RailsRoutes.parsed_hook = lambda {|a| a.reject{|h| h["name"] =~ /^admin/}}
145
+
146
+ This hook operates on the raw "parsed" (Array/Hash) data before conversion to ResourceTemplate objects.
147
+
139
148
  == REQUIREMENTS:
140
149
 
141
150
  Rails, for the Rake tasks and Rails controller. The ResourceTemplate class and its formats are however Rails-independent.
data/Rakefile CHANGED
@@ -36,5 +36,6 @@ task :test do
36
36
  end
37
37
 
38
38
  task :clean do
39
- Dir.chdir("test_rails_app"){ sh "rake log:clear tmp:clear" }
39
+ rubyopt = "-I#{File.dirname(__FILE__) + '/lib'} #{ENV['RUBYOPT']}"
40
+ Dir.chdir("test_rails_app"){ sh "RUBYOPT=\"#{rubyopt}\" rake log:clear tmp:clear" }
40
41
  end
@@ -2,11 +2,21 @@ require 'described_routes/resource_template'
2
2
 
3
3
  module DescribedRoutes
4
4
  module RailsRoutes
5
+
6
+ #
7
+ # Hook to customise the "parsed" (Array/Hash) data. For example, to remove certain sensitive routes:
8
+ #
9
+ # DescribedRoutes::RailsRoutes.parsed_hook = lambda {|a| a.reject{|h| h["name"] =~ /^admin/}}
10
+ #
11
+ mattr_accessor :parsed_hook
12
+
5
13
  #
6
14
  # Process Rails routes and return an array of DescribedRoutes::ResourceTemplate objects
7
15
  #
8
16
  def self.get_resource_templates(base_url = nil)
9
- DescribedRoutes::ResourceTemplate.from_parsed(get_parsed_rails_resources(base_url))
17
+ parsed = get_parsed_rails_resources(base_url)
18
+ parsed = parsed_hook.call(parsed) if parsed_hook
19
+ DescribedRoutes::ResourceTemplate.from_parsed(parsed)
10
20
  end
11
21
 
12
22
  #
@@ -2,5 +2,5 @@ require 'described_routes/resource_template'
2
2
 
3
3
  module DescribedRoutes
4
4
  # rubygem version
5
- VERSION = "0.3.4"
5
+ VERSION = "0.3.5"
6
6
  end
@@ -0,0 +1,62 @@
1
+ ---
2
+ - name: root
3
+ path_template: /
4
+ - name: described_routes
5
+ - name: new_described_route
6
+ path_template: /described_routes/new{-prefix|.|format}
7
+ rel: new_described_route
8
+ - name: described_route
9
+ - name: edit_described_route
10
+ path_template: /described_routes/{route_name}/edit{-prefix|.|format}
11
+ rel: edit
12
+ path_template: /described_routes/{route_name}{-prefix|.|format}
13
+ path_template: /described_routes{-prefix|.|format}
14
+ - name: pages
15
+ - name: new_page
16
+ path_template: /pages/new{-prefix|.|format}
17
+ rel: new_page
18
+ - name: page
19
+ - name: edit_page
20
+ path_template: /pages/{page_id}/edit{-prefix|.|format}
21
+ rel: edit
22
+ - name: summary_page
23
+ path_template: /pages/{page_id}/summary{-prefix|.|format}
24
+ rel: summary
25
+ - name: toggle_visibility_page
26
+ path_template: /pages/{page_id}/toggle_visibility{-prefix|.|format}
27
+ rel: toggle_visibility
28
+ path_template: /pages/{page_id}{-prefix|.|format}
29
+ path_template: /pages{-prefix|.|format}
30
+ - name: users
31
+ - name: new_user
32
+ path_template: /users/new{-prefix|.|format}
33
+ rel: new_user
34
+ - name: user
35
+ - name: edit_user
36
+ path_template: /users/{user_id}/edit{-prefix|.|format}
37
+ rel: edit
38
+ - name: user_articles
39
+ - name: new_user_article
40
+ path_template: /users/{user_id}/articles/new{-prefix|.|format}
41
+ rel: new_user_article
42
+ - name: recent_user_articles
43
+ path_template: /users/{user_id}/articles/recent{-prefix|.|format}
44
+ rel: recent
45
+ - name: user_article
46
+ - name: edit_user_article
47
+ path_template: /users/{user_id}/articles/{article_id}/edit{-prefix|.|format}
48
+ rel: edit
49
+ path_template: /users/{user_id}/articles/{article_id}{-prefix|.|format}
50
+ path_template: /users/{user_id}/articles{-prefix|.|format}
51
+ rel: articles
52
+ - name: user_profile
53
+ - name: edit_user_profile
54
+ path_template: /users/{user_id}/profile/edit{-prefix|.|format}
55
+ rel: edit
56
+ - name: new_user_profile
57
+ path_template: /users/{user_id}/profile/new{-prefix|.|format}
58
+ rel: new
59
+ path_template: /users/{user_id}/profile{-prefix|.|format}
60
+ rel: profile
61
+ path_template: /users/{user_id}{-prefix|.|format}
62
+ path_template: /users{-prefix|.|format}
@@ -3,6 +3,14 @@ require 'test/test_helper'
3
3
  require 'described_routes/rake_task_methods'
4
4
 
5
5
  class RakeTasksTest < Test::Unit::TestCase
6
+ def setup
7
+ DescribedRoutes::RailsRoutes.parsed_hook = nil
8
+ end
9
+
10
+ def teardown
11
+ DescribedRoutes::RailsRoutes.parsed_hook = nil
12
+ end
13
+
6
14
  def read_fixture(extension)
7
15
  File.read(File.dirname(__FILE__) + '/../fixtures/build_time/described_routes.' + extension)
8
16
  end
@@ -26,4 +34,9 @@ class RakeTasksTest < Test::Unit::TestCase
26
34
  def test_xml
27
35
  assert_equal(read_fixture("xml"), DescribedRoutes::RakeTaskMethods.xml)
28
36
  end
37
+
38
+ def test_parsed_hook
39
+ DescribedRoutes::RailsRoutes.parsed_hook = lambda {|a| a.reject{|h| h["name"] =~ /^admin/}}
40
+ assert_equal(read_fixture("yaml_short_no_admin"), DescribedRoutes::RakeTaskMethods.yaml_short)
41
+ end
29
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: described_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Burrows
@@ -86,6 +86,7 @@ files:
86
86
  - test_rails_app/test/fixtures/build_time/described_routes.xml
87
87
  - test_rails_app/test/fixtures/build_time/described_routes.yaml
88
88
  - test_rails_app/test/fixtures/build_time/described_routes.yaml_short
89
+ - test_rails_app/test/fixtures/build_time/described_routes.yaml_short_no_admin
89
90
  - test_rails_app/test/fixtures/run_time/described_routes.json
90
91
  - test_rails_app/test/fixtures/run_time/described_routes.text
91
92
  - test_rails_app/test/fixtures/run_time/described_routes.xml