diff --git a/lib/puppet-strings/yard/code_objects/task.rb b/lib/puppet-strings/yard/code_objects/task.rb index e527bbf87..ceff39346 100644 --- a/lib/puppet-strings/yard/code_objects/task.rb +++ b/lib/puppet-strings/yard/code_objects/task.rb @@ -59,7 +59,7 @@ def to_hash file: statement.file, line: statement.line, docstring: { - text: statement.json['description'], + text: statement.docstring, tags: parameters }, source: statement.source, diff --git a/lib/puppet-strings/yard/parsers/json/task_statement.rb b/lib/puppet-strings/yard/parsers/json/task_statement.rb index 723779411..5445e8591 100644 --- a/lib/puppet-strings/yard/parsers/json/task_statement.rb +++ b/lib/puppet-strings/yard/parsers/json/task_statement.rb @@ -1,7 +1,7 @@ module PuppetStrings::Yard::Parsers::JSON # Represents the Puppet Task statement. class TaskStatement - attr_reader :line, :comments, :comments_range, :json, :file, :source + attr_reader :line, :comments, :comments_range, :json, :file, :source, :docstring def initialize(json, source, file) @file = file @@ -9,10 +9,7 @@ def initialize(json, source, file) @json = json @line = 0 @comments_range = nil - end - - def docstring - YARD::Docstring.new(json['description'] || "") + @docstring = YARD::Docstring.new(@json['description']) end def parameters @@ -28,7 +25,7 @@ def show end def comments - "" + docstring.all end def name diff --git a/spec/fixtures/unit/markdown/output.md b/spec/fixtures/unit/markdown/output.md index 9d225c872..ee42a92e5 100644 --- a/spec/fixtures/unit/markdown/output.md +++ b/spec/fixtures/unit/markdown/output.md @@ -15,6 +15,8 @@ * [`func3x`](#func3x): Documentation for an example 3.x function. * [`func4x`](#func4x): An example 4.x function. * [`func4x_1`](#func4x_1): An example 4.x function with only one signature. +## Tasks +* [`(stdin)`](#(stdin)): Allows you to backup your database to local file. ## Classes ### klass @@ -381,3 +383,39 @@ Data type: `Integer` The first parameter. +## Tasks + +### (stdin) + +Allows you to backup your database to local file. + +#### Input + +Input method: stdin + +#### Parameters + +##### `database` + +Data type: `Optional[String[1]]` + +Database to connect to + +##### `user` + +Data type: `Optional[String[1]]` + +The user + +##### `password` + +Data type: `Optional[String[1]]` + +The password + +##### `sql` + +Data type: `String[1]` + +Path to file you want backup to + diff --git a/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb b/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb index 65f455355..1fbbbf35e 100644 --- a/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +++ b/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb @@ -64,7 +64,7 @@ class foo { subject.parse expect(subject.enumerator.size).to eq(1) statement = subject.enumerator.first - expect(statement).to be_instance_of(Hash) + expect(statement).to be_instance_of(PuppetStrings::Yard::Parsers::JSON::TaskStatement) end end end diff --git a/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb b/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb new file mode 100644 index 000000000..e20a01ad4 --- /dev/null +++ b/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe PuppetStrings::Yard::Parsers::JSON::TaskStatement do + let(:source) { <<-SOURCE +{ + "description": "Allows you to backup your database to local file.", + "input_method": "stdin", + "parameters": { + "database": { + "description": "Database to connect to", + "type": "Optional[String[1]]" + }, + "user": { + "description": "The user", + "type": "Optional[String[1]]" + }, + "password": { + "description": "The password", + "type": "Optional[String[1]]" + }, + "sql": { + "description": "Path to file you want backup to", + "type": "String[1]" + } + } +} +SOURCE + } + let(:json) { JSON.parse(source) } + subject { PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, source, "test.json") } + describe '#comments' do + it 'returns docstring' do + expect(subject.comments).to eq "Allows you to backup your database to local file." + end + end + describe '#parameters' do + context 'with params' do + it 'returns params' do + expect(subject.parameters.size > 0).to be true + end + end + context 'no params' do + let(:source) { <<-SOURCE +{ + "description": "Allows you to backup your database to local file.", + "input_method": "stdin" +} +SOURCE + } + it 'returns an empty hash' do + expect(subject.parameters).to eq({}) + end + end + end + +end