described_routes 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/described_routes.rb
CHANGED
@@ -2,7 +2,7 @@ require 'described_routes/resource_template'
|
|
2
2
|
|
3
3
|
module DescribedRoutes
|
4
4
|
# rubygem version
|
5
|
-
VERSION = "0.0
|
5
|
+
VERSION = "0.1.0"
|
6
6
|
|
7
7
|
# Convert an array of ResourceTemplate objects to array of hashes equivalent to their JSON or YAML representations
|
8
8
|
def self.to_parsed(resource_templates)
|
@@ -81,7 +81,7 @@ module DescribedRoutes
|
|
81
81
|
#
|
82
82
|
# Takes the routes from Rails and produces the required tree structure.
|
83
83
|
#
|
84
|
-
def self.get_resources
|
84
|
+
def self.get_resources(base_url = nil)
|
85
85
|
resources = get_rails_resources
|
86
86
|
resources.delete_if{|k, v| v["name"].blank? or v["name"] =~ /^formatted/}
|
87
87
|
|
@@ -93,6 +93,7 @@ module DescribedRoutes
|
|
93
93
|
resource = resources[key]
|
94
94
|
resource["resource_templates"] = children unless children.empty?
|
95
95
|
resource.delete("options") if resource["options"] == [""]
|
96
|
+
resource["uri_template"] = base_url + resource["path_template"] if base_url && resource["path_template"]
|
96
97
|
|
97
98
|
# compare parent and child names, and populate "rel" with either
|
98
99
|
# 1) a prefix (probably an action name)
|
@@ -12,6 +12,9 @@ module DescribedRoutes
|
|
12
12
|
# Collection members generally don't need a rel as they are identified by their params
|
13
13
|
attr_reader :rel
|
14
14
|
|
15
|
+
# A template for generating URIs.
|
16
|
+
attr_reader :uri_template
|
17
|
+
|
15
18
|
# A template for generating paths relative to the application's base.
|
16
19
|
attr_reader :path_template
|
17
20
|
|
@@ -28,8 +31,8 @@ module DescribedRoutes
|
|
28
31
|
attr_reader :resource_templates
|
29
32
|
|
30
33
|
# Initialize a ResourceTemplate. See the attribute descriptions above for explanations of the parameters.
|
31
|
-
def initialize(name, rel, path_template, params, optional_params, options, resource_templates)
|
32
|
-
@name, @rel, @path_template = name, rel, path_template
|
34
|
+
def initialize(name, rel, uri_template, path_template, params, optional_params, options, resource_templates)
|
35
|
+
@name, @rel, @uri_template, @path_template = name, rel, uri_template, path_template
|
33
36
|
@params = params || []
|
34
37
|
@optional_params = optional_params || []
|
35
38
|
@options = options || []
|
@@ -38,7 +41,7 @@ module DescribedRoutes
|
|
38
41
|
|
39
42
|
# Create a ResourceTemplate from its Hash representation
|
40
43
|
def self.from_hash(hash)
|
41
|
-
attributes = %w(name rel path_template params optional_params options).map{|k| hash[k]}
|
44
|
+
attributes = %w(name rel uri_template path_template params optional_params options).map{|k| hash[k]}
|
42
45
|
if hash["resource_templates"]
|
43
46
|
attributes << hash["resource_templates"].map{|h| from_hash(h)} if hash["resource_templates"]
|
44
47
|
else
|
@@ -52,6 +55,7 @@ module DescribedRoutes
|
|
52
55
|
hash = {}
|
53
56
|
hash["name"] = name if name && !name.empty?
|
54
57
|
hash["rel"] = rel if rel && !rel.empty?
|
58
|
+
hash["uri_template"] = path_template if uri_template && !path_template.empty?
|
55
59
|
hash["path_template"] = path_template if path_template && !path_template.empty?
|
56
60
|
|
57
61
|
hash["options"] = options if options && !options.empty?
|
@@ -16,7 +16,7 @@ namespace :described_routes do
|
|
16
16
|
|
17
17
|
desc "Describe resource structure in YAML format (basic structure only)"
|
18
18
|
task :yaml_short => :environment do
|
19
|
-
puts DescribedRoutes::RailsRoutes.get_resources.to_yaml.grep(/name|rel|path_template|resources
|
19
|
+
puts DescribedRoutes::RailsRoutes.get_resources.to_yaml.grep(/(name|rel|path_template|uri_template|resources):|^---/)
|
20
20
|
end
|
21
21
|
|
22
22
|
desc "Describe resource structure in XML format"
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Burrows
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-28 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|