lazy_resource 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,6 +40,14 @@ module LazyResource
40
40
  @site = site
41
41
  end
42
42
 
43
+ def from
44
+ @from
45
+ end
46
+
47
+ def from=(from)
48
+ @from = from
49
+ end
50
+
43
51
  def request_queue
44
52
  Thread.current[:request_queue] ||= Typhoeus::Hydra.new
45
53
  end
@@ -51,6 +51,7 @@ module LazyResource
51
51
  # +query_options+ - A \hash to add items to the query string for the request.
52
52
  def element_path(id, prefix_options = {}, query_options = nil, from = nil)
53
53
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
54
+ from = self.from if from.nil? && respond_to?(:from)
54
55
  "#{prefix(prefix_options)}#{from || collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
55
56
  end
56
57
 
@@ -60,6 +61,7 @@ module LazyResource
60
61
  # * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
61
62
  # would yield a URL like <tt>/accounts/19/purchases/new.json</tt>).
62
63
  def new_element_path(prefix_options = {}, from = nil)
64
+ from = self.from if from.nil? && respond_to?(:from)
63
65
  "#{prefix(prefix_options)}#{from || collection_name}/new"
64
66
  end
65
67
 
@@ -72,6 +74,7 @@ module LazyResource
72
74
  # * +query_options+ - A hash to add items to the query string for the request.
73
75
  def collection_path(prefix_options = {}, query_options = nil, from = nil)
74
76
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
77
+ from = self.from if from.nil? && respond_to?(:from)
75
78
  "#{prefix(prefix_options)}#{from || collection_name}#{query_string(query_options)}"
76
79
  end
77
80
 
@@ -1,3 +1,3 @@
1
1
  module LazyResource
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -356,6 +356,46 @@ describe LazyResource::Resource do
356
356
  end
357
357
  end
358
358
 
359
+ describe '.from' do
360
+ before :each do
361
+ @from = User.from
362
+ end
363
+
364
+ after :each do
365
+ User.from = @from
366
+ end
367
+
368
+ it 'returns the from value if set' do
369
+ User.from = 'people'
370
+ User.from.should == 'people'
371
+ end
372
+
373
+ it 'uses the from value to generate a collection path' do
374
+ User.from = 'people'
375
+ User.collection_path.should == '/people'
376
+ end
377
+
378
+ it 'uses the from value to generate an element path' do
379
+ User.from = 'people'
380
+ User.element_path(1).should == '/people/1'
381
+ end
382
+ end
383
+
384
+ describe '.from=' do
385
+ before :each do
386
+ @from = User.from
387
+ end
388
+
389
+ after :each do
390
+ User.from = @from
391
+ end
392
+
393
+ it 'sets the from value' do
394
+ User.from = 'people'
395
+ User.from.should == 'people'
396
+ end
397
+ end
398
+
359
399
  describe '.root_node_name=' do
360
400
  before :each do
361
401
  LazyResource::Mapping.root_node_name = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: -143928251561470554
135
+ hash: 1026372521155159703
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: -143928251561470554
144
+ hash: 1026372521155159703
145
145
  requirements: []
146
146
  rubyforge_project:
147
147
  rubygems_version: 1.8.24