Sha256: 2649f84ad967bc46f08511231d8285948f1500333e4b8d5c31ee465f284213e4

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'guard'
require 'guard/plugin'
require 'yard'

module Guard
  class Yard < Plugin
    autoload :NoServer, 'guard/yard/no_server'
    autoload :Server, 'guard/yard/server'
    attr_accessor :server

    def initialize(options = {})
      super
      options[:server] = true unless options.key?(:server)
      @server = options[:server] ? Server.new(options) : NoServer.new
    end

    def start
      boot
    end

    def stop
      server.kill
    end

    def reload
      boot
    end

    def run_all
      UI.info "[Guard::Yard] Generating all documentation."
      system('rm -rf .yardoc && yard doc')
      UI.info "[Guard::Yard] Documentation has been generated."
      true
    end

    def run_on_changes(paths)
      UI.info "[Guard::Yard] Detected changes in #{paths.join(',')}."
      paths.each { |path| document([path]) }
      UI.info "[Guard::Yard] Updated documentation for #{paths.join(',')}."
    end

    private

    def check
      return true if File.exists?('.yardoc')
      UI.info "[Guard::Yard] Documentation missing."
      run_all and true
    end

    def boot
      check and server.kill and server.spawn and server.verify
    end

    def document files
      ::YARD::Registry.load!
      ::YARD::Registry.load(files, true)
      ::YARD::Registry.load_all
      yardoc = ::YARD::CLI::Yardoc.new
      yardoc.parse_arguments
      options = yardoc.options
      objects = ::YARD::Registry.all(:root, :module, :class).reject do |object|
        (!options[:serializer] || options[:serializer].exists?(object)) \
          && !object.files.any?{|f,line| files.include?(f)}
      end
      ::YARD::Templates::Engine.generate(objects, options)
      save_registry
    end

    def save_registry
      ::YARD::Registry.save(true)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-yard-2.1.4 lib/guard/yard.rb