Module: Granite::Util
Instance Method Summary collapse
-
#conditions_satisfied?(**options) ⇒ Boolean
Evaluates ‘if` or `unless` conditions present in the supplied `options` being it a symbol or callable.
-
#evaluate(value) ⇒ Object
Evaluates value and returns result based on what was passed: - if Proc was passed, then executes it in context of self - if Symbol was passed, then calls a method with that name and returns result - otherwise just returns the value itself.
Instance Method Details
#conditions_satisfied?(**options) ⇒ Boolean
Evaluates ‘if` or `unless` conditions present in the supplied `options` being it a symbol or callable.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/granite/util.rb', line 29 def conditions_satisfied?(**) fail ArgumentError, 'You cannot specify both if and unless' if .key?(:if) && .key?(:unless) if .key?(:if) evaluate([:if]) elsif .key?(:unless) !evaluate([:unless]) else true end end |
#evaluate(value) ⇒ Object
Evaluates value and returns result based on what was passed:
-
if Proc was passed, then executes it in context of self
-
if Symbol was passed, then calls a method with that name and returns result
-
otherwise just returns the value itself
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/granite/util.rb', line 11 def evaluate(value) case value when Proc evaluate_proc(value) when Symbol evaluate_symbol(value) else value end end |