shutl_resource 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ shutl_resource
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p429
@@ -81,6 +81,11 @@ module Shutl::Resource
81
81
  response_object = response.parsed_response[@resource_name.pluralize].map do |h|
82
82
  new_object(args.merge(h), response)
83
83
  end
84
+ if order_collection?
85
+ response_object.sort! do |a,b|
86
+ a.send(@order_collection_by) <=> b.send(@order_collection_by)
87
+ end
88
+ end
84
89
  RestCollection.new(response_object, response.parsed_response['pagination'])
85
90
  end
86
91
 
@@ -139,6 +144,10 @@ module Shutl::Resource
139
144
  @remote_resource_url = url
140
145
  end
141
146
 
147
+ def order_collection_by(field)
148
+ @order_collection_by = field
149
+ end
150
+
142
151
  def convert_new_id attributes
143
152
  if attributes[:new_id]
144
153
  attributes = attributes.clone.tap { |h| h[:id] = h[:new_id]; h.delete(:new_id) }
@@ -255,6 +264,10 @@ module Shutl::Resource
255
264
  url
256
265
  end
257
266
 
267
+ def order_collection?
268
+ !!@order_collection_by
269
+ end
270
+
258
271
  private
259
272
  def replace_args_from_pattern! args, url
260
273
  args = args.reject! do |key, value|
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '0.9.4'
3
+ VERSION = '0.10.0'
4
4
  end
5
5
  end
@@ -109,11 +109,14 @@ describe Shutl::Resource::Rest do
109
109
  describe '#all' do
110
110
 
111
111
  context 'with no arguments' do
112
- before do
113
- body = '{
112
+ let(:body) do
113
+ '{
114
114
  "test_rests": [{ "a": "a", "b": 2 }],
115
115
  "pagination":{"page": 0,"items_on_page": 1,"total_count": 3, "number_of_pages": 3}
116
116
  }'
117
+ end
118
+
119
+ before do
117
120
  @request = stub_request(:get, 'http://host/test_rests').
118
121
  to_return(:status => 200, :body => body, :headers => headers)
119
122
  end
@@ -152,6 +155,27 @@ describe Shutl::Resource::Rest do
152
155
  lambda { TestRest.all }.should raise_error(Shutl::ForbiddenAccess)
153
156
 
154
157
  end
158
+
159
+ context 'ordering the collection' do
160
+ let(:body) do
161
+ '{
162
+ "test_rests": [{ "name": "d" }, {"name": "e"}, {"name": "a"}],
163
+ "pagination":{"page": 0,"items_on_page": 1,"total_count": 3, "number_of_pages": 3}
164
+ }'
165
+ end
166
+
167
+ before do
168
+ TestRest.order_collection_by :name
169
+ end
170
+
171
+ after do
172
+ TestRest.instance_variable_set(:@order_collection_by, nil)
173
+ end
174
+
175
+ it 're-orders the result' do
176
+ TestRest.all.map(&:name).should == %w(a d e)
177
+ end
178
+ end
155
179
  end
156
180
 
157
181
  context 'with no arguments' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-06-18 00:00:00.000000000 Z
14
+ date: 2013-07-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -135,8 +135,9 @@ extensions: []
135
135
  extra_rdoc_files: []
136
136
  files:
137
137
  - .gitignore
138
- - .rbenv-version
139
138
  - .rspec
139
+ - .ruby-gemset
140
+ - .ruby-version
140
141
  - .travis.yml
141
142
  - Gemfile
142
143
  - LICENSE
@@ -171,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
172
  version: '0'
172
173
  segments:
173
174
  - 0
174
- hash: 988710357628793965
175
+ hash: -1118351529069476530
175
176
  required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  none: false
177
178
  requirements:
@@ -180,10 +181,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  segments:
182
183
  - 0
183
- hash: 988710357628793965
184
+ hash: -1118351529069476530
184
185
  requirements: []
185
186
  rubyforge_project:
186
- rubygems_version: 1.8.25
187
+ rubygems_version: 1.8.23
187
188
  signing_key:
188
189
  specification_version: 3
189
190
  summary: Manage Shutl Rest resource. Parse/Serialize JSON
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p327-perf