apes 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rubocop.yml +82 -0
- data/.travis-gemfile +15 -0
- data/.travis.yml +15 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +22 -0
- data/README.md +177 -0
- data/Rakefile +44 -0
- data/apes.gemspec +34 -0
- data/doc/Apes.html +130 -0
- data/doc/Apes/Concerns.html +127 -0
- data/doc/Apes/Concerns/Errors.html +1089 -0
- data/doc/Apes/Concerns/Pagination.html +636 -0
- data/doc/Apes/Concerns/Request.html +766 -0
- data/doc/Apes/Concerns/Response.html +940 -0
- data/doc/Apes/Controller.html +1100 -0
- data/doc/Apes/Errors.html +125 -0
- data/doc/Apes/Errors/AuthenticationError.html +133 -0
- data/doc/Apes/Errors/BadRequestError.html +157 -0
- data/doc/Apes/Errors/BaseError.html +320 -0
- data/doc/Apes/Errors/InvalidDataError.html +157 -0
- data/doc/Apes/Errors/MissingDataError.html +157 -0
- data/doc/Apes/Model.html +378 -0
- data/doc/Apes/PaginationCursor.html +2138 -0
- data/doc/Apes/RuntimeConfiguration.html +909 -0
- data/doc/Apes/Serializers.html +125 -0
- data/doc/Apes/Serializers/JSON.html +389 -0
- data/doc/Apes/Serializers/JWT.html +452 -0
- data/doc/Apes/Serializers/List.html +347 -0
- data/doc/Apes/UrlsParser.html +1432 -0
- data/doc/Apes/Validators.html +125 -0
- data/doc/Apes/Validators/BaseValidator.html +278 -0
- data/doc/Apes/Validators/BooleanValidator.html +494 -0
- data/doc/Apes/Validators/EmailValidator.html +350 -0
- data/doc/Apes/Validators/PhoneValidator.html +375 -0
- data/doc/Apes/Validators/ReferenceValidator.html +372 -0
- data/doc/Apes/Validators/TimestampValidator.html +640 -0
- data/doc/Apes/Validators/UuidValidator.html +372 -0
- data/doc/Apes/Validators/ZipCodeValidator.html +372 -0
- data/doc/Apes/Version.html +189 -0
- data/doc/ApplicationController.html +547 -0
- data/doc/Concerns.html +128 -0
- data/doc/Concerns/ErrorHandling.html +826 -0
- data/doc/Concerns/PaginationHandling.html +463 -0
- data/doc/Concerns/RequestHandling.html +512 -0
- data/doc/Concerns/ResponseHandling.html +579 -0
- data/doc/Errors.html +126 -0
- data/doc/Errors/AuthenticationError.html +123 -0
- data/doc/Errors/BadRequestError.html +147 -0
- data/doc/Errors/BaseError.html +289 -0
- data/doc/Errors/InvalidDataError.html +147 -0
- data/doc/Errors/MissingDataError.html +147 -0
- data/doc/Model.html +315 -0
- data/doc/PaginationCursor.html +764 -0
- data/doc/Serializers.html +126 -0
- data/doc/Serializers/JSON.html +253 -0
- data/doc/Serializers/JWT.html +253 -0
- data/doc/Serializers/List.html +245 -0
- data/doc/Validators.html +126 -0
- data/doc/Validators/BaseValidator.html +209 -0
- data/doc/Validators/BooleanValidator.html +391 -0
- data/doc/Validators/EmailValidator.html +298 -0
- data/doc/Validators/PhoneValidator.html +313 -0
- data/doc/Validators/ReferenceValidator.html +284 -0
- data/doc/Validators/TimestampValidator.html +476 -0
- data/doc/Validators/UuidValidator.html +310 -0
- data/doc/Validators/ZipCodeValidator.html +310 -0
- data/doc/_index.html +435 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +252 -0
- data/doc/file_list.html +60 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +252 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +615 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/apes.rb +40 -0
- data/lib/apes/concerns/errors.rb +111 -0
- data/lib/apes/concerns/pagination.rb +81 -0
- data/lib/apes/concerns/request.rb +237 -0
- data/lib/apes/concerns/response.rb +74 -0
- data/lib/apes/controller.rb +77 -0
- data/lib/apes/errors.rb +38 -0
- data/lib/apes/model.rb +94 -0
- data/lib/apes/pagination_cursor.rb +152 -0
- data/lib/apes/runtime_configuration.rb +80 -0
- data/lib/apes/serializers.rb +88 -0
- data/lib/apes/urls_parser.rb +233 -0
- data/lib/apes/validators.rb +234 -0
- data/lib/apes/version.rb +24 -0
- data/spec/apes/concerns/errors_spec.rb +141 -0
- data/spec/apes/concerns/pagination_spec.rb +114 -0
- data/spec/apes/concerns/request_spec.rb +244 -0
- data/spec/apes/concerns/response_spec.rb +79 -0
- data/spec/apes/controller_spec.rb +54 -0
- data/spec/apes/errors_spec.rb +14 -0
- data/spec/apes/models_spec.rb +148 -0
- data/spec/apes/pagination_cursor_spec.rb +113 -0
- data/spec/apes/runtime_configuration_spec.rb +100 -0
- data/spec/apes/serializers_spec.rb +70 -0
- data/spec/apes/urls_parser_spec.rb +150 -0
- data/spec/apes/validators_spec.rb +237 -0
- data/spec/spec_helper.rb +30 -0
- data/views/_included.json.jbuilder +9 -0
- data/views/_pagination.json.jbuilder +9 -0
- data/views/collection.json.jbuilder +4 -0
- data/views/errors/400.json.jbuilder +9 -0
- data/views/errors/403.json.jbuilder +7 -0
- data/views/errors/404.json.jbuilder +6 -0
- data/views/errors/422.json.jbuilder +19 -0
- data/views/errors/500.json.jbuilder +12 -0
- data/views/errors/501.json.jbuilder +7 -0
- data/views/layouts/general.json.jbuilder +36 -0
- data/views/object.json.jbuilder +4 -0
- metadata +262 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# This file is part of the apes gem. Copyright (C) 2016 and above Shogun <shogun@cowtech.it>.
|
3
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "bundler/setup"
|
7
|
+
|
8
|
+
if ENV["COVERAGE"]
|
9
|
+
require "simplecov"
|
10
|
+
require "coveralls"
|
11
|
+
|
12
|
+
Coveralls.wear! if ENV["CI"]
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
root = Pathname.new(File.dirname(__FILE__)) + ".."
|
16
|
+
|
17
|
+
add_filter do |src_file|
|
18
|
+
path = Pathname.new(src_file.filename).relative_path_from(root).to_s
|
19
|
+
path !~ /^lib/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "active_record"
|
25
|
+
require "lazier"
|
26
|
+
::I18n.enforce_available_locales = false
|
27
|
+
Lazier::I18n.default_locale = :en
|
28
|
+
|
29
|
+
require File.dirname(__FILE__) + "/../lib/apes"
|
30
|
+
Lazier.load!(:hash)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
included = response_included(local_assigns[:included])
|
2
|
+
|
3
|
+
if included.present?
|
4
|
+
json.included(included.values) do |(resource, template)|
|
5
|
+
template ||= resource.class.to_s.underscore.singularize
|
6
|
+
|
7
|
+
json.partial!("models/#{template}", locals: {object: resource, included: true}) if resource
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
if @errors.is_a?(Hash)
|
2
|
+
errors = @errors.map {|field, errors|
|
3
|
+
[field, errors.ensure_array.first]
|
4
|
+
}
|
5
|
+
|
6
|
+
json.errors errors do |(field, error)|
|
7
|
+
json.code 422
|
8
|
+
json.title "Bad Attribute"
|
9
|
+
json.field field
|
10
|
+
error += "." unless error.end_with?(".")
|
11
|
+
json.detail error.capitalize
|
12
|
+
end
|
13
|
+
else
|
14
|
+
json.errors @errors.ensure_array do |error|
|
15
|
+
json.code 422
|
16
|
+
json.title "Unknown Attribute"
|
17
|
+
json.field error
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
json.jsonapi do
|
2
|
+
json.version "1.0"
|
3
|
+
end
|
4
|
+
|
5
|
+
json.meta do
|
6
|
+
json.status response.status
|
7
|
+
json.success response.status / 100 == 2 || response.status == 418
|
8
|
+
json.debug @debug || local_assigns[:debug] if @debug || local_assigns.key?(:debug)
|
9
|
+
json.handler sprintf("%s/%s", controller_name, action_name) unless Rails.env.production?
|
10
|
+
end
|
11
|
+
|
12
|
+
# Meta
|
13
|
+
meta = response_meta(local_assigns[:meta])
|
14
|
+
json.meta meta if meta.present?
|
15
|
+
|
16
|
+
if @count || @page_size
|
17
|
+
json.meta do
|
18
|
+
json.total @count
|
19
|
+
json.size @page_size || @cursor.size
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Data
|
24
|
+
data = response_data(local_assigns[:data])
|
25
|
+
json.data data if data.present?
|
26
|
+
|
27
|
+
# Template
|
28
|
+
json.merge! JSON.parse(yield) if block_given? && !local_assigns[:empty]
|
29
|
+
|
30
|
+
# Links
|
31
|
+
links = response_links(local_assigns[:links])
|
32
|
+
json.links links if links.present?
|
33
|
+
|
34
|
+
# Included and pagination
|
35
|
+
json.partial! "/included"
|
36
|
+
json.partial! "/pagination" if @objects && !pagination_skip? && pagination_supported?
|
metadata
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shogun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lazier
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mustache
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jwt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jbuilder
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails-api
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
97
|
+
description: A tiny JSON API framework for Ruby on Rails.
|
98
|
+
email:
|
99
|
+
- shogun@cowtech.it
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".travis-gemfile"
|
107
|
+
- ".travis.yml"
|
108
|
+
- ".yardopts"
|
109
|
+
- CHANGELOG.md
|
110
|
+
- Gemfile
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- apes.gemspec
|
114
|
+
- doc/Apes.html
|
115
|
+
- doc/Apes/Concerns.html
|
116
|
+
- doc/Apes/Concerns/Errors.html
|
117
|
+
- doc/Apes/Concerns/Pagination.html
|
118
|
+
- doc/Apes/Concerns/Request.html
|
119
|
+
- doc/Apes/Concerns/Response.html
|
120
|
+
- doc/Apes/Controller.html
|
121
|
+
- doc/Apes/Errors.html
|
122
|
+
- doc/Apes/Errors/AuthenticationError.html
|
123
|
+
- doc/Apes/Errors/BadRequestError.html
|
124
|
+
- doc/Apes/Errors/BaseError.html
|
125
|
+
- doc/Apes/Errors/InvalidDataError.html
|
126
|
+
- doc/Apes/Errors/MissingDataError.html
|
127
|
+
- doc/Apes/Model.html
|
128
|
+
- doc/Apes/PaginationCursor.html
|
129
|
+
- doc/Apes/RuntimeConfiguration.html
|
130
|
+
- doc/Apes/Serializers.html
|
131
|
+
- doc/Apes/Serializers/JSON.html
|
132
|
+
- doc/Apes/Serializers/JWT.html
|
133
|
+
- doc/Apes/Serializers/List.html
|
134
|
+
- doc/Apes/UrlsParser.html
|
135
|
+
- doc/Apes/Validators.html
|
136
|
+
- doc/Apes/Validators/BaseValidator.html
|
137
|
+
- doc/Apes/Validators/BooleanValidator.html
|
138
|
+
- doc/Apes/Validators/EmailValidator.html
|
139
|
+
- doc/Apes/Validators/PhoneValidator.html
|
140
|
+
- doc/Apes/Validators/ReferenceValidator.html
|
141
|
+
- doc/Apes/Validators/TimestampValidator.html
|
142
|
+
- doc/Apes/Validators/UuidValidator.html
|
143
|
+
- doc/Apes/Validators/ZipCodeValidator.html
|
144
|
+
- doc/Apes/Version.html
|
145
|
+
- doc/ApplicationController.html
|
146
|
+
- doc/Concerns.html
|
147
|
+
- doc/Concerns/ErrorHandling.html
|
148
|
+
- doc/Concerns/PaginationHandling.html
|
149
|
+
- doc/Concerns/RequestHandling.html
|
150
|
+
- doc/Concerns/ResponseHandling.html
|
151
|
+
- doc/Errors.html
|
152
|
+
- doc/Errors/AuthenticationError.html
|
153
|
+
- doc/Errors/BadRequestError.html
|
154
|
+
- doc/Errors/BaseError.html
|
155
|
+
- doc/Errors/InvalidDataError.html
|
156
|
+
- doc/Errors/MissingDataError.html
|
157
|
+
- doc/Model.html
|
158
|
+
- doc/PaginationCursor.html
|
159
|
+
- doc/Serializers.html
|
160
|
+
- doc/Serializers/JSON.html
|
161
|
+
- doc/Serializers/JWT.html
|
162
|
+
- doc/Serializers/List.html
|
163
|
+
- doc/Validators.html
|
164
|
+
- doc/Validators/BaseValidator.html
|
165
|
+
- doc/Validators/BooleanValidator.html
|
166
|
+
- doc/Validators/EmailValidator.html
|
167
|
+
- doc/Validators/PhoneValidator.html
|
168
|
+
- doc/Validators/ReferenceValidator.html
|
169
|
+
- doc/Validators/TimestampValidator.html
|
170
|
+
- doc/Validators/UuidValidator.html
|
171
|
+
- doc/Validators/ZipCodeValidator.html
|
172
|
+
- doc/_index.html
|
173
|
+
- doc/class_list.html
|
174
|
+
- doc/css/common.css
|
175
|
+
- doc/css/full_list.css
|
176
|
+
- doc/css/style.css
|
177
|
+
- doc/file.README.html
|
178
|
+
- doc/file_list.html
|
179
|
+
- doc/frames.html
|
180
|
+
- doc/index.html
|
181
|
+
- doc/js/app.js
|
182
|
+
- doc/js/full_list.js
|
183
|
+
- doc/js/jquery.js
|
184
|
+
- doc/method_list.html
|
185
|
+
- doc/top-level-namespace.html
|
186
|
+
- lib/apes.rb
|
187
|
+
- lib/apes/concerns/errors.rb
|
188
|
+
- lib/apes/concerns/pagination.rb
|
189
|
+
- lib/apes/concerns/request.rb
|
190
|
+
- lib/apes/concerns/response.rb
|
191
|
+
- lib/apes/controller.rb
|
192
|
+
- lib/apes/errors.rb
|
193
|
+
- lib/apes/model.rb
|
194
|
+
- lib/apes/pagination_cursor.rb
|
195
|
+
- lib/apes/runtime_configuration.rb
|
196
|
+
- lib/apes/serializers.rb
|
197
|
+
- lib/apes/urls_parser.rb
|
198
|
+
- lib/apes/validators.rb
|
199
|
+
- lib/apes/version.rb
|
200
|
+
- spec/apes/concerns/errors_spec.rb
|
201
|
+
- spec/apes/concerns/pagination_spec.rb
|
202
|
+
- spec/apes/concerns/request_spec.rb
|
203
|
+
- spec/apes/concerns/response_spec.rb
|
204
|
+
- spec/apes/controller_spec.rb
|
205
|
+
- spec/apes/errors_spec.rb
|
206
|
+
- spec/apes/models_spec.rb
|
207
|
+
- spec/apes/pagination_cursor_spec.rb
|
208
|
+
- spec/apes/runtime_configuration_spec.rb
|
209
|
+
- spec/apes/serializers_spec.rb
|
210
|
+
- spec/apes/urls_parser_spec.rb
|
211
|
+
- spec/apes/validators_spec.rb
|
212
|
+
- spec/spec_helper.rb
|
213
|
+
- views/_included.json.jbuilder
|
214
|
+
- views/_pagination.json.jbuilder
|
215
|
+
- views/collection.json.jbuilder
|
216
|
+
- views/errors/400.json.jbuilder
|
217
|
+
- views/errors/403.json.jbuilder
|
218
|
+
- views/errors/404.json.jbuilder
|
219
|
+
- views/errors/422.json.jbuilder
|
220
|
+
- views/errors/500.json.jbuilder
|
221
|
+
- views/errors/501.json.jbuilder
|
222
|
+
- views/layouts/general.json.jbuilder
|
223
|
+
- views/object.json.jbuilder
|
224
|
+
homepage: https://github.com/ShogunPanda/apes
|
225
|
+
licenses:
|
226
|
+
- MIT
|
227
|
+
metadata: {}
|
228
|
+
post_install_message:
|
229
|
+
rdoc_options: []
|
230
|
+
require_paths:
|
231
|
+
- lib
|
232
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 2.3.0
|
237
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
version: '0'
|
242
|
+
requirements: []
|
243
|
+
rubyforge_project: apes
|
244
|
+
rubygems_version: 2.5.1
|
245
|
+
signing_key:
|
246
|
+
specification_version: 4
|
247
|
+
summary: A tiny JSON API framework for Ruby on Rails.
|
248
|
+
test_files:
|
249
|
+
- spec/apes/concerns/errors_spec.rb
|
250
|
+
- spec/apes/concerns/pagination_spec.rb
|
251
|
+
- spec/apes/concerns/request_spec.rb
|
252
|
+
- spec/apes/concerns/response_spec.rb
|
253
|
+
- spec/apes/controller_spec.rb
|
254
|
+
- spec/apes/errors_spec.rb
|
255
|
+
- spec/apes/models_spec.rb
|
256
|
+
- spec/apes/pagination_cursor_spec.rb
|
257
|
+
- spec/apes/runtime_configuration_spec.rb
|
258
|
+
- spec/apes/serializers_spec.rb
|
259
|
+
- spec/apes/urls_parser_spec.rb
|
260
|
+
- spec/apes/validators_spec.rb
|
261
|
+
- spec/spec_helper.rb
|
262
|
+
has_rdoc:
|