rollbar-notification-rules-generator 0.2.2 → 0.2.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: b69971ea33eb831637b2fbc7170b01dd6cce53e45f02d6f0b2c45c019900ed5a
4
- data.tar.gz: 43b362b542727d83795bbc5efd0f9f219a224e0f2030d3579be755e97477f111
3
+ metadata.gz: fe4a75ed31e8bae4026c17a16bcee7b013e110191673d4557f4a635c77c08daa
4
+ data.tar.gz: 99b315f25a48a018df9aae2308d0cf0cc010371f6899c8b73fd5d611cde190a7
5
5
  SHA512:
6
- metadata.gz: f61baf0e620d426b92f9bcd5ea00709969d1b183febcbfe0f4cc8b9f288f2f23e33d4aea71d8e4a0357eb441b4a111ebbdfd40b45e54d37df971ff475df061ec
7
- data.tar.gz: 0baee819bff11502752157d296a978a5a50e48f2e9efcaac4593a9820e192fe3801c2cafa1566857f12dc2b2df98fcd8e570fd17c8b760548a1c893effd48bc4
6
+ metadata.gz: 1e64c8ac68a6d9bc60d2f8f5e6edeced34b536a8b2c5ce732f813992a60277e89d75af2f73f96c507dbb294da04a0343f6d42e28dc67225152d5bdefd4d16d24
7
+ data.tar.gz: ea48d084b210f270e4808260718002214f4ff945704f35c3baa5e1726547fe7aeb973cfbaebac7e5c3a500421f98e27e98cdb2a0ecab31b0bc40e95c76048623
data/Gemfile CHANGED
@@ -8,3 +8,7 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
+
12
+ # For generating sig/defs.rbs
13
+ gem "yard"
14
+ gem "sord"
data/README.md CHANGED
@@ -161,7 +161,7 @@ See the YAML files in [spec/files/yaml](spec/files/yaml). Their output files are
161
161
 
162
162
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
163
163
 
