Sha256: ca58fd4882be5b62d94ba041bc1ced724bbc0ff8d350f3b1d268cbf82683019c

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'guard/compat/plugin'

module Guard
  class Jasmine < Plugin
    # The inspector verifies if the changed paths are valid
    # for Guard::Jasmine. Please note that request to {.clean}
    # paths keeps the current valid files cached until {.clear} is
    # called.
    #
    module Inspector
      class << self
        # Clean the changed paths and return only valid
        # Jasmine specs in either JavaScript or CoffeeScript.
        #
        # @param [Array<String>] paths the changed paths
        # @param [Hash] options the options for the Guard
        # @option options [String] :spec_dir the directory with the Jasmine specs
        # @return [Array<String>] the valid spec files
        #
        def clean(paths, options)
          paths.uniq!
          paths.compact!
          paths = if paths.include?(options[:spec_dir])
                    [options[:spec_dir]]
                  else
                    paths.select { |p| jasmine_spec?(p) }
                  end

          paths
        end

        private

        # Tests if the file is valid.
        #
        # @param [String] path the file
        # @return [Boolean] when the file valid
        #
        def jasmine_spec?(path)
          path =~ /(?:_s|S)pec\.(js|coffee|js\.coffee|cjsx|js\.cjsx)$/ && File.exist?(path)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
guard-jasmine-3.1.0 lib/guard/jasmine/inspector.rb
guard-jasmine-3.0.0 lib/guard/jasmine/inspector.rb
guard-jasmine-2.1.0 lib/guard/jasmine/inspector.rb