Module: RestMyCase::Helpers

Defined in:
lib/rest_my_case/helpers.rb

Class Method Summary collapse

Class Method Details

.blank?(object) ⇒ Boolean



13
14
15
16
17
18
19
# File 'lib/rest_my_case/helpers.rb', line 13

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



55
56
57
58
59
60
61
# File 'lib/rest_my_case/helpers.rb', line 55

def call_proc_or_method(base, proc_or_method, object = nil)
  if proc_or_method.is_a?(Proc)
    base.instance_exec(object, &proc_or_method)
  else
    base.send(proc_or_method, object)
  end
end

.except(hash, *keys) ⇒ Object



43
44
45
46
47
# File 'lib/rest_my_case/helpers.rb', line 43

def except(hash, *keys)
  hash = hash.dup
  keys.each { |key| hash.delete(key) }
  hash
end

.extract_options!(array) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/rest_my_case/helpers.rb', line 27

def extract_options!(array)
  if array.last.is_a?(Hash) && array.last.instance_of?(Hash)
    array.pop
  else
    {}
  end
end

.marked_for_destruction?(object) ⇒ Boolean



21
22
23
24
25
# File 'lib/rest_my_case/helpers.rb', line 21

def marked_for_destruction?(object)
  return false unless object.respond_to?(:marked_for_destruction?)

  object.marked_for_destruction?
end

.slice(hash, *keys) ⇒ Object



49
50
51
52
53
# File 'lib/rest_my_case/helpers.rb', line 49

def slice(hash, *keys)
  keys.each_with_object({}) do |key, sliced_hash|
    sliced_hash[key] = hash[key]
  end
end

.super_method(object, method_name, *args) ⇒ Object



7
8
9
10
11
# File 'lib/rest_my_case/helpers.rb', line 7

def super_method(object, method_name, *args)
  return nil unless object.superclass.respond_to? method_name

  object.superclass.send method_name, *args
end

.symbolyze_keys(hash) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/rest_my_case/helpers.rb', line 35

def symbolyze_keys(hash)
  {}.tap do |symbolyzed_hash|
    hash.each do |key, value|
      symbolyzed_hash[key.to_sym] = value
    end
  end
end