apipie-dsl 2.2.7 → 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: 751af0c065bd8a384dc9c710dc53da2275015666c7076c3a13eb4c89f47860d3
4
- data.tar.gz: fab345212215d732917c7c16375088d850933f147f4c49d757732dea8576ad0f
3
+ metadata.gz: 95dfead8f64abaa0afb0acb4c8af97c43a484d0486596a08049420baff6ba9a4
4
+ data.tar.gz: 5f454030f583bd23a2728693c6950c6c145223289448f1f6ae681c021cc0897f
5
5
  SHA512:
6
- metadata.gz: 490ad088339064f5495b3c1271ec549446444b17b4c0b7fc71b16ad1afc5b458b6d22525e2e2158a73f41aab346c4201333410f95c509bad971dcda5f17aa694
7
- data.tar.gz: 9e6285a8b353bdc8e87bf7485955bd6ce250734bd2140272329518080da2ebe316d9fc7c7f70b146d04263d601f8eb0b017b3cc8eda4e3f44dee730279c61954
6
+ metadata.gz: e0d8dccd8fdaa5bbd2c8cc1ef4a89cdda096fa000ace242518f5196a420cf7cc7e62f4790d3f9e6c1b7335bdc2dd65c5b6dbe5133fceb7b6477376d3bf95d640
7
+ data.tar.gz: c5a0a6ba9167b2bf13e117ca608d997689ab97eb76e422a69423dab1c8152c7e203594dde8d9d6216e661c4116a5d6f5f113ed95913b41b8d41cb6418f8f3232
@@ -12,17 +12,35 @@ module ApipieDslHelper
12
12
  end
13
13
  end
14
14
 
15
- def escaped_method_name(method, escaping = '')
16
- return method.gsub('?', escaping) if method.is_a?(String)
15
+ def escaped_method_name(method, options = {})
16
+ options[:escaping] ||= ''
17
+ options[:pattern] ||= /[?]/
18
+ return method.gsub(options[:pattern], options[:escaping]) if method.is_a?(String)
19
+ end
20
+
21
+ def apipie_dsl_menu
22
+ content_tag(:ul, class: 'breadcrumb') do
23
+ content = dsl_sections.map do |section|
24
+ content_tag(:li, class: section == @section ? 'active' : '') do
25
+ link_to(_(section.titleize), @doc[:doc_url] + section_ext(section) + @doc[:link_extension])
26
+ end
27
+ end.join(' | ').html_safe
28
+
29
+ unless ApipieDSL.configuration.help_layout.nil?
30
+ content += content_tag(:li, class: "pull-right #{'active' if @section == 'help'}") do
31
+ link_to(_('Help'), @doc[:doc_url] + section_ext('help') + @doc[:link_extension])
32
+ end
33
+ end
34
+ end
17
35
  end
18
36
 
19
37
  def apipie_dsl_example(source, output = nil)
20
38
  text = content_tag(:p, _('Example input:')) +
21
- content_tag(:pre, source)
39
+ content_tag(:pre, source, class: 'wiki')
22
40
 
23
41
  if output.present?
24
42
  text += content_tag(:p, _('Example output:')) +
25
- content_tag(:pre, output)
43
+ content_tag(:pre, output, class: 'wiki')
26
44
  end
27
45
 
28
46
  text.html_safe
@@ -31,11 +49,11 @@ module ApipieDslHelper
31
49
  def apipie_erb_wrap(content, mode: :loud, open_trim: false, close_trim: false)
32
50
  case mode
33
51
  when :loud
34
- '<%= ' + content + " #{close_trim ? '-' : ''}%>"
52
+ "<%= #{content} #{close_trim ? '-' : ''}%>"
35
53
  when :comment
36
- '<%# ' + content + " #{close_trim ? '-' : ''}%>"
54
+ "<%# #{content} #{close_trim ? '-' : ''}%>"
37
55
  else
38
- "<%#{open_trim ? '- ' : ' '}" + content + " #{close_trim ? '-' : ''}%>"
56
+ "<%#{open_trim ? '-' : ''} #{content} #{close_trim ? '-' : ''}%>"
39
57
  end
