Sha256: 4fab8512ff1be0cdfe1123475c1d28da6d8e1c21a606bd487298de362cea49b9

Contents?: true

Size: 974 Bytes

Versions: 9

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.new - 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.new - 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

9 entries across 9 versions & 1 rubygems

Version Path
adrian-1.3.2 lib/adrian/filters.rb
adrian-1.3.1 lib/adrian/filters.rb
adrian-1.3.0 lib/adrian/filters.rb
adrian-1.2.0 lib/adrian/filters.rb
adrian-1.1.2 lib/adrian/filters.rb
adrian-1.1.1 lib/adrian/filters.rb
adrian-1.1.0 lib/adrian/filters.rb
adrian-1.0.1 lib/adrian/filters.rb
adrian-1.0.0 lib/adrian/filters.rb