class Checkability::Checkable

Implements check method to Iterate on chechers Possible to implemet as Iterator in future

Attributes

check_obj[RW]
handler_confs[RW]

Public Class Methods

new(check_obj) click to toggle source
# File lib/checkability/checkable.rb, line 15
def initialize(check_obj)
  @check_obj = check_obj
end

Public Instance Methods

check() click to toggle source

As in result handlers should behave like this: validator .next_handler(storage) storage .next_handler(api_validator) api_validator.next_handler(api_finder) api_validator.next_handler(nil)

validator.handle(request)

ChainOfResponsibilty

# File lib/checkability/checkable.rb, line 29
def check
  _first_handler.handle(check_obj)
rescue StandardError => e
  check_obj.ch_messages << "false:::#{e}: #{handler_confs}."
  false
end

Private Instance Methods

_first_handler() click to toggle source
# File lib/checkability/checkable.rb, line 38
def _first_handler
  _handlers[ch_conf.keys.first]
end
_handlers() click to toggle source
# File lib/checkability/checkable.rb, line 42
def _handlers
  handlers = _make_handlers
  handlers.each_value.with_index do |handler, i|
    next_handler = handlers[handlers.keys[i + 1]]
    handler.next_handler(next_handler) if next_handler
  end
  handlers
end
_make_handler(conf) click to toggle source
# File lib/checkability/checkable.rb, line 55
def _make_handler(conf)
  Checkability.const_get(conf[:name].to_s.camelize)
              .new(conf)
end
_make_handlers() click to toggle source
# File lib/checkability/checkable.rb, line 51
def _make_handlers
  ch_conf.transform_values { |conf| _make_handler(conf) }
end