u-observers 0.1.0 → 0.2.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/.gitignore +2 -0
- data/lib/micro/observers.rb +2 -2
- data/lib/micro/observers/manager.rb +9 -4
- data/lib/micro/observers/version.rb +1 -1
- metadata +1 -2
- data/Gemfile.lock +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74f927670b4695760167dbbc2c1758cedbe112233b22d938cbcd79083cd8526
|
4
|
+
data.tar.gz: b268b6f4b5d9c92469c20c8ba891bc12146fa52b09e6a44ccb664c6155d9b45f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1830ebe8c59bd1f7fe66588d2b6b5b8839b487af1fe3c75a876eecc28773996e86dbd61a65af44c28c1b29bbe1a9497a9a234801d50ec19b53878b43f85bc89
|
7
|
+
data.tar.gz: 4d7d0b6289ed0045e85e4edbacd6482d11c5577932f215cab19f0885c7049a20ad2015ceffaea21e1d6a7459727dd64f370cd4555e45b97d78b2c6b1a5e31575
|
data/.gitignore
CHANGED
data/lib/micro/observers.rb
CHANGED
@@ -8,7 +8,7 @@ module Micro
|
|
8
8
|
def call_observers(with: :call)
|
9
9
|
proc do |object|
|
10
10
|
Array(with)
|
11
|
-
.each { |action| object.observers.call(
|
11
|
+
.each { |action| object.observers.call(action: action) }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -22,7 +22,7 @@ module Micro
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def observers
|
25
|
-
@observers ||= Observers::Manager.
|
25
|
+
@observers ||= Observers::Manager.for(self)
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
@@ -6,7 +6,12 @@ module Micro
|
|
6
6
|
class Manager
|
7
7
|
EMPTY_HASH = {}.freeze
|
8
8
|
|
9
|
-
def
|
9
|
+
def self.for(subject)
|
10
|
+
new(subject)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(subject, list = nil)
|
14
|
+
@subject = subject
|
10
15
|
@list = (list.kind_of?(Array) ? list : []).flatten.tap(&:compact!)
|
11
16
|
end
|
12
17
|
|
@@ -24,15 +29,15 @@ module Micro
|
|
24
29
|
self
|
25
30
|
end
|
26
31
|
|
27
|
-
def call(
|
32
|
+
def call(action: :call)
|
28
33
|
@list.each do |observer, data|
|
29
34
|
next unless observer.respond_to?(action)
|
30
35
|
|
31
36
|
handler = observer.method(action)
|
32
37
|
|
33
38
|
case handler.arity
|
34
|
-
when 2 then handler.call(subject, data)
|
35
|
-
when 1 then handler.call(subject)
|
39
|
+
when 2 then handler.call(@subject, data)
|
40
|
+
when 1 then handler.call(@subject)
|
36
41
|
else raise NotImplementedError
|
37
42
|
end
|
38
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-observers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
@@ -21,7 +21,6 @@ files:
|
|
21
21
|
- ".travis.yml"
|
22
22
|
- CODE_OF_CONDUCT.md
|
23
23
|
- Gemfile
|
24
|
-
- Gemfile.lock
|
25
24
|
- LICENSE.txt
|
26
25
|
- README.md
|
27
26
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
u-observers (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activemodel (6.0.3.3)
|
10
|
-
activesupport (= 6.0.3.3)
|
11
|
-
activerecord (6.0.3.3)
|
12
|
-
activemodel (= 6.0.3.3)
|
13
|
-
activesupport (= 6.0.3.3)
|
14
|
-
activesupport (6.0.3.3)
|
15
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
-
i18n (>= 0.7, < 2)
|
17
|
-
minitest (~> 5.1)
|
18
|
-
tzinfo (~> 1.1)
|
19
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
20
|
-
concurrent-ruby (1.1.7)
|
21
|
-
docile (1.3.2)
|
22
|
-
i18n (1.8.5)
|
23
|
-
concurrent-ruby (~> 1.0)
|
24
|
-
minitest (5.14.2)
|
25
|
-
rake (12.3.3)
|
26
|
-
simplecov (0.19.0)
|
27
|
-
docile (~> 1.1)
|
28
|
-
simplecov-html (~> 0.11)
|
29
|
-
simplecov-html (0.12.2)
|
30
|
-
sqlite3 (1.4.2)
|
31
|
-
thread_safe (0.3.6)
|
32
|
-
tzinfo (1.2.7)
|
33
|
-
thread_safe (~> 0.1)
|
34
|
-
zeitwerk (2.4.0)
|
35
|
-
|
36
|
-
PLATFORMS
|
37
|
-
ruby
|
38
|
-
|
39
|
-
DEPENDENCIES
|
40
|
-
activerecord
|
41
|
-
minitest (~> 5.0)
|
42
|
-
rake (~> 12.0)
|
43
|
-
simplecov (~> 0.19)
|
44
|
-
sqlite3
|
45
|
-
u-observers!
|
46
|
-
|
47
|
-
BUNDLED WITH
|
48
|
-
2.1.4
|