class ConfigFor::Capistrano::Task
Rake Task
generator for generating and uploading config files through Capistrano
. @example generating task for database.yml
ConfigFor::Capistrano::Task.new(:database)
@example changing the folder
ConfigFor::Capistrano::Task.new(:database) { |task| task.folder = 'configuration' }
Attributes
config[R]
@!attribute config
@return [ConfigFor::Capistrano::UploadFileTask] the task used to generate the config
folder[RW]
@!attribute folder
@return [String] folder to upload the generated config
name[RW]
@!attribute name
@return [String] the name of the task and subtasks namespace
Public Class Methods
new(name, options = {}) { |self| ... }
click to toggle source
Generates new tasks with for uploading name
@param [String, Symbol] name name of this tasks and subtasks @param &block gets evaluated before defining the tasks @option options [true,false] :override (false) upload file on every run @yieldparam [Task] task the task itself so you can modify it before it gets defined
# File lib/config_for/capistrano.rb, line 112 def initialize(name, options = {}, &block) @name = name @folder = 'config' @file = "#{name}.yml" @variable = "#{name}_yml".to_sym @roles = options.fetch(:roles, :all) @override = options.fetch(:override, false) yield(self) if block_given? @config = ConfigFor::Capistrano::UploadFileTask.new(path, roles: @roles, override: @override, &method(:generate)) desc "Generate #{name} uploader" unless ::Rake.application.last_description define end
Public Instance Methods
path()
click to toggle source
Is a join of folder
and file
# File lib/config_for/capistrano.rb, line 130 def path ::File.join(@folder, @file) end
run_task(_task, _args)
click to toggle source
Invokes the task to do the upload
# File lib/config_for/capistrano.rb, line 135 def run_task(_task, _args) invoke("#{name}:upload") end
yaml()
click to toggle source
Generated YAML content Gets the configuration from variable, deep stringifies keys and returns YAML @return [String] serialized YAML
# File lib/config_for/capistrano.rb, line 142 def yaml config = fetch(@variable, {}) stringified = if config.respond_to?(:deep_stringify_keys) config.deep_stringify_keys else # TODO: remove when dropping rails 3 support # two level stringify for rails 3 compatibility config.stringify_keys.each_value(&:stringify_keys!) end stringified.to_yaml end
Private Instance Methods
define()
click to toggle source
# File lib/config_for/capistrano.rb, line 162 def define namespace name do desc "Upload #{path} to remote servers" task upload: path desc "Remove #{path} from current and shared path" task :remove do files = [] files << shared_path.join(path) files << current_path.join(path) files.each do |file| escaped = file.to_s.shellescape on roles(@roles) do if test "[ -e #{escaped} ]" execute :rm, escaped end end end end desc "Reset #{name} config" task reset: [:remove, :upload] end before 'deploy:check:linked_files', @name desc "Generate #{path}" task(name, &method(:run_task)) end
generate(file)
click to toggle source
# File lib/config_for/capistrano.rb, line 158 def generate(file) file.write(yaml) end