Module: CheckerJobs::DSL

Defined in:
lib/checker_jobs/dsl.rb

Overview

DSL to declare checker jobs. It provides predicates:

  • ensure_no

  • ensure_more

  • ensure_fewer

And configuration methods:

  • options

  • notify

  • interval

Instance Method Summary collapse

Instance Method Details

#add_check(klass, name, options, block) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/checker_jobs/dsl.rb', line 68

def add_check(klass, name, options, block)
  name = name.to_s

  raise CheckerJobs::DuplicateCheckerName, name if checks.key?(name)

  checks[name] = klass.new(self, name, options, block)
end

#checksObject



64
65
66
# File 'lib/checker_jobs/dsl.rb', line 64

def checks
  @checks ||= {}
end

#ensure_fewer(name, options = {}, &block) ⇒ Object



36
37
38
# File 'lib/checker_jobs/dsl.rb', line 36

def ensure_fewer(name, options = {}, &block)
  add_check CheckerJobs::Checks::EnsureFewer, name, options, block
end

#ensure_more(name, options = {}, &block) ⇒ Object



32
33
34
# File 'lib/checker_jobs/dsl.rb', line 32

def ensure_more(name, options = {}, &block)
  add_check CheckerJobs::Checks::EnsureMore, name, options, block
end

#ensure_no(name, options = {}, &block) ⇒ Object



28
29
30
# File 'lib/checker_jobs/dsl.rb', line 28

def ensure_no(name, options = {}, &block)
  add_check CheckerJobs::Checks::EnsureNo, name, options, block
end

#interval(duration) ⇒ Object



24
25
26
# File 'lib/checker_jobs/dsl.rb', line 24

def interval(duration)
  @time_between_checks = duration
end

#notifierObject

Private API



44
45
46
47
48
# File 'lib/checker_jobs/dsl.rb', line 44

def notifier
  raise CheckerJobs::MissingNotifier, self.class unless defined?(@notifier)

  @notifier
end

#notifier_optionsObject



50
51
52
53
54
# File 'lib/checker_jobs/dsl.rb', line 50

def notifier_options
  raise CheckerJobs::MissingNotifier, self.class unless defined?(@notifier)

  @notifier_options
end

#notify(notifier, notifier_options = {}) ⇒ Object



19
20
21
22
# File 'lib/checker_jobs/dsl.rb', line 19

def notify(notifier, notifier_options = {})
  @notifier = notifier
  @notifier_options = notifier_options
end

#option(key, default = nil) ⇒ Object



60
61
62
# File 'lib/checker_jobs/dsl.rb', line 60

def option(key, default = nil)
  @options && @options[key] || default
end

#options(options_hash) ⇒ Object



15
16
17
# File 'lib/checker_jobs/dsl.rb', line 15

def options(options_hash)
  @options = options_hash
end

#perform_check(check_name) ⇒ Object



76
77
78
# File 'lib/checker_jobs/dsl.rb', line 76

def perform_check(check_name)
  checks.fetch(check_name.to_s).perform
end

#time_between_checksObject



56
57
58
# File 'lib/checker_jobs/dsl.rb', line 56

def time_between_checks
  @time_between_checks || CheckerJobs.configuration.time_between_checks
end