/
sanity_checks.rb
75 lines (63 loc) · 2.6 KB
/
sanity_checks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright (C) 2009 Ryan Stenhouse
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class SanityChecks
cattr_accessor :errors
def self.jobby_rails_installed?
return true if File.exists?(File.dirname(__FILE__) + "/.jobbyRailsInstalled")
@@errors = []
jobby_jobs_table_exists
javascripts_are_where_they_should_be
if (errors.nitems == 0)
system("touch '#{File.dirname(__FILE__)}/.jobbyRailsInstalled'")
return true
else
return false
end
end
def self.jobby_jobs_table_exists
ActiveRecord::Base.establish_connection(YAML::load(IO.read(RAILS_ROOT + '/config/database.yml'))[RAILS_ENV.downcase])
if not ActiveRecord::Base.connection.tables.include?('jobby_jobs')
@@errors << "'jobby_jobs' table not found. Run migration!"
end
end
def self.javascripts_are_where_they_should_be
if not File.exists?("#{RAILS_ROOT}/public/javascripts/jobby_notifications.js")
@@errors << "Jobby Notifications is not in rails Javascripts Directory"
end
if not File.exists?("#{RAILS_ROOT}/public/javascripts/jquery.gritter.min.js")
@@errors << "Gritter JQuery plugin is not in rails Javascripts Directory"
end
if not File.exists?("#{RAILS_ROOT}/public/javascripts/jquery.js")
@@errors << "JQuery is not in rails Javascripts Directory"
end
if not File.exists?("#{RAILS_ROOT}/public/javascripts/jquery.timers.js")
@@errors << "Timer JQuery plugin is not in rails Javascripts Directory"
end
end
def self.error_banner
return <<-ERR
Warning! Jobby Rails has not been correctly installed!
------------------------------------------------------
After installing the plugin, there is a rake task which
needs to be run to make sure the required assets are
copied accross and all manner of other fun things are
set up.
If you aren't bothered about the specific problem, run
rake jobby_rails:install and it'll do the steps that
need to be completed to install.
ERR
end
end