40
58
  end
41
59
 
@@ -45,6 +63,10 @@ module ApipieDslHelper
45
63
  'nil'
46
64
  when ''
47
65
  "\"\""
66
+ when Symbol
67
+ ":#{default}"
68
+ when String
69
+ "\"#{default}\""
48
70
  else
49
71
  default
50
72
  end
@@ -81,6 +103,9 @@ module ApipieDslHelper
81
103
  # Try to convert to a constant in case of LazyValidator usage
82
104
  # Will raise const missing exception in case of wrong usage of the method
83
105
  if obj.is_a?(String)
106
+ ref = ApipieDSL.refs[version][ApipieDSL.get_class_name(obj)]
107
+ return "<a href='#{ref.doc_url(ref.sections.first)}#{link_extension}'>#{obj}</a>" if ref
108
+
84
109
  obj = ApipieDSL.configuration.rails? ? obj.constantize : obj.split('::').reduce(::Module, :const_get)
85
110
  end
86
111
  return obj.to_s unless [::Module, ::Class, ::Array].include?(obj.class)
@@ -119,9 +144,10 @@ module ApipieDslHelper
119
144
  end
120
145
 
121
146
  def current_version(classes)
122
- if classes.is_a?(Array)
147
+ case classes
148
+ when Array
123
149
  classes.first[:version]
124
- elsif classes.is_a?(Hash)
150
+ when Hash
125
151
  classes.values.first[:version]
126
152
  else
127
153
  raise ApipieDSL::Error, "Cannot find current version for #{classes}"
@@ -5,3 +5,14 @@ body {
5
5
  .sidebar-nav {
6
6
  padding: 9px 0;
7
7
  }
8
+
9
+ pre:not(.prettyprint):not(.wiki) {
10
+ margin: 0 0 9px;
11
+ padding: 0;
12
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
13
+ font-size: 13px;
14
+ line-height: 18px;
15
+ color: #333333;
16
+ background-color: inherit;
17
+ border: none;
18
+ }
@@ -1,7 +1,7 @@
1
1
  <% if prop[:show] %>
2
2
  <tr>
3
3
  <td>
4
- <a href='<%= doc_url %><%= link_extension %>#link-description-<%= escaped_method_name(prop[:name], '_') %>'>
4
+ <a href='<%= doc_url %><%= link_extension %>#link-description-<%= escaped_method_name(prop[:name], escaping: '_') %>'>
5
5
  <%= prop[:name] %>
6
6
  </a>
7
7
  <% if prop[:deprecated] %>
@@ -8,7 +8,7 @@
8
8
  <div>
9
9
  <% (meth[:signature] || [method_signature(meth)]).each do |signature| %>
10
10
  <h2>
11
- <a href='#description-<%= escaped_method_name(meth[:name], '_') %>'
11
+ <a href='#description-<%= escaped_method_name(meth[:name], escaping: '_') %>'
12
12
  class='accordion-toggle'
13
13
  data-toggle='collapse'
14
14
  data-parent='#meth-accordion'>
@@ -29,7 +29,7 @@
29
29
  Also see <%= meth[:see].map { |s| link_to(s[:description] || s[:link], "#{s[:url]}#{link_extension}") }.to_sentence.html_safe %>.
30
30
  <% end %>
31
31
 
32
- <div id='description-<%= escaped_method_name(meth[:name], '_') %>' class='collapse accordion-body'>
32
+ <div id='description-<%= escaped_method_name(meth[:name], escaping: '_') %>' class='collapse accordion-body'>
33
33
  <%= render partial: 'method_detail', locals: { method: meth, h_level: 3 } %>
34
34
  </div>
35
35
  </td>
@@ -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>
@@ -4,7 +4,7 @@
4
4
  <td>
5
5
  <div>
6
6
  <h2>
7
- <a id='link-description-<%= escaped_method_name(prop[:name], '_') %>' href='#description-<%= escaped_method_name(prop[:name], '_') %>'
7
+ <a id='link-description-<%= escaped_method_name(prop[:name], escaping: '_', pattern: /[?!]/) %>' href='#description-<%= escaped_method_name(prop[:name], escaping: '_', pattern: /[?!]/) %>'
8
8
  class='accordion-toggle'
9
9
  data-toggle='collapse'
10
10
  data-parent='#prop-accordion'>
@@ -15,7 +15,7 @@
15
15
  </h2>
16
16
  </div>
17
17
 
18
- <div id='description-<%= escaped_method_name(prop[:name], '_') %>' class='collapse accordion-body'>
18
+ <div id='description-<%= escaped_method_name(prop[:name], escaping: '_', pattern: /[?!]/) %>' class='collapse accordion-body'>
19
19
  <%= render partial: 'property_detail', locals: { property: prop, h_level: 3 } %>
20
20
  </div>
21
21
  </td>
@@ -3,6 +3,16 @@
3
3
  <%= render(partial: 'metadata', locals: { meta: property[:metadata] }) %>
4
4
  <% end %>
5
5
 
6
+ <% unless property[:examples].blank? %>
7
+ <%= heading(t('apipie_dsl.examples'), h_level) %>
8
+ <% property[:examples].each do |example| %>
9
+ <% if example[:desc] %>
10
+ <p><%= example[:desc] %></p>
11
+ <% end %>
12
+ <pre class="prettyprint"><%= example[:example] %></pre>
13
+ <% end %>
14
+ <% end %>
15
+
6
16
  <% unless property[:params].blank? %>
7
17
  <%= heading(t('apipie_dsl.params'), h_level) %>
8
18
  <table class='table'>
@@ -1,18 +1,4 @@
1
- <ul class='breadcrumb'>
2
- <% dsl_sections.each do |section| %>
3
- <% if section == @section %>
4
- <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{@section}") %></a></li>
5
- <% else %>
6
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
7
- <% end %>
8
- <% end %>
9
- <% unless ApipieDSL.configuration.help_layout.nil? %>
10
- <li class='pull-right'>
11
- <% section = 'help' %>
12
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
13
- </li>
14
- <% end %>
15
- </ul>
1
+ <%= apipie_dsl_menu %>
16
2
  <ul class='breadcrumb'>
17
3
  <li>
18
4
  <a href='<%= @doc[:doc_url] %><%= section_ext(@section) %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @klass[:version] %></a>
@@ -1,12 +1,4 @@
1
1
  <% if ApipieDSL.configuration.help_layout %>
2
- <ul class='breadcrumb'>
3
- <% dsl_sections.each do |section| %>
4
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
5
- <% end %>
6
- <li class='active pull-right'>
7
- <% section = 'help' %>
8
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
9
- </li>
10
- </ul>
2
+ <%= apipie_dsl_menu %>
11
3
  <%= render_help %>
12
4
  <% end %>
@@ -1,18 +1,5 @@
1
- <ul class='breadcrumb'>
2
- <% dsl_sections.each do |section| %>
3
- <% if section == @section %>
4
- <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{@section}") %></a></li>
5
- <% else %>
6
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
7
- <% end %>
8
- <% end %>
9
- <% unless ApipieDSL.configuration.help_layout.nil? %>
10
- <li class='pull-right'>
11
- <% section = 'help' %>
12
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
13
- </li>
14
- <% end %>
15
- </ul>
1
+ <%= apipie_dsl_menu %>
2
+
16
3
  <ul class='breadcrumb'>
17
4
  <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(@section) %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= current_version(@doc[:classes]) %></a></li>
18
5
  <%= render(partial: 'languages', locals: { doc_url: @doc[:doc_url] + section_ext(@section) }) %>
@@ -27,7 +14,7 @@
27
14
 
28
15
  <h1 class='page-header'><%= t('apipie_dsl.classes') %></h1>
29
16
 
30
- <% @doc[:classes].each_value do |klass| %>
17
+ <% @doc[:classes].sort_by { |id, c| c[:name] }.each do |id, klass| %>
31
18
  <% next unless klass[:show] && in_section?(@section, klass[:id]) %>
32
19
  <h2>
33
20
  <a href='<%= klass[:doc_url] %><%= @doc[:link_extension] %>'>
@@ -1,18 +1,4 @@
1
- <ul class='breadcrumb'>
2
- <% dsl_sections.each do |section| %>
3
- <% if section == @section %>
4
- <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{@section}") %></a></li>
5
- <% else %>
6
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
7
- <% end %>
8
- <% end %>
9
- <% unless ApipieDSL.configuration.help_layout.nil? %>
10
- <li class='pull-right'>
11
- <% section = 'help' %>
12
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
13
- </li>
14
- <% end %>
15
- </ul>
1
+ <%= apipie_dsl_menu %>
16
2
  <ul class='breadcrumb'>
17
3
  <li>
18
4
  <a href='<%= @doc[:doc_url] %><%= section_ext(@section) %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @klass[:version] %></a>
@@ -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>
@@ -42,7 +42,10 @@
42
42
  <% unless prop[:examples].blank? %>
43
43
  <h4><%= t('apipie_dsl.examples') %></h4>
44
44
  <% prop[:examples].each do |example| %>
45
- <pre class="wiki"><%= example %></pre>
45
+ <% if example[:desc] %>
46
+ <p><%= example[:desc] %></p>
47
+ <% end %>
48
+ <pre class="wiki"><%= example[:example] %></pre>
46
49
  <% end %>
47
50
  <% end %>
48
51
 
@@ -79,7 +82,10 @@
79
82
  <% unless method[:examples].blank? %>
80
83
  <h4><%= t('apipie_dsl.examples') %></h4>
81
84
  <% method[:examples].each do |example| %>
82
- <pre class="wiki"><%= example %></pre>
85
+ <% if example[:desc] %>
86
+ <p><%= example[:desc] %></p>
87
+ <% end %>
88
+ <pre class="wiki"><%= example[:example] %></pre>
83
89
  <% end %>
84
90
  <% end %>
85
91
 
@@ -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>
@@ -59,7 +59,10 @@
59
59
  <% unless prop[:examples].blank? %>
60
60
  <h2><%= t('apipie_dsl.examples') %></h2>
61
61
  <% prop[:examples].each do |example| %>
62
- <pre><%= example %></pre>
62
+ <% if example[:desc] %>
63
+ <p><%= example[:desc] %></p>
64
+ <% end %>
65
+ <pre><%= example[:example] %></pre>
63
66
  <% end %>
64
67
  <% end %>
65
68
 
@@ -107,7 +110,10 @@
107
110
  <% unless method[:examples].blank? %>
108
111
  <h2><%= t('apipie_dsl.examples') %></h2>
109
112
  <% method[:examples].each do |example| %>
110
- <pre><%= example %></pre>
113
+ <% if example[:desc] %>
114
+ <p><%= example[:desc] %></p>
115
+ <% end %>
116
+ <pre class="prettyprint"><%= example[:example] %></pre>
111
117
  <% end %>
112
118
  <% end %>
113
119
 
@@ -6,7 +6,7 @@ module ApipieDSL
6
6
  require 'apipie_dsl/static_dispatcher'
7
7
 
8
8
  class Engine < Rails::Engine
9
- initializer 'static assets', :before => :build_middleware_stack do |app|
9
+ initializer 'static assets', before: :build_middleware_stack do |app|
10
10
  app.middleware.use ::ApipieDSL::StaticDispatcher, "#{root}/app/public"
11
11
  end
12
12
  end
@@ -12,7 +12,7 @@ module ApipieDSL
12
12
  @properties = []
13
13
  @version = version || ApipieDSL.configuration.default_version
14
14
  @parent = ApipieDSL.get_class_description(ApipieDSL.superclass_for(klass), version)
15
- @refs = []
15
+ @refs = [@name]
16
16
  @sections = []
17
17
  @show = true
18
18
  update_from_dsl_data(dsl_data) if dsl_data
@@ -20,17 +20,22 @@ module ApipieDSL
20
20
 
21
21
  def update_from_dsl_data(dsl_data)
22
22
  @name = dsl_data[:class_name] if dsl_data[:class_name]
23
- @full_description = ApipieDSL.markup_to_html(dsl_data[:description])
24
- @short_description = dsl_data[:short_description]
23
+ @full_description = ApipieDSL.markup_to_html(dsl_data[:description]) if dsl_data[:description]
24
+ @short_description = dsl_data[:short_description] || @short_description
25
25
  @tag_list = dsl_data[:tag_list]
26
- @metadata = dsl_data[:meta]
26
+ if dsl_data[:meta].is_a?(Hash)
27
+ @metadata&.merge!(dsl_data[:meta])
28
+ elsif dsl_data[:meta]
29
+ @metadata = dsl_data[:meta]
30
+ end
27
31
  @deprecated = dsl_data[:deprecated] || false
28
32
  @show = dsl_data[:show] || @show
29
- @properties = (dsl_data[:properties] || []).map do |args|
30
- ApipieDSL::MethodDescription.from_dsl_data(self, args)
33
+ prop_names = @properties.map(&:name)
34
+ (dsl_data[:properties] || []).each do |args|
35
+ @properties << ApipieDSL::MethodDescription.from_dsl_data(self, args) unless prop_names.include?(args.first.to_s)
31
36
  end
32
- @refs = dsl_data[:refs] || [@name]
33
- @sections = dsl_data[:sections] || @sections
37
+ @refs = (@refs + dsl_data[:refs]).uniq if dsl_data[:refs]
38
+ @sections = (@sections + dsl_data[:sections]).uniq if dsl_data[:sections]
34
39
  return unless dsl_data[:app_info]
35
40
 
36
41
  ApipieDSL.configuration.app_info[version] = dsl_data[:app_info]
@@ -65,10 +70,6 @@ module ApipieDSL
65
70
  @methods.values
66
71
  end
67
72
 
68
- def property_descriptions
69
- @properties
70
- end
71
-
72
73
  def doc_url(section = nil)
73
74
  crumbs = []
74
75
  crumbs << version if ApipieDSL.configuration.version_in_url
@@ -97,8 +98,8 @@ module ApipieDSL
97
98
  full_description: ApipieDSL.translate(@full_description, lang),
98
99
  version: version,
99
100
  metadata: @metadata,
100
- properties: @properties.map { |prop_desc| prop_desc.docs(section, lang) },
101
- 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] },
102
103
  deprecated: @deprecated,
103
104
  show: @show
104
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
@@ -347,7 +348,7 @@ module ApipieDSL
347
348
  include ApipieDSL::Klass
348
349
  include ApipieDSL::Method
349
350
 
350
- attr_reader :class_scope
351
+ attr_accessor :class_scope
351
352
 
352
353
  def initialize(class_scope)
353
354
  @class_scope = class_scope
@@ -385,10 +386,9 @@ module ApipieDSL
385
386
  end
386
387
 
387
388
  def self.extension_data
388
- @extension_data ||= []
389
+ @extension_data ||= { methods: [] }
389
390
  end
390
391
 
391
- # rubocop:disable Metrics/AbcSize
392
392
  def self.define_validators(class_scope, method_desc)
393
393
  return if method_desc.nil? || ![true, :implicitly, :explicitly].include?(ApipieDSL.configuration.validate)
394
394
  return unless [true, :implicitly].include?(ApipieDSL.configuration.validate)
@@ -415,7 +415,7 @@ module ApipieDSL
415
415
  def self.update_method_desc(method_desc, dsl_data)
416
416
  method_desc.full_description = dsl_data[:description] || method_desc.full_description
417
417
  method_desc.short_description = dsl_data[:short_description] || method_desc.short_description
418
- if dsl_data[:meta]&.is_a?(Hash)
418
+ if dsl_data[:meta].is_a?(Hash)
419
419
  method_desc.metadata&.merge!(dsl_data[:meta])
420
420
  else
421
421
  method_desc.metadata = dsl_data[:meta]
@@ -430,7 +430,6 @@ module ApipieDSL
430
430
  end
431
431
  ParameterDescription.merge(method_desc.plain_params, params)
432
432
  end
433
- # rubocop:enable Metrics/AbcSize
434
433
  end
435
434
  end
436
435
 
@@ -456,9 +455,10 @@ module ApipieDSL
456
455
  end
457
456
 
458
457
  def apipie(context = :method, desc_or_options = nil, options = {}, &block)
459
- if desc_or_options.is_a?(Hash)
458
+ case desc_or_options
459
+ when Hash
460
460
  options = options.merge(desc_or_options)
461
- elsif desc_or_options.is_a?(String)
461
+ when String
462
462
  options[:desc] = desc_or_options
463
463
  end
464
464
  options[:name] ||= context.to_s
@@ -509,9 +509,10 @@ module ApipieDSL
509
509
  private
510
510
 
511
511
  def prepare_delegatee(scope, desc_or_options, options, &block)
512
- if desc_or_options.is_a?(Hash)
512
+ case desc_or_options
513
+ when Hash
513
514
  options = options.merge(desc_or_options)
514
- elsif desc_or_options.is_a?(String)
515
+ when String
515
516
  options[:desc] = desc_or_options
516
517
  end
517
518
 
@@ -530,9 +531,10 @@ module ApipieDSL
530
531
  include ApipieDSL::Delegatable
531
532
 
532
533
  def apipie(context = :method, desc_or_options = nil, options = {}, &block)
533
- if desc_or_options.is_a?(Hash)
534
+ case desc_or_options
535
+ when Hash
534
536
  options = options.merge(desc_or_options)
535
- elsif desc_or_options.is_a?(String)
537
+ when String
536
538
  options[:desc] = desc_or_options
537
539
  end
538
540
  options[:name] ||= context.to_s
@@ -553,16 +555,19 @@ module ApipieDSL
553
555
 
554
556
  delegatee = Delegatee.instance_for(self).with(&block)
555
557
  delegatee.dsl_data[:update_only] = true
556
- # Don't eval the block, since it will be evaluated after method is defined
558
+
557
559
  return if context == :method
558
560
 
559
- # Currently method extensions are supported only
561
+ # Save instance to reuse when actual scope is set
562
+ Delegatee.extension_data[:class] = delegatee
560
563
  Delegatee.instance_reset
561
564
  end
562
565
 
563
566
  def prepended(klass)
564
567
  super
565
- Delegatee.extension_data.each do |method_name, dsl_data|
568
+ Delegatee.extension_data[:class]&.class_scope = klass
569
+ Delegatee.extension_data[:class]&.eval_dsl_for(:class)
570
+ Delegatee.extension_data[:methods].each do |method_name, dsl_data|
566
571
  class_scope = klass
567
572
  if dsl_data[:update_only]
568
573
  class_name = ApipieDSL.get_class_name(class_scope)
@@ -592,7 +597,7 @@ module ApipieDSL
592
597
  return if Delegatee.instance.nil?
593
598
 
594
599
  dsl_data = Delegatee.instance.eval_dsl_for(:method)
595
- Delegatee.extension_data << [method_name, dsl_data]
600
+ Delegatee.extension_data[:methods] << [method_name, dsl_data]
596
601
  ensure
597
602
  Delegatee.instance_reset
598
603
  end
@@ -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
 
@@ -33,7 +33,6 @@ module ApipieDSL
33
33
  end
34
34
  end
35
35
 
36
- # rubocop:disable Metrics/ParameterLists
37
36
  def initialize(method_description, name, validator, desc_or_options = nil, options = {}, &block)
38
37
  if desc_or_options.is_a?(Hash)
39
38
  options = options.merge(desc_or_options)
@@ -64,7 +63,6 @@ module ApipieDSL
64
63
  end
65
64
  raise StandardError, "Validator for #{validator} not found." unless @validator
