Sha256: 4639a925efb513f5af7f503db8ceacdfc6fafe1692876d228e95f13b711fed08

Contents?: true

Size: 713 Bytes

Versions: 8

Compression:

Stored size: 713 Bytes

Contents

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

8 entries across 8 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.3.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.1.4 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.1.3 lib/thinking_sphinx/guard/files.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/guard/files.rb