Sha256: 0bbadce6d5ea0b786d9eeef8f9ba28eb24ebd2e6316ef48a609eb1bff84f3a7f

Contents?: true

Size: 744 Bytes

Versions: 17

Compression:

Stored size: 744 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::Guard::Files
  def self.call(names, &block)
    new(names).call(&block)
  end

  def initialize(names)
    @names = names
  end

  def call(&block)
    return if unlocked.empty?

    unlocked.each &:lock
    block.call unlocked.collect(&:name)
  rescue => error
    raise error
  ensure
    unlocked.each &:unlock
  end

  private

  attr_reader :names

  def log_lock(file)
    ThinkingSphinx::Logger.log :guard,
      "Guard file for index #{file.name} exists, not indexing: #{file.path}."
  end

  def unlocked
    @unlocked ||= names.collect { |name|
      ThinkingSphinx::Guard::File.new name
    }.reject { |file|
      log_lock file if file.locked?
      file.locked?
    }
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/guard/files.rb