Class: Fetcher::Base
- Inherits:
-
Object
- Object
- Fetcher::Base
- Defined in:
- lib/fetcher/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#fetch ⇒ Object
Run the fetching process.
-
#initialize(options = {}) ⇒ Base
constructor
Options: *
:server
- Server to connect to.
Constructor Details
#initialize(options = {}) ⇒ Base
Options:
-
:server
- Server to connect to. -
:username
- Username to use when connecting to server. -
:password
- Password to use when connecting to server. -
:receiver
- Receiver object to pass messages to. Assumes the
receiver object has a receive method that takes a message as it’s argument
Additional protocol-specific options implimented by sub-classes
Example:
Fetcher::Base.new(:server => 'mail.example.com',
:username => 'pam',
:password => 'test',
:receiver => IncomingMailHandler)
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fetcher/base.rb', line 17 def initialize(={}) %w(server username password receiver).each do |opt| raise ArgumentError, "#{opt} is required" unless [opt.to_sym] # convert receiver to a Class if it isn't already. if opt == "receiver" && [:receiver].is_a?(String) [:receiver] = Kernel.const_get([:receiver]) end instance_eval("@#{opt} = options[:#{opt}]") end end |
Instance Method Details
#fetch ⇒ Object
Run the fetching process
30 31 32 33 34 |
# File 'lib/fetcher/base.rb', line 30 def fetch establish_connection close_connection end |