Class: Ftpeter::Transport::Lftp
- Inherits:
-
Object
- Object
- Ftpeter::Transport::Lftp
- Defined in:
- lib/ftpeter/transport/lftp.rb
Instance Attribute Summary collapse
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #commands ⇒ Object
- #execute ⇒ Object
- #inform ⇒ Object
-
#initialize(connection, changes) ⇒ Lftp
constructor
A new instance of Lftp.
- #persist ⇒ Object
- #prepare ⇒ Object
Constructor Details
#initialize(connection, changes) ⇒ Lftp
Returns a new instance of Lftp.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ftpeter/transport/lftp.rb', line 9 def initialize(connection, changes) @changes = changes @lftp_script = [] @script = Pathname.new('./lftp_script'). @host = connection.host @credentials = connection.credentials @dir = connection.dir @commands = connection.commands prepare end |
Instance Attribute Details
#script ⇒ Object (readonly)
Returns the value of attribute script.
7 8 9 |
# File 'lib/ftpeter/transport/lftp.rb', line 7 def script @script end |
Instance Method Details
#cleanup ⇒ Object
73 74 75 |
# File 'lib/ftpeter/transport/lftp.rb', line 73 def cleanup script.delete end |
#commands ⇒ Object
54 55 56 |
# File 'lib/ftpeter/transport/lftp.rb', line 54 def commands @lftp_script end |
#execute ⇒ Object
69 70 71 |
# File 'lib/ftpeter/transport/lftp.rb', line 69 def execute system("lftp -f #{script}") end |
#inform ⇒ Object
58 59 60 |
# File 'lib/ftpeter/transport/lftp.rb', line 58 def inform @lftp_script.join("\n") end |
#persist ⇒ Object
62 63 64 65 66 67 |
# File 'lib/ftpeter/transport/lftp.rb', line 62 def persist script.open('w') do |f| f << @lftp_script.flatten.join("\n") f << "\n" end end |
#prepare ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ftpeter/transport/lftp.rb', line 22 def prepare # lftp connection header @lftp_script << "open #{@host}" if @credentials @lftp_script << "user #{@credentials['user']} #{@credentials['pass']}" end @lftp_script << "cd #{@dir}" # lftp file commands @lftp_script << @changes.deleted.map do |fn| "rm #{fn}" end @lftp_script << @changes.newdirs.map do |fn| "mkdir -p #{fn}" end @lftp_script << @changes.added.map do |fn| "put #{fn} -o #{fn}" end @lftp_script << @changes.changed.map do |fn| "put #{fn} -o #{fn}" end @lftp_script << @commands.split("\n").map do |cmd| "!#{cmd}" end if @commands @lftp_script << '!echo ""' @lftp_script << '!echo "Deployment complete"' @lftp_script.flatten!.compact! @lftp_script end |