Class: StaticSync::Uploadable
- Inherits:
-
Struct
- Object
- Struct
- StaticSync::Uploadable
- Defined in:
- lib/static_sync/uploadable.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #cache_time ⇒ Object
- #content ⇒ Object
- #content_encoding ⇒ Object
- #content_type ⇒ Object
- #etag ⇒ Object
- #gzipped? ⇒ Boolean
- #headers ⇒ Object
- #md5 ⇒ Object
- #mime ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config
10 11 12 |
# File 'lib/static_sync/uploadable.rb', line 10 def config @config end |
#path ⇒ Object
Returns the value of attribute path
10 11 12 |
# File 'lib/static_sync/uploadable.rb', line 10 def path @path end |
Instance Method Details
#cache_time ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/static_sync/uploadable.rb', line 36 def cache_time if mime type = mime.sub_type type = mime.media_type if mime.media_type == "image" if config.cache.has_key?(type) return config.cache[type].to_i end end end |
#content ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/static_sync/uploadable.rb', line 46 def content @content ||= begin result = File.open(path, 'rb') { |f| f.read } if gzipped? result = File.open(gzip(result), 'rb') { |f| f.read } end result rescue "" end end |
#content_encoding ⇒ Object
30 31 32 33 34 |
# File 'lib/static_sync/uploadable.rb', line 30 def content_encoding if gzipped? 'gzip' end end |
#content_type ⇒ Object
20 21 22 23 24 |
# File 'lib/static_sync/uploadable.rb', line 20 def content_type if mime MIME::Type.simplified(mime) end end |
#etag ⇒ Object
58 59 60 |
# File 'lib/static_sync/uploadable.rb', line 58 def etag @etag ||= Digest::MD5.hexdigest(content) end |
#gzipped? ⇒ Boolean
26 27 28 |
# File 'lib/static_sync/uploadable.rb', line 26 def gzipped? mime && mime.ascii? end |
#headers ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/static_sync/uploadable.rb', line 66 def headers base_headers = { :key => path, :body => content, :etag => etag, :content_md5 => md5, :storage_class => 'REDUCED_REDUNDANCY', :public => true } base_headers.merge!(:cache_control => "public, max-age=#{cache_time}") if cache_time base_headers.merge!(:content_type => content_type) if content_type base_headers.merge!(:content_encoding => content_encoding) if content_encoding base_headers.merge!(:expires => CGI.rfc1123_date(Time.now + cache_time)) if cache_time base_headers end |
#md5 ⇒ Object
62 63 64 |
# File 'lib/static_sync/uploadable.rb', line 62 def md5 @md5 ||= Digest::MD5.base64digest(content) end |
#mime ⇒ Object
16 17 18 |
# File 'lib/static_sync/uploadable.rb', line 16 def mime MIME::Types::of(path).first end |