Module: BraintreeLyre::Helpers

Included in:
Lyre, TransparentRedirect
Defined in:
lib/braintree_lyre/helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelize(str) ⇒ Object



22
23
24
25
26
# File 'lib/braintree_lyre/helpers.rb', line 22

def camelize(str)
  segments = str.split('_')

  segments.inject("") { |acc, s| acc << s.capitalize }
end

#constantize(camel_cased_word) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/braintree_lyre/helpers.rb', line 28

def constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end

#gzip(content) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/braintree_lyre/helpers.rb', line 6

def gzip(content)
  StringIO.new.tap do |io|
    gz = Zlib::GzipWriter.new(io)
  
    begin
      gz.write(content)
    ensure
      gz.close
    end
  end.string
end

#gzipped_response(status_code, uncompressed_content) ⇒ Object



18
19
20
# File 'lib/braintree_lyre/helpers.rb', line 18

def gzipped_response(status_code, uncompressed_content)
  [status_code, { "Content-Encoding" => "gzip" }, gzip(uncompressed_content)]
end