Class: DiffRunner::Registary
- Inherits:
-
Object
- Object
- DiffRunner::Registary
- Defined in:
- lib/diff-runner/registary.rb
Constant Summary collapse
- @@instance =
Registary.new
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Registary
constructor
A new instance of Registary.
- #is_listening?(path) ⇒ Boolean
- #register(path, action) ⇒ Object
- #unregister(path) ⇒ Object
Constructor Details
#initialize ⇒ Registary
Returns a new instance of Registary.
6 7 8 |
# File 'lib/diff-runner/registary.rb', line 6 def initialize @listeners = {} end |
Class Method Details
.instance ⇒ Object
12 13 14 |
# File 'lib/diff-runner/registary.rb', line 12 def self.instance @@instance end |
Instance Method Details
#clear ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/diff-runner/registary.rb', line 26 def clear @listeners.each do |path, listener| listener.stop end @listeners = {} end |
#is_listening?(path) ⇒ Boolean
40 41 42 |
# File 'lib/diff-runner/registary.rb', line 40 def is_listening?(path) @listeners.key? path end |
#register(path, action) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/diff-runner/registary.rb', line 16 def register(path, action) listener = Listen.to(path) do |m, a, d| action.run end listener.start @listeners[path] = listener end |
#unregister(path) ⇒ Object
34 35 36 37 38 |
# File 'lib/diff-runner/registary.rb', line 34 def unregister(path) if @listeners.has_key? path @listeners.delete(path).stop end end |