164
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `rollbar-notification-rules-generator.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
164
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `exe/rollbar-notification-rules-generator`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
165
165
 
166
166
  ## Contributing
167
167
 
data/Rakefile CHANGED
@@ -6,3 +6,8 @@ require "rspec/core/rake_task"
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  task default: :spec
9
+
10
+ task :generate_rbs do
11
+ sh "sord sig/defs.rbs"
12
+ sh %q{sed -i$([ $(uname) = "Darwin" ] && echo ' ""') '1s/^/# This file was generated by "rake generate_rbs"\n/' sig/defs.rbs}
13
+ end
@@ -3,6 +3,7 @@ require "optparse"
3
3
 
4
4
  require "rollbar/notification"
5
5
 
6
+ Version = "0.2.4"
6
7
  FORMATS = %w[terraform text]
7
8
 
8
9
  opts = { format: "terraform" }
@@ -4,13 +4,14 @@ require "rollbar/notification/trigger"
4
4
  module Rollbar
5
5
  class Notification
6
6
  class Channel
7
+ # @return [Hash{String => String}]
7
8
  CHANNEL_TO_TEXT = {
8
9
  "slack" => "Slack",
9
10
  "pagerduty" => "PagerDuty",
10
11
  }
11
12
 
12
13
  # @param channel [String]
13
- # @param triggers [Hash{String => Array<Hash>}]
14
+ # @param triggers [Hash{String => Array<Hash{String => Object}>}]
14
15
  # @param variables [Hash{String => String}]
15
16
  def initialize(channel, triggers, variables)
16
17
  unless CHANNEL_TO_TEXT.include?(channel)
@@ -28,7 +29,9 @@ module Rollbar
28
29
  "# #{CHANNEL_TO_TEXT.fetch(@channel)}\n#{@triggers.map(&:to_s).join.chomp}"
29
30
  end
30
31
 
31
- # @param provider [String]
32
+ # @param provider [String, nil]
33
+ # @param namespace [String, nil]
34
+ # @return [String]
32
35
  def to_tf(provider, namespace)
33
36
  @triggers.map { |t| t.to_tf(provider, namespace) }.join("\n")
34
37
  end
@@ -3,6 +3,12 @@
3
3
  module Rollbar
4
4
  class Notification
5
5
  module Condition
6
+ # @!attribute [r] type
7
+ # @return [String]
8
+ # @!attribute [r] operation
9
+ # @return [String]
10
+ # @!attribute [r] value
11
+ # @return [String]
6
12
  class Base
7
13
  attr_reader :type, :operation, :value
8
14
 
@@ -27,10 +33,18 @@ module Rollbar
27
33
  end
28
34
  alias :eql? :==
29
35
 
36
+ # @return [Integer]
30
37
  def hash
31
38
  [self.class, type, operation, value].hash
32
39
  end
33
40
 
41
+ # @param other [Base, Rate]
42
+ # @return [false]
43
+ def never_met_with?(other)
44
+ false
45
+ end
46
+
47
+ # @return [String]
34
48
  def to_tf
35
49
  <<~TF
36
50
  filters {
@@ -41,7 +55,7 @@ module Rollbar
41
55
  TF
42
56
  end
43
57
 
44
- # @param other [Base]
58
+ # @param other [Base, Rate]
45
59
  # @return [Boolean]
46
60
  def redundant_to?(other)
47
61
  self.class == other.class &&
@@ -5,6 +5,7 @@ module Rollbar
5
5
  class Notification
6
6
  module Condition
7
7
  class Environment < Base
8
+ # @return [Array<String>]
8
9
  SUPPORTED_OPERATIONS = %w[eq neq]
9
10
 
10
11
  def initialize(operation, value)
@@ -12,14 +13,21 @@ module Rollbar
12
13
  @type = "environment"
13
14
  end
14
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
+
15
23
  # @return [String]
16
24
  def to_s
17
25
  "#{@type} #{@operation == "eq" ? "==" : "!="} #{@value}"
18
26
  end
19
27
 
20
- # @return [Environment]
21
- def build_complement_condition
22
- 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)]
23
31
  end
24
32
  end
25
33
  end
@@ -5,6 +5,7 @@ module Rollbar
5
5
  class Notification
6
6
  module Condition
7
7
  class Framework < Base
8
+ # @return [Array<String>]
8
9
  SUPPORTED_OPERATIONS = %w[eq]
9
10
 
10
11
  def initialize(operation, value)
@@ -4,14 +4,21 @@ require "rollbar/notification/condition/base"
4
4
  module Rollbar
5
5
  class Notification
6
6
  module Condition
7
+ # @!attribute [r] level
8
+ # @return [Integer]
7
9
  class Level < Base
10
+ # @return [Array<String>]
8
11
  SUPPORTED_OPERATIONS = %w[eq gte]
12
+ # @return [Array<String>]
9
13
  SUPPORTED_VALUES = %w[debug info warning error critical]
10
14
 
11
15
  # @param lowest_target_level [Integer]
12
16
  # @return [Array<Level>]
13
17
  def self.build_eq_conditions_from(lowest_target_level)
14
- SUPPORTED_VALUES[lowest_target_level..].map do |value|
18
+ target_level_values = SUPPORTED_VALUES[lowest_target_level..]
19
+ raise "lowest_target_level is out of range" if target_level_values.nil?
20
+
21
+ target_level_values.map do |value|
15
22
  new("eq", value)
16
23
  end
17
24
  end
@@ -24,10 +31,11 @@ module Rollbar
24
31
  super
25
32
  @type = "level"
26
33
 
27
- @level = SUPPORTED_VALUES.index(value)
28
- unless @level
34
+ level = SUPPORTED_VALUES.index(value)
35
+ unless level
29
36
  raise ArgumentError, "Unsupported value: #{value}"
30
37
  end
38
+ @level = level
31
39
  end
32
40
 
33
41
  # @return [String]
@@ -37,7 +45,8 @@ module Rollbar
37
45
 
38
46
  # @return [Array<String>]
39
47
  def target_level_values
40
- @operation == "eq" ? [@value] : SUPPORTED_VALUES[@level..]
48
+ # NOTE: `SUPPORTED_VALUES[@level..]` cannot be nil but `|| []` is required to suppress the warning "Incompatible nilability"
49
+ @operation == "eq" ? [@value] : SUPPORTED_VALUES[@level..] || []
41
50
  end
42
51
  end
43
52
  end
@@ -4,8 +4,12 @@ require "rollbar/notification/condition/base"
4
4
  module Rollbar
5
5
  class Notification
6
6
  module Condition
7
+ # @!attribute [r] path
8
+ # @return [String]
7
9
  class Path < Base
10
+ # @return [Array<String>]
8
11
  SUPPORTED_OPERATIONS = %w[eq neq within nwithin regex nregex exists nexists]
12
+ # @return [Hash{String => String}]
9
13
  OPERATION_TO_TEXT = {
10
14
  "eq" => "==",
11
15
  "neq" => "!=",
@@ -16,6 +20,8 @@ module Rollbar
16
20
  "exists" => "exists",
17
21
  "nexists" => "does not exist",
18
22
  }
23
+ # @return [Array<String>]
24
+ OPERATIONS_MET_ONLY_IF_PATH_EXISTS = %w[eq within nwithin regex nregex exists]
19
25
 
20
26
  attr_reader :path
21
27
 
@@ -35,11 +41,22 @@ module Rollbar
35
41
  end
36
42
  alias :eql? :==
37
43
 
44
+ # @return [Integer]
38
45
  def hash
39
46
  [self.class, type, operation, value, path].hash
40
47
  end
41
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
42
58
 
59
+ # @return [String]
43
60
  def to_tf
44
61
  <<~TF
45
62
  filters {
@@ -53,19 +70,34 @@ module Rollbar
53
70
 
54
71
  # @return [String]
55
72
  def to_s
56
- %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
57
76
  end
58
77
 
59
- # @return [Path]
60
- def build_complement_condition
61
- new_operation = @operation.start_with?("n") ? @operation.delete_prefix("n") : "n#{@operation}"
62
- 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
63
89
  end
64
90
 
91
+ # @param other [Base, Rate]
65
92
  # @return [Boolean]
66
93
  def redundant_to?(other)
67
94
  super && @path == other.path
68
95
  end
96
+
97
+ # @return [String]
98
+ def inverse_operation
99
+ @operation.start_with?("n") ? @operation.delete_prefix("n") : "n#{@operation}"
100
+ end
69
101
  end
70
102
  end
71
103
  end
@@ -3,7 +3,10 @@
3
3
  module Rollbar
4
4
  class Notification
5
5
  module Condition
6
+ # @!attribute [r] type
7
+ # @return [String]
6
8
  class Rate
9
+ # @return [Hash{Integer => String}]
7
10
  PERIOD_TO_TEXT = {
8
11
  60 => "1 minute",
9
12
  300 => "5 minutes",
@@ -22,11 +25,18 @@ module Rollbar
22
25
  @period = period
23
26
  end
24
27
 
28
+ # @param other [Base, Rate]
29
+ # @return [false]
30
+ def never_met_with?(other)
31
+ false
32
+ end
33
+
25
34
  # @return [String]
26
35
  def to_s
27
36
  "At least #{@count} occurrences within #{PERIOD_TO_TEXT[@period]}"
28
37
  end
29
38
 
39
+ # @return [String]
30
40
  def to_tf
31
41
  <<~TF
32
42
  filters {
@@ -37,7 +47,7 @@ module Rollbar
37
47
  TF
38
48
  end
39
49
 
40
- # @param other [Base]
50
+ # @param other [Base, Rate]
41
51
  # @return [Boolean]
42
52
  def redundant_to?(other)
43
53
  false
@@ -5,7 +5,9 @@ module Rollbar
5
5
  class Notification
6
6
  module Condition
7
7
  class Title < Base
8
+ # @return [Array<String>]
8
9
  SUPPORTED_OPERATIONS = %w[within nwithin regex nregex]
10
+ # @return [Hash{String => String}]
9
11
  OPERATION_TO_TEXT = {
10
12
  "within" => "contains substring",
11
13
  "nwithin" => "does not contain substring",
@@ -18,14 +20,22 @@ module Rollbar
18
20
  @type = "title"
19
21
  end
20
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
+
21
30
  # @return [String]
22
31
  def to_s
23
32
  %Q{#{@type} #{OPERATION_TO_TEXT[@operation]} "#{@value}"}
24
33
  end
25
34
 
26
- def build_complement_condition
35
+ # @return [Array<Title>]
36
+ def build_complement_conditions
27
37
  new_operation = @operation.start_with?("n") ? @operation.delete_prefix("n") : "n#{@operation}"
28
- self.class.new(new_operation, @value)
38
+ [self.class.new(new_operation, @value)]
29
39
  end
30
40
  end
31
41
  end
@@ -8,10 +8,25 @@ require "rollbar/notification/condition/title"
8
8
 
9
9
  module Rollbar
10
10
  class Notification
11
+ # @!attribute [r] conditions
12
+ # @return [Array<Condition::Base, Condition::Rate>]
13
+ # @!attribute [r] configs
14
+ # @return [Array<Hash{String => Object}>]
11
15
  class Rule
16
+ # @param conditions [Array<Condition::Base, Condition::Rate>]
17
+ # @return [Boolean]
18
+ def self.never_met?(conditions)
19
+ conditions.each.with_index.any? do |condition, i|
20
+ # NOTE: `@conditions[i + 1 ..]` cannot be nil but `|| []` is required to suppress the warning "'any?' may produce 'NoMethodError'"
21
+ (conditions[i + 1 ..] || []).any? do |other|
22
+ condition.never_met_with?(other)
23
+ end
24
+ end
25
+ end
26
+
12
27
  attr_reader :conditions, :configs
13
28
 
14
- # @param rule [Hash]
29
+ # @param rule [Hash{String => Array<Object>}]
15
30
  def initialize(rule)
16
31
  @conditions = rule.fetch("conditions").map do |condition|
17
32
  case condition.fetch("type")
@@ -34,6 +49,8 @@ module Rollbar
34
49
  @configs = rule.fetch("configs", [{}])
35
50
  end
36
51
 
52
+ # @param original [Rule]
53
+ # @return [void]
37
54
  def initialize_dup(original)
38
55
  @conditions = original.conditions.dup
39
56
  remove_instance_variable(:@level_condition)
@@ -58,12 +75,7 @@ module Rollbar
58
75
  end
59
76
 
60
77
  def never_met?
61
- @conditions.each.with_index.any? do |condition, i|
62
- @conditions[i + 1 ..].any? do |other|
63
- next false unless condition.respond_to?(:build_complement_condition)
64
- other == condition.build_complement_condition
65
- end
66
- end
78
+ self.class.never_met?(@conditions)
67
79
  end
68
80
 
69
81
  # @param old_condition [Condition::Base]
@@ -127,29 +139,36 @@ module Rollbar
127
139
  def build_additional_conditions_set_for_subsequent_rules
128
140
  target_levels = level_condition&.target_level_values || Rollbar::Notification::Condition::Level::SUPPORTED_VALUES
129
141
 
130
- 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) }
131
143
  return {} if conditions_with_complement.empty?
132
144
 
145
+ # Build set of conditions for the complement condition
146
+ # e.g.
147
+ # [cond1, cond2]
148
+ # => [[not-cond1], [cond1, not-cond2]]
149
+ #
133
150
  # [cond1, cond2, cond3]
151
+ # => [[not-cond1], [cond1, not-cond2], [cond1, cond2, not-cond3]]
152
+ #
153
+ # [cond1, cond2, cond3, cond4]
134
154
  # => [
135
- # [cond1, cond2, not-cond3],
136
- # [cond1, not-cond2, cond3],
137
- # [cond1, not-cond2, not-cond3],
138
- # [not-cond1, cond2, cond3],
139
- # [not-cond1, cond2, not-cond3],
140
- # [not-cond1, not-cond2, cond3],
141
- # [not-cond1, not-cond2, not-cond3],
142
- # ]
143
- first_cond, *other_conds = conditions_with_complement.map do |condition|
144
- [condition, condition.build_complement_condition]
155
+ # [not-cond1],
156
+ # [cond1, not-cond2],
157
+ # [cond1, cond2, not-cond3],
158
+ # [cond1, cond2, cond3, not-cond4],
159
+ # ]
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
145
164
  end
146
- additional_conditions_set = first_cond.product(*other_conds) - [conditions_with_complement]
147
165
 
148
166
  target_levels.zip([additional_conditions_set].cycle).to_h
149
167
  end
150
168
 
151
169
  private
152
170
 
171
+ # @return [Condition::Level, nil]
153
172
  def level_condition
154
173
  return @level_condition if defined?(@level_condition)
155
174
  @level_condition = @conditions.find { |c| c.type == "level" }
@@ -6,6 +6,7 @@ require "rollbar/notification/rule"
6
6
  module Rollbar
7
7
  class Notification
8
8
  class Trigger
9
+ # @return [Hash{String => String}]
9
10
  TRIGGER_TO_TEXT = {
10
11
  "deploy" => "Deploy",
11
12
  "exp_repeat_item" => "10^nth Occurrence",
@@ -17,6 +18,7 @@ module Rollbar
17
18
  "resolved_item" => "Item Resolved",
18
19
  }
19
20
 
21
+ # @return [ERB]
20
22
  TEXT_TEMPLATE = ERB.new(<<~TEXT)
21
23
  conditions:
22
24
  <%= conditions.map { |condition| condition.to_s.gsub(/^/, " ") }.join("\n").chomp %><% unless config.empty? %><% max_key_len = config.keys.map(&:size).max %>
@@ -25,6 +27,7 @@ module Rollbar
25
27
  <%= config.compact.map { |key, value| ' %-*s = %s' % [max_key_len, key, value.inspect] }.join("\n") %><% end %>
26
28
  TEXT
27
29
 
30
+ # @return [ERB]
28
31
  TF_TEMPLATE = ERB.new(<<~TF)
29
32
  resource "rollbar_notification" "<%= resource_name %>" {<% if provider %>
30
33
  provider = <%= provider %>
@@ -43,7 +46,8 @@ module Rollbar
43
46
 
44
47
  # @param channel [String]
45
48
  # @param name [String]
46
- # @param rules [Array<Hash>]
49
+ # @param rules [Array<Hash{String => Object}>]
50
+ # @param variables [Hash{String => String}]
47
51
  def initialize(channel, name, rules, variables)
48
52
  @channel = channel
49
53
  @name = name
@@ -53,6 +57,7 @@ module Rollbar
53
57
  @variables = variables
54
58
  end
55
59
 
60
+ # @return [String]
56
61
  def to_s
57
62
  str = +"## #{TRIGGER_TO_TEXT.fetch(@name)}\n"
58
63
  i = -1
@@ -71,6 +76,9 @@ module Rollbar
71
76
  str
72
77
  end
73
78
 
79
+ # @param provider [String, nil]
80
+ # @param namespace [String, nil]
81
+ # @return [String]
74
82
  def to_tf(provider, namespace)
75
83
  i = -1
76
84
  build_mutually_exclusive_rules.flat_map do |rule|
@@ -117,14 +125,9 @@ module Rollbar
117
125
  highest_lowest_target_level = lowest_target_level
118
126
  end
119
127
  level_value_to_additional_conditions_set.merge!(rule.build_additional_conditions_set_for_subsequent_rules) do |_, v1, v2|
128
+ # @type [Array<Array<Condition::Base>>]
120
129
  additional_conditions_set = v1.product(v2).map(&:flatten)
121
-
122
- additional_conditions_set.reject! do |conditions|
123
- conditions.each.with_index.any? do |condition, i|
124
- conditions[i + 1 ..].any? { |other| other == condition.build_complement_condition }
125
- end
126
- end
127
-
130
+ additional_conditions_set.reject!(&Rule.method(:never_met?))
128
131
  additional_conditions_set
129
132
  end
130
133
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rollbar-notification-rules-generator"
5
- spec.version = "0.2.2"
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/array.rbs ADDED
@@ -0,0 +1,5 @@
1
+ # TODO: Delete this file after https://github.com/ruby/rbs/pull/1187 is merged
2
+ class Array[unchecked out Elem] < Object
3
+ def zip: [T] (::Enumerator[T] arg) -> ::Array[[ Elem, T? ]]
4
+ | ...
5
+ end
data/sig/defs.rbs ADDED
@@ -0,0 +1,266 @@
1
+ # This file was generated by "rake generate_rbs"
2
+ module Rollbar
3
+ class Notification
4
+ # _@param_ `config_file`
5
+ def initialize: (String config_file) -> void
6
+
7
+ def to_s: () -> String
8
+
9
+ def to_tf: () -> String
10
+
11
+ # @!attribute [r] conditions
12
+ # @return [Array<Condition::Base, Condition::Rate>]
13
+ # @!attribute [r] configs
14
+ # @return [Array<Hash{String => Object}>]
15
+ class Rule
16
+ # _@param_ `conditions`
17
+ def self.never_met?: (::Array[(Condition::Base | Condition::Rate)] conditions) -> bool
18
+
19
+ # _@param_ `rule`
20
+ def initialize: (::Hash[String, ::Array[Object]] rule) -> void
21
+
22
+ # _@param_ `original`
23
+ def initialize_dup: (Rule original) -> void
24
+
25
+ # _@param_ `other`
26
+ def ==: (Object other) -> bool
27
+
28
+ def remove_redundant_conditions!: () -> Rule
29
+
30
+ def never_met?: () -> bool
31
+
32
+ # _@param_ `old_condition`
33
+ #
34
+ # _@param_ `new_condition`
35
+ def replace_condition!: (Condition::Base old_condition, Condition::Base new_condition) -> Rule
36
+
37
+ def lowest_target_level: () -> Integer
38
+
39
+ def lowest_target_level_value: () -> String
40
+
41
+ # Splits rules if necessary.
42
+ # Assuming the following two rules:
43
+ # level = critical, title contains substring "bar"
44
+ # level >= error, title contains substring "baz"
45
+ # the second rule will be split into two rules with "eq" operation:
46
+ # level = critical, title contains substring "bar"
47
+ # level = critical, title contains substring "baz"
48
+ # level = error, title contains substring "baz"
49
+ # whereas assuming the following two rules:
50
+ # level = warning, title contains substring "bar"
51
+ # level >= error, title contains substring "baz"
52
+ # this method doesn't split the second rule because each rule
53
+ # is already mutually exclusive.
54
+ #
55
+ # _@param_ `highest_lowest_target_level` — the highest lowest_target_level among the preceding rules.
56
+ def split_rules: (Integer highest_lowest_target_level) -> ::Array[Rule]
57
+
58
+ # _@param_ `new_conditions`
59
+ def add_conditions!: ((Condition::Base | ::Array[Condition::Base]) new_conditions) -> Rule
60
+
61
+ def build_additional_conditions_set_for_subsequent_rules: () -> ::Hash[String, ::Array[::Array[Condition::Base]]]
62
+
63
+ def level_condition: () -> Condition::Level?
64
+
65
+ attr_reader conditions: ::Array[(Condition::Base | Condition::Rate)]
66
+
67
+ attr_reader configs: ::Array[::Hash[String, Object]]
68
+ end
69
+
70
+ class Channel
71
+ CHANNEL_TO_TEXT: ::Hash[String, String]
72
+
73
+ # _@param_ `channel`
74
+ #
75
+ # _@param_ `triggers`
76
+ #
77
+ # _@param_ `variables`
78
+ def initialize: (String channel, ::Hash[String, ::Array[::Hash[String, Object]]] triggers, ::Hash[String, String] variables) -> void
79
+
80
+ def to_s: () -> String
81
+
82
+ # _@param_ `provider`
83
+ #
84
+ # _@param_ `namespace`
85
+ def to_tf: (String? provider, String? namespace) -> String
86
+ end
87
+
88
+ class Trigger
89
+ TRIGGER_TO_TEXT: ::Hash[String, String]
90
+ TEXT_TEMPLATE: ERB
91
+ TF_TEMPLATE: ERB
92
+
93
+ # _@param_ `channel`
94
+ #
95
+ # _@param_ `name`
96
+ #
97
+ # _@param_ `rules`
98
+ #
99
+ # _@param_ `variables`
100
+ def initialize: (
101
+ String channel,
102
+ String name,
103
+ ::Array[::Hash[String, Object]] rules,
104
+ ::Hash[String, String] variables
105
+ ) -> void
106
+
107
+ def to_s: () -> String
108
+
109
+ # _@param_ `provider`
110
+ #
111
+ # _@param_ `namespace`
112
+ def to_tf: (String? provider, String? namespace) -> String
113
+
114
+ def build_mutually_exclusive_rules: () -> ::Array[Rule]
115
+ end
116
+
117
+ module Condition
118
+ # @!attribute [r] type
119
+ # @return [String]
120
+ # @!attribute [r] operation
121
+ # @return [String]
122
+ # @!attribute [r] value
123
+ # @return [String]
124
+ class Base
125
+ # _@param_ `operation`
126
+ #
127
+ # _@param_ `value`
128
+ def initialize: (String operation, String value) -> void
129
+
130
+ # _@param_ `other`
131
+ def ==: (Object other) -> bool
132
+
133
+ def hash: () -> Integer
134
+
135
+ # _@param_ `other`
136
+ def never_met_with?: ((Base | Rate) other) -> bool
137
+
138
+ def to_tf: () -> String
139
+
140
+ # _@param_ `other`
141
+ def redundant_to?: ((Base | Rate) other) -> bool
142
+
143
+ attr_reader type: String
144
+
145
+ attr_reader operation: String
146
+
147
+ attr_reader value: String
148
+ end
149
+
150
+ # @!attribute [r] path
151
+ # @return [String]
152
+ class Path < Rollbar::Notification::Condition::Base
153
+ SUPPORTED_OPERATIONS: ::Array[String]
154
+ OPERATION_TO_TEXT: ::Hash[String, String]
155
+ OPERATIONS_MET_ONLY_IF_PATH_EXISTS: ::Array[String]
156
+
157
+ # _@param_ `path`
158
+ #
159
+ # _@param_ `operation`
160
+ #
161
+ # _@param_ `value`
162
+ def initialize: (String path, String operation, String value) -> void
163
+
164
+ # _@param_ `other`
165
+ def ==: (Object other) -> bool
166
+
167
+ def hash: () -> Integer
168
+
169
+ # _@param_ `other`
170
+ def never_met_with?: ((Base | Rate) other) -> bool
171
+
172
+ def to_tf: () -> String
173
+
174
+ def to_s: () -> String
175
+
176
+ def build_complement_conditions: () -> ::Array[Path]
177
+
178
+ # _@param_ `other`
179
+ def redundant_to?: ((Base | Rate) other) -> bool
180
+
181
+ def inverse_operation: () -> String
182
+
183
+ attr_reader path: String
184
+ end
185
+
186
+ # @!attribute [r] type
187
+ # @return [String]
188
+ class Rate
189
+ PERIOD_TO_TEXT: ::Hash[Integer, String]
190
+
191
+ # _@param_ `count`
192
+ #
193
+ # _@param_ `period`
194
+ def initialize: (Integer count, Integer period) -> void
195
+
196
+ # _@param_ `other`
197
+ def never_met_with?: ((Base | Rate) other) -> bool
198
+
199
+ def to_s: () -> String
200
+
201
+ def to_tf: () -> String
202
+
203
+ # _@param_ `other`
204
+ def redundant_to?: ((Base | Rate) other) -> bool
205
+
206
+ attr_reader type: String
207
+ end
208
+
209
+ # @!attribute [r] level
210
+ # @return [Integer]
211
+ class Level < Rollbar::Notification::Condition::Base
212
+ SUPPORTED_OPERATIONS: ::Array[String]
213
+ SUPPORTED_VALUES: ::Array[String]
214
+
215
+ # _@param_ `lowest_target_level`
216
+ def self.build_eq_conditions_from: (Integer lowest_target_level) -> ::Array[Level]
217
+
218
+ # _@param_ `operation`
219
+ #
220
+ # _@param_ `value`
221
+ def initialize: (String operation, String value) -> void
222
+
223
+ def to_s: () -> String
224
+
225
+ def target_level_values: () -> ::Array[String]
226
+
227
+ attr_reader level: Integer
228
+ end
229
+
230
+ class Title < Rollbar::Notification::Condition::Base
231
+ SUPPORTED_OPERATIONS: ::Array[String]
232
+ OPERATION_TO_TEXT: ::Hash[String, String]
233
+
234
+ def initialize: (String operation, String value) -> void
235
+
236
+ # _@param_ `other`
237
+ def never_met_with?: ((Base | Rate) other) -> bool
238
+
239
+ def to_s: () -> String
240
+
241
+ def build_complement_conditions: () -> ::Array[Title]
242
+ end
243
+
244
+ class Framework < Rollbar::Notification::Condition::Base
245
+ SUPPORTED_OPERATIONS: ::Array[String]
246
+
247
+ def initialize: (String operation, String value) -> void
248
+
249
+ def to_s: () -> String
250
+ end
251
+
252
+ class Environment < Rollbar::Notification::Condition::Base
253
+ SUPPORTED_OPERATIONS: ::Array[String]
254
+
255
+ def initialize: (String operation, String value) -> void
256
+
257
+ # _@param_ `other`
258
+ def never_met_with?: ((Base | Rate) other) -> bool
259
+
260
+ def to_s: () -> String
261
+
262
+ def build_complement_conditions: () -> ::Array[Environment]
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,8 @@
1
+ module Rollbar
2
+ class Notification
3
+ class Channel
4
+ @channel: String
5
+ @triggers: Array[Trigger]
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Rollbar
2
+ class Notification
3
+ module Condition
4
+ class Rate
5
+ @count: Integer
6
+ @period: Integer
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Rollbar
2
+ class Notification
3
+ class Rule
4
+ @level_condition: Condition::Level?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Rollbar
2
+ class Notification
3
+ class Trigger
4
+ @channel: String
5
+ @name: String
6
+ @rules: Array[Rollbar::Notification::Rule]
7
+ @variables: Hash[String, String]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Rollbar
2
+ class Notification
3
+ @config: Hash[String, untyped]
4
+ @channel: Channel
5
+ end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar-notification-rules-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - abicky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-20 00:00:00.000000000 Z
11
+ date: 2022-12-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This tool generates Rollbar notification rules that are mutually exclusive
14
14
  from a simple YAML file.
@@ -37,6 +37,13 @@ files:
37
37
  - lib/rollbar/notification/rule.rb
38
38
  - lib/rollbar/notification/trigger.rb
39
39
  - rollbar-notification-rules-generator.gemspec
40
+ - sig/array.rbs
41
+ - sig/defs.rbs
42
+ - sig/rollbar/notification.rbs
43
+ - sig/rollbar/notification/channel.rbs
44
+ - sig/rollbar/notification/condition/rate.rbs
45
+ - sig/rollbar/notification/rule.rbs
46
+ - sig/rollbar/notification/trigger.rbs
40
47
  homepage: https://github.com/abicky/rollbar-notification-rules-generator
41
48
  licenses:
42
49
  - MIT