path-to 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.5.1 2009-05-25
2
+
3
+ * More ResourceTemplate refactoring
4
+
1
5
  == 0.5.0 2009-05-20
2
6
 
3
7
  * Incorporate described_routes refactor (ResourceTemplate is now a top level class)
@@ -37,23 +37,14 @@ module PathTo
37
37
  end
38
38
 
39
39
  #
40
- # Get and cache the uri template from the resource tamplte
41
- #
42
- def uri_template
43
- @uri_template ||= resource_template.uri_template || (application.base + resource_template.path_template)
44
- end
45
-
46
- #
47
- # Create and cache the URI by filling in the URI template with params
40
+ # Creates and caches the URI by filling in the resource template's URI template with params
48
41
  #
49
42
  def uri
50
- @uri ||= begin
51
- Addressable::Template.new(uri_template).expand(params).to_s
52
- end
43
+ @uri ||= resource_template.uri_for(params, application.base)
53
44
  end
54
45
 
55
46
  #
56
- # Finds (once) the application in the parent hierarchy.
47
+ # Finds and caches the application in the parent hierarchy.
57
48
  #
58
49
  def application
59
50
  @application ||= parent.application if parent
@@ -76,10 +67,8 @@ module PathTo
76
67
  positional_params, params_hash = extract_params(args, params)
77
68
  known_keys = params_hash.keys
78
69
 
79
- child_resource_template = resource_template.resource_templates.detect do |t|
80
- if t.rel.nil?
81
- (t.positional_params(resource_template)[positional_params.length..-1] - t.optional_params - known_keys).empty?
82
- end
70
+ child_resource_template = resource_template.find_by_rel(nil).detect do |t|
71
+ (t.positional_params(resource_template)[positional_params.length..-1] - t.optional_params - known_keys).empty?
83
72
  end
84
73
 
85
74
  if child_resource_template
@@ -112,7 +101,7 @@ module PathTo
112
101
  # users("dojo", "format" => "json")
113
102
  #
114
103
  def method_missing(method, *args)
115
- child_resource_template = resource_template.resource_templates.detect{|t| t.rel == method.to_s}
104
+ child_resource_template = resource_template.find_by_rel(method.to_s).first
116
105
  if child_resource_template && (child_class = child_class_for(self, method, params, child_resource_template))
117
106
  positional_params, params_hash = extract_params(args, params)
118
107
  complete_params_hash!(params_hash, child_resource_template.positional_params(resource_template), positional_params)
@@ -155,9 +144,9 @@ module PathTo
155
144
  @resource_templates = options[:resource_templates]
156
145
  unless @resource_templates
157
146
  if (json = options[:json])
158
- @resource_templates = ResourceTemplate::ResourceTemplates.parse_json(json)
147
+ @resource_templates = ResourceTemplate::ResourceTemplates.new(JSON.parse(json))
159
148
  elsif (yaml = options[:yaml])
160
- @resource_templates = ResourceTemplate::ResourceTemplates.parse_yaml(yaml)
149
+ @resource_templates = ResourceTemplate::ResourceTemplates.new(YAML.load(yaml))
161
150
  elsif (xml = options[:xml])
162
151
  @resource_templates = ResourceTemplate::ResourceTemplates.parse_xml(xml)
163
152
  end
data/lib/path-to.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module PathTo
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
4
4
 
5
5
  $:.push File.dirname(__FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: path-to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Burrows (asplake)
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-22 00:00:00 +01:00
12
+ date: 2009-05-25 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency