Sha256: aa27a9bf0fa27cda0babdeb6a46e9f6aa15cd462fe58079969e7f1898233b585

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module Guard
  class Strainer
    class Runner
      attr_reader :cabinet

      def initialize(options)
        @options = options
        @cabinet = {}
      end

      def run!(paths = [])
        cookbooks = paths.map{|path| find_cookbook_name(path)}
        runner = runner_for_cookbooks(cookbooks)

        UI.info "Straining: #{cookbooks.join(',')}"
        runner.run!
      end

      def run_all!
        paths = Dir[File.join('**', 'metadata.rb')].sort
        run!(paths)
      end

      protected
      def find_cookbook_name(path)
        current_path = Pathname.new(File.dirname(path))
        cookbook = nil

        until current_path == ::Guard::Dsl.options["guardfile_path"] do
          if File.exist?(File.join(current_path, 'metadata.rb'))
            cookbook = current_path.basename
            break
          else
            current_path = current_path.parent
          end
        end

        cookbook
      end

      def runner_for_cookbooks(cookbooks)
        @cabinet.fetch(cookbooks) do |books|
          ::Strainer::Runner.new(books, @options.merge({strainer_file: File.join(File.dirname(::Guard::Dsl.options["guardfile_path"]), ::Strainer::Strainerfile::DEFAULT_FILENAME)}))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-strainer-1.0.0 lib/guard/strainer/runner.rb