Module: Dragonfly::Utils

Defined in:
lib/dragonfly/utils.rb

Class Method Summary collapse

Class Method Details

.new_tempfile(ext = nil, content = nil) ⇒ Object


9
10
11
12
13
14
15
# File 'lib/dragonfly/utils.rb', line 9

def new_tempfile(ext=nil, content=nil)
  tempfile = ext ? Tempfile.new(['dragonfly', ".#{ext}"]) : Tempfile.new('dragonfly')
  tempfile.binmode
  tempfile.write(content) if content
  tempfile.close
  tempfile
end

.symbolize_keys(hash) ⇒ Object


17
18
19
20
21
22
# File 'lib/dragonfly/utils.rb', line 17

def symbolize_keys(hash)
  hash.inject({}) do |new_hash, (key, value)|
    new_hash[key.to_sym] = value
    new_hash
  end
end

.uri_escape_segment(string) ⇒ Object


24
25
26
# File 'lib/dragonfly/utils.rb', line 24

def uri_escape_segment(string)
  Rack::Utils.escape_path(string)
end

.uri_unescape(string) ⇒ Object


28
29
30
# File 'lib/dragonfly/utils.rb', line 28

def uri_unescape(string)
  URI.unescape(string)
end