shaf 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/shaf/extensions/resource_uris.rb +48 -11
- data/lib/shaf/generator/serializer.rb +11 -0
- data/lib/shaf/version.rb +1 -1
- data/templates/api/controllers/docs_controller.rb +2 -2
- data/templates/config/directories.rb +30 -14
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c865a1b9a6d772f631b559f0cb82d170e22661ea7cbf0138cac2dcd41c8c94
|
4
|
+
data.tar.gz: 036cc7276471887b64083989a91760c4781c20ddddecd3b62bfd74f000b364a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b812af36d9a0d79c69ed73c68b84ddc056fe62f9c34086d183148a9f1f709e06cee65daa46942b09de95f81f60454ba54c502d04079d2dafaedbca1984138aae
|
7
|
+
data.tar.gz: '075085884194b73706e217760914aa7f5707f5f1960968d30b643c76c39801b054ac77b15d65c678a79f5f866a323d4f12cc49da134c036075e7d177fc34031f'
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -126,9 +126,9 @@ module Shaf
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def call
|
129
|
-
if UriHelper.respond_to?
|
129
|
+
if UriHelper.respond_to? uri_method_name
|
130
130
|
raise "resource uri #{@name} can't be registered. " \
|
131
|
-
"Method :#{
|
131
|
+
"Method :#{uri_method_name} already exist!"
|
132
132
|
end
|
133
133
|
|
134
134
|
if @alt_uri.nil?
|
@@ -141,24 +141,38 @@ module Shaf
|
|
141
141
|
private
|
142
142
|
|
143
143
|
def build_methods
|
144
|
-
UriHelperMethods.eval_method
|
144
|
+
UriHelperMethods.eval_method uri_method_string
|
145
|
+
UriHelperMethods.eval_method path_method_string
|
145
146
|
UriHelperMethods.register(template_method_name, &template_proc)
|
146
147
|
end
|
147
148
|
|
148
149
|
def build_methods_with_optional_arg
|
149
|
-
UriHelperMethods.eval_method
|
150
|
+
UriHelperMethods.eval_method uri_method_with_optional_arg_string
|
151
|
+
UriHelperMethods.eval_method path_method_with_optional_arg_string
|
150
152
|
UriHelperMethods.register(template_method_name, &template_proc)
|
151
153
|
end
|
152
154
|
|
153
|
-
def
|
155
|
+
def uri_method_name
|
154
156
|
"#{@name}_uri".freeze
|
155
157
|
end
|
156
158
|
|
159
|
+
def path_method_name
|
160
|
+
"#{@name}_path".freeze
|
161
|
+
end
|
162
|
+
|
157
163
|
def template_method_name
|
158
|
-
"#{
|
164
|
+
"#{uri_method_name}_template".freeze
|
165
|
+
end
|
166
|
+
|
167
|
+
def uri_signature(optional_args: 0)
|
168
|
+
signature(uri_method_name, optional_args: optional_args)
|
169
|
+
end
|
170
|
+
|
171
|
+
def path_signature(optional_args: 0)
|
172
|
+
signature(path_method_name, optional_args: optional_args)
|
159
173
|
end
|
160
174
|
|
161
|
-
def signature(optional_args: 0)
|
175
|
+
def signature(method_name, optional_args: 0)
|
162
176
|
s = "#{method_name}("
|
163
177
|
|
164
178
|
symbols = extract_symbols.size.times.map { |i| "arg#{i}" }
|
@@ -175,21 +189,30 @@ module Shaf
|
|
175
189
|
s << (args.empty? ? "**query)" : "#{args.join(', ')}, **query)")
|
176
190
|
end
|
177
191
|
|
178
|
-
def
|
192
|
+
def uri_method_string
|
179
193
|
base_uri = UriHelper.base_uri
|
180
194
|
<<~Ruby
|
181
|
-
def #{
|
195
|
+
def #{uri_signature}
|
182
196
|
query_str = Shaf::MethodBuilder.query_string(query)
|
183
197
|
\"#{base_uri}#{interpolated_uri_string(@uri)}\#{query_str}\".freeze
|
184
198
|
end
|
185
199
|
Ruby
|
186
200
|
end
|
187
201
|
|
188
|
-
def
|
202
|
+
def path_method_string
|
203
|
+
<<~Ruby
|
204
|
+
def #{path_signature}
|
205
|
+
query_str = Shaf::MethodBuilder.query_string(query)
|
206
|
+
\"#{interpolated_uri_string(@uri)}\#{query_str}\".freeze
|
207
|
+
end
|
208
|
+
Ruby
|
209
|
+
end
|
210
|
+
|
211
|
+
def uri_method_with_optional_arg_string
|
189
212
|
base_uri = UriHelper.base_uri
|
190
213
|
arg_no = extract_symbols.size - 1
|
191
214
|
<<~Ruby
|
192
|
-
def #{
|
215
|
+
def #{uri_signature(optional_args: 1)}
|
193
216
|
query_str = Shaf::MethodBuilder.query_string(query)
|
194
217
|
if arg#{arg_no}.nil?
|
195
218
|
\"#{base_uri}#{interpolated_uri_string(@alt_uri)}\#{query_str}\".freeze
|
@@ -200,6 +223,20 @@ module Shaf
|
|
200
223
|
Ruby
|
201
224
|
end
|
202
225
|
|
226
|
+
def path_method_with_optional_arg_string
|
227
|
+
arg_no = extract_symbols.size - 1
|
228
|
+
<<~Ruby
|
229
|
+
def #{path_signature(optional_args: 1)}
|
230
|
+
query_str = Shaf::MethodBuilder.query_string(query)
|
231
|
+
if arg#{arg_no}.nil?
|
232
|
+
\"#{interpolated_uri_string(@alt_uri)}\#{query_str}\".freeze
|
233
|
+
else
|
234
|
+
\"#{interpolated_uri_string(@uri)}\#{query_str}\".freeze
|
235
|
+
end
|
236
|
+
end
|
237
|
+
Ruby
|
238
|
+
end
|
239
|
+
|
203
240
|
def extract_symbols(uri = @uri)
|
204
241
|
uri.split('/').grep(/:.*/).map { |t| t[1..-1].to_sym }
|
205
242
|
end
|
@@ -140,6 +140,15 @@ module Shaf
|
|
140
140
|
)
|
141
141
|
end
|
142
142
|
|
143
|
+
def create_link
|
144
|
+
link(
|
145
|
+
rel: "doc:create-form",
|
146
|
+
desc: "Link to a form used to create new #{name} resources",
|
147
|
+
uri: "new_#{name}_uri",
|
148
|
+
uri_helper: "new_#{name}_uri"
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
143
152
|
def link(rel:, method: "GET", desc:, uri:, uri_helper:)
|
144
153
|
<<~EOS.split("\n")
|
145
154
|
# Auto generated doc:
|
@@ -178,6 +187,8 @@ module Shaf
|
|
178
187
|
collection of: '#{plural_name}' do
|
179
188
|
link :self, #{plural_name}_uri
|
180
189
|
link :up, root_uri
|
190
|
+
|
191
|
+
#{create_link.join("\n ")}
|
181
192
|
link :'doc:create-form', new_#{name}_uri
|
182
193
|
curie(:doc) { doc_curie_uri('#{name}') }
|
183
194
|
end
|
data/lib/shaf/version.rb
CHANGED
@@ -3,12 +3,12 @@ class DocsController < BaseController
|
|
3
3
|
register_uri :doc_curie, '/doc/:resource/rels/{rel}'
|
4
4
|
register_uri :documentation, '/doc/:resource'
|
5
5
|
|
6
|
-
get
|
6
|
+
get :doc_curie_uri do
|
7
7
|
cache_control(:private, http_cache_max_age: :long)
|
8
8
|
doc.link(params[:rel])
|
9
9
|
end
|
10
10
|
|
11
|
-
get
|
11
|
+
get :documentation_uri do
|
12
12
|
cache_control(:private, http_cache_max_age: :long)
|
13
13
|
doc.to_s
|
14
14
|
end
|
@@ -4,20 +4,36 @@ $:.unshift APP_DIR
|
|
4
4
|
|
5
5
|
def sort_files(files)
|
6
6
|
files.sort_by do |file|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
directory_priority(file) + file_priority(file)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def directory_priority(file)
|
12
|
+
case file
|
13
|
+
when /\Alib/
|
14
|
+
0
|
15
|
+
when /\Ahelpers/
|
16
|
+
10
|
17
|
+
when /\Amodels/
|
18
|
+
20
|
19
|
+
when /\Apolicies/
|
20
|
+
30
|
21
|
+
when /\Acontrollers/
|
22
|
+
40
|
23
|
+
when /\Aserializers/
|
24
|
+
50
|
25
|
+
else
|
26
|
+
60
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def file_priority(file)
|
32
|
+
case File.basename(file)
|
33
|
+
when /\Abase[\._]/
|
34
|
+
0
|
35
|
+
else
|
36
|
+
9
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sammy Henningsson
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
ZMhjYR7sRczGJx+GxGU2EaR0bjRsPVlC4ywtFxoOfRG3WaJcpWGEoAoMJX6Z0bRv
|
31
31
|
M40=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-
|
33
|
+
date: 2018-09-05 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rake
|
metadata.gz.sig
CHANGED
Binary file
|