class ThinkingSphinx::Guard::Files

Attributes

names[R]

Public Class Methods

call(names, &block) click to toggle source
# File lib/thinking_sphinx/guard/files.rb, line 4
def self.call(names, &block)
  new(names).call(&block)
end
new(names) click to toggle source
# File lib/thinking_sphinx/guard/files.rb, line 8
def initialize(names)
  @names = names
end

Public Instance Methods

call(&block) click to toggle source
# File lib/thinking_sphinx/guard/files.rb, line 12
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 Instance Methods

log_lock(file) click to toggle source
# File lib/thinking_sphinx/guard/files.rb, line 27
def log_lock(file)
  ThinkingSphinx::Logger.log :guard,
    "Guard file for index #{file.name} exists, not indexing: #{file.path}."
end
unlocked() click to toggle source
# File lib/thinking_sphinx/guard/files.rb, line 32
def unlocked
  @unlocked ||= names.collect { |name|
    ThinkingSphinx::Guard::File.new name
  }.reject { |file|
    log_lock file if file.locked?
    file.locked?
  }
end