observers 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/observers.rb +7 -2
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c38971f478fd313e247a319a800bcc05ff9ebc7988c2667998f158d2fcc3ed9c
|
|
4
|
+
data.tar.gz: 3de19946713ee620c28a81b8ed4660c54d6f626a1f3fdec5b961d72864b4d228
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b874d0023082d05272169f7043664f366c956af07aac5c001fb851f38aaa8ffddb95015a42a1433f040d28f7afd5663f96db060c7d6d303e2a2bbf70cbf9125
|
|
7
|
+
data.tar.gz: 2736567734f313b0bc7308b9a6e92231f2628f2d97015b061fefb6075cce94f8ef0461dcdd0007dae2dcddeaceb2bb810f4676ed29f5eb9b8eb1c371710998fc
|
data/lib/observers.rb
CHANGED
|
@@ -37,8 +37,13 @@ module Observers
|
|
|
37
37
|
end.new(key)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
# Observe a key with "observe key, action: :action", or keys and their actions with "observe key => :action".
|
|
41
|
+
# Ruby passes "key => :action" as keyword arguments when the key isn't a symbol, so they arrive in key_actions.
|
|
42
|
+
def observe(key = nil, action: nil, **key_actions)
|
|
43
|
+
key_actions = key.is_a?(Hash) ? key : { key => action } unless key.nil?
|
|
44
|
+
raise ArgumentError, 'Missing key to observe' if key_actions.empty?
|
|
45
|
+
|
|
46
|
+
key_actions.each { |each_key, each_action| Keys[each_key].observe(object: self, action: each_action) }
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
def trigger(key: self, action: nil, event: nil)
|
data/lib/version.rb
CHANGED