class Razor::Rake::FTP::Push

Attributes

dir[RW]
port[RW]
url_base[RW]

Public Class Methods

new(hostname, name='ftp:push') { |self| ... } click to toggle source
# File lib/razor/rake/ftp_push.rb, line 21
def initialize(hostname, name='ftp:push')
        @name = name
        @hostname = hostname
        @dir = ''
        @port = nil
        @url_base = '/'
        yield self if block_given?
        define_task
end

Public Instance Methods

define_task() click to toggle source
# File lib/razor/rake/ftp_push.rb, line 31
def define_task
        task(@name) {
                hl = HighLine.new
                host = [@hostname]
                host << @port if @port
                ftp = Net::FTP.new(*host)
                begin
                        username = hl.ask("FTP Username : ")
                        psswd = hl.ask("Password : ", String) { |q| q.echo = false }
                        ftp.login(username, psswd)
                        ftp.chdir @dir
                        ftp.rm_contents '.'
                        Dir.mktmpdir { |tmp|
                                Razor.generate(generate_options, '.', tmp)
                                ftp.put_contents tmp
                        }
                ensure
                        ftp.close
                end
        }
end
generate_options() click to toggle source
# File lib/razor/rake/ftp_push.rb, line 53
def generate_options
        {
                :url_base => @url_base
        }
end