Module: Paggio::Utils

Defined in:
lib/paggio/utils.rb

Class Method Summary collapse

Class Method Details

.deep_merge(a, b) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/paggio/utils.rb', line 20

def self.deep_merge(a, b)
  merger = proc {|key, v1, v2|
    if Hash === v1 && Hash === v2
      v1.merge(v2, &merger)
    else
      v2
    end
  }

  a.merge(b, &merger)
end

.deep_merge!(a, b) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/paggio/utils.rb', line 32

def self.deep_merge!(a, b)
  merger = proc {|key, v1, v2|
    if Hash === v1 && Hash === v2
      v1.merge!(v2, &merger)
      v1
    else
      v2
    end
  }

  a.merge!(b, &merger)
end

.heredoc(string) ⇒ Object



14
15
16
17
18
# File 'lib/paggio/utils.rb', line 14

def self.heredoc(string)
  indent = string.scan(/^[ \t]*(?=\S)/).min.size rescue 0

  string.gsub(/^[ \t]{#{indent}}/, '')
end