Top Level Namespace

Defined Under Namespace

Modules: TodoOrDie

Instance Method Summary collapse

Instance Method Details

#TodoOrDie(message, by: by_omitted = true, if: if_omitted = true, warn_by: warn_by_omitted = true) ⇒ Object

The main event



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/todo_or_die.rb', line 55

def TodoOrDie(message, by: by_omitted = true, if: if_omitted = true, warn_by: warn_by_omitted = true) # rubocop:disable Naming/MethodName
  due_at = Time.parse(by.to_s) unless by_omitted
  warn_at = Time.parse(warn_by.to_s) unless warn_by_omitted
  condition = binding.local_variable_get(:if) unless if_omitted

  should_warn = !warn_by_omitted && Time.now > warn_at
  is_due = by_omitted || Time.now > due_at
  die_condition_met = if_omitted || (condition.respond_to?(:call) ? condition.call : condition)
  should_die = is_due && die_condition_met

  if should_die
    die = TodoOrDie.config[:die]
    die.call(*[message, due_at, condition].take(die.arity.abs))
  elsif should_warn
    warn = TodoOrDie.config[:warn]
    warn.call(*[message, due_at, warn_at, condition].take(warn.arity.abs))
  end
end