Class: Plog::LogFile
- Inherits:
-
File
- Object
- File
- Plog::LogFile
- Defined in:
- lib/log_file.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #check_dump_dir_consistency! ⇒ Object
-
#initialize(file, dump_dir) ⇒ LogFile
constructor
A new instance of LogFile.
- #object_path ⇒ Object
- #objects_recipient_path ⇒ Object
- #parse_completed_line ⇒ Object
- #parse_completed_lines! ⇒ Object
- #validate(file) ⇒ Object
Constructor Details
#initialize(file, dump_dir) ⇒ LogFile
Returns a new instance of LogFile.
7 8 9 10 11 12 |
# File 'lib/log_file.rb', line 7 def initialize(file, dump_dir) @dump_dir = dump_dir check_dump_dir_consistency! super(file, 'r') @name = file end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/log_file.rb', line 5 def name @name end |
Instance Method Details
#check_dump_dir_consistency! ⇒ Object
14 15 16 17 18 |
# File 'lib/log_file.rb', line 14 def check_dump_dir_consistency! unless File.exist? objects_recipient_path FileUtils.mkdir_p objects_recipient_path end end |
#object_path ⇒ Object
42 43 44 |
# File 'lib/log_file.rb', line 42 def object_path File.join(objects_recipient_path, CompletedLine.url.hashify) end |
#objects_recipient_path ⇒ Object
46 47 48 |
# File 'lib/log_file.rb', line 46 def objects_recipient_path @objects_recipient_path ||= File.join(@dump_dir, 'objects') end |
#parse_completed_line ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/log_file.rb', line 31 def parse_completed_line of = ObjectFile.new(object_path, 'w+') of.simplified_url = CompletedLine.url.simplify of.append_total_time CompletedLine.total_time of.append_db_time CompletedLine.db_time of.append_view_time CompletedLine.view_time of.append_hits 1 of.save_changes! of.close end |
#parse_completed_lines! ⇒ Object
24 25 26 27 28 29 |
# File 'lib/log_file.rb', line 24 def parse_completed_lines! each_line do |line| CompletedLine.read! line parse_completed_line if CompletedLine.valid? end end |
#validate(file) ⇒ Object
20 21 22 |
# File 'lib/log_file.rb', line 20 def validate(file) abort 'File not found: ' + file.inspect unless File.exist? file end |