Class: Herpes::Callback
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#discriminator ⇒ Object
readonly
Returns the value of attribute discriminator.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #call(herpes, &block) ⇒ Object
- #called! ⇒ Object
- #calling! ⇒ Object
- #calling? ⇒ Boolean
- #gonna_call! ⇒ Object
- #gonna_call? ⇒ Boolean
-
#initialize(time, discriminator, one_shot = false, &block) ⇒ Callback
constructor
A new instance of Callback.
- #next_in ⇒ Object
- #one_shot? ⇒ Boolean
Constructor Details
#initialize(time, discriminator, one_shot = false, &block) ⇒ Callback
Returns a new instance of Callback.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/herpes.rb', line 20 def initialize (time, discriminator, one_shot = false, &block) raise ArgumentError, 'no block has been passed' unless block @time = time @discriminator = discriminator @one_shot = one_shot @block = block if !one_shot? @last = Time.at 0 else called! end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
18 19 20 |
# File 'lib/herpes.rb', line 18 def block @block end |
#discriminator ⇒ Object (readonly)
Returns the value of attribute discriminator.
18 19 20 |
# File 'lib/herpes.rb', line 18 def discriminator @discriminator end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
18 19 20 |
# File 'lib/herpes.rb', line 18 def last @last end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
18 19 20 |
# File 'lib/herpes.rb', line 18 def time @time end |
Instance Method Details
#call(herpes, &block) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/herpes.rb', line 66 def call (herpes, &block) return if calling? calling! @block.call(&block) ensure called! herpes.wake_up end |
#called! ⇒ Object
57 58 59 60 |
# File 'lib/herpes.rb', line 57 def called! @last = Time.now @calling = false end |
#calling! ⇒ Object
53 54 55 |
# File 'lib/herpes.rb', line 53 def calling! @calling = true end |
#calling? ⇒ Boolean
62 63 64 |
# File 'lib/herpes.rb', line 62 def calling? @calling == true end |
#gonna_call! ⇒ Object
43 44 45 46 47 |
# File 'lib/herpes.rb', line 43 def gonna_call! return if calling? @calling = :gonna end |
#gonna_call? ⇒ Boolean
49 50 51 |
# File 'lib/herpes.rb', line 49 def gonna_call? @calling == :gonna end |
#next_in ⇒ Object
39 40 41 |
# File 'lib/herpes.rb', line 39 def next_in time - (Time.now - last) end |
#one_shot? ⇒ Boolean
35 36 37 |
# File 'lib/herpes.rb', line 35 def one_shot? @one_shot end |