Class: ConfigFor::Capistrano::UploadFileTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Capistrano::DSL
Defined in:
lib/config_for/capistrano.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) {|file| ... } ⇒ UploadFileTask

Rake Task generator for uploading files through Capistrano

Examples:

generating task for config/unicorn.rb

ConfigFor::Capistrano::UploadFileTask.new('config/unicorn.rb', roles: :web) do |file|
  file.write('some template')
end

Rake::Task['config/unicorn.rb'].invoke # uploads that file if it does not exist

Parameters:

  • path (Pathname, String)

    the path of the file to be uploaded

  • options (Hash) (defaults to: {})

    the options

Options Hash (options):

  • :roles (Array<Symbol>, Symbol) — default: :all

    the roles of servers to apply to

  • :override (true, false) — default: false

    upload file on every run

Yield Parameters:

  • file (Tempfile)

    yields the tempfile so you generate the file to be uploaded



30
31
32
33
34
35
36
37
38
# File 'lib/config_for/capistrano.rb', line 30

def initialize(path, options = {}, &block)
  @path = path
  @roles = options.fetch(:roles, :all)
  @override = options.fetch(:override, false)
  @tempfile = ::Tempfile.new(File.basename(@path))
  @generator = block || ->(_file){ puts 'Did not passed file generator' }

  define
end

Instance Attribute Details

#generatorObject

Returns the value of attribute generator.



16
17
18
# File 'lib/config_for/capistrano.rb', line 16

def generator
  @generator
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/config_for/capistrano.rb', line 14

def path
  @path
end

#tempfileObject (readonly)

Returns the value of attribute tempfile.



14
15
16
# File 'lib/config_for/capistrano.rb', line 14

def tempfile
  @tempfile
end