apipie-dsl 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8be129129902b76525b6f6f49af8ceb5966f658cb12734725a15d7a85e44612
4
- data.tar.gz: 538ddde32dfe9058739a350a0f641ed64fbc40d8ae529a0ce48e08ce8aa6bbb5
3
+ metadata.gz: 95dfead8f64abaa0afb0acb4c8af97c43a484d0486596a08049420baff6ba9a4
4
+ data.tar.gz: 5f454030f583bd23a2728693c6950c6c145223289448f1f6ae681c021cc0897f
5
5
  SHA512:
6
- metadata.gz: 7c645ba1b449e181d24b1e4710a493056f0332b6408ee6adf51fb2e496d42c37dee53895f03f89425e2a9d10dd5151a163e9c5d1e04a1b8adea6d75dd17860ef
7
- data.tar.gz: 3b1ae75bc8dc25968e5fc0524a66339212598abe751b9254b21715ab705b42dd9e9b29c6e06c54accb2ec1901a149eb58d1dff60bb8b0b507ba4ae7bad14eb2b
6
+ metadata.gz: e0d8dccd8fdaa5bbd2c8cc1ef4a89cdda096fa000ace242518f5196a420cf7cc7e62f4790d3f9e6c1b7335bdc2dd65c5b6dbe5133fceb7b6477376d3bf95d640
7
+ data.tar.gz: c5a0a6ba9167b2bf13e117ca608d997689ab97eb76e422a69423dab1c8152c7e203594dde8d9d6216e661c4116a5d6f5f113ed95913b41b8d41cb6418f8f3232
@@ -49,11 +49,11 @@ module ApipieDslHelper
49
49
  def apipie_erb_wrap(content, mode: :loud, open_trim: false, close_trim: false)
50
50
  case mode
51
51
  when :loud
52
- '<%= ' + content + " #{close_trim ? '-' : ''}%>"
52
+ "<%= #{content} #{close_trim ? '-' : ''}%>"
53
53
  when :comment
54
- '<%# ' + content + " #{close_trim ? '-' : ''}%>"
54
+ "<%# #{content} #{close_trim ? '-' : ''}%>"
55
55
  else
56
- "<%#{open_trim ? '- ' : ' '}" + content + " #{close_trim ? '-' : ''}%>"
56
+ "<%#{open_trim ? '-' : ''} #{content} #{close_trim ? '-' : ''}%>"
57
57
  end
58
58
  end
59
59
 
@@ -65,6 +65,8 @@ module ApipieDslHelper
65
65
  "\"\""
66
66
  when Symbol
67
67
  ":#{default}"
68
+ when String
69
+ "\"#{default}\""
68
70
  else
69
71
  default
70
72
  end
@@ -142,9 +144,10 @@ module ApipieDslHelper
142
144
  end
143
145
 
144
146
  def current_version(classes)
145
- if classes.is_a?(Array)
147
+ case classes
148
+ when Array
146
149
  classes.first[:version]
147
- elsif classes.is_a?(Hash)
150
+ when Hash
148
151
  classes.values.first[:version]
149
152
  else
150
153
  raise ApipieDSL::Error, "Cannot find current version for #{classes}"
@@ -9,7 +9,8 @@
9
9
  <td>
10
10
  <strong><%= param[:full_name] %> </strong><br>
11
11
  <small>
12
- <%= t("apipie_dsl.#{param[:type]}") %>
12
+ <%= t("apipie_dsl.#{param[:type]}") %><br>
13
+ <%= param[:type] == 'keyword' ? 'Optional' : '' %>
13
14
  </small>
14
15
  </td>
15
16
  <td>
@@ -14,7 +14,7 @@
14
14
 
15
15
  <h1 class='page-header'><%= t('apipie_dsl.classes') %></h1>
16
16
 
17
- <% @doc[:classes].each_value do |klass| %>
17
+ <% @doc[:classes].sort_by { |id, c| c[:name] }.each do |id, klass| %>
18
18
  <% next unless klass[:show] && in_section?(@section, klass[:id]) %>
19
19
  <h2>
20
20
  <a href='<%= klass[:doc_url] %><%= @doc[:link_extension] %>'>
