Class: Burp::FileModel

Inherits:
Object
  • Object
show all
Defined in:
app/models/burp/file_model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_path) ⇒ FileModel

Returns a new instance of FileModel.



6
7
8
# File 'app/models/burp/file_model.rb', line 6

def initialize(public_path)
  self.public_path = public_path
end

Instance Attribute Details

#public_pathObject

Returns the value of attribute public_path.



4
5
6
# File 'app/models/burp/file_model.rb', line 4

def public_path
  @public_path
end

Class Method Details

.allObject



10
11
12
13
14
# File 'app/models/burp/file_model.rb', line 10

def self.all
  @file_paths = Dir.glob("#{Burp.content_directory}uploads/*").select{|path| File.file?(path) }
  @file_paths = @file_paths.map {|path| path.gsub("#{Burp.content_directory}uploads/","/burp/files/") }
  @file_paths.map {|path| FileModel.new(path)}.sort.reverse
end

Instance Method Details

#<=>(other) ⇒ Object



32
33
34
# File 'app/models/burp/file_model.rb', line 32

def <=>(other)
  other.is_a?(FileModel) ? self.mtime <=> other.mtime : 0
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/burp/file_model.rb', line 36

def eql?(other)
  self.class == other.class && self.hash == other.hash
end

#hashObject



40
41
42
# File 'app/models/burp/file_model.rb', line 40

def hash
  public_path.hash
end

#mtimeObject



24
25
26
# File 'app/models/burp/file_model.rb', line 24

def mtime
  @mtime_cache ||= File.mtime(on_disk_path)
end

#on_disk_pathObject



20
21
22
# File 'app/models/burp/file_model.rb', line 20

def on_disk_path
  public_path.gsub("/burp/files/","#{Burp.content_directory}uploads/")
end

#sizeObject



28
29
30
# File 'app/models/burp/file_model.rb', line 28

def size
  @size_cache ||= File.size(on_disk_path)
end

#to_paramObject



16
17
18
# File 'app/models/burp/file_model.rb', line 16

def to_param
  public_path
end