Class: Razor::Rake::FTP::Push

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/razor/rake/ftp_push.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, name = 'ftp:push') {|_self| ... } ⇒ Push

Returns a new instance of Push.

Yields:

  • (_self)

Yield Parameters:



21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



18
19
20
# File 'lib/razor/rake/ftp_push.rb', line 18

def dir
  @dir
end

#portObject

Returns the value of attribute port.



17
18
19
# File 'lib/razor/rake/ftp_push.rb', line 17

def port
  @port
end

#url_baseObject

Returns the value of attribute url_base.



19
20
21
# File 'lib/razor/rake/ftp_push.rb', line 19

def url_base
  @url_base
end

Instance Method Details

#define_taskObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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.(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_optionsObject



53
54
55
56
57
# File 'lib/razor/rake/ftp_push.rb', line 53

def generate_options
  {
    :url_base => @url_base
  }
end