nested 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -50
  3. data/lib/nested.rb +19 -3
  4. data/nested.gemspec +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e59bb33223f6b09ae1e78f0af958533f430ff90c
4
- data.tar.gz: 9fedc4f9b0557ffe08afa28c40262499c01cf65a
3
+ metadata.gz: 7505747ad7eac679ad8c41141fb048f60dd62144
4
+ data.tar.gz: 4df39444b401cc046ca9df82b9e7702b6c512954
5
5
  SHA512:
6
- metadata.gz: 25a5e634ad799ece06b774dac6fb596e784b1e0efa367aeae6e3b8901b979239b000b94a41d40ca572fcc5613471de2de7f8e1dc2ca557509518cb6030ee0d8b
7
- data.tar.gz: dccf00f2fa6b24baa29f48cd36a597020604f16c3b73aaabb3c66330d54bd4a222dcae16e117d10097c6197580cef02b09a3764d2d92aa784af8fa286ff0d5cb
6
+ metadata.gz: 3b9ff324edd1ea97db727208c6a974e35b6a66f895a56fcc1da45038237d90ecbd602bc0c1bb5df9bca65f83b20c4a5654a8dd2722e08096b4b027920204ff77
7
+ data.tar.gz: 42f0520f7569731de9476208831e07372c29a5045c8b142ac0909cb55a032114b788602f97a23c387ebce5bc2191647204011b8877460c65501851e739dc58ff
data/README.md CHANGED
@@ -1,51 +1,4 @@
1
- # Nested
2
- Nested is an opinionated Domain Specific Language (DSL) to implement RESTful APIs.
1
+ nested
2
+ ======
3
3
 
4
- ## Philosophy
5
- - convention of configuration
6
- - honor exiting defacto standards
7
-
8
- ## Getting Started
9
- ```
10
- class TodoApp < Sinatra::Base
11
-
12
- many :projects do
13
- get
14
-
15
- one do
16
- many :tasks do
17
- get
18
-
19
- one do
20
- get
21
- end
22
- end
23
-
24
- singleton :creator, ->{ @project.creator } do
25
- get
26
- end
27
- end
28
-
29
- end
30
-
31
- singleton :user, ->{ User.current } do
32
- get
33
- end
34
- end
35
- ```
36
-
37
- ## Building Blocks
38
-
39
- ### Singleton
40
- Lorem ipsum dolor sit amet, consectetur adipisicing elit.
41
-
42
- ### Many
43
- Lorem ipsum dolor sit amet, consectetur adipisicing elit.
44
-
45
- ### One
46
- Lorem ipsum dolor sit amet, consectetur adipisicing elit.
47
-
48
-
49
-
50
- ## Credits
51
- Nested is using the fantastic Sinatra framework under the hood.
4
+ a nestable dsl to create a restful api
data/lib/nested.rb CHANGED
@@ -233,7 +233,12 @@ module Nested
233
233
  end
234
234
 
235
235
  def sinatra_response(sinatra, method)
236
- response = sinatra.instance_variable_get("@#{self.instance_variable_name}")
236
+ response = if sinatra.errors.empty?
237
+ sinatra.instance_variable_get("@#{self.instance_variable_name}")
238
+ else
239
+ sinatra.errors
240
+ end
241
+
237
242
  response = self.send(:"sinatra_response_create_#{sinatra_response_type(response)}", sinatra, response, method)
238
243
 
239
244
  case response
@@ -280,6 +285,15 @@ module Nested
280
285
  puts "sinatra router [#{method}] #{@sinatra.nested_config[:prefix]}#{route}"
281
286
 
282
287
  @sinatra.send(method, route) do
288
+
289
+ def self.error(message)
290
+ errors.add(:base, message)
291
+ end
292
+
293
+ def self.errors
294
+ @__errors ||= ActiveModel::Errors.new({})
295
+ end
296
+
283
297
  content_type :json
284
298
 
285
299
  resource.self_and_parents.reverse.each do |res|
@@ -394,7 +408,7 @@ module Nested
394
408
 
395
409
  module_name = "nested_#{resource.name}".camelcase(:lower)
396
410
 
397
- js << "angular.module('#{module_name}', ['ngResource'])"
411
+ js << "angular.module('#{module_name}', [])"
398
412
  js << ".factory('#{resource.name.to_s.camelcase.capitalize}#{nested_angular_config[:service_suffix]}', function($http, $q){"
399
413
 
400
414
  js << " var impl = {}"
@@ -403,9 +417,11 @@ module Nested
403
417
 
404
418
  js << "})"
405
419
 
420
+ response_transform = nested_angular_config[:response_transform] || ->(code){ code }
421
+
406
422
  get "/#{resource.name}.js" do
407
423
  content_type :js
408
- js.join("\n")
424
+ instance_exec(js.join("\n"), &response_transform)
409
425
  end
410
426
  end
411
427
  end
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.17"
3
+ s.version = "0.0.18"
4
4
 
5
5
  s.authors = ["Jan Zimmek"]
6
6
  s.email = %q{jan.zimmek@web.de}
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.17
4
+ version: 0.0.18
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-26 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport