nested 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55bc0e32ebd2026fff78d9f51d3442b566644d8c
4
- data.tar.gz: 258a00be59fff86245c67a1a229de723e94b28e3
3
+ metadata.gz: 7063cd0594194d6e5f4036d64efe0bc45f6ed93c
4
+ data.tar.gz: 4c9f893b97e071121ac3b48e8e75e650f72b75ef
5
5
  SHA512:
6
- metadata.gz: d6059be129db9adc1bd3d1b97590427029c19e15852570875cfa460577fd9421ece0ab5ece5c57edff733f3e11af10d96661278383eddeabf03b716003b772df
7
- data.tar.gz: f70c325da379d55242d92ca7cd06f3bf9f2abfc3c86fe87514b01b4d125e5e1edce99e5e1e27b0c2843eb10e0a2d7b0952c830f1389f179aeddb2f2bd4314bee
6
+ metadata.gz: f5cb48d77b00da7a4289cb9ea3d0ac6da5a78f035cb801d370e2830044bd540e8ecc7eff38f0c9946c299ef258156e0b54570b6d8559c3378c8ecb275864135b
7
+ data.tar.gz: 84d5537846238eb86517ad44145134a423112b572659689f6eaf28341bce9530e936b34806d1acbbede9ece32b6c4310c711e4e266f26610a1912ba69ad31073
data/lib/nested.rb CHANGED
@@ -179,28 +179,36 @@ module Nested
179
179
  end
180
180
 
181
181
  def sinatra_exec_get_block(sinatra, &block)
182
- sinatra.instance_exec(&block)
182
+ sinatra_init_data(:get, sinatra, &block)
183
+ sinatra.instance_exec(*sinatra.instance_variable_get("@__data"), &block)
183
184
  end
184
185
 
185
186
  def sinatra_exec_delete_block(sinatra, &block)
186
- sinatra.instance_exec(&block)
187
+ sinatra_init_data(:delete, sinatra, &block)
188
+ sinatra.instance_exec(*sinatra.instance_variable_get("@__data"), &block)
187
189
  end
188
190
 
189
- def sinatra_init_data(sinatra, &block)
190
- sinatra.request.body.rewind
191
- raw_data = HashWithIndifferentAccess.new(JSON.parse(sinatra.request.body.read))
191
+ def sinatra_init_data(method, sinatra, &block)
192
+ raw_data = if [:put, :post].include?(method)
193
+ sinatra.request.body.rewind
194
+ HashWithIndifferentAccess.new(JSON.parse(sinatra.request.body.read))
195
+ elsif [:get, :delete].include?(method)
196
+ sinatra.params
197
+ else
198
+ {}
199
+ end
192
200
 
193
201
  sinatra.instance_variable_set("@__raw_data", raw_data)
194
202
  sinatra.instance_variable_set("@__data", raw_data.values_at(*block.parameters.map(&:last)))
195
203
  end
196
204
 
197
205
  def sinatra_exec_put_block(sinatra, &block)
198
- sinatra_init_data(sinatra, &block)
206
+ sinatra_init_data(:put, sinatra, &block)
199
207
  sinatra.instance_exec(*sinatra.instance_variable_get("@__data"), &block)
200
208
  end
201
209
 
202
210
  def sinatra_exec_post_block(sinatra, &block)
203
- sinatra_init_data(sinatra, &block)
211
+ sinatra_init_data(:post, sinatra, &block)
204
212
  res = sinatra.instance_exec(*sinatra.instance_variable_get("@__data"), &block)
205
213
  sinatra.instance_variable_set("@#{self.instance_variable_name}", res)
206
214
  end
@@ -241,7 +249,7 @@ module Nested
241
249
  end
242
250
 
243
251
  def create_sinatra_route(method, action, &block)
244
- @actions << {method: method, action: action}
252
+ @actions << {method: method, action: action, block: block}
245
253
 
246
254
  resource = self
247
255
 
@@ -285,7 +293,8 @@ module Nested
285
293
 
286
294
  def angular_add_functions(js, resource)
287
295
  resource.actions.each do |e|
288
- method, action = e.values_at :method, :action
296
+ method, action, block = e.values_at :method, :action, :block
297
+ block_args = block.parameters.map(&:last)
289
298
 
290
299
  fun_name = Nested::JsUtil::generate_function_name(resource, method, action)
291
300
 
@@ -300,10 +309,16 @@ module Nested
300
309
  when_args = args.map{|a| "$q.when(#{a})"}
301
310
 
302
311
  if [:get, :delete].include?(method)
312
+ args << "data" if !block_args.empty?
313
+
303
314
  js << " impl.#{fun_name} = function(#{args.join(',')}){"
304
315
  js << " var deferred = $q.defer()"
305
316
  js << " $q.all([#{when_args.join(',')}]).then(function(values){"
306
- js << " $http({method: '#{method}', url: '#{route}'})"
317
+ js << " $http({"
318
+ js << " method: '#{method}', "
319
+ js << (" url: '#{route}'" + (block_args.empty? ? "" : ","))
320
+ js << " params: data" unless block_args.empty?
321
+ js << " })"
307
322
  js << " .success(function(responseData){"
308
323
  js << " deferred[responseData.ok ? 'resolve' : 'reject'](responseData.data)"
309
324
  js << " })"
@@ -324,7 +339,7 @@ module Nested
324
339
  js << " return deferred.promise"
325
340
  js << " }"
326
341
  elsif method == :put
327
- args << "data" if args.empty?
342
+ args << "data" if args.empty? || !block_args.empty?
328
343
 
329
344
  js << " impl.#{fun_name} = function(#{args.join(',')}){"
330
345
  js << " var deferred = $q.defer()"
data/nested.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nested"
3
- s.version = "0.0.13"
3
+ s.version = "0.0.14"
4
4
 
5
5
  s.authors = ["Jan Zimmek"]
6
6
  s.email = %q{jan.zimmek@web.de}
data/test/nested_test.rb CHANGED
@@ -294,20 +294,21 @@ class NestedTest < Test::Unit::TestCase
294
294
  singleton!
295
295
 
296
296
  @sinatra.expects(:send).with(:get, "/project")
297
- @r.create_sinatra_route(:get, nil) { }
298
- assert_equal [{method: :get, action: nil}], @r.actions
297
+ block = ->{ }
298
+ @r.create_sinatra_route(:get, nil, &block)
299
+ assert_equal [{method: :get, action: nil, block: block}], @r.actions
299
300
 
300
301
  singleton!
301
302
 
302
303
  @sinatra.expects(:send).with(:post, "/project")
303
- @r.create_sinatra_route(:post, nil) { }
304
- assert_equal [{method: :post, action: nil}], @r.actions
304
+ @r.create_sinatra_route(:post, nil, &block)
305
+ assert_equal [{method: :post, action: nil, block: block}], @r.actions
305
306
 
306
307
  singleton!
307
308
 
308
309
  @sinatra.expects(:send).with(:post, "/project/action")
309
- @r.create_sinatra_route(:post, :action) { }
310
- assert_equal [{method: :post, action: :action}], @r.actions
310
+ @r.create_sinatra_route(:post, :action, &block)
311
+ assert_equal [{method: :post, action: :action, block: block}], @r.actions
311
312
  end
312
313
 
313
314
  def test_serializer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2013-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport