u-observers 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b6af97772fa9dd076bce666422332213179f338466d8be317fa7d324fc82c84
4
- data.tar.gz: 133d22595bb0ad4dc70c7b6d2be2481f2dc0522acf7bddc7d015cd2141362f63
3
+ metadata.gz: a74f927670b4695760167dbbc2c1758cedbe112233b22d938cbcd79083cd8526
4
+ data.tar.gz: b268b6f4b5d9c92469c20c8ba891bc12146fa52b09e6a44ccb664c6155d9b45f
5
5
  SHA512:
6
- metadata.gz: 775bc25517f90cea5b657ae9753a025796ba7091062033b515b3311b390f126315db16fb7732763f3b618cc0df4ae9430d211740f6dce1a8733eabee73fa9214
7
- data.tar.gz: 29ab84f8b07117108c431c05810727532afd63e42c88cc8c6799e4e6efb7c12ef40ddc8f1e8c526d23326cbd9a6792b2de1853d7121ee2abe2c45fe0f95ad3d1
6
+ metadata.gz: b1830ebe8c59bd1f7fe66588d2b6b5b8839b487af1fe3c75a876eecc28773996e86dbd61a65af44c28c1b29bbe1a9497a9a234801d50ec19b53878b43f85bc89
7
+ data.tar.gz: 4d7d0b6289ed0045e85e4edbacd6482d11c5577932f215cab19f0885c7049a20ad2015ceffaea21e1d6a7459727dd64f370cd4555e45b97d78b2c6b1a5e31575
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ Gemfile.lock
@@ -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(object, action: action) }
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.new
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 initialize(list = nil)
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(subject, action: :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
@@ -1,5 +1,5 @@
1
1
  module Micro
2
2
  module Observers
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  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.1.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
@@ -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