Class: Mailcrate
- Inherits:
-
Object
- Object
- Mailcrate
- Defined in:
- lib/mailcrate.rb
Instance Attribute Summary collapse
-
#mails ⇒ Object
readonly
Returns the value of attribute mails.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(port) ⇒ Mailcrate
constructor
A new instance of Mailcrate.
- #start(opts = {}) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port) ⇒ Mailcrate
Returns a new instance of Mailcrate.
11 12 13 14 |
# File 'lib/mailcrate.rb', line 11 def initialize(port) @port = port @mails = [] end |
Instance Attribute Details
#mails ⇒ Object (readonly)
Returns the value of attribute mails.
9 10 11 |
# File 'lib/mailcrate.rb', line 9 def mails @mails end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/mailcrate.rb', line 9 def port @port end |
Class Method Details
.used_ports ⇒ Object
5 6 7 |
# File 'lib/mailcrate.rb', line 5 def self.used_ports @used_ports ||= [] end |
Instance Method Details
#start(opts = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/mailcrate.rb', line 16 def start(opts = {}) raise Errno::EADDRINUSE if self.class.used_ports.include?(@port) self.class.used_ports << @port @service = opts[:service] || TCPServer.new('localhost', @port) @thread = Thread.new { accept(@service) } end |
#stop ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mailcrate.rb', line 23 def stop self.class.used_ports.delete(@port) @thread.kill unless @thread.nil? @thread.join unless @thread.nil? @service.close unless @service.nil? || @service.closed? end |