hey-you 1.3.2 → 1.4.2

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: 6fc4f5a3d663c2e8496f01efec20e020f02b03088d4a83c182cf1a673deb2886
4
- data.tar.gz: d442018540664c329f346ebaabd4c558d4da11b39763a703b990dd09d6e8a1dd
3
+ metadata.gz: 3679941e8f2ff22ed129c4fdbb90c8d8c27f860e2aa1f8514855afec34c86852
4
+ data.tar.gz: 6a1b5bb70850f69a7a017ac5c29125138ba22ec722d192666360daf9bbb2b1ad
5
5
  SHA512:
6
- metadata.gz: 7cfad0eac54d8256b0347bffeff673e938e265c16ca4adf724390588e77046449bc62cab904171fb8baf114d47e5255cef60fa0d19b6a79f5d7fbcdf6085c113
7
- data.tar.gz: 64b3e74fb8269048f2fc3dccd3fd49824c4d905ba0dec1376d1c8a7ab659d4af91805a7699c9d4f05e398e6e4aba212fb6bae774d38c30abc4e679b8b47b7f25
6
+ metadata.gz: a6a8430acbcc2c0399c87b899cd61e42915c2d7a5b9d06fac81df719b55bfa59716245ce6c50d12056d4707ceb6c4881017d06d1f444e728df2be6e71b504d02
7
+ data.tar.gz: 52412155756eaed0bd09aed322cbf34ce933d9a99965327264096834bcf1f70b7c6e5eb2d2d7f36cc8653d7183b0c7d893e94866cd5a2481ba3e0d1696e043a1
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Changelog for hey-you gem
2
- ## 1.3.0
2
+
3
+ ## 1.4.2
4
+ - Improvement: Freeze loaded collection to prevent changes notification templates in memory
5
+
6
+ ## 1.4.1
7
+ - Improvement: custom complex classes in Sender
8
+
9
+ ## 1.4.0
10
+ - Improvement: configs validations for custom classes
11
+ - Improvement: allow custom classes with '_' in name
12
+
13
+ ## 1.3.0 - 1.3.4
3
14
  - Feature: `body_part` in email builder.
15
+ - Fixes
4
16
 
5
17
  ### 1.2.3
6
18
  - Improvement: fix ruby 2.7 warnings
@@ -37,8 +37,8 @@ module HeyYou
37
37
  return
38
38
  end
39
39
 
40
- ch_builder =
41
- HeyYou::Builder.const_get("#{ch.downcase.capitalize}").new(data[ch.to_s], key, **options)
40
+ klass_name = ch.to_s.downcase.split('_').map(&:capitalize).join
41
+ ch_builder = HeyYou::Builder.const_get(klass_name).new(data[ch.to_s], key, **options)
42
42
  instance_variable_set("@#{ch}".to_sym, ch_builder)
43
43
 
44
44
  define_ch_method(ch)
@@ -74,4 +74,4 @@ module HeyYou
74
74
  class DataNotFound < StandardError; end
75
75
  class RequiredChannelNotFound < StandardError; end
76
76
  end
77
- end
77
+ end
@@ -10,7 +10,7 @@ module HeyYou
10
10
  @mailer_method = ch_data.fetch('mailer_method', nil)
11
11
  @delivery_method = ch_data.fetch('delivery_method', nil)
12
12
  @body = interpolate(ch_data['body'], options) if ch_data['body']
13
- @body_parts = interpolate_each(ch_data.fetch('body_parts', nil), options)
13
+ @body_parts = interpolate_each(ch_data.fetch('body_parts', nil)&.deep_dup, options)
14
14
  @subject = interpolate(ch_data.fetch('subject'), options)
15
15
  end
16
16
 
@@ -28,7 +28,7 @@ module HeyYou
28
28
 
29
29
  begin
30
30
  notification_hash[k] = v % options
31
- rescue KeyError
31
+ rescue KeyError => err
32
32
  raise InterpolationError, "Failed build notification string `#{v}`: #{err.message}"
33
33
  end
34
34
  end
