Sha256: 61255e534a5ae86ee898429d944d6e4193b58af4bc70cc6d58d1bd8ff22d7fe5

Contents?: true

Size: 830 Bytes

Versions: 24

Compression:

Stored size: 830 Bytes

Contents

module LitmusPaper
  module Dependency
    class FileContents
      def initialize(path, regex, options = {})
        @path = path
        @regex = regex
        @timeout = options.fetch(:timeout, 5)
      end

      def available?
        Timeout.timeout(@timeout) do
          if File.read(@path).match(@regex)
            true
          else
            LitmusPaper.logger.info("Available check of #{@path} failed, content did not match #{@regex.inspect}")
            false
          end
        end
      rescue Timeout::Error
        LitmusPaper.logger.info("Timeout reading #{@path}")
        false
      rescue => e
        LitmusPaper.logger.info("Error reading #{@path}: '#{e.message}'")
        false
      end

      def to_s
        "Dependency::FileContents(#{@path}, #{@regex.inspect})"
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
litmus_paper-1.6.2 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.6.1 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.6.0 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.5.0 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.4.2 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.4.1 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.3.0 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.2.0 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.1.1 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.1.0 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-1.0.0 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.9 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.7 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.6 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.5 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.4 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.3 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.2 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.1 lib/litmus_paper/dependency/file_contents.rb
litmus_paper-0.9.0 lib/litmus_paper/dependency/file_contents.rb