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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ef999e9f5ceac2a21b21e33ae805a6f576bc1363c6cbd4622cbbbdf715e8252
4
- data.tar.gz: '0030305862359ea34e55516b2d49abcd78c20eb1393ae9d99eabcb86d1b30de4'
3
+ metadata.gz: 39c865a1b9a6d772f631b559f0cb82d170e22661ea7cbf0138cac2dcd41c8c94
4
+ data.tar.gz: 036cc7276471887b64083989a91760c4781c20ddddecd3b62bfd74f000b364a8
5
5
  SHA512:
6
- metadata.gz: 3ac44a36ff0d58fce2e7fb58d9f85187dc75e1077cc801f5fcfd637738be364619c3ccbb3d5ea28b0cd46319f258d36a6047f4c22f53564487a4af8652569ffd
7
- data.tar.gz: d4bddad299a6236d0930d861a2fdc054531f5892c29cc9c2f5c918066d6943c0aa888b9e2fa346a7733784f2311da5845c475632c4641949711a8f0784546d15
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? method_name
129
+ if UriHelper.respond_to? uri_method_name
130
130
  raise "resource uri #{@name} can't be registered. " \
131
- "Method :#{method_name} already exist!"
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 method_string
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 method_with_optional_arg_string
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 method_name
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
- "#{method_name}_template".freeze
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 method_string
192
+ def uri_method_string
179
193
  base_uri = UriHelper.base_uri
180
194
  <<~Ruby
181
- def #{signature}
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 method_with_optional_arg_string
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 #{signature(optional_args: 1)}
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
@@ -1,3 +1,3 @@
1
1
  module Shaf
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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 doc_curie_uri_template do
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 documentation_uri_template do
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
- case file
8
- when /\Alib/
9
- 0
10
- when /\Ahelpers/
11
- 1
12
- when /\Amodels/
13
- 2
14
- when /\Acontrollers/
15
- 3
16
- when /\Apolicies/
17
- 4
18
- else
19
- 5
20
- end
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.0
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-08-25 00:00:00.000000000 Z
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