Module: UseCaseValidations::Helpers
Instance Method Summary collapse
- #_blank?(object) ⇒ Boolean
- #_call_proc_or_method(base, proc_or_method, object = nil) ⇒ Object
- #_except(hash, *keys) ⇒ Object
- #_extract_options!(array) ⇒ Object
- #_marked_for_destruction?(object) ⇒ Boolean
- #_symbolyze_keys(hash) ⇒ Object
Instance Method Details
#_blank?(object) ⇒ Boolean
7 8 9 10 11 12 13 |
# File 'lib/usecasing_validations/helpers.rb', line 7 def _blank?(object) if object.is_a?(String) object !~ /[^[:space:]]/ else object.respond_to?(:empty?) ? object.empty? : !object end end |
#_call_proc_or_method(base, proc_or_method, object = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/usecasing_validations/helpers.rb', line 40 def _call_proc_or_method(base, proc_or_method, object = nil) if object.nil? proc_or_method.is_a?(Proc) ? base.instance_exec(&proc_or_method) : base.send(proc_or_method) else proc_or_method.is_a?(Proc) ? base.instance_exec(object, &proc_or_method) : base.send(proc_or_method, object) end end |
#_except(hash, *keys) ⇒ Object
34 35 36 37 38 |
# File 'lib/usecasing_validations/helpers.rb', line 34 def _except(hash, *keys) _hash = hash.dup keys.each { |key| _hash.delete(key) } _hash end |
#_extract_options!(array) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/usecasing_validations/helpers.rb', line 19 def (array) if array.last.is_a?(Hash) && array.last.instance_of?(Hash) array.pop else {} end end |
#_marked_for_destruction?(object) ⇒ Boolean
15 16 17 |
# File 'lib/usecasing_validations/helpers.rb', line 15 def _marked_for_destruction?(object) object.respond_to?(:marked_for_destruction?) ? object.marked_for_destruction? : false end |
#_symbolyze_keys(hash) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/usecasing_validations/helpers.rb', line 27 def _symbolyze_keys(hash) hash.keys.reduce({ }) do |acc, key| acc[key.to_sym] = hash[key] acc end end |