I'm new to Ruby, coming primarily from C# and ActionScript 3 (among other langauges). I'm curious about abstracting functionality. Specifically, wrapping and abstracting Ruby's FTP and SFTP libs.
I was searching around and came across a gem called Backup. It really got my attention because it supports backing stuff up via S3, SCP, SFTP and FTP. So I thought, "wow, here's a perfect example!" I started browsing the source, but then I came across code like:
case backup.procedure.storage_name.to_sym
when :s3 then records = Backup::Record::S3.all :conditions => {:trigger => trigger}
when :scp then records = Backup::Record::SCP.all :conditions => {:trigger => trigger}
when :ftp then records = Backup::Record::FTP.all :conditions => {:trigger => trigger}
when :sftp then records = Backup::Record::SFTP.all :conditions => {:trigger => trigger}
end
view the full source on GitHub
It's littered with case/when statements! If I were attacking this in C#, I'd write a Protocol interface (or abstract class) and let FTP and SFTP implement it. Then my client class would just pass around an instance of Protocol without caring about the implementation. Zero switch/cases.
I'd appreciate a little guidance on best practices in this situation when coding in Ruby.