Sha256: bab70aafec4d919f3398bb1d68ff1db0fe9447e24ddad1c24fc39c04ca5df286

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

module Guard
  class Jasmine

    # 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
        # @return [Array<String>] the valid spec files
        #
        def clean(paths)
          paths.uniq!
          paths.compact!

          if paths.include?('spec/javascripts')
            paths = ['spec/javascripts']
          else
            paths = paths.select { |p| jasmine_spec?(p) }
          end

          paths
        end

        # Clears the list of Jasmine specs in this project.
        #
        def clear
          @jasmine_specs = nil
        end

        private

        # Tests if the file is valid.
        #
        # @param [String] file the file
        # @return [Boolean] when the file valid
        #
        def jasmine_spec?(path)
          jasmine_specs.include?(path)
        end

        # Scans the project and keeps a list of all
        # JavaScript and CoffeeScript files in the `spec`
        # directory.
        #
        # @see #clear
        # @return [Array<String>] the valid files
        #
        def jasmine_specs
          @jasmine_specs ||= Dir.glob('spec/**/*_spec.{js,js.coffee}')
        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
guard-jasmine-0.8.1 lib/guard/jasmine/inspector.rb
guard-jasmine-0.8.0 lib/guard/jasmine/inspector.rb
guard-jasmine-0.7.2 lib/guard/jasmine/inspector.rb
guard-jasmine-0.7.1 lib/guard/jasmine/inspector.rb
guard-jasmine-0.7.0 lib/guard/jasmine/inspector.rb
guard-jasmine-0.6.2 lib/guard/jasmine/inspector.rb
guard-jasmine-0.6.1 lib/guard/jasmine/inspector.rb
guard-jasmine-0.6.0 lib/guard/jasmine/inspector.rb