@@ -1,4 +1,4 @@
1
- <% @doc[:classes].sort_by(&:first).each do |key, klass| %>
1
+ <% @doc[:classes].sort_by { |id, c| c[:name] }.each do |key, klass| %>
2
2
  <% next unless klass[:show] %>
3
3
  <h4><a href='#<%= key %>'><%= klass[:name] %></a></h4>
4
4
  <ul>
@@ -14,7 +14,7 @@
14
14
  </ul>
15
15
  <% end %>
16
16
 
17
- <% @doc[:classes].sort_by(&:first).each do |key, klass| %>
17
+ <% @doc[:classes].sort_by { |id, c| c[:name] }.each do |key, klass| %>
18
18
  <% next unless klass[:show] %>
19
19
  <hr/>
20
20
  <div>
@@ -1,4 +1,4 @@
1
- <% @doc[:classes].sort_by(&:first).each do |key, klass| %>
1
+ <% @doc[:classes].sort_by { |id, c| c[:name] }.each do |key, klass| %>
2
2
  <% next unless klass[:show] %>
3
3
  <h4><a href='#<%= key %>'><%= klass[:name] %></a></h4>
4
4
  <ul>
@@ -18,7 +18,7 @@
18
18
 
19
19
  <hr>
20
20
 
21
- <% @doc[:classes].sort_by(&:first).each do |key, klass| %>
21
+ <% @doc[:classes].sort_by { |id, c| c[:name] }.each do |key, klass| %>
22
22
  <% next unless klass[:show] %>
23
23
  <ul class='breadcrumb' id='<%= key %>'>
24
24
  <li><a href='#'><%= @doc[:name] %></a><span class='divider'>/</span></li>
@@ -23,7 +23,7 @@ module ApipieDSL
23
23
  @full_description = ApipieDSL.markup_to_html(dsl_data[:description]) if dsl_data[:description]
24
24
  @short_description = dsl_data[:short_description] || @short_description
25
25
  @tag_list = dsl_data[:tag_list]
26
- if dsl_data[:meta]&.is_a?(Hash)
26
+ if dsl_data[:meta].is_a?(Hash)
27
27
  @metadata&.merge!(dsl_data[:meta])
28
28
  elsif dsl_data[:meta]
29
29
  @metadata = dsl_data[:meta]
@@ -98,8 +98,8 @@ module ApipieDSL
98
98
  full_description: ApipieDSL.translate(@full_description, lang),
99
99
  version: version,
100
100
  metadata: @metadata,
101
- properties: @properties.map { |prop_desc| prop_desc.docs(section, lang) },
102
- methods: methods,
101
+ properties: @properties.map { |prop_desc| prop_desc.docs(section, lang) }.sort_by { |p| p[:name] },
102
+ methods: methods.sort_by { |m| m[:name] },
103
103
  deprecated: @deprecated,
104
104
  show: @show
105
105
  }
@@ -202,9 +202,10 @@ module ApipieDSL
202
202
  options[:desc] = desc_or_options
203
203
  end
204
204
 
205
- if retobj_or_options.is_a?(Hash)
205
+ case retobj_or_options
206
+ when Hash
206
207
  options.merge!(retobj_or_options)
207
- elsif retobj_or_options.is_a?(Symbol)
208
+ when Symbol
208
209
  options[:param_group] = retobj_or_options
209
210
  else
210
211
  options[:object_of] ||= retobj_or_options
@@ -414,7 +415,7 @@ module ApipieDSL
414
415
  def self.update_method_desc(method_desc, dsl_data)
415
416
  method_desc.full_description = dsl_data[:description] || method_desc.full_description
416
417
  method_desc.short_description = dsl_data[:short_description] || method_desc.short_description
417
- if dsl_data[:meta]&.is_a?(Hash)
418
+ if dsl_data[:meta].is_a?(Hash)
418
419
  method_desc.metadata&.merge!(dsl_data[:meta])
419
420
  else
420
421
  method_desc.metadata = dsl_data[:meta]
@@ -454,9 +455,10 @@ module ApipieDSL
454
455
  end
455
456
 
456
457
  def apipie(context = :method, desc_or_options = nil, options = {}, &block)
