Sha256: 2fb06f0bdc18e1114724d412dd386d8781144b9cf87da4106f90e6bba98440e3

Contents?: true

Size: 1.14 KB

Versions: 14

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

class ThinkingSphinx::Commands::Base
  include ThinkingSphinx::WithOutput

  def self.call(configuration, options, stream = STDOUT)
    new(configuration, options, stream).call_with_handling
  end

  def call_with_handling
    call
  rescue Riddle::CommandFailedError => error
    handle_failure error.command_result
  end

  private

  delegate :controller, :to => :configuration

  def command(command, extra_options = {})
    ThinkingSphinx::Commander.call(
      command, configuration, options.merge(extra_options), stream
    )
  end

  def command_output(output)
    return "See above\n" if output.nil?

    "\n\t" + output.gsub("\n", "\n\t")
  end

  def handle_failure(result)
    stream.puts <<-TXT

The Sphinx #{type} command failed:
  Command: #{result.command}
  Status:  #{result.status}
  Output:  #{command_output result.output}
There may be more information about the failure in #{configuration.searchd.log}.
    TXT
    exit(result.status || 1)
  end

  def log(message)
    return if options[:silent]

    stream.puts message
  end

  def skip_directories?
    configuration.settings['skip_directory_creation']
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/commands/base.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/commands/base.rb