Sha256: 76422aeae74cb0130e1792603f72cb97d9a2b084b69f7dc32deb4a4045d355c0

Contents?: true

Size: 906 Bytes

Versions: 7

Compression:

Stored size: 906 Bytes

Contents

require 'tempfile'
require 'uri'
require 'rack'

module Dragonfly
  module Utils

    module_function

    def blank?(obj)
      obj.respond_to?(:empty?) ? obj.empty? : !obj
    end

    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

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

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

    def uri_escape_segment(string)
      URI.encode_www_form_component(string).gsub('+','%20')
    end

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

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dragonfly-1.2.0 lib/dragonfly/utils.rb
dragonfly-1.1.5 lib/dragonfly/utils.rb
dragonfly-1.1.4 lib/dragonfly/utils.rb
dragonfly-1.1.3 lib/dragonfly/utils.rb
dragonfly-1.1.2 lib/dragonfly/utils.rb
dragonfly-1.1.1 lib/dragonfly/utils.rb
dragonfly-1.1.0 lib/dragonfly/utils.rb