Sha256: 475c8bd417819bddda48a77b2e847b23f81897e9e2c3ee7e5adadefd59961452

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 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::DEFAULT_PARSER.unescape(string)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dragonfly-1.4.1 lib/dragonfly/utils.rb
dragonfly-1.4.0 lib/dragonfly/utils.rb
dragonfly-1.3.0 lib/dragonfly/utils.rb
dragonfly-1.2.1 lib/dragonfly/utils.rb