Sha256: cb0f1c70b3b28fed03831fbcf2e05e48afc2834ddf3bc50519e337f8e766feed

Contents?: true

Size: 884 Bytes

Versions: 13

Compression:

Stored size: 884 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)
      Rack::Utils.escape_path(string)
    end

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

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dragonfly-1.0.12 lib/dragonfly/utils.rb
dragonfly-1.0.11 lib/dragonfly/utils.rb
dragonfly-1.0.10 lib/dragonfly/utils.rb
dragonfly-1.0.9 lib/dragonfly/utils.rb
dragonfly-1.0.8 lib/dragonfly/utils.rb
dragonfly-1.0.7 lib/dragonfly/utils.rb
dragonfly-1.0.6 lib/dragonfly/utils.rb
dragonfly-1.0.5 lib/dragonfly/utils.rb
dragonfly-1.0.4 lib/dragonfly/utils.rb
dragonfly-1.0.3 lib/dragonfly/utils.rb
dragonfly-1.0.2 lib/dragonfly/utils.rb
dragonfly-1.0.1 lib/dragonfly/utils.rb
dragonfly-1.0 lib/dragonfly/utils.rb