diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-15 20:19:03 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-15 20:19:03 +0000 |
| commit | a0bcf5a355569633de420e109bce493cc8808a26 (patch) | |
| tree | abf3d0c64bac724862405032ee213fc4403deaa9 | |
| parent | 122e2bc780e2b135c8d95ce28be74eac5a6e3fd2 (diff) | |
| download | puppet-a0bcf5a355569633de420e109bce493cc8808a26.tar.gz puppet-a0bcf5a355569633de420e109bce493cc8808a26.tar.xz puppet-a0bcf5a355569633de420e109bce493cc8808a26.zip | |
Adding code to try for the rails gem if the library cannot be found normally, and adding some protections in case there are problems
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1198 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/rails.rb | 21 | ||||
| -rw-r--r-- | lib/puppet/rails/database.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/rails/host.rb | 5 |
3 files changed, 24 insertions, 6 deletions
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb index 016d7374a..d035968eb 100644 --- a/lib/puppet/rails.rb +++ b/lib/puppet/rails.rb @@ -22,6 +22,16 @@ rescue LoadError => detail end end +# If we couldn't find it the normal way, try using a Gem. +unless defined? ActiveRecord + begin + require 'rubygems' + require_gem 'rails' + rescue LoadError + # Nothing + end +end + module Puppet::Rails Puppet.config.setdefaults(:puppetmaster, :dblocation => { :default => "$statedir/clientconfigs.sqlite3", @@ -84,9 +94,16 @@ module Puppet::Rails if Puppet[:dbadapter] == "sqlite3" and ! FileTest.exists?(Puppet[:dblocation]) require 'puppet/rails/database' - Puppet::Rails::Database.up + begin + Puppet::Rails::Database.up + rescue => detail + if Puppet[:debug] + puts detail.backtrace + end + raise Puppet::Error, "Could not initialize database: %s" % detail + end end - Puppet.config.use(:puppetmaster) + Puppet.config.use(:puppetmaster) end end diff --git a/lib/puppet/rails/database.rb b/lib/puppet/rails/database.rb index e0a91cb7a..caf87cbb8 100644 --- a/lib/puppet/rails/database.rb +++ b/lib/puppet/rails/database.rb @@ -2,7 +2,9 @@ class Puppet::Rails::Database < ActiveRecord::Migration require 'sqlite3' def self.up - ActiveRecord::Migration.verbose = false + if ActiveRecord::Migration.respond_to?(:verbose) + ActiveRecord::Migration.verbose = false + end create_table :rails_objects do |table| table.column :name, :string, :null => false diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index ace906117..77123c871 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -2,7 +2,6 @@ require 'puppet/rails/rails_object' #RailsObject = Puppet::Rails::RailsObject class Puppet::Rails::Host < ActiveRecord::Base - Host = self serialize :facts, Hash serialize :classes, Array @@ -10,7 +9,7 @@ class Puppet::Rails::Host < ActiveRecord::Base # If the host already exists, get rid of its objects def self.clean(host) - if obj = Host.find_by_name(host) + if obj = self.find_by_name(host) obj.rails_objects.clear return obj else @@ -47,7 +46,7 @@ class Puppet::Rails::Host < ActiveRecord::Base end host.addobjects(objects) else - host = Host.new(hostargs) do |hostobj| + host = self.new(hostargs) do |hostobj| hostobj.addobjects(objects) end end |
