Module: UseCaseValidations::Helpers
Instance Method Summary collapse
- #_blank?(object) ⇒ Boolean
- #_call_proc_or_method(base, proc_or_method, object = nil) ⇒ Object
- #_duplicate(object) ⇒ Object
- #_except(hash, *keys) ⇒ Object
- #_extract_options!(array) ⇒ Object
- #_get_instance_variable(object, variable, default_value) ⇒ Object
- #_marked_for_destruction?(object) ⇒ Boolean
- #_slice(hash, *keys) ⇒ Object
- #_super_method(object, method_name, *args) ⇒ Object
- #_symbolyze_keys(hash) ⇒ Object
Instance Method Details
#_blank?(object) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/usecasing_validations/helpers.rb', line 31 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
70 71 72 73 74 75 76 |
# File 'lib/usecasing_validations/helpers.rb', line 70 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 |
#_duplicate(object) ⇒ Object
27 28 29 |
# File 'lib/usecasing_validations/helpers.rb', line 27 def _duplicate(object) object.dup rescue object end |
#_except(hash, *keys) ⇒ Object
58 59 60 61 62 |
# File 'lib/usecasing_validations/helpers.rb', line 58 def _except(hash, *keys) _hash = hash.dup keys.each { |key| _hash.delete(key) } _hash end |
#_extract_options!(array) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/usecasing_validations/helpers.rb', line 43 def (array) if array.last.is_a?(Hash) && array.last.instance_of?(Hash) array.pop else {} end end |
#_get_instance_variable(object, variable, default_value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/usecasing_validations/helpers.rb', line 13 def _get_instance_variable(object, variable, default_value) instance_var = object.instance_variable_get("@#{variable}") return instance_var unless instance_var.nil? instance_var = (_super_method(object, variable) || default_value) if instance_var.class == Class object.instance_variable_set("@#{variable}", instance_var) else object.instance_variable_set("@#{variable}", _duplicate(instance_var)) end end |
#_marked_for_destruction?(object) ⇒ Boolean
39 40 41 |
# File 'lib/usecasing_validations/helpers.rb', line 39 def _marked_for_destruction?(object) object.respond_to?(:marked_for_destruction?) ? object.marked_for_destruction? : false end |
#_slice(hash, *keys) ⇒ Object
64 65 66 67 68 |
# File 'lib/usecasing_validations/helpers.rb', line 64 def _slice(hash, *keys) _hash = {} keys.each { |key| _hash[key] = hash[key] } _hash end |
#_super_method(object, method_name, *args) ⇒ Object
7 8 9 10 11 |
# File 'lib/usecasing_validations/helpers.rb', line 7 def _super_method(object, method_name, *args) if object.superclass.respond_to?(method_name) object.superclass.send(method_name, *args) end end |
#_symbolyze_keys(hash) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/usecasing_validations/helpers.rb', line 51 def _symbolyze_keys(hash) hash.keys.reduce({ }) do |acc, key| acc[key.to_sym] = hash[key] acc end end |