Class: Aspera::Transfer::SpecDoc
- Inherits:
-
Object
- Object
- Aspera::Transfer::SpecDoc
- Defined in:
- lib/aspera/transfer/spec_doc.rb
Overview
Generate documentation from Schema, for Transfer Spec, or async Conf spec
Constant Summary collapse
- AGENT_LIST =
Agents shown in manual for parameters (sub list)
Agent::Factory.instance.list.map do |agent_sym| [agent_sym, agent_sym.to_s.capitalize, agent_to_short(agent_sym)] end.sort_by(&:last).freeze
Class Method Summary collapse
-
.agent_to_short(agent_sym) ⇒ Object
First letter of agent name symbol.
-
.man_table(formatter, include_option: false, agent_columns: true, schema: Spec::SCHEMA) ⇒ Array
A table suitable to display in manual.
Class Method Details
.agent_to_short(agent_sym) ⇒ Object
First letter of agent name symbol
12 13 14 |
# File 'lib/aspera/transfer/spec_doc.rb', line 12 def agent_to_short(agent_sym) agent_sym.to_sym.eql?(:direct) ? :a : agent_sym.to_s[0].to_sym end |
.man_table(formatter, include_option: false, agent_columns: true, schema: Spec::SCHEMA) ⇒ Array
Returns a table suitable to display in manual.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/aspera/transfer/spec_doc.rb', line 21 def man_table(formatter, include_option: false, agent_columns: true, schema: Spec::SCHEMA) col_local = agent_to_short(:direct) cols = %i[name type description] cols.insert(-2, *AGENT_LIST.map(&:last)) if agent_columns rows = [] schema['properties'].each do |name, info| rows.concat(man_table(formatter, include_option: include_option, agent_columns: agent_columns, schema: info).last.map{ |h| h.merge(name: "#{name}.#{h[:name]}")}) if info['type'].eql?('object') && info['properties'] rows.concat(man_table(formatter, include_option: include_option, agent_columns: agent_columns, schema: info['items']).last.map{ |h| h.merge(name: "#{name}[].#{h[:name]}")}) if info['type'].eql?('array') && info['items'] && info['items']['properties'] # Manual table columns = { name: name, type: info['type'], description: [] } # Render Markdown formatting and split lines columns[:description] = info['description'] .gsub(Markdown::FORMATS){formatter.markdown(Regexp.last_match)} .split("\n") if info.key?('description') columns[:description].unshift("DEPRECATED: #{info['x-deprecation']}") if info.key?('x-deprecation') # Add flags for supported agents in doc agents = [] AGENT_LIST.each do |agent_info| agents.push(agent_info.last) if info['x-agents'].nil? || info['x-agents'].include?(agent_info.first.to_s) end Aspera.assert(agents.include?(col_local)){"#{name}: x-cli-option requires agent direct (or nil)"} if info['x-cli-option'] if agent_columns AGENT_LIST.each do |agent_info| columns[agent_info.last] = formatter.tick(agents.include?(agent_info.last)) end else columns[:description].push("(#{agents.map(&:upcase).join(', ')})") unless agents.length.eql?(AGENT_LIST.length) end # Only keep lines that are usable in supported agents next false if agents.empty? columns[:description].push("Allowed values: #{info['enum'].map{ |v| formatter.markdown("`#{v}`")}.join(', ')}") if info.key?('enum') if include_option envvar_prefix = '' cli_option = if info.key?('x-cli-envvar') envvar_prefix = 'env:' info['x-cli-envvar'] elsif info['x-cli-switch'] info['x-cli-option'] elsif info['x-cli-option'] arg_type = info.key?('enum') ? '{enum}' : "{#{[info['type']].flatten.join('|')}}" # conversion_tag = info['x-cli-convert'] conversion_tag = info.key?('x-cli-convert') ? 'conversion' : nil sep = info['x-cli-option'].start_with?('--') ? '=' : ' ' "#{info['x-cli-option']}#{sep}#{"(#{conversion_tag})" if conversion_tag}#{arg_type}" end short = info.key?('x-cli-short') ? "(#{info['x-cli-short']})" : nil columns[:description].push("(#{'special:' if info['x-cli-special']}#{envvar_prefix}#{formatter.markdown("`#{cli_option}`")})#{short}") if cli_option end rows.push(formatter.check_row(columns)) end [cols, rows.sort_by{ |i| i[:name]}] end |