Class: S3Website::Upload
- Inherits:
-
Object
- Object
- S3Website::Upload
- Defined in:
- lib/s3_website/upload.rb
Constant Summary collapse
- BLACKLISTED_FILES =
['s3_website.yml']
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#full_path ⇒ Object
readonly
Returns the value of attribute full_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#s3 ⇒ Object
readonly
Returns the value of attribute s3.
Class Method Summary collapse
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(path, s3, config, site_dir) ⇒ Upload
constructor
A new instance of Upload.
- #perform! ⇒ Object
Constructor Details
#initialize(path, s3, config, site_dir) ⇒ Upload
Returns a new instance of Upload.
9 10 11 12 13 14 15 16 |
# File 'lib/s3_website/upload.rb', line 9 def initialize(path, s3, config, site_dir) raise "May not upload #{path}, because it's blacklisted" if Upload.is_blacklisted path @path = path @full_path = "#{site_dir}/#{path}" @file = File.open("#{site_dir}/#{path}") @s3 = s3 @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/s3_website/upload.rb', line 6 def config @config end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/s3_website/upload.rb', line 6 def file @file end |
#full_path ⇒ Object (readonly)
Returns the value of attribute full_path.
6 7 8 |
# File 'lib/s3_website/upload.rb', line 6 def full_path @full_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/s3_website/upload.rb', line 6 def path @path end |
#s3 ⇒ Object (readonly)
Returns the value of attribute s3.
6 7 8 |
# File 'lib/s3_website/upload.rb', line 6 def s3 @s3 end |
Class Method Details
.is_blacklisted(path) ⇒ Object
28 29 30 31 32 |
# File 'lib/s3_website/upload.rb', line 28 def self.is_blacklisted(path) BLACKLISTED_FILES.any? do |blacklisted_file| path.include? blacklisted_file end end |
Instance Method Details
#details ⇒ Object
24 25 26 |
# File 'lib/s3_website/upload.rb', line 24 def details "#{path}#{" [gzipped]" if gzip?}#{" [max-age=#{max_age}]" if cache_control?}" end |
#perform! ⇒ Object
18 19 20 21 22 |
# File 'lib/s3_website/upload.rb', line 18 def perform! success = s3.buckets[config['s3_bucket']].objects[path].write(upload_file, ) upload_file.close success end |