/
init.rb
60 lines (50 loc) · 1.94 KB
/
init.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
# Copyright (C) 2008, 2009 Ryan Stenhouse & Mark Somerville
#
# 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
# Calculate RAILS_ROOT on the off chance that it isnt defined, we need
# this to get the Production database configuration.
#
if not defined? RAILS_ROOT
RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../') rescue nil
end
# Set the Freelancer's path
#
JOBBY_FREELANCERS_PATH = RAILS_ROOT + '/lib/freelancers'
unless File.exists?(JOBBY_FREELANCERS_PATH)
`mkdir #{JOBBY_FREELANCERS_PATH}`
end
# Pull in the required code
#
require File.dirname(__FILE__) + "/lib/jobby_dispatcher.rb"
require File.dirname(__FILE__) + "/lib/freelancer.rb"
require File.dirname(__FILE__) + "/lib/methods.rb"
# Job will always connect to the #{RAILS_ENV} database. This won't impact on any
# of the other models.
#
begin
Jobby::Job.establish_connection(YAML::load(IO.read(RAILS_ROOT + '/config/database.yml'))[RAILS_ENV.downcase])
rescue Exception => error
puts <<-TXT
The Jobby-Rails Plugin failed to load because it couldn't establish
a connection to your #{RAILS_ENV} database environment.
The exact exception raised was:
#{error}
TXT
exit(-1)
end
# Give all the actions our methods
#
ActionController::Base.send(:include, Jobby::Methods)
puts "=> PCCL Rails / Jobby Interface Loaded"