Module: Dragonfly::Utils
- Defined in:
- lib/dragonfly/utils.rb
Class Method Summary collapse
- .blank?(obj) ⇒ Boolean
- .new_tempfile(ext = nil, content = nil) ⇒ Object
- .stringify_keys(hash) ⇒ Object
- .symbolize_keys(hash) ⇒ Object
- .uri_escape_segment(string) ⇒ Object
- .uri_unescape(string) ⇒ Object
Class Method Details
.blank?(obj) ⇒ Boolean
10 11 12 |
# File 'lib/dragonfly/utils.rb', line 10 def blank?(obj) obj.respond_to?(:empty?) ? obj.empty? : !obj end |
.new_tempfile(ext = nil, content = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/dragonfly/utils.rb', line 14 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 |
.stringify_keys(hash) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/dragonfly/utils.rb', line 29 def stringify_keys(hash) hash.inject({}) do |new_hash, (key, value)| new_hash[key.to_s] = value new_hash end end |
.symbolize_keys(hash) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/dragonfly/utils.rb', line 22 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
36 37 38 |
# File 'lib/dragonfly/utils.rb', line 36 def uri_escape_segment(string) URI.encode_www_form_component(string).gsub('+','%20') end |
.uri_unescape(string) ⇒ Object
40 41 42 |
# File 'lib/dragonfly/utils.rb', line 40 def uri_unescape(string) URI::DEFAULT_PARSER.unescape(string) end |