Simplify subclassing by adding all arguments to the initializer. Also, clean up the method signatures for existing exporters.

This commit is contained in:
Chris Lowder
2012-01-24 15:10:18 +00:00
parent 4080b3f1f2
commit 1b701cddf3
10 changed files with 45 additions and 33 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ class Foreman::CLI < Thor
error "Unknown export format: #{format} (unable to load file 'foreman/export/#{ format.tr('-', '_') }')."
end
formatter.new(engine, options).export(location)
formatter.new(location, engine, options).export
rescue Foreman::Export::Exception => ex
error ex.message
end
+4 -2
View File
@@ -3,10 +3,12 @@ require "foreman/utils"
class Foreman::Export::Base
attr_reader :engine, :app, :log, :port, :user, :template, :concurrency
attr_reader :location, :engine, :options, :app, :log, :port, :user, :template, :concurrency
def initialize(engine, options={})
def initialize(location, engine, options={})
@location = location
@engine = engine
@options = options
@app = options[:app]
@log = options[:log]
@port = options[:port]
+1 -1
View File
@@ -3,7 +3,7 @@ require "foreman/export"
class Foreman::Export::Bluepill < Foreman::Export::Base
def export(location, options={})
def export
error("Must specify a location") unless location
FileUtils.mkdir_p location
+1 -1
View File
@@ -2,7 +2,7 @@ require "foreman/export"
class Foreman::Export::Inittab < Foreman::Export::Base
def export(fname=nil, options={})
def export
app = self.app || File.basename(engine.directory)
user = self.user || app
log_root = self.log || "/var/log/#{app}"
+1 -1
View File
@@ -4,7 +4,7 @@ require "foreman/export"
class Foreman::Export::Runit < Foreman::Export::Base
ENV_VARIABLE_REGEX = /([a-zA-Z_]+[a-zA-Z0-9_]*)=(\S+)/
def export(location, options={})
def export
error("Must specify a location") unless location
app = self.app || File.basename(engine.directory)
+1 -1
View File
@@ -3,7 +3,7 @@ require "foreman/export"
class Foreman::Export::Upstart < Foreman::Export::Base
def export(location, options={})
def export
error("Must specify a location") unless location
FileUtils.mkdir_p location