forked from sprinkle-tool/sprinkle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced config task that allows for uploading of config files
- Loading branch information
Tobias Lütke
committed
Dec 5, 2008
1 parent
fbf76da
commit 81d1ec6
Showing
8 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'open-uri' | ||
|
||
module Sprinkle | ||
module Installers | ||
# = Config Installer | ||
# | ||
# Allows you to upload config files to the server | ||
# | ||
# == Example Usage | ||
# | ||
# config do | ||
# put '/etc/apache2/ports.conf', 'Listen 8080' | ||
# end | ||
# | ||
class Config | ||
include Sprinkle::Configurable | ||
|
||
attr_accessor :package, :delivery, :pending_uploads #:nodoc: | ||
|
||
def initialize(package, &block) #:nodoc: | ||
@package = package | ||
@pending_uploads = {} | ||
self.instance_eval(&block) if block | ||
end | ||
|
||
def put(file, content) | ||
@pending_uploads[file] = content | ||
end | ||
|
||
def put_file(file, source) | ||
@pending_uploads[file] = open(source).read | ||
end | ||
|
||
def process(roles) #:nodoc: | ||
assert_delivery | ||
|
||
if logger.debug? | ||
pending = @pending_uploads.keys.join(", "); | ||
logger.debug "#{@package.name} uploading: #{pending} for roles: #{roles}\n" | ||
end | ||
|
||
unless Sprinkle::OPTIONS[:testing] | ||
pending = @pending_uploads.keys.join(", "); | ||
logger.info "--> #{@package.name} uploading for roles: #{roles}" | ||
logger.info " #{pending}" | ||
@delivery.put(@package.name, @pending_uploads, roles) | ||
end | ||
|
||
end | ||
|
||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
|
||
describe Sprinkle::Installers::Config do | ||
|
||
before do | ||
@package = mock(Sprinkle::Package, :name => 'package') | ||
end | ||
|
||
def create_config(&block) | ||
Sprinkle::Installers::Config.new(@package, &block) | ||
end | ||
|
||
describe 'during initialization' do | ||
|
||
before do | ||
@installer = create_config do | ||
put "hello.txt", 'world' | ||
end | ||
end | ||
|
||
it 'should store content in a pending hash' do | ||
@installer.pending_uploads.has_key?('hello.txt').should == true | ||
@installer.pending_uploads['hello.txt'].should == 'world' | ||
end | ||
|
||
end | ||
end |