Sha256: cec085383c994d932eede8ff271e3bda5d5f1ecbe5dd0c350f2a2292f3fee4ed

Contents?: true

Size: 905 Bytes

Versions: 2

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

module God
  module Conditions
    # Condition Symbol :file_touched
    # Type: Poll
    #
    # Trigger when a specified file is touched.
    #
    # Parameters
    #   Required
    #     +path+ is the path to the file to watch.
    #
    # Examples
    #
    # Trigger if 'tmp/restart.txt' file is touched (from a Watch):
    #
    #   on.condition(:file_touched) do |c|
    #     c.path = 'tmp/restart.txt'
    #   end
    #
    class FileTouched < PollCondition
      attr_accessor :path

      def initialize
        super
        self.path = nil
      end

      def valid?
        valid = true
        valid &= complain("Attribute 'path' must be specified", self) if path.nil?
        valid
      end

      def test
        if File.exist?(path)
          (Time.now - File.mtime(path)) <= interval
        else
          false
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
resurrected_god-1.1.1 lib/god/conditions/file_touched.rb
resurrected_god-1.1.0 lib/god/conditions/file_touched.rb