wisper_plus 0.1.3 → 0.1.4

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: 59894c1fa699b69e342ac88ad598630a093c2c9e99e33fd266ab85a6afb5790b
4
- data.tar.gz: 4e7644aa0f78b6fdfeb5fbaa3a1f1dfb9dc1a19ecd2a3c77ddffba1cc253e643
3
+ metadata.gz: 8b983012a8318f5055600e1ec96302dcb8eb1b24563d5b0ad6650d686dfebd53
4
+ data.tar.gz: 9a5bbd463fec537212d446dda329d198d451eb7f5bb5726ef6c77f40a9c86986
5
5
  SHA512:
6
- metadata.gz: 4a71b7705fcf7d5a96c653f2d18ae2f2749ce9ab363bb28f68ecb363fa9f68e732fa2600b33257ea309a71231c3924ed3507e696e221b2644f598bafc16af0dc
7
- data.tar.gz: 15a7688dad794bd8423f5b89b5c6f598098a1f49d8e4d8c9b764a2d86ce47a63a13be4f8437016a889513183906f0031cc410067b0f80c9ab42b8b88886288d2
6
+ metadata.gz: 76026e2a0de474cca4e9de38a473b819365025214f44d36f1894e9edc1f3db73cdff14881facf14270bbe89717f95d495b30807d894172b3e0ddd04fa24ead20
7
+ data.tar.gz: a7483b72f8a6c451bdad41a4f5931109e88c5ec4e7f0d320b7a787f0652cb0c4db90fa45f124fb1a06ef56e4d2ac6377ddff049e0304c41ffcba8789ef8951cf
data/CHANGELOG.md CHANGED
@@ -1,2 +1,9 @@
1
- # 0.1.1
1
+ # Changelog
2
+
3
+ ## 0.1.4
4
+ - allow multiple subscribers to subscribe to a model
5
+ - fix global subscriber
6
+ - better error reporting
7
+
8
+ ## 0.1.1
2
9
  - make publish/broadcast a public method
@@ -2,32 +2,74 @@ require 'rails'
2
2
 
3
3
  class WisperPlus::Railtie < Rails::Railtie
4
4
 
5
+ def self.subscribe(model_klass, subscriber_klass)
6
+ model_class = model_klass
7
+ if model_class != 'Global'
8
+ begin
9
+ model_class = model_class.constantize
10
+ if !model_class.ancestors.include?(ApplicationRecord)
11
+ # puts "🔸 #{model_class} is not an ActiveRecord model".yellow
12
+ return
13
+ end
14
+ if !model_class.ancestors.include?(Wisper::Publisher)
15
+ puts "🔸 #{model_class} is not including Wisper::ActiveRecord::Publisher. Cannot Subscribe #{subscriber_klass.magenta}.".yellow
16
+ return
17
+ end
18
+ rescue NameError
19
+ model_class = model_class.split("::")
20
+ model_class.pop
21
+ if model_class.size.positive?
22
+ model_class = model_class.join('::')
23
+ retry
24
+ else
25
+ puts "🔸 #{model_klass} not found"
26
+ return
27
+ end
28
+ end
29
+ end
30
+
31
+ begin
32
+ subscriber_klass = subscriber_klass.constantize
33
+ rescue NameError
34
+ puts "🔸 #{subscriber_klass} not found"
35
+ end
36
+
37
+ begin
38
+ if model_class != 'Global'
39
+ model_class.subscribe(subscriber_klass.new, async: false)
40
+ else
41
+ Wisper.subscribe(subscriber_klass.new)
42
+ end
43
+ rescue NoMethodError
44
+ puts "🔸 #{model_class}.subscribe() not found"
45
+ end
46
+
47
+ if Rails.env.development?
48
+ puts "🔹 #{subscriber_klass.to_s.magenta} => #{model_class.to_s.blue}"
49
+ end
50
+ end
51
+
5
52
  config.to_prepare do
6
53
  Wisper.clear if Rails.env.development?
7
54
 
8
55
  # AUTOLINK models to subscribers if DB exists
9
56
  if (::ActiveRecord::Base.connection rescue false)
10
57
  # Link any Models to their <Model>Subscriber class
11
- Dir.glob(Rails.root.join('app/models/**/*.rb').to_s) do |filename|
12
- next if filename.index('/concerns/')
13
- filename = filename.remove(Rails.root.join('app/models/').to_s)[0..-4]
14
- klass = filename.camelize.constantize
15
- next unless klass.ancestors.include?(ApplicationRecord)
16
- begin
17
- notifier_klass = "#{klass}Subscriber".constantize
18
- klass.subscribe(notifier_klass.new, async: false)
19
- if Rails.env.development?
20
- puts "🔹 #{klass.to_s.magenta} #{'subscriber'.blue}"
21
- end
22
- if !klass.ancestors.include?(Wisper::Publisher)
23
- puts "🔸 #{klass} is not including Wisper::ActiveRecord::Publisher".yellow
58
+ Dir.glob(Rails.root.join('app/subscribers/**/*.rb').to_s) do |filename|
59
+ filename = filename.remove(Rails.root.join('app/subscribers/').to_s)[0..-4]
60
+ subscriber_klass = filename.classify
61
+ model_klass = subscriber_klass.chomp("Subscriber")
62
+ WisperPlus::Railtie.subscribe(model_klass, subscriber_klass)
63
+
64
+ subscribers_dir = Rails.root.join('app','subscribers',filename)
65
+ if subscribers_dir.directory?
66
+ subscribers_dir.each_child do |fpath|
67
+ ap fpath
24
68
  end
25
- rescue NameError
26
- # ignore
27
69
  end
28
70
  end
29
71
  end
30
-
31
72
  end
32
73
 
74
+
33
75
  end
@@ -1,3 +1,3 @@
1
1
  module WisperPlus
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/wisper_plus.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "bundler", ">= 1.16"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
 
36
36
  spec.add_runtime_dependency 'activesupport', '>= 3', '< 6'
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisper_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sharpe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-14 00:00:00.000000000 Z
11
+ date: 2019-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.16'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
27
  - !ruby/object:Gem::Dependency