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.



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

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



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

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

.find(filename) ⇒ Object



14
15
16
17
18
19
# File 'app/models/peephole/logfile.rb', line 14

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

Instance Method Details

#bytes(page) ⇒ Object



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

def bytes(page)
  Logline.bytes(path, page)
end

#lines(page) ⇒ Object



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

def lines(page)
  Logline.lines(path, page)
end

#sizeObject



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

def size
  (File.size(path) / 1024.0).ceil
end

#to_paramObject



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

def to_param
  filename
end

#updated_atObject



48
49
50
# File 'app/models/peephole/logfile.rb', line 48

def updated_at
  File.mtime(path)
end