Class: Wlog::LogEntry
- Inherits:
-
Object
- Object
- Wlog::LogEntry
- Includes:
- LogEntrySql
- Defined in:
- lib/wlog/domain/log_entry.rb
Overview
Active Record Domain object for a log entry
Constant Summary
Constants included from LogEntrySql
Wlog::LogEntrySql::DeleteSql, Wlog::LogEntrySql::InsertSql, Wlog::LogEntrySql::Select, Wlog::LogEntrySql::SelectAll, Wlog::LogEntrySql::SelectAllByIssue, Wlog::LogEntrySql::SelectAllLimit, Wlog::LogEntrySql::SelectDescriptionLike, Wlog::LogEntrySql::TableName, Wlog::LogEntrySql::UpdateSql
Instance Attribute Summary collapse
-
#date ⇒ Object
Date the entry was created.
-
#db ⇒ Object
The db handle.
-
#description ⇒ Object
Text description for the log entry.
-
#id ⇒ Object
The identity field for the log entry DO.
-
#issue_id ⇒ Object
The issue id (parent of this log entry).
Class Method Summary collapse
-
.delete_by_id(db, id) ⇒ Object
Delete a log entry with a given id.
- .find(db, id) ⇒ Object
- .find_all(db) ⇒ Object
- .find_all_by_issue_id(db, id) ⇒ Object
-
.search_descriptions(db, term) ⇒ Object
Search by string to find a matching description with ‘LIKE’.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete the loaded log entry currently in memory, by passing its id.
-
#initialize(db_handle) ⇒ LogEntry
constructor
A new instance of LogEntry.
- #insert ⇒ Object
- #quick_assign!(id, desc, date, issue_id) ⇒ Object
-
#to_s ⇒ Object
Print things nicely formmated no more than 80 cars (well, unless you stick the time in the end which is not counted for).
-
#update ⇒ Object
update the entry.
Constructor Details
#initialize(db_handle) ⇒ LogEntry
Returns a new instance of LogEntry.
12 13 14 15 |
# File 'lib/wlog/domain/log_entry.rb', line 12 def initialize(db_handle) @date = Time.new @db = db_handle end |
Instance Attribute Details
#date ⇒ Object
Date the entry was created
95 96 97 |
# File 'lib/wlog/domain/log_entry.rb', line 95 def date @date end |
#db ⇒ Object
The db handle
101 102 103 |
# File 'lib/wlog/domain/log_entry.rb', line 101 def db @db end |
#description ⇒ Object
Text description for the log entry
92 93 94 |
# File 'lib/wlog/domain/log_entry.rb', line 92 def description @description end |
#id ⇒ Object
The identity field for the log entry DO
89 90 91 |
# File 'lib/wlog/domain/log_entry.rb', line 89 def id @id end |
#issue_id ⇒ Object
The issue id (parent of this log entry)
98 99 100 |
# File 'lib/wlog/domain/log_entry.rb', line 98 def issue_id @issue_id end |
Class Method Details
.delete_by_id(db, id) ⇒ Object
Delete a log entry with a given id.
38 39 40 |
# File 'lib/wlog/domain/log_entry.rb', line 38 def self.delete_by_id(db, id) db.execute(DeleteSql,id) end |
.find(db, id) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/wlog/domain/log_entry.rb', line 17 def self.find(db, id) row = db.execute(Select,id).first le = nil if row && !row.empty? le = LogEntry.new(db) le.quick_assign!(row[0], row[1], Time.at(row[2]), row[3]) end le end |
.find_all(db) ⇒ Object
26 27 28 |
# File 'lib/wlog/domain/log_entry.rb', line 26 def self.find_all(db) self.generic_find_all(db, SelectAll) end |
.find_all_by_issue_id(db, id) ⇒ Object
30 31 32 |
# File 'lib/wlog/domain/log_entry.rb', line 30 def self.find_all_by_issue_id(db, id) self.generic_find_all(db, SelectAllByIssue, id) end |
.search_descriptions(db, term) ⇒ Object
Search by string to find a matching description with ‘LIKE’.
48 49 50 51 52 53 54 55 |
# File 'lib/wlog/domain/log_entry.rb', line 48 def self.search_descriptions(db, term) all = Array.new db.execute(SelectDescriptionLike,"%#{term}%").each do |row| le = LogEntry.new le.quick_assign!(row[0], row[1], Time.at(row[2])) all.push le end all end |
Instance Method Details
#delete ⇒ Object
Delete the loaded log entry currently in memory, by passing its id
66 67 68 69 70 71 |
# File 'lib/wlog/domain/log_entry.rb', line 66 def delete if @id LogEntry.delete_by_id(@db, @id) @id = nil end end |
#insert ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/wlog/domain/log_entry.rb', line 57 def insert raise 'Need issue_id' unless @issue_id unless @id @db.execute(InsertSql, @description, @date.to_i, @issue_id) @id = @db.last_row_from(TableName).first[0].to_i end end |
#quick_assign!(id, desc, date, issue_id) ⇒ Object
73 74 75 |
# File 'lib/wlog/domain/log_entry.rb', line 73 def quick_assign!(id,desc,date,issue_id) @id, @description, @date, @issue_id = id, desc, date, issue_id end |
#to_s ⇒ Object
Print things nicely formmated no more than 80 cars (well, unless you stick the time in the end which is not counted for).
79 80 81 82 83 84 85 86 |
# File 'lib/wlog/domain/log_entry.rb', line 79 def to_s str = "[#{@id}] " tmp = "#{@description} [#{@date.strftime("%H:%M:%S")}]" desc = Helpers.break_string(tmp,80) indent = " " * (id.to_s.split('').count + 5) desc.gsub!(/#{$/}/, "#{$/}#{indent}") str.concat(desc) str end |
#update ⇒ Object
update the entry
43 44 45 |
# File 'lib/wlog/domain/log_entry.rb', line 43 def update @db.execute(UpdateSql,@description,@id) end |