yodatra 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/yodatra/models_controller.rb +23 -16
- data/lib/yodatra/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e006ebdfb069d9c91cd2c9309627500a53292eb
|
4
|
+
data.tar.gz: b1985c1d88db58d34ddcea1ab36dd34cc5c28f53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e49e4b3968858f06e20ba0593bc9231f4f0e114d86f1c4b8668ff44b6270a4bcf4daa09a427afe59da5a13229cedcb911d6f77e7a8084bf9a468d3790b4650b6
|
7
|
+
data.tar.gz: f5ed3b5319b89f81b2977a583e625378b6c6e0139e1dc89ab6e3054a8938f72581795a8d39e5ce16d65861c86855f45656cdff165b220b4e35919fa79094d31c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Yodatra
|
2
2
|
===
|
3
|
-
[![Build Status](https://travis-ci.org/squareteam/yodatra.png?branch=master)](https://travis-ci.org/squareteam/yodatra) [![Coverage Status](https://coveralls.io/repos/squareteam/yodatra/badge.png)](https://coveralls.io/r/squareteam/yodatra) [![Gem Version](https://badge.fury.io/rb/yodatra.png)](http://badge.fury.io/rb/yodatra) [![Code Climate](https://codeclimate.com/github/squareteam/yodatra.png)](https://codeclimate.com/github/squareteam/yodatra) [![Dependency Status](https://gemnasium.com/squareteam/
|
3
|
+
[![Build Status](https://travis-ci.org/squareteam/yodatra.png?branch=master)](https://travis-ci.org/squareteam/yodatra) [![Coverage Status](https://coveralls.io/repos/squareteam/yodatra/badge.png)](https://coveralls.io/r/squareteam/yodatra) [![Gem Version](https://badge.fury.io/rb/yodatra.png)](http://badge.fury.io/rb/yodatra) [![Code Climate](https://codeclimate.com/github/squareteam/yodatra.png)](https://codeclimate.com/github/squareteam/yodatra) [![Dependency Status](https://gemnasium.com/squareteam/yodatra.png)](https://gemnasium.com/squareteam/yodatra)
|
4
4
|
|
5
5
|
Backend development you shall do. And yodatra you shall use.
|
6
6
|
|
@@ -63,14 +63,14 @@ module Yodatra
|
|
63
63
|
READ_ALL = :read_all
|
64
64
|
get ALL_ROUTE do
|
65
65
|
retrieve_resources READ_ALL do |resource|
|
66
|
-
resource.all.as_json(read_scope)
|
66
|
+
resource.all.as_json(read_scope)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
READ_ONE = :read
|
71
71
|
get ONE_ROUTE do
|
72
72
|
retrieve_resources READ_ONE do |resource|
|
73
|
-
resource.as_json(read_scope)
|
73
|
+
resource.as_json(read_scope)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -82,9 +82,9 @@ module Yodatra
|
|
82
82
|
|
83
83
|
if @one.id.nil?
|
84
84
|
status 400
|
85
|
-
@one.errors.full_messages
|
85
|
+
@one.errors.full_messages
|
86
86
|
else
|
87
|
-
@one.as_json(read_scope)
|
87
|
+
@one.as_json(read_scope)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -94,10 +94,10 @@ module Yodatra
|
|
94
94
|
retrieve_resources UPDATE_ONE do |resource|
|
95
95
|
hash = self.send("#{model_name.underscore}_params".to_sym)
|
96
96
|
if resource.update_attributes(hash)
|
97
|
-
resource.as_json(read_scope)
|
97
|
+
resource.as_json(read_scope)
|
98
98
|
else
|
99
99
|
status 400
|
100
|
-
resource.errors.full_messages
|
100
|
+
resource.errors.full_messages
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -106,10 +106,10 @@ module Yodatra
|
|
106
106
|
delete ONE_ROUTE do
|
107
107
|
retrieve_resources DELETE_ONE do |resource|
|
108
108
|
if resource.destroy
|
109
|
-
resource.as_json(read_scope)
|
109
|
+
resource.as_json(read_scope)
|
110
110
|
else
|
111
111
|
status 400
|
112
|
-
resource.errors.full_messages
|
112
|
+
resource.errors.full_messages
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -157,7 +157,7 @@ module Yodatra
|
|
157
157
|
end
|
158
158
|
|
159
159
|
resource.where(search_terms.reduce(:or)).limit(100).
|
160
|
-
flatten.as_json(read_scope)
|
160
|
+
flatten.as_json(read_scope)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -169,9 +169,10 @@ module Yodatra
|
|
169
169
|
# Defines a nested route or not and retrieves the correct resource (or resources)
|
170
170
|
# @param disables is the name to check if it was disabled
|
171
171
|
# @param &block to be yield with the retrieved resource
|
172
|
-
|
172
|
+
# @returns resource in json format
|
173
|
+
def retrieve_resources(action)
|
173
174
|
pass unless involved?
|
174
|
-
no_route if disabled?
|
175
|
+
no_route if disabled? action
|
175
176
|
|
176
177
|
model = model_name.constantize
|
177
178
|
nested = nested_resources if nested?
|
@@ -179,13 +180,19 @@ module Yodatra
|
|
179
180
|
if model.nil? || nested.nil? && nested?
|
180
181
|
raise ActiveRecord::RecordNotFound
|
181
182
|
else
|
182
|
-
|
183
|
+
resource = nested? ? nested : model
|
184
|
+
|
185
|
+
# Check access to the resource
|
186
|
+
method = "prepare_#{action}"
|
187
|
+
resource = send(method, resource) if respond_to? method
|
188
|
+
|
189
|
+
# ONE resource else COLLECTION
|
183
190
|
one_id = nested? ? params[:captures].fourth : params[:captures].second if params[:captures].length == 4
|
184
|
-
|
185
|
-
yield(
|
191
|
+
resource = resource.find one_id unless one_id.nil?
|
192
|
+
yield(resource).to_json
|
186
193
|
end
|
187
194
|
rescue ActiveRecord::RecordNotFound
|
188
|
-
record_not_found
|
195
|
+
record_not_found.to_json
|
189
196
|
end
|
190
197
|
|
191
198
|
def nested?
|
@@ -259,7 +266,7 @@ module Yodatra
|
|
259
266
|
|
260
267
|
def record_not_found
|
261
268
|
status 404
|
262
|
-
['record not found']
|
269
|
+
['record not found']
|
263
270
|
end
|
264
271
|
|
265
272
|
end
|
data/lib/yodatra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yodatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Bonaud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|