Class: Mosaico::LocalBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaico/local_backend.rb

Direct Known Subclasses

LocalImageBackend, LocalPlaceholderBackend

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path, base_url) ⇒ LocalBackend

Returns a new instance of LocalBackend.



5
6
7
8
# File 'lib/mosaico/local_backend.rb', line 5

def initialize(base_path, base_url)
  @base_path = base_path
  @base_url = base_url
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



3
4
5
# File 'lib/mosaico/local_backend.rb', line 3

def base_path
  @base_path
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



3
4
5
# File 'lib/mosaico/local_backend.rb', line 3

def base_url
  @base_url
end

Instance Method Details

#retrieve(filename) ⇒ Object



15
16
17
# File 'lib/mosaico/local_backend.rb', line 15

def retrieve(filename)
  File.join(base_path, filename)
end

#store(source, as:) ⇒ Object



10
11
12
13
# File 'lib/mosaico/local_backend.rb', line 10

def store(source, as:)
  FileUtils.mkdir_p(base_path)
  FileUtils.cp(source, File.join(base_path, as))
end

#url_to(filename) ⇒ Object



19
20
21
# File 'lib/mosaico/local_backend.rb', line 19

def url_to(filename)
  Mosaico.url_join(base_url, filename)
end