Browse files

Monkey patched pathname to work with puppet better, so we don't have …

…to call rails_root.to_s everywhere.
  • Loading branch information...
1 parent 978af64 commit fc2b9430cedf6b49374855591b42c74a9353ed40 @technicalpickles technicalpickles committed Feb 17, 2010
Showing with 28 additions and 4 deletions.
  1. +1 −0 lib/moonshine.rb
  2. +12 −0 lib/moonshine/core_ext.rb
  3. +4 −4 lib/moonshine/manifest/rails/rails.rb
  4. +11 −0 test/test_pathname.rb
View
1 lib/moonshine.rb
@@ -14,5 +14,6 @@ module Moonshine #:nodoc:
$LOAD_PATH.unshift(here)
end
+require 'moonshine/core_ext'
require 'moonshine/manifest'
require 'moonshine/manifest/rails'
View
12 lib/moonshine/core_ext.rb
@@ -0,0 +1,12 @@
+# These extensions to Pathname let us use Pathname with puppet more easily
+# ie exec "blah", :cwd => Pathname.new('/etc')
+Pathname.class_eval do
+ def =~(pattern)
+ to_s =~ pattern
+ end
+
+ def gsub(*args)
+ to_s.gsub(*args)
+ end
+
+end
View
8 lib/moonshine/manifest/rails/rails.rb
@@ -71,7 +71,7 @@ def rails_rake_environment
exec 'rake tasks',
:command => 'rake environment 2>&1 | tee -a /var/log/moonshine_rake.log',
:user => configuration[:user],
- :cwd => rails_root.to_s,
+ :cwd => rails_root,
:environment => "RAILS_ENV=#{ENV['RAILS_ENV']}",
:logoutput => true,
:require => [
@@ -129,15 +129,15 @@ def rails_gems
:user => configuration[:user]
exec 'bundle install',
:command => 'bundle install',
- :cwd => rails_root.to_s,
+ :cwd => rails_root,
:before => [exec('rails_gems'), exec('bundle lock')],
:require => file('/etc/gemrc'),
:user => configuration[:user]
# this is a hack for getting passenger to load the bundler load path
# http://groups.google.com/group/phusion-passenger/browse_thread/thread/6642823360242cab/b75495c82b565fb1?#b75495c82b565fb1
exec 'bundle lock',
:command => 'bundle lock',
- :cwd => rails_root.to_s,
+ :cwd => rails_root,
:creates => gemfile_lock_path.to_s,
:user => configuration[:user]
else
@@ -269,7 +269,7 @@ def rake(name, options = {})
exec("rake #{name}", {
:command => "rake #{name} 2>&1 | tee -a /var/log/moonshine_rake.log",
:user => configuration[:user],
- :cwd => rails_root.to_s,
+ :cwd => rails_root,
:environment => "RAILS_ENV=#{ENV['RAILS_ENV']}",
:require => exec('rake tasks'),
:logoutput => true,
View
11 test/test_pathname.rb
@@ -0,0 +1,11 @@
+require 'test_helper'
+
+class TestPathname < Test::Unit::TestCase
+ def test_match
+ assert Pathname.new('/etc') =~ /#{File::SEPARATOR}/
+ end
+
+ def test_gsub
+ assert_equal '/tmp', Pathname.new('/etc').gsub('etc', 'tmp')
+ end
+end

0 comments on commit fc2b943

Please sign in to comment.