Class: S3Dir::Uploader
- Inherits:
-
Object
- Object
- S3Dir::Uploader
- Defined in:
- lib/s3_dir.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#files_path ⇒ Object
readonly
Returns the value of attribute files_path.
-
#is_public ⇒ Object
readonly
Returns the value of attribute is_public.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
-
#initialize(dir, key, options) ⇒ Uploader
constructor
A new instance of Uploader.
- #upload ⇒ Object
Constructor Details
#initialize(dir, key, options) ⇒ Uploader
Returns a new instance of Uploader.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/s3_dir.rb', line 44 def initialize dir, key, @files_path = File.(dir) # Merge defaults with passed-in options settings = {credential: ENV['FOG_CREDENTIAL'], private: false}.merge() # Configure Fog Fog.credential = settings[:credential] # Get a region region = Fog.credentials[:region] || 'us-west-2' # If we don't specify this endpoint, Fog will complain about # not using the correct endpoint if the bucket has dots in # the name (i.e. website bucket) endpoint = 'http://s3.amazonaws.com' # This may be a public bucket @is_public = !settings[:private] # Set up our storage object # We have to specify path_style here because Fog will complain about # our website bucket (if we're using a bucket with dots in the name) # not being covered by the SSL certificate. = Fog.credentials.merge({provider: 'aws', path_style: true, region: region, endpoint: endpoint}) .delete(:key_name) @storage = Fog::Storage.new() @bucket = storage.directories.get(key) @bucket ||= storage.directories.create(key: key, public: is_public) @key = key end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
39 40 41 |
# File 'lib/s3_dir.rb', line 39 def bucket @bucket end |
#files_path ⇒ Object (readonly)
Returns the value of attribute files_path.
42 43 44 |
# File 'lib/s3_dir.rb', line 42 def files_path @files_path end |
#is_public ⇒ Object (readonly)
Returns the value of attribute is_public.
41 42 43 |
# File 'lib/s3_dir.rb', line 41 def is_public @is_public end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
38 39 40 |
# File 'lib/s3_dir.rb', line 38 def key @key end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
40 41 42 |
# File 'lib/s3_dir.rb', line 40 def storage @storage end |
Instance Method Details
#upload ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/s3_dir.rb', line 78 def upload Dir.chdir(files_path) do Dir['**/*'].each do |entry| File.directory?(entry) ? create_directory(entry) : create_file(entry) end end end |