Class: Vcs4sql::Changelog

Inherits:
Object
  • Object
show all
Defined in:
lib/vcs4sql/changelog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, applied, version, md5sum, sql, id: 0) ⇒ Changelog

Returns a new instance of Changelog.



30
31
32
33
34
35
36
37
# File 'lib/vcs4sql/changelog.rb', line 30

def initialize(file, applied, version, md5sum, sql, id: 0)
  @file = file
  @applied = applied
  @version = version
  @md5sum = md5sum
  @sql = sql
  @id = id
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



28
29
30
# File 'lib/vcs4sql/changelog.rb', line 28

def file
  @file
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/vcs4sql/changelog.rb', line 28

def id
  @id
end

#md5sumObject (readonly)

Returns the value of attribute md5sum.



28
29
30
# File 'lib/vcs4sql/changelog.rb', line 28

def md5sum
  @md5sum
end

#sqlObject (readonly)

Returns the value of attribute sql.



28
29
30
# File 'lib/vcs4sql/changelog.rb', line 28

def sql
  @sql
end

#versionObject (readonly)

Returns the value of attribute version.



28
29
30
# File 'lib/vcs4sql/changelog.rb', line 28

def version
  @version
end

Instance Method Details

#apply(conn) ⇒ Object

TODO:

#/DEV Raise the exception in case if

  • this.* are empty or null

  • conn is empty or null



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vcs4sql/changelog.rb', line 42

def apply(conn)
  # @todo #/DEV Wrap the sql's execution to separate blocks which will:
  #  - catch the error
  #  - provide the detailed description
  #  - populate the error code
  conn.execute_batch @sql
  conn.execute "insert /* ll.sqlid:#{__FILE__}:#{__method__} */
                into changelog(file,version,md5sum,applied,sql)
                values(?,?,?,?,?)",
               @file, @version, @md5sum, @applied, @sql
end

#matches(exist) ⇒ Object



58
59
60
# File 'lib/vcs4sql/changelog.rb', line 58

def matches(exist)
  @md5sum == exist.md5sum
end

#to_sObject



54
55
56
# File 'lib/vcs4sql/changelog.rb', line 54

def to_s
  "#{@version}: #{@file} #{@md5sum}"
end