Class: DataChecks::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/data_checks/check.rb

Direct Known Subclasses

EnsureEqual, EnsureLess, EnsureMore, EnsureNo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, block) ⇒ Check

Returns a new instance of Check.



7
8
9
10
11
12
# File 'lib/data_checks/check.rb', line 7

def initialize(name, options, block)
  @name = name.to_s
  @options = options
  @tag = options[:tag]&.to_s
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/data_checks/check.rb', line 5

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/data_checks/check.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/data_checks/check.rb', line 5

def options
  @options
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/data_checks/check.rb', line 5

def tag
  @tag
end

Instance Method Details

#check_runObject



22
23
24
# File 'lib/data_checks/check.rb', line 22

def check_run
  @check_run ||= CheckRun.find_by(name: name)
end

#notifiersObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/data_checks/check.rb', line 26

def notifiers
  configured_notifiers = DataChecks.config.notifier_options
  notifiers = Array(options[:notify] || configured_notifiers.keys).map(&:to_s)

  notifiers.map do |notifier|
    raise "Unknown notifier: '#{notifier}'" unless configured_notifiers.key?(notifier)

    type = configured_notifiers[notifier][:type]
    klass = Notifiers.lookup(type)
    klass.new(configured_notifiers[notifier])
  end
end

#runObject



14
15
16
17
18
19
20
# File 'lib/data_checks/check.rb', line 14

def run
  result = block.call
rescue Exception => e # rubocop:disable Lint/RescueException
  error_result(e)
else
  handle_result(result)
end