Class: Saviour::ReadOnlyFile

Inherits:
Object
  • Object
show all
Defined in:
lib/saviour/read_only_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(persisted_path, storage) ⇒ ReadOnlyFile

Returns a new instance of ReadOnlyFile.



5
6
7
8
# File 'lib/saviour/read_only_file.rb', line 5

def initialize(persisted_path, storage)
  @persisted_path = persisted_path
  @storage = storage
end

Instance Attribute Details

#persisted_pathObject (readonly)

Returns the value of attribute persisted_path.



3
4
5
# File 'lib/saviour/read_only_file.rb', line 3

def persisted_path
  @persisted_path
end

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/saviour/read_only_file.rb', line 3

def storage
  @storage
end

Instance Method Details

#==(another_file) ⇒ Object



25
26
27
28
29
30
# File 'lib/saviour/read_only_file.rb', line 25

def ==(another_file)
  return false unless another_file.is_a?(Saviour::File) || another_file.is_a?(ReadOnlyFile)
  return false unless another_file.persisted?

  another_file.persisted_path == persisted_path
end

#exists?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/saviour/read_only_file.rb', line 10

def exists?
  persisted? && @storage.exists?(@persisted_path)
end

#persisted?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/saviour/read_only_file.rb', line 32

def persisted?
  true
end

#public_urlObject Also known as: url



19
20
21
22
# File 'lib/saviour/read_only_file.rb', line 19

def public_url
  return nil unless persisted?
  @storage.public_url(@persisted_path)
end

#readObject



14
15
16
17
# File 'lib/saviour/read_only_file.rb', line 14

def read
  return nil unless persisted?
  @storage.read(@persisted_path)
end