457
- if desc_or_options.is_a?(Hash)
458
+ case desc_or_options
459
+ when Hash
458
460
  options = options.merge(desc_or_options)
459
- elsif desc_or_options.is_a?(String)
461
+ when String
460
462
  options[:desc] = desc_or_options
461
463
  end
462
464
  options[:name] ||= context.to_s
@@ -507,9 +509,10 @@ module ApipieDSL
507
509
  private
508
510
 
509
511
  def prepare_delegatee(scope, desc_or_options, options, &block)
510
- if desc_or_options.is_a?(Hash)
512
+ case desc_or_options
513
+ when Hash
511
514
  options = options.merge(desc_or_options)
512
- elsif desc_or_options.is_a?(String)
515
+ when String
513
516
  options[:desc] = desc_or_options
514
517
  end
515
518
 
@@ -528,9 +531,10 @@ module ApipieDSL
528
531
  include ApipieDSL::Delegatable
529
532
 
530
533
  def apipie(context = :method, desc_or_options = nil, options = {}, &block)
531
- if desc_or_options.is_a?(Hash)
534
+ case desc_or_options
535
+ when Hash
532
536
  options = options.merge(desc_or_options)
533
- elsif desc_or_options.is_a?(String)
537
+ when String
534
538
  options[:desc] = desc_or_options
535
539
  end
536
540
  options[:name] ||= context.to_s
@@ -2,10 +2,12 @@
2
2
 
3
3
  module ApipieDSL
4
4
  class Error < StandardError; end
5
+
5
6
  class ParamError < Error
6
7
  attr_accessor :param
7
8
 
8
9
  def initialize(param)
10
+ super
9
11
  @param = param
10
12
  end
11
13
  end
@@ -46,6 +48,7 @@ module ApipieDSL
46
48
  attr_accessor :value
47
49
 
48
50
  def initialize(value)
51
+ super
49
52
  @value = value
50
53
  end
51
54
 
@@ -70,6 +73,7 @@ module ApipieDSL
70
73
  attr_reader :value
71
74
 
72
75
  def initialize(value)
76
+ super
73
77
  @value = value
74
78
  end
75
79
 
@@ -34,40 +34,40 @@ module ApipieDSL
34
34
  end
35
35
 
36
36
  def initialize(method_description, name, validator, desc_or_options = nil, options = {}, &block)
37
- if desc_or_options.is_a?(Hash)
38
- options = options.merge(desc_or_options)
39
- elsif desc_or_options.is_a?(String)
40
- options[:desc] = desc_or_options
41
- elsif !desc_or_options.nil?
42
- raise ArgumentError, 'Parameter description: expected description or options as 3rd parameter'
43
- end
37
+ if desc_or_options.is_a?(Hash)
38
+ options = options.merge(desc_or_options)
39
+ elsif desc_or_options.is_a?(String)
40
+ options[:desc] = desc_or_options
41
+ elsif !desc_or_options.nil?
42
+ raise ArgumentError, 'Parameter description: expected description or options as 3rd parameter'
43
+ end
44
44
 
45
- @options = options.transform_keys(&:to_sym)
45
+ @options = options.transform_keys(&:to_sym)
46
46
 
47
- @method_description = method_description
48
- @name = name
49
- @desc = @options[:desc]
50
- @type = @options[:type] || :required
51
- @schema = @options[:schema]
52
- @default_value = @options[:default]
53
- @parent = @options[:parent]
54
- @metadata = @options[:meta]
55
- @show = @options.key?(:show) ? @options[:show] : true
47
+ @method_description = method_description
48
+ @name = name
49
+ @desc = @options[:desc]
50
+ @type = @options[:type] || :required
51
+ @schema = @options[:schema]
52
+ @default_value = @options[:default]
53
+ @parent = @options[:parent]
54
+ @metadata = @options[:meta]
55
+ @show = @options.key?(:show) ? @options[:show] : true
56
56
 
57
- return unless validator
57
+ return unless validator
58
58
 
