Module: Granite::Form::Util
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/granite/form/util.rb
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, *args) ⇒ 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.
-
#evaluate_if_proc(value, *args) ⇒ Object
Evaluates value and returns result based on what was passed: - if Proc was passed, then executes it in context of self - 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.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/granite/form/util.rb', line 32 def conditions_satisfied?(**) raise 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, *args) ⇒ 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
12 13 14 |
# File 'lib/granite/form/util.rb', line 12 def evaluate(value, *args) value.is_a?(Symbol) ? evaluate_symbol(value, *args) : evaluate_if_proc(value, *args) end |
#evaluate_if_proc(value, *args) ⇒ Object
Evaluates value and returns result based on what was passed:
-
if Proc was passed, then executes it in context of self
-
otherwise just returns the value itself
21 22 23 |
# File 'lib/granite/form/util.rb', line 21 def evaluate_if_proc(value, *args) value.is_a?(Proc) ? evaluate_proc(value, *args) : value end |