Module: RestMyCase::Helpers

Defined in:
lib/rest_my_case/helpers.rb

Class Method Summary collapse

Class Method Details

.blank?(object) ⇒ Boolean

Returns:

  • (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



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

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



41
42
43
44
45
# File 'lib/rest_my_case/helpers.rb', line 41

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

Returns:

  • (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



47
48
49
50
51
# File 'lib/rest_my_case/helpers.rb', line 47

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
# File 'lib/rest_my_case/helpers.rb', line 35

def symbolyze_keys(hash)
  hash.keys.each_with_object({}) do |key, symbolyzed_hash|
    symbolyzed_hash[key.to_sym] = hash[key]
  end
end