diff --git a/contribute.rb b/contribute.rb
index c567a8b1e..8664082f2 100755
--- a/contribute.rb
+++ b/contribute.rb
@@ -1,15 +1,24 @@
#!/usr/bin/env ruby
+require 'rubygems'
module ContributeHelper; end
class Contribute
include ContributeHelper
+
+ def dependencies
+ [
+ Dependencies::Sphinx,
+ Dependencies::Mysql,
+ Dependencies::Ginger
+ ]
+ end
def show
show_welcome_screen
(
- check_for_mysql_gem &&
+ check_for_dependencies &&
create_database_yaml &&
check_mysql_gem_is_working &&
create_test_database
@@ -20,11 +29,12 @@ def show
private
WELCOME_SCREEN = <<-EO_WELCOME
- Thinking Sphinx Contribution
+Thinking Sphinx Contribution
Thanks for contributing to Thinking Sphinx.
In this script we'll help you get started contributing to Thinking Sphinx
+
EO_WELCOME
def show_welcome_screen
@@ -34,35 +44,91 @@ def show_welcome_screen
def show_done_screen
puts "done!"
end
-
- # check / install mysql gem
- def check_for_mysql_gem
- puts "check_for_mysql_gem"
- true
+
+ def check_for_dependencies
+ colour_puts "Checking for required software"
+ puts
+
+ all_found = true
+
+ dependencies.each do |klass|
+ dep = klass.new
+ print " * #{dep.name}... "
+ dep.check!
+
+ if dep.found?
+ if dep.location
+ colour_puts "found at #{dep.location}"
+ else
+ colour_puts "found"
+ end
+ else
+ all_found &= false
+ colour_puts "not found"
+ end
+ end
+
+ puts
+
+ all_found
end
- def check_mysql_gem_is_working
- puts "check_mysql_gem_is_working"
+ def check_mysql_is_working
+ colour_puts "check mysql gem is working"
false
end
# create database.yml
def create_database_yaml
- puts "create_database_yaml"
+ colour_puts "creating database yaml"
false
end
# create test db
def create_test_database
- puts "create_test_database"
+ colour_puts "create test database"
false
end
end
module ContributeHelper
+ class Dependency
+ def self.name(name=nil)
+ if name then @name = name else @name end
+ end
+
+ attr_reader :location
+
+ def initialize
+ @found = false
+ @location = nil
+ end
+
+ def name; self.class.name end
+
+ def check; false end
+ def check!
+ @found = check
+ end
+
+ def found?
+ @found
+ end
+ end
+
+ class Gem < Dependency
+ def gem_name; self.class.name end
+ def name; "#{super} gem" end
+
+ def check
+ ::Gem.available? self.gem_name
+ end
+ end
+
+
+
DEFAULT_TERMINAL_COLORS = "\e[0m\e[37m\e[40m"
def subs_colour(data)
-
data = data.gsub(%r{(.*?)}m, "\e[1m\\1#{DEFAULT_TERMINAL_COLORS}")
data.gsub!(%r{(.*?)}m, "\e[1m\e[31m\\1#{DEFAULT_TERMINAL_COLORS}")
data.gsub!(%r{(.*?)}m, "\e[1m\e[32m\\1#{DEFAULT_TERMINAL_COLORS}")
@@ -77,4 +143,24 @@ def colour_puts(text)
end
end
+module Dependencies
+ class Mysql < ContributeHelper::Gem
+ name 'mysql'
+ end
+
+ class Ginger < ContributeHelper::Gem
+ name 'ginger'
+ end
+
+ class Sphinx < ContributeHelper::Dependency
+ name 'sphinx'
+
+ def check
+ output = `which searchd`
+ @location = output.chomp if $? == 0
+ $? == 0
+ end
+ end
+end
+
Contribute.new.show
\ No newline at end of file