59
- @validator = if validator.is_a?(String)
60
- ApipieDSL::Validator::Lazy.new(self, validator, @options, block)
61
- else
62
- ApipieDSL::Validator::BaseValidator.find(self, validator, @options, block)
63
- end
64
- raise StandardError, "Validator for #{validator} not found." unless @validator
59
+ @validator = if validator.is_a?(String)
60
+ ApipieDSL::Validator::Lazy.new(self, validator, @options, block)
61
+ else
62
+ ApipieDSL::Validator::BaseValidator.find(self, validator, @options, block)
63
+ end
64
+ raise StandardError, "Validator for #{validator} not found." unless @validator
65
65
  end
66
66
 
67
67
  def validator
68
- return @validator unless @validator.is_a?(ApipieDSL::Validator::Lazy)
68
+ return @validator unless @validator.is_a?(ApipieDSL::Validator::Lazy)
69
69
 
70
- @validator = @validator.build
70
+ @validator = @validator.build
71
71
  end
72
72
 
73
73
  def validate(value)
@@ -12,8 +12,6 @@ module ApipieDSL
12
12
  @param_group = { scope: @scope }
13
13
  @options = options
14
14
  @return_type = (@options.keys & %i[array_of one_of object_of param_group]).first
15
-
16
- return unless @options[@return_type].is_a?(::Class)
17
15
  end
18
16
 
19
17
  # this routine overrides Param#default_param_group_scope
@@ -21,8 +21,8 @@ module ApipieDSL
21
21
  base_paths.unshift("#{Rails.root}/app/views/apipie_dsl/apipie_dsls") if File.directory?("#{Rails.root}/app/views/apipie_dsl/apipie_dsls")
22
22
  end
23
23
  layouts_paths = [File.expand_path('../../app/views/layouts', __dir__)]
24
- if ApipieDSL.configuration.rails?
25
- layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie_dsl")
24
+ if ApipieDSL.configuration.rails? && File.directory?("#{Rails.root}/app/views/layouts/apipie_dsl")
25
+ layouts_paths.unshift("#{Rails.root}/app/views/layouts")
26
26
  end
27
27
  paths = ActionView::PathSet.new(base_paths + layouts_paths)
28
28
  @renderer = ActionView::Base.new(paths, {})
@@ -60,18 +60,7 @@ module ApipieDSL
60
60
  end
61
61
  end
62
62
  end
63
- if RUBY_VERSION < '2.5.0'
64
- class Hash
65
- def transform_keys
66
- result = {}
67
- each do |key, value|
68
- new_key = yield key
69
- result[new_key] = value
70
- end
71
- result
72
- end
73
- end
74
- end
63
+
75
64
  if defined? Rails
76
65
  class Module
77
66
  # https://github.com/rails/rails/pull/35035
@@ -17,6 +17,7 @@ module ApipieDSL
17
17
  BaseValidator.find(@param_description, @argument.constantize, @options, @block)
18
18
  end
19
19
  end
20
+
20
21
  # To create a new validator, inherit from ApipieDSL::Validator::BaseValidator
21
22
  # and implement class method 'build' and instance method 'validate'
22
23
  class BaseValidator
@@ -49,6 +50,7 @@ module ApipieDSL
49
50
  end
50
51
 
51
52
  def self.inherited(subclass)
53
+ super(subclass)
52
54
  @validators ||= []
53
55
  @validators.unshift(subclass)
54
56
  end
@@ -325,9 +327,7 @@ module ApipieDSL
325
327
  return false unless value.is_a?(Hash)
326
328
 
327
329
  @hash_params&.each do |name, param|
328
- if ApipieDSL.configuration.validate_value?
329
- param.validate(value[name]) if value.key?(name)
330
- end
330
+ param.validate(value[name]) if ApipieDSL.configuration.validate_value? && value.key?(name)
331
331
  end
332
332
  true
333
333
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApipieDSL
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleh Fedorenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -206,14 +206,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="
208
208
  - !ruby/object:Gem::Version
209
- version: 2.3.0
209
+ version: 2.5.0
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  requirements:
212
212
  - - ">="
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
215
  requirements: []
216
- rubygems_version: 3.1.2
216
+ rubygems_version: 3.0.8
217
217
  signing_key:
218
218
  specification_version: 4
219
219
  summary: Ruby DSL documentation tool