Module: Appium::Thor::Docs
- Included in:
- Default
- Defined in:
- lib/appium_thor/docs.rb
Instance Method Summary collapse
- #globs(paths) ⇒ Object
- #last_sha ⇒ Object
- #mobj_to_md(obj) ⇒ Object
- #run(out_file, globs) ⇒ Object
- #space(amount) ⇒ Object
Instance Method Details
#globs(paths) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/appium_thor/docs.rb', line 74 def globs(paths) # Convert single string to array for map paths = [paths] unless paths.kind_of? Array # Adjust path based on system paths.map! { |path| "#{Dir.pwd}#{path}" } end |
#last_sha ⇒ Object
8 9 10 |
# File 'lib/appium_thor/docs.rb', line 8 def last_sha `git rev-parse --verify HEAD`.strip end |
#mobj_to_md(obj) ⇒ Object
12 13 14 15 16 17 18 19 20 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 |
# File 'lib/appium_thor/docs.rb', line 12 def mobj_to_md obj out = '' # skip objects without method signatures sig = obj.signature return out unless sig # skip class vars if sig.start_with?('@@') || # skip methods marked private obj.tag('private') || # skip date and version from version.rb obj.name.match(/DATE|VERSION/) return out end method_path = obj.file.split('/lib/').last os = method_path.downcase.match(/ios|android/) || 'common' out.concat("##### [#{obj.name.to_s}](https://github.com/#{github_owner}/#{github_name}/blob/#{last_sha}/lib/#{method_path}#L#{obj.line}) #{os}\n\n") out.concat("> #{obj.signature}\n\n") out.concat("#{obj.docstring}\n\n") indent = space 5 params = obj..select { |tag| tag.tag_name == 'param' } unless params.empty? out.concat("__Parameters:__\n\n") params.each do |param| out.concat("#{indent}[#{param.types.join(', ') unless param.types.nil?}] ") out.concat("#{param.name} - #{param.text}\n\n") end end ret = obj.tag 'return' if ret out.concat("__Returns:__\n\n") out.concat("#{indent}[#{ret.types.join(', ') unless ret.types.nil?}] #{ret.text}\n\n") end out.concat("--\n\n") out end |
#run(out_file, globs) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/appium_thor/docs.rb', line 55 def run(out_file, globs) YARD::Registry.clear puts "Globbing: #{globs}" puts "Writing: #{out_file}" FileUtils.mkdir_p File.dirname out_file YARD::Parser::SourceParser.parse globs File.open(out_file, 'w') do |file| entries = YARD::Registry.entries entries_length = entries.length puts "Processing: #{entries_length} entries" raise 'No entries to process' if entries_length <= 0 YARD::Registry.entries.each do |entry| file.write mobj_to_md entry end end raise 'Empty file generated' if File.size(out_file) <= 0 end |
#space(amount) ⇒ Object
4 5 6 |
# File 'lib/appium_thor/docs.rb', line 4 def space amount ' ' * amount end |