Sha256: e1ec38d48c3346ceee939a276e71bd66e15e22542d8069a94d471680d3cf0f1d

Contents?: true

Size: 974 Bytes

Versions: 6

Compression:

Stored size: 974 Bytes

Contents

module Adrian
  module Filters

    def filters
      @filters ||= []
    end

    def filter?(item)
      !filters.all? { |filter| filter.allow?(item) }
    end

    class Delay
      FIFTEEN_MINUTES = 900

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

      def allow?(item)
        item.updated_at <= (Time.now - duration)
      end

      def duration
        @options[:duration] ||= FIFTEEN_MINUTES
      end

    end

    class FileLock
      ONE_HOUR = 3_600

      def initialize(options = {})
        @options       = options
        @reserved_path = @options.fetch(:reserved_path)
      end

      def allow?(item)
        !locked?(item) || lock_expired?(item)
      end

      def lock_expired?(item)
        item.updated_at <= (Time.now - duration)
      end

      def locked?(item)
        @reserved_path == File.dirname(item.path)
      end

      def duration
        @options[:duration] ||= ONE_HOUR
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
adrian-2.0.2 lib/adrian/filters.rb
adrian-2.0.1 lib/adrian/filters.rb
adrian-2.0.0 lib/adrian/filters.rb
adrian-1.5.0 lib/adrian/filters.rb
adrian-1.4.0 lib/adrian/filters.rb
adrian-1.3.3 lib/adrian/filters.rb