Module: Writefully::Storage

Defined in:
lib/writefully/storage.rb

Class Method Summary collapse

Class Method Details

.connectionObject



28
29
30
31
32
33
34
35
# File 'lib/writefully/storage.rb', line 28

def connection
  @connection ||= Fog::Storage.new({
    provider:              Writefully.options[:storage_provider],
    aws_access_key_id:     Writefully.options[:storage_key],
    aws_secret_access_key: Writefully.options[:storage_secret],
    region:                Writefully.options[:storage_region]
  })
end

.directoryObject



4
5
6
# File 'lib/writefully/storage.rb', line 4

def directory
  @directory ||= connection.directories.get(Writefully.options[:storage_folder])
end

.endpointObject



20
21
22
# File 'lib/writefully/storage.rb', line 20

def endpoint
  Writefully.options[:assets_host] || provider_endpoints[Writefully.options[:storage_provider].downcase.to_sym]
end

.provider_endpointsObject



24
25
26
# File 'lib/writefully/storage.rb', line 24

def provider_endpoints
  { aws: "https://#{Writefully.options[: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