Uploading a file using Net::SFTP I have a method to upload a file using the Net::SFTP gem:

class Uploader

 def initialize(host,user,password)
   @host = host
   @user = user
   @password = password
 end

 def upload(local_file_path,remote_file_path)
  Net::SFTP.start(@host,@user,:password =&gt; @password) do |sftp|
   sftp.upload!(local_file_path,remote_file_path) do |event,uploader,*args|
     case event
     when :open
       Rails.logger("Starting upload...")
     when :finished
       Rails.logger("Finishing upload...")
     end
   end
  end
 end
end


The upload method seems rather large to me. Any suggestions on how I could split it up into smaller components?
I don't see much reason to worry about this method's length. At least not right now - if you add more event handling, yeah, it might become a little cumbersome. But for what it does now, there's no pressing need to do anything.

I would recommend more whitespace, though. There's no reason to compress,every,line,that,has,commas,in,it. Just makes it harder to read.

I'm also fairly sure that the :finished event is actually called :finish

Structurally, just for the sake of it, you could do something like:

class Uploader
  attr_reader :host, :user, :password

  def initialize(host, user, password)
    @host = host
    @user = user
    @password = password
  end

  def upload(local_file_path, remote_file_path)
    Net::SFTP.start(host, user, password: password) do |sftp|
      sftp.upload!(local_file_path, remote_file_path) do |event, uploader, *args|
        send(event, uploader, *args) if respond_to?(event, true)
      end
    end
  end

  private

  def open(uploader, *args)
    Rails.logger("Starting upload...")
  end

  def close(uploader, *args)
    Rails.logger("Upload complete")
  end

  def finish(uploader, *args)
    Rails.logger("All done")
  end
end


Basically, we're handling events with methods instead of a case block. I've added the close method/event handler as an example.