@@ -50,11 +50,11 @@ module HeyYou
50
50
  end
51
51
 
52
52
  def collection
53
- @collection ||= load_collection
53
+ @collection ||= deep_freeze(load_collection)
54
54
  end
55
55
 
56
56
  def env_collection
57
- @env_collection ||= load_env_collection
57
+ @env_collection ||= deep_freeze(load_env_collection)
58
58
  end
59
59
 
60
60
  def registrate_receiver(receiver_class)
@@ -62,6 +62,13 @@ module HeyYou
62
62
  @registered_receivers << receiver_class
63
63
  end
64
64
 
65
+ def validate_config
66
+ registered_channels.each do |ch|
67
+ ch_config = send(ch)
68
+ ch_config.validate_config if ch_config.respond_to?(:validate_config)
69
+ end
70
+ end
71
+
65
72
  # Registrate new custom channel.
66
73
  # For successful registration, in application must be exists:
67
74
  # 1. HeyYou::Channels::<YOUR_CHANNEL_NAME> < HeyYou::Channels::Base
@@ -94,12 +101,21 @@ module HeyYou
94
101
  # For example, if ch == 'push' will define method #push for class instance.
95
102
  # New method will return instance of channel config instance
96
103
  def define_ch_config_method(ch)
97
- method_proc = -> { self.class.const_get(ch.capitalize).config }
104
+ klass_name = ch.to_s.split('_').map(&:capitalize).join
105
+ method_proc = -> { self.class.const_get(klass_name).config }
98
106
  self.class.send(:define_method, ch, method_proc)
99
107
  end
100
108
 
101
109
  def load_collection
102
110
  data_source.load_data
103
111
  end
112
+
113
+ def deep_freeze(val)
114
+ if val.respond_to? :each
115
+ val.class == Hash ? val.each { |_, val| deep_freeze(val) } : val.each { |val| deep_freeze(val) }
116
+ end
117
+
118
+ val.freeze unless val.frozen?
119
+ end
104
120
  end
105
- end
121
+ end
@@ -13,6 +13,7 @@ module HeyYou
13
13
  def configure(&block)
14
14
  @configured ? raise(AlreadyConfiguredError, 'You already configure HeyYou') : instance_eval(&block)
15
15
  @configured = true
16
+ instance.validate_config if instance.respond_to?(:validate_config)
16
17
  end
17
18
 
18
19
  def config
@@ -20,6 +21,7 @@ module HeyYou
20
21
  end
21
22
 
22
23
  class AlreadyConfiguredError < StandardError; end
24
+ class RequiredConfigsNotPassed < StandardError; end
23
25
  end
24
26
  end
25
- end
27
+ end
@@ -38,7 +38,7 @@ module HeyYou
38
38
  # Fetch receiver's info for sending: phone_number, email, etc
39
39
  subject: receiver.public_send("#{ch}_ch_receive_info"),
40
40
  # Fetch receiver's options like :mailer_class
41
- options: receiver.public_send("#{ch}_ch_receive_options") || {}
41
+ options: receiver.public_send("#{ch}_ch_receive_options").merge(options) || {}
42
42
  }
43
43
  end
44
44
 
@@ -55,7 +55,8 @@ module HeyYou
55
55
  " and options: #{receive_info[ch][:options]}"
56
56
  )
57
57
  receive_options = receive_info[ch].fetch(:options, {}) || {}
58
- response[ch] = Channels.const_get(ch.to_s.capitalize).send!(
58
+ klass_name = ch.to_s.downcase.split('_').map(&:capitalize).join
59
+ response[ch] = Channels.const_get(klass_name).send!(
59
60
  builder, to: receive_info[ch][:subject], **receive_options
60
61
  )
61
62
  else
@@ -89,4 +90,4 @@ module HeyYou
89
90
 
90
91
  class NotRegisteredReceiver < StandardError; end
91
92
  end
92
- end
93
+ end
@@ -1,3 +1,3 @@
1
1
  module HeyYou
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hey-you
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Nesterov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fcm