module HealthBit
Constants
- DEFAULT_FAIL_CODE
- DEFAULT_HEADERS
- DEFAULT_SUCCESS_CODE
- DEFAULT_SUCCESS_TEXT
- VERSION
Attributes
fail_code[W]
headers[W]
show_backtrace[RW]
success_code[W]
success_text[W]
Public Instance Methods
add(name, handler = nil, &block)
click to toggle source
@return [self]
# File lib/health_bit.rb, line 48 def add(name, handler = nil, &block) raise ArgumentError, <<~MSG if handler && block Both <handler> and <block> were passed to the <#{name}> check MSG raise ArgumentError, <<~MSG unless handler || block Nor <handler> or <block> were passed to the <#{name}> check MSG checks.push(Check.new(name, handler || block)) self end
check()
click to toggle source
@return [nil, CheckError]
# File lib/health_bit.rb, line 63 def check checks.each do |check| (exception = check.call).nil? ? next : (return exception) end nil end
checks()
click to toggle source
# File lib/health_bit.rb, line 39 def checks @checks ||= [] end
clone()
click to toggle source
# File lib/health_bit.rb, line 87 def clone Module.new.tap do |dolly| dolly.singleton_class.include(HealthBit) end end
configure() { |self| ... }
click to toggle source
# File lib/health_bit.rb, line 43 def configure yield(self) end
fail_code()
click to toggle source
# File lib/health_bit.rb, line 31 def fail_code @fail_code || DEFAULT_FAIL_CODE end
headers()
click to toggle source
# File lib/health_bit.rb, line 35 def headers (@headers || DEFAULT_HEADERS).dup end
rack(this = self)
click to toggle source
# File lib/health_bit.rb, line 71 def rack(this = self) @rack ||= begin format = this.show_backtrace ? CheckError::FORMAT_FULL : CheckError::FORMAT_SHORT Rack::Builder.new do run ->(_env) do if (error = this.check) [this.fail_code, this.headers, [error.to_s(format)]] else [this.success_code, this.headers, [this.success_text]] end end end end end
success_code()
click to toggle source
# File lib/health_bit.rb, line 27 def success_code @success_code || DEFAULT_SUCCESS_CODE end
success_text()
click to toggle source
# File lib/health_bit.rb, line 23 def success_text format(@success_text || DEFAULT_SUCCESS_TEXT, count: checks.length) end