Class: Peephole::Logfile

Inherits:
Object
  • Object
show all
Defined in:
app/models/peephole/logfile.rb

Constant Summary collapse

LOG_PATH =
Rails.root.join('log')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Logfile

Returns a new instance of Logfile.



26
27
28
29
# File 'app/models/peephole/logfile.rb', line 26

def initialize(path)
  self.path = path
  self.filename = File.basename(path)
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



3
4
5
# File 'app/models/peephole/logfile.rb', line 3

def filename
  @filename
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'app/models/peephole/logfile.rb', line 3

def path
  @path
end

Class Method Details

.allObject



12
13
14
15
16
# File 'app/models/peephole/logfile.rb', line 12

def all
  glob.map do |path|
    Logfile.new(path)
  end
end

.find(filename) ⇒ Object



18
19
20
21
22
23
# File 'app/models/peephole/logfile.rb', line 18

def find(filename)
  path = glob.find do |path|
    File.basename(path) == filename
  end
  Logfile.new(path)
end

.globObject



8
9
10
# File 'app/models/peephole/logfile.rb', line 8

def glob
  Dir.glob(LOG_PATH.join("#{Rails.env}.log*"))
end

Instance Method Details

#loglines(page) ⇒ Object



35
36
37
# File 'app/models/peephole/logfile.rb', line 35

def loglines(page)
  Logline.where(path, page)
end

#sizeObject



39
40
41
# File 'app/models/peephole/logfile.rb', line 39

def size
  File.size(path) / 1024
end

#to_paramObject



31
32
33
# File 'app/models/peephole/logfile.rb', line 31

def to_param
  filename
end

#updated_atObject



43
44
45
# File 'app/models/peephole/logfile.rb', line 43

def updated_at
  File.mtime(path)
end