Sha256: 87132568bccf2c12acd5115c588c8a19fd0bcb2b614521186443a0bcfabef9be
Contents?: true
Size: 1.18 KB
Versions: 24
Compression:
Stored size: 1.18 KB
Contents
module RsrGroup class Base def self.connect(options = {}) requires!(options, :username, :password) Net::FTP.open(RsrGroup.config.ftp_host, options[:username], options[:password]) do |ftp| ftp.debug_mode = RsrGroup.config.debug_mode ftp.passive = true yield ftp end end protected def self.requires!(hash, *params) params.each do |param| if param.is_a?(Array) raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first) valid_options = param[1..-1] raise ArgumentError.new("Parameter: #{param.first} must be one of: #{valid_options.join(', ')}") unless valid_options.include?(hash[param.first]) else raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param) end end end # Wrapper to `self.requires!` that can be used as an instance method. def requires!(*args) self.class.requires!(*args) end # Instance methods become class methods through inheritance def connect(options) self.class.connect(options) do |ftp| yield ftp end end end end
Version data entries
24 entries across 24 versions & 1 rubygems