Class: Vedeu::Event
- Inherits:
-
Object
- Object
- Vedeu::Event
- Defined in:
- lib/vedeu/support/event.rb
Instance Attribute Summary collapse
-
#closure ⇒ Object
readonly
private
Returns the value of attribute closure.
-
#deadline ⇒ Object
private
Returns the value of attribute deadline.
-
#executed_at ⇒ Object
private
Returns the value of attribute executed_at.
-
#now ⇒ Object
private
Returns the value of attribute now.
Instance Method Summary collapse
- #debounce ⇒ Fixnum|Float private private
- #debouncing? ⇒ TrueClass|FalseClass private private
- #defaults ⇒ Hash private private
- #delay ⇒ Fixnum|Float private private
- #elapsed_time ⇒ Float private private
-
#execute(*args) ⇒ Object
private
private
[].
- #has_deadline? ⇒ TrueClass|FalseClass private private
- #initialize(closure, options = {}) ⇒ Event constructor
- #options ⇒ Hash private private
- #reset_deadline ⇒ Fixnum private private
- #reset_time ⇒ Fixnum private private
- #set_deadline ⇒ NilClass private private
- #set_executed ⇒ Float private private
- #set_time ⇒ Float private private
- #throttling? ⇒ TrueClass|FalseClass private private
-
#trigger(*args) ⇒ Object
[].
Constructor Details
#initialize(closure, options = {}) ⇒ Event
7 8 9 10 11 12 13 |
# File 'lib/vedeu/support/event.rb', line 7 def initialize(closure, = {}) @closure = closure = @deadline = 0 @executed_at = 0 @now = 0 end |
Instance Attribute Details
#closure ⇒ Object (readonly, private)
Returns the value of attribute closure.
27 28 29 |
# File 'lib/vedeu/support/event.rb', line 27 def closure @closure end |
#deadline ⇒ Object (private)
Returns the value of attribute deadline.
28 29 30 |
# File 'lib/vedeu/support/event.rb', line 28 def deadline @deadline end |
#executed_at ⇒ Object (private)
Returns the value of attribute executed_at.
28 29 30 |
# File 'lib/vedeu/support/event.rb', line 28 def executed_at @executed_at end |
#now ⇒ Object (private)
Returns the value of attribute now.
28 29 30 |
# File 'lib/vedeu/support/event.rb', line 28 def now @now end |
Instance Method Details
#debounce ⇒ Fixnum|Float (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 |
# File 'lib/vedeu/support/event.rb', line 106 def debounce [:debounce] end |
#debouncing? ⇒ TrueClass|FalseClass (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 57 58 |
# File 'lib/vedeu/support/event.rb', line 52 def debouncing? set_time set_deadline unless has_deadline? [:debounce] > 0 end |
#defaults ⇒ Hash (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
124 125 126 127 128 129 |
# File 'lib/vedeu/support/event.rb', line 124 def defaults { delay: 0, debounce: 0 } end |
#delay ⇒ Fixnum|Float (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 |
# File 'lib/vedeu/support/event.rb', line 112 def delay [:delay] end |
#elapsed_time ⇒ Float (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/vedeu/support/event.rb', line 62 def elapsed_time now - @executed_at end |
#execute(*args) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns [].
32 33 34 35 36 37 38 39 40 |
# File 'lib/vedeu/support/event.rb', line 32 def execute(*args) reset_deadline set_executed reset_time closure.call(*args) end |
#has_deadline? ⇒ TrueClass|FalseClass (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/vedeu/support/event.rb', line 86 def has_deadline? @deadline > 0 end |
#options ⇒ Hash (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 |
# File 'lib/vedeu/support/event.rb', line 118 def defaults.merge!() end |
#reset_deadline ⇒ Fixnum (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
92 93 94 |
# File 'lib/vedeu/support/event.rb', line 92 def reset_deadline @deadline = 0 end |
#reset_time ⇒ Fixnum (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'lib/vedeu/support/event.rb', line 80 def reset_time @now = 0 end |
#set_deadline ⇒ NilClass (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 101 102 |
# File 'lib/vedeu/support/event.rb', line 98 def set_deadline @deadline = now + debounce nil end |
#set_executed ⇒ Float (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/vedeu/support/event.rb', line 68 def set_executed @executed_at = now end |
#set_time ⇒ Float (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/vedeu/support/event.rb', line 74 def set_time @now = Time.now.to_f end |
#throttling? ⇒ TrueClass|FalseClass (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 47 48 |
# File 'lib/vedeu/support/event.rb', line 44 def throttling? set_time [:delay] > 0 end |
#trigger(*args) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/vedeu/support/event.rb', line 17 def trigger(*args) return execute(*args) unless debouncing? || throttling? return execute(*args) if debouncing? && set_executed > deadline return execute(*args) if throttling? && elapsed_time > delay end |