Module: Writefully::Storage
- Defined in:
- lib/writefully/storage.rb
Class Method Summary collapse
- .connection ⇒ Object
- .directory ⇒ Object
- .endpoint ⇒ Object
- .provider_endpoints ⇒ Object
- .remove_file(key) ⇒ Object
- .store_file(path, body) ⇒ Object
Class Method Details
.connection ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/writefully/storage.rb', line 28 def connection @connection ||= Fog::Storage.new({ provider: Writefully.[:storage_provider], aws_access_key_id: Writefully.[:storage_key], aws_secret_access_key: Writefully.[:storage_secret], region: Writefully.[:storage_region] }) end |
.directory ⇒ Object
4 5 6 |
# File 'lib/writefully/storage.rb', line 4 def directory @directory ||= connection.directories.get(Writefully.[:storage_folder]) end |
.endpoint ⇒ Object
20 21 22 |
# File 'lib/writefully/storage.rb', line 20 def endpoint Writefully.[:assets_host] || provider_endpoints[Writefully.[:storage_provider].downcase.to_sym] end |
.provider_endpoints ⇒ Object
24 25 26 |
# File 'lib/writefully/storage.rb', line 24 def provider_endpoints { aws: "https://#{Writefully.[:storage_folder]}.s3.amazonaws.com"} end |
.remove_file(key) ⇒ Object
16 17 18 |
# File 'lib/writefully/storage.rb', line 16 def remove_file(key) directory.files.get(key).destroy end |
.store_file(path, body) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/writefully/storage.rb', line 8 def store_file(path, body) directory.files.create({ key: path, body: body, public: true }) end |