Module: Observers
- Defined in:
- lib/keys.rb,
lib/version.rb,
lib/observers.rb,
lib/models/key.rb,
lib/models/observer.rb
Defined Under Namespace
Classes: Config, Key, Keys, Observer
Constant Summary
collapse
- VERSION =
'0.7.0'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.[](key) ⇒ Object
10
11
12
|
# File 'lib/observers.rb', line 10
def [](key)
Keys[key].observers
end
|
.config ⇒ Object
18
19
20
|
# File 'lib/observers.rb', line 18
def config
@config ||= Config.new(key_callback: nil)
end
|
22
23
24
|
# File 'lib/observers.rb', line 22
def configure
yield(config)
end
|
.included(klass) ⇒ Object
14
15
16
|
# File 'lib/observers.rb', line 14
def included(klass)
klass.extend Observers
end
|
Instance Method Details
#observe(key, action: nil) ⇒ Object
40
41
42
|
# File 'lib/observers.rb', line 40
def observe(key, action: nil)
Keys[key].observe(object: self, action:)
end
|
#observers(key = self) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/observers.rb', line 27
def observers(key = self)
Struct.new(:key) do
def push(object, action: nil)
Keys[key].observe(object:, action:)
end
alias :<< :push
def count
Keys[key].observers.count
end
end.new(key)
end
|
#take(key: self, action: nil, event: nil) ⇒ Object
48
49
50
|
# File 'lib/observers.rb', line 48
def take(key: self, action: nil, event: nil)
Keys[key].take(action:, event:)
end
|
#trigger(key: self, action: nil, event: nil) ⇒ Object
44
45
46
|
# File 'lib/observers.rb', line 44
def trigger(key: self, action: nil, event: nil)
Keys[key].trigger(action:, event:)
end
|