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

Yield Parameters:

  • file (Tempfile)

    yields the tempfile so you generate the file to be uploaded



28
29
30
31
32
33
34
35
# File 'lib/config_for/capistrano.rb', line 28

def initialize(path, options = {}, &block)
  @path = path
  @roles = options.fetch(:roles, :all)
  @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.



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

def generator
  @generator
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#tempfileObject (readonly)

Returns the value of attribute tempfile.



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

def tempfile
  @tempfile
end