Class: Turntables::VersionHistory
- Inherits:
-
Object
- Object
- Turntables::VersionHistory
- Includes:
- VersionHistorySql
- Defined in:
- lib/turntables/version_history.rb
Overview
lightweight and small (therefore not too many components are needed yet).
Constant Summary
Constants included from VersionHistorySql
Turntables::VersionHistorySql::Create, Turntables::VersionHistorySql::Insert, Turntables::VersionHistorySql::SelectAll, Turntables::VersionHistorySql::SelectById, Turntables::VersionHistorySql::SelectLast, Turntables::VersionHistorySql::TableName
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#date ⇒ Object
Returns the value of attribute date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.check ⇒ Object
Check if the required database exists.
-
.find(id) ⇒ Object
Find a version history record by id.
-
.find_all ⇒ Object
Get all the stored version histories.
-
.find_last ⇒ Object
Find the last version history added by checking the max id.
-
.insert(vhistory) ⇒ Object
Insert a row into the table for version histories.
-
.pull_up! ⇒ Object
Create the table of this model.
-
.to_version_history(record) ⇒ Object
Make an array representing the persisted object, into an object in memory.
Instance Method Summary collapse
-
#initialize(version, comment, date = Time.now.to_i) ⇒ VersionHistory
constructor
Create the version history object by giving version number and comment.
Constructor Details
#initialize(version, comment, date = Time.now.to_i) ⇒ VersionHistory
Create the version history object by giving version number and comment. The date can be omitted, and it will be set to the current time of the local system.
22 23 24 25 26 |
# File 'lib/turntables/version_history.rb', line 22 def initialize(version,comment,date=Time.now.to_i) @version = version @comment = comment @date = date end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
86 87 88 |
# File 'lib/turntables/version_history.rb', line 86 def comment @comment end |
#date ⇒ Object
Returns the value of attribute date.
85 86 87 |
# File 'lib/turntables/version_history.rb', line 85 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
83 84 85 |
# File 'lib/turntables/version_history.rb', line 83 def id @id end |
#version ⇒ Object
Returns the value of attribute version.
84 85 86 |
# File 'lib/turntables/version_history.rb', line 84 def version @version end |
Class Method Details
.check ⇒ Object
Check if the required database exists. Check to see if the database has the version_histories table as well.
30 31 32 33 34 35 36 |
# File 'lib/turntables/version_history.rb', line 30 def self.check if DbRegistry.instance.table_exists? TableName return VersionHistory.find_last else # db does not exist return :fresh end end |
.find(id) ⇒ Object
Find a version history record by id
56 57 58 59 |
# File 'lib/turntables/version_history.rb', line 56 def self.find(id) ret = DbRegistry.instance.execute(SelectById, id) VersionHistory.to_version_history(ret.first) end |
.find_all ⇒ Object
Get all the stored version histories
39 40 41 42 43 44 45 |
# File 'lib/turntables/version_history.rb', line 39 def self.find_all vhs = Array.new DbRegistry.instance.execute(SelectAll).each do |row| vhs.push VersionHistory.to_version_history(row) end vhs end |
.find_last ⇒ Object
Find the last version history added by checking the max id
49 50 51 52 |
# File 'lib/turntables/version_history.rb', line 49 def self.find_last ret = DbRegistry.instance.execute(SelectLast) VersionHistory.to_version_history(ret.first) end |
.insert(vhistory) ⇒ Object
Insert a row into the table for version histories
63 64 65 66 |
# File 'lib/turntables/version_history.rb', line 63 def self.insert(vhistory) DbRegistry.instance.execute(Insert, vhistory.version, vhistory.date, vhistory.comment) end |
.pull_up! ⇒ Object
Create the table of this model
70 71 72 |
# File 'lib/turntables/version_history.rb', line 70 def self.pull_up! DbRegistry.instance.execute(Create) end |
.to_version_history(record) ⇒ Object
Make an array representing the persisted object, into an object in memory
77 78 79 80 81 |
# File 'lib/turntables/version_history.rb', line 77 def self.to_version_history(record) vh = VersionHistory.new(record[1], record[2], record[3]) vh.id = record[0] vh end |