Browse files

Improved shared_config handling.

Now, items in shared_config are symlinked in a more intuitive manner.

:shared_config:
  - config/database.yml
  - private/foo.txt

The above will now result in:

...shared/config/database.yml
...shared/private/foo.txt

Additionally, it'll also symlink these items to the same path in the
current rails root.
  • Loading branch information...
1 parent 65b3797 commit 8fbcadc0112e0a6943a5d72537be1518bc8166ee @wfarr wfarr committed Jun 17, 2010
View
33 lib/moonshine/capistrano_integration.rb
@@ -181,9 +181,11 @@ def self.load_into(capistrano_config)
DESC
task :upload do
fetch(:local_config).each do |file|
- filename = File.split(file).last
+ filename = File.basename(file)
+ path = File.dirname(file)
if File.exist?(file)
- parent.upload(file, "#{shared_path}/config/#{filename}")
+ run "mkdir -p '#{shared_path}/#{path}'" unless path.empty?
+ parent.upload(file, "#{shared_path}/#{path}/#{filename}")
end
end
end
@@ -193,8 +195,10 @@ def self.load_into(capistrano_config)
DESC
task :symlink do
fetch(:local_config).each do |file|
- filename = File.split(file).last
- run "ls #{latest_release}/#{file} 2> /dev/null || ln -nfs #{shared_path}/config/#{filename} #{latest_release}/#{file}"
+ filename = File.basename(file)
+ path = File.dirname(file)
+ run "mkdir -p '#{latest_release}/#{path}'" unless path.empty?
+ run "ls #{latest_release}/#{file} 2> /dev/null || ln -nfs #{shared_path}/#{path}/#{filename} #{latest_release}/#{file}"
end
end
@@ -208,9 +212,11 @@ def self.load_into(capistrano_config)
DESC
task :upload do
fetch(:shared_config).each do |file|
- filename = File.split(file).last
+ filename = File.basename(file)
+ path = File.dirname(file)
if File.exist?(file)
- put File.read(file), "#{shared_path}/config/#{filename}"
+ run "mkdir -p '#{shared_path}/#{path}'" unless path.empty?
+ parent.upload(file, "#{shared_path}/#{path}/#{filename}")
end
end
end
@@ -221,10 +227,11 @@ def self.load_into(capistrano_config)
DESC
task :download do
fetch(:shared_config).each do |file|
- filename = File.split(file).last
- if File.exist?(file)
- get "#{shared_path}/config/#{filename}", file
- end
+ require 'fileutils'
+ filename = File.basename(file)
+ path = File.dirname(file)
+ FileUtils.mkdir_p(path) unless path.empty?
+ get "#{shared_path}/#{path}/#{filename}", file
end
end
@@ -233,8 +240,10 @@ def self.load_into(capistrano_config)
DESC
task :symlink do
fetch(:shared_config).each do |file|
- filename = File.split(file).last
- run "ls #{latest_release}/#{file} 2> /dev/null || ln -nfs #{shared_path}/config/#{filename} #{latest_release}/#{file}"
+ filename = File.basename(file)
+ path = File.dirname(file)
+ run "mkdir -p '#{latest_release}/#{path}'" unless path.empty?
+ run "ls #{latest_release}/#{file} 2> /dev/null || ln -nfs #{shared_path}/#{path}/#{filename} #{latest_release}/#{file}"
end
end
end
View
27 spec/moonshine/capistrano_integration_spec.rb
@@ -62,6 +62,31 @@
@configuration.application.should == 'zomg'
end
+ context "shared_config" do
+ before do
+ @shared_config = @configuration.shared_config.moonshine_yml[:shared_config]
+ end
+
+ it "has some items in shared_config" do
+ @shared_config.should have(2).items
+ @shared_config.should include "config/database.yml"
+ end
+
+ it "uploads files to the fake rails root" do
+ pending
+ end
+
+ it "downloads files from the fake rails root" do
+ pending
+ end
+
+ it "symlinks files to the fake rails root" do
+ pending
+ end
+
+ def full_path(path)
+ @configuration.rails_root.join(path)
+ end
+ end
end
-
end
View
5 spec/rails_root/config/moonshine.yml
@@ -16,8 +16,9 @@
#
# Use :shared_config to copy directories straight from your local project directory
# to the server: these are files that you don't have/want in scm.
-#:shared_config:
-# - config/database.yml
+:shared_config:
+ - config/database.yml
+ - config/sample/foo
#
# The entries in shared_children are created in #{application}/shared
:shared_children:
View
1 spec/rails_root/config/sample/foo
@@ -0,0 +1 @@
+foo bar baz

0 comments on commit 8fbcadc

Please sign in to comment.