66
65
  end
67
- # rubocop:enable Metrics/ParameterLists
68
66
 
69
67
  def validator
70
68
  return @validator unless @validator.is_a?(ApipieDSL::Validator::Lazy)
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ApipieDSL
2
4
  module Routing
3
5
  module MapperExtensions
@@ -8,6 +8,9 @@ namespace :apipie_dsl do
8
8
  task :cache, [:include_json] => :environment do |_task, args|
9
9
  args.with_defaults(include_json: false)
10
10
  include_json = %w[1 true].include?(args[:include_json])
11
+ cache_part = ENV['cache_part']
12
+ generate_index = (cache_part == 'classes' ? false : true)
13
+ generate_classes = (cache_part == 'index' ? false : true)
11
14
  time_start = Time.now
12
15
  puts "#{time_start} | Started"
13
16
  ApipieDSL::TasksUtils.with_loaded_documentation do
@@ -24,12 +27,16 @@ namespace :apipie_dsl do
24
27
  ApipieDSL.url_prefix = "../../#{subdir}"
25
28
  doc = ApipieDSL.docs(version, nil, nil, lang, section)
26
29
  doc[:docs][:link_extension] = "#{ApipieDSL::TasksUtils.lang_ext(lang)}.html"
27
- ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
28
- ApipieDSL.url_prefix = "../../../#{subdir}"
29
- section_out = "#{file_base_version}/#{section}"
30
- ApipieDSL::TasksUtils.generate_class_pages(version, section_out, doc, include_json, lang, section)
31
- ApipieDSL.url_prefix = "../../../../#{subdir}"
32
- ApipieDSL::TasksUtils.generate_method_pages(version, section_out, doc, include_json, lang, section)
30
+ if generate_index
31
+ ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
32
+ end
33
+ if generate_classes
34
+ ApipieDSL.url_prefix = "../../../#{subdir}"
35
+ section_out = "#{file_base_version}/#{section}"
36
+ ApipieDSL::TasksUtils.generate_class_pages(version, section_out, doc, include_json, lang, section)
37
+ ApipieDSL.url_prefix = "../../../../#{subdir}"
38
+ ApipieDSL::TasksUtils.generate_method_pages(version, section_out, doc, include_json, lang, section)
39
+ end
33
40
  end
34
41
  ApipieDSL.url_prefix = "../../#{subdir}"
35
42
  doc = ApipieDSL.docs(version, nil, nil, lang)
@@ -61,12 +68,16 @@ namespace :apipie_dsl do
61
68
  ApipieDSL.url_prefix = "../../#{subdir}"
62
69
  doc = ApipieDSL.docs(version, nil, nil, lang, section)
63
70
  doc[:docs][:link_extension] = "#{ApipieDSL::TasksUtils.lang_ext(lang)}.html"
64
- ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
65
- ApipieDSL.url_prefix = "../../../#{subdir}"
66
- section_out = "#{file_base_version}/#{section}"
67
- ApipieDSL::TasksUtils.generate_class_pages(version, section_out, doc, include_json, lang, section)
68
- ApipieDSL.url_prefix = "../../../../#{subdir}"
69
- ApipieDSL::TasksUtils.generate_method_pages(version, section_out, doc, include_json, lang, section)
71
+ if generate_index
72
+ ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
73
+ end
74
+ if generate_classes
75
+ ApipieDSL.url_prefix = "../../../#{subdir}"
76
+ section_out = "#{file_base_version}/#{section}"
77
+ ApipieDSL::TasksUtils.generate_class_pages(version, section_out, doc, include_json, lang, section)
78
+ ApipieDSL.url_prefix = "../../../../#{subdir}"
79
+ ApipieDSL::TasksUtils.generate_method_pages(version, section_out, doc, include_json, lang, section)
80
+ end
70
81
  end
71
82
  ApipieDSL.url_prefix = "../../#{subdir}"
72
83
  doc = ApipieDSL.docs(version, nil, nil, lang)
@@ -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.2.7'
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.2.7
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-06-26 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