Class: Mmailer::ServerHelper
- Inherits:
-
Object
- Object
- Mmailer::ServerHelper
- Defined in:
- lib/mmailer/server_helper.rb
Instance Attribute Summary collapse
-
#machine ⇒ Object
Returns the value of attribute machine.
-
#stream ⇒ Object
Returns the value of attribute stream.
-
#worker ⇒ Object
Returns the value of attribute worker.
Instance Method Summary collapse
- #config(options) ⇒ Object
- #display_state ⇒ Object
-
#initialize ⇒ ServerHelper
constructor
A new instance of ServerHelper.
- #pause ⇒ Object
- #puts(str) ⇒ Object
- #resume ⇒ Object
- #start(from = 0) ⇒ Object
- #state ⇒ Object
- #stop ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize ⇒ ServerHelper
Returns a new instance of ServerHelper.
5 6 7 8 9 10 11 12 |
# File 'lib/mmailer/server_helper.rb', line 5 def initialize @stream = $stdout self.machine = MicroMachine.new(:stopped) machine.when(:start, :stopped => :started) machine.when(:resume, :paused => :started) machine.when(:stop, :started => :stopped, :paused => :stopped) machine.when(:pause, :started => :paused) end |
Instance Attribute Details
#machine ⇒ Object
Returns the value of attribute machine.
3 4 5 |
# File 'lib/mmailer/server_helper.rb', line 3 def machine @machine end |
#stream ⇒ Object
Returns the value of attribute stream.
3 4 5 |
# File 'lib/mmailer/server_helper.rb', line 3 def stream @stream end |
#worker ⇒ Object
Returns the value of attribute worker.
3 4 5 |
# File 'lib/mmailer/server_helper.rb', line 3 def worker @worker end |
Instance Method Details
#config(options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mmailer/server_helper.rb', line 61 def config() if .empty? puts "I will send emails every #{Mmailer.configuration.time_interval} seconds. After #{Mmailer.configuration.mail_interval} emails, I will sleep for #{Mmailer.configuration.sleep_time} seconds." else Mmailer.configuration.sleep_time = .fetch("sleep_time", Mmailer.configuration.sleep_time) Mmailer.configuration.mail_interval = .fetch("mail_interval", Mmailer.configuration.mail_interval) Mmailer.configuration.time_interval = .fetch("time_interval", Mmailer.configuration.time_interval) puts "#{options}. OK." end end |
#display_state ⇒ Object
14 15 16 |
# File 'lib/mmailer/server_helper.rb', line 14 def display_state stream.puts state end |
#pause ⇒ Object
44 45 46 47 48 49 |
# File 'lib/mmailer/server_helper.rb', line 44 def pause if machine.trigger(:pause) display_state machine.state end end |
#puts(str) ⇒ Object
22 23 24 |
# File 'lib/mmailer/server_helper.rb', line 22 def puts(str) stream.puts(str) end |
#resume ⇒ Object
30 31 32 33 34 35 |
# File 'lib/mmailer/server_helper.rb', line 30 def resume if machine.trigger(:resume) display_state machine.state end end |
#start(from = 0) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/mmailer/server_helper.rb', line 51 def start(from=0) if machine.trigger(:start) puts "starting from #{from}" Thread.abort_on_exception = true @worker = Thread.new(from) do |from| Worker.new(from) end end end |
#state ⇒ Object
18 19 20 |
# File 'lib/mmailer/server_helper.rb', line 18 def state machine.state end |
#stop ⇒ Object
37 38 39 40 41 42 |
# File 'lib/mmailer/server_helper.rb', line 37 def stop if machine.trigger(:stop) display_state machine.state end end |
#up? ⇒ Boolean
26 27 28 |
# File 'lib/mmailer/server_helper.rb', line 26 def up? true end |