Module: MethodCachable::Helper

Included in:
MethodCachable
Defined in:
lib/method_cachable/helper.rb

Instance Method Summary collapse

Instance Method Details

#createsig(body) ⇒ Object



4
5
6
# File 'lib/method_cachable/helper.rb', line 4

def createsig(body)
  Digest::MD5.hexdigest( sigflat body )
end

#sigflat(body) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/method_cachable/helper.rb', line 8

def sigflat(body)
  res = nil
  if body.class == Hash
    arr = []
    body.each do |key, value|
      arr << "#{sigflat key}=>#{sigflat value}"
    end
    res = arr
  end
  if body.class == Array
    str = ''
    res = body.map do |value|
      sigflat value
    end.sort!.each do |value|
      str << value
    end
  end
  if body.class != String
    res = body.to_s << body.class.to_s
  end
  res || body
end