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
- #add_check(klass, name, options, block) ⇒ Object
- #checks ⇒ Object
- #ensure_fewer(name, options = {}, &block) ⇒ Object
- #ensure_more(name, options = {}, &block) ⇒ Object
- #ensure_no(name, options = {}, &block) ⇒ Object
- #interval(duration) ⇒ Object
-
#notifier ⇒ Object
Private API.
- #notifier_options ⇒ Object
- #notify(notifier, notifier_options = {}) ⇒ Object
- #option(key, default = nil) ⇒ Object
- #options(options_hash) ⇒ Object
- #perform_check(check_name) ⇒ Object
- #time_between_checks ⇒ Object
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, , block) name = name.to_s raise CheckerJobs::DuplicateCheckerName, name if checks.key?(name) checks[name] = klass.new(self, name, , block) end |
#checks ⇒ Object
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, = {}, &block) add_check CheckerJobs::Checks::EnsureFewer, name, , block end |
#ensure_more(name, options = {}, &block) ⇒ Object
32 33 34 |
# File 'lib/checker_jobs/dsl.rb', line 32 def ensure_more(name, = {}, &block) add_check CheckerJobs::Checks::EnsureMore, name, , block end |
#ensure_no(name, options = {}, &block) ⇒ Object
28 29 30 |
# File 'lib/checker_jobs/dsl.rb', line 28 def ensure_no(name, = {}, &block) add_check CheckerJobs::Checks::EnsureNo, name, , block end |
#interval(duration) ⇒ Object
24 25 26 |
# File 'lib/checker_jobs/dsl.rb', line 24 def interval(duration) @time_between_checks = duration end |
#notifier ⇒ Object
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_options ⇒ Object
50 51 52 53 54 |
# File 'lib/checker_jobs/dsl.rb', line 50 def 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 = notifier @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 = 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_checks ⇒ Object
56 57 58 |
# File 'lib/checker_jobs/dsl.rb', line 56 def time_between_checks @time_between_checks || CheckerJobs.configuration.time_between_checks end |