rollbar-notification-rules-generator 0.2.3 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95d4d2186d8360cf8577ed75ab8037ddcd90ac998b77cb7b7c5803a8e78c6e64
4
- data.tar.gz: 95e31245d3c6d273b1888e82ec84c75fc05628d03b7cbbd53d401d1d0b47b617
3
+ metadata.gz: fe4a75ed31e8bae4026c17a16bcee7b013e110191673d4557f4a635c77c08daa
4
+ data.tar.gz: 99b315f25a48a018df9aae2308d0cf0cc010371f6899c8b73fd5d611cde190a7
5
5
  SHA512:
6
- metadata.gz: 0e3d15a47f9fe36caf190a0e859f75ef8bcb7ee799db31a77c55afbd3823d0caaebda20664d35df57f10c4c5bd52862048c7160118bca6e6cd3b4b2ce7659ca9
7
- data.tar.gz: 2a71e00cdc373796f676d93e26d9b3c5b9166d805d6c7cf3037e426e3b9133e957953b6e6fd77abdb2f8e7ad9f8c2d4eac1930ec8ed9afec7d2877c57ef345c6
6
+ metadata.gz: 1e64c8ac68a6d9bc60d2f8f5e6edeced34b536a8b2c5ce732f813992a60277e89d75af2f73f96c507dbb294da04a0343f6d42e28dc67225152d5bdefd4d16d24
7
+ data.tar.gz: ea48d084b210f270e4808260718002214f4ff945704f35c3baa5e1726547fe7aeb973cfbaebac7e5c3a500421f98e27e98cdb2a0ecab31b0bc40e95c76048623
@@ -3,7 +3,7 @@ require "optparse"
3
3
 
4
4
  require "rollbar/notification"
5
5
 
6
- Version = "0.2.3"
6
+ Version = "0.2.4"
7
7
  FORMATS = %w[terraform text]
8
8
 
9
9
  opts = { format: "terraform" }
@@ -38,6 +38,12 @@ module Rollbar
38
38
  [self.class, type, operation, value].hash
39
39
  end
40
40
 
41
+ # @param other [Base, Rate]
42
+ # @return [false]
43
+ def never_met_with?(other)
44
+ false
45
+ end
46
+
41
47
  # @return [String]
42
48
  def to_tf
43
49
  <<~TF
@@ -13,14 +13,21 @@ module Rollbar
13
13
  @type = "environment"
14
14
  end
15
15
 
16
+ # @param other [Base, Rate]
17
+ # @return [Boolean]
18
+ def never_met_with?(other)
19
+ self.class == other.class &&
20
+ self == other.build_complement_conditions.first
21
+ end
22
+
16
23
  # @return [String]
17
24
  def to_s
18
25
  "#{@type} #{@operation == "eq" ? "==" : "!="} #{@value}"
19
26
  end
20
27
 
21
- # @return [Environment]
22
- def build_complement_condition
23
- self.class.new(@operation == "eq" ? "neq" : "eq", @value)
28
+ # @return [Array<Environment>]
29
+ def build_complement_conditions
30
+ [self.class.new(@operation == "eq" ? "neq" : "eq", @value)]
24
31
  end
25
32
  end
26
33
  end
@@ -20,6 +20,8 @@ module Rollbar
20
20
  "exists" => "exists",
21
21
  "nexists" => "does not exist",
22
22
  }
23
+ # @return [Array<String>]
24
+ OPERATIONS_MET_ONLY_IF_PATH_EXISTS = %w[eq within nwithin regex nregex exists]
23
25
 
24
26
  attr_reader :path
25
27
 
@@ -44,6 +46,16 @@ module Rollbar
44
46
  [self.class, type, operation, value, path].hash
45
47
  end
46
48
 
49
+ # @param other [Base, Rate]
50
+ # @return [Boolean]
51
+ def never_met_with?(other)
52
+ return false if self.class != other.class || path != other.path
53
+ return true if operation == other.inverse_operation && value == other.value
54
+ return true if operation == "nexists" && OPERATIONS_MET_ONLY_IF_PATH_EXISTS.include?(other.operation)
55
+ return true if other.operation == "nexists" && OPERATIONS_MET_ONLY_IF_PATH_EXISTS.include?(operation)
56
+ false
57
+ end
58
+
47
59
  # @return [String]
48
60
  def to_tf
49
61
  <<~TF
@@ -58,13 +70,22 @@ module Rollbar
58
70
 
59
71
  # @return [String]
60
72
  def to_s
61
- %Q{#{@type} #{@path} #{OPERATION_TO_TEXT[@operation]} "#{@value}"}
73
+ s = +%Q{#{@type} #{@path} #{OPERATION_TO_TEXT[@operation]}}
74
+ s << %Q{ "#{@value}"} unless @operation.end_with?("exists")
75
+ s
62
76
  end
63
77
 
64
- # @return [Path]
65
- def build_complement_condition
66
- new_operation = @operation.start_with?("n") ? @operation.delete_prefix("n") : "n#{@operation}"
67
- self.class.new(@path, new_operation, @value)
78
+ # @return [Array<Path>]
79
+ def build_complement_conditions
80
+ complement_cond = self.class.new(@path, inverse_operation, @value)
81
+ case @operation
82
+ when "within", "nwithin", "regex", "nregex"
83
+ # Neither "nwithin" nor "nregex" matches the condition if the path doesn't exist,
84
+ # so the complement condition of these operations equals (`complement_cond` OR nexists)
85
+ [complement_cond, self.class.new(@path, "nexists", "")]
86
+ else
87
+ [complement_cond]
88
+ end
68
89
  end
69
90
 
70
91
  # @param other [Base, Rate]
@@ -72,6 +93,11 @@ module Rollbar
72
93
  def redundant_to?(other)
73
94
  super && @path == other.path
74
95
  end
96
+
97
+ # @return [String]
98
+ def inverse_operation
99
+ @operation.start_with?("n") ? @operation.delete_prefix("n") : "n#{@operation}"
100
+ end
75
101
  end
76
102
  end
77
103
  end
@@ -25,6 +25,12 @@ module Rollbar
25
25
  @period = period
26
26
  end
27
27
 
28
+ # @param other [Base, Rate]
29
+ # @return [false]
30
+ def never_met_with?(other)
31
+ false
32
+ end
33
+
28
34
  # @return [String]
29
35
  def to_s
30
36
  "At least #{@count} occurrences within #{PERIOD_TO_TEXT[@period]}"
@@ -20,15 +20,22 @@ module Rollbar
20
20
  @type = "title"
21
21
  end
22
22
 
23
+ # @param other [Base, Rate]
24
+ # @return [Boolean]
25
+ def never_met_with?(other)
26
+ self.class == other.class &&
27
+ self == other.build_complement_conditions.first
28
+ end
29
+
23
30
  # @return [String]
24
31
  def to_s
25
32
  %Q{#{@type} #{OPERATION_TO_TEXT[@operation]} "#{@value}"}
26
33
  end
27
34
 
28
- # @return [Title]
29
- def build_complement_condition
35
+ # @return [Array<Title>]
36
+ def build_complement_conditions
30
37
  new_operation = @operation.start_with?("n") ? @operation.delete_prefix("n") : "n#{@operation}"
31
- self.class.new(new_operation, @value)
38
+ [self.class.new(new_operation, @value)]
32
39
  end
33
40
  end
34
41
  end
@@ -19,8 +19,7 @@ module Rollbar
19
19
  conditions.each.with_index.any? do |condition, i|
20
20
  # NOTE: `@conditions[i + 1 ..]` cannot be nil but `|| []` is required to suppress the warning "'any?' may produce 'NoMethodError'"
21
21
  (conditions[i + 1 ..] || []).any? do |other|
22
- next false unless condition.respond_to?(:build_complement_condition)
23
- other == condition.build_complement_condition
22
+ condition.never_met_with?(other)
24
23
  end
25
24
  end
26
25
  end
@@ -140,7 +139,7 @@ module Rollbar
140
139
  def build_additional_conditions_set_for_subsequent_rules
141
140
  target_levels = level_condition&.target_level_values || Rollbar::Notification::Condition::Level::SUPPORTED_VALUES
142
141
 
143
- conditions_with_complement = @conditions.select { |c| c.respond_to?(:build_complement_condition) }
142
+ conditions_with_complement = @conditions.select { |c| c.respond_to?(:build_complement_conditions) }
144
143
  return {} if conditions_with_complement.empty?
145
144
 
146
145
  # Build set of conditions for the complement condition
@@ -158,8 +157,10 @@ module Rollbar
158
157
  # [cond1, cond2, not-cond3],
159
158
  # [cond1, cond2, cond3, not-cond4],
160
159
  # ]
161
- additional_conditions_set = conditions_with_complement.map.with_index do |cond, i|
162
- [*conditions_with_complement[... i], cond.build_complement_condition]
160
+ additional_conditions_set = conditions_with_complement.flat_map.with_index do |cond, i|
161
+ cond.build_complement_conditions.map do |complement_cond|
162
+ [*conditions_with_complement[... i], complement_cond]
163
+ end
163
164
  end
164
165
 
165
166
  target_levels.zip([additional_conditions_set].cycle).to_h
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rollbar-notification-rules-generator"
5
- spec.version = `ruby -Ilib exe/rollbar-notification-rules-generator --version`.split(" ").last.chomp
5
+ spec.version = `RUBYOPT='' ruby -Ilib exe/rollbar-notification-rules-generator --version`.split(" ").last.chomp
6
6
  spec.authors = ["abicky"]
7
7
  spec.email = ["takeshi.arabiki@gmail.com"]
8
8
 
data/sig/defs.rbs CHANGED
@@ -132,6 +132,9 @@ module Rollbar
132
132
 
133
133
  def hash: () -> Integer
134
134
 
135
+ # _@param_ `other`
136
+ def never_met_with?: ((Base | Rate) other) -> bool
137
+
135
138
  def to_tf: () -> String
136
139
 
137
140
  # _@param_ `other`
@@ -149,6 +152,7 @@ module Rollbar
149
152
  class Path < Rollbar::Notification::Condition::Base
150
153
  SUPPORTED_OPERATIONS: ::Array[String]
151
154
  OPERATION_TO_TEXT: ::Hash[String, String]
155
+ OPERATIONS_MET_ONLY_IF_PATH_EXISTS: ::Array[String]
152
156
 
153
157
  # _@param_ `path`
154
158
  #
@@ -162,15 +166,20 @@ module Rollbar
162
166
 
163
167
  def hash: () -> Integer
164
168
 
169
+ # _@param_ `other`
170
+ def never_met_with?: ((Base | Rate) other) -> bool
171
+
165
172
  def to_tf: () -> String
166
173
 
167
174
  def to_s: () -> String
168
175
 
169
- def build_complement_condition: () -> Path
176
+ def build_complement_conditions: () -> ::Array[Path]
170
177
 
171
178
  # _@param_ `other`
172
179
  def redundant_to?: ((Base | Rate) other) -> bool
173
180
 
181
+ def inverse_operation: () -> String
182
+
174
183
  attr_reader path: String
175
184
  end
176
185
 
@@ -184,6 +193,9 @@ module Rollbar
184
193
  # _@param_ `period`
185
194
  def initialize: (Integer count, Integer period) -> void
186
195
 
196
+ # _@param_ `other`
197
+ def never_met_with?: ((Base | Rate) other) -> bool
198
+
187
199
  def to_s: () -> String
188
200
 
189
201
  def to_tf: () -> String
@@ -221,9 +233,12 @@ module Rollbar
221
233
 
222
234
  def initialize: (String operation, String value) -> void
223
235
 
236
+ # _@param_ `other`
237
+ def never_met_with?: ((Base | Rate) other) -> bool
238
+
224
239
  def to_s: () -> String
225
240
 
226
- def build_complement_condition: () -> Title
241
+ def build_complement_conditions: () -> ::Array[Title]
227
242
  end
228
243
 
229
244
  class Framework < Rollbar::Notification::Condition::Base
@@ -239,9 +254,12 @@ module Rollbar
239
254
 
240
255
  def initialize: (String operation, String value) -> void
241
256
 
257
+ # _@param_ `other`
258
+ def never_met_with?: ((Base | Rate) other) -> bool
259
+
242
260
  def to_s: () -> String
243
261
 
244
- def build_complement_condition: () -> Environment
262
+ def build_complement_conditions: () -> ::Array[Environment]
245
263
  end
246
264
  end
247
265
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar-notification-rules-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - abicky