Class: Prick::SchemaVersion

Inherits:
PrickFile show all
Defined in:
lib/prick/state.rb

Instance Attribute Summary

Attributes inherited from PrickFile

#path

Instance Method Summary collapse

Methods inherited from PrickFile

#exist?

Constructor Details

#initialize(schema = SCHEMAS_DIR) ⇒ SchemaVersion

Returns a new instance of SchemaVersion.



94
# File 'lib/prick/state.rb', line 94

def initialize(schema = SCHEMAS_DIR) super(File.join(schema, "prick", "data.sql")) end

Instance Method Details

#createObject

Raises:



130
# File 'lib/prick/state.rb', line 130

def create() raise Internal, "This should not happen" end

#read(**opts) ⇒ Object

Raises:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/prick/state.rb', line 96

def read(**opts)
  lines = do_readlines
  while !lines.empty?
    line = lines.shift.chomp
    next if line != COPY_STMT
    l = lines.shift.chomp
    a = l.split("\t")[1..].map { |val| val == '\N' ? nil : val }
    a.size == FIELDS.size or raise Fail, "Illegal data format in #{path}"
    custom, major, minor, patch, pre = a[0], *a[1..-2].map { |val| val && val.to_i }
    v = Version.new("0.0.0", custom: (custom == '\N' ? nil : custom))
    v.major = major
    v.minor = minor
    v.patch = patch
    v.pre = (pre == "null" ? nil : pre)
    return v
  end
  raise Fail, "No COPY statement in #{path}"
end

#write(version) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/prick/state.rb', line 115

def write(version)
  version_string = version.truncate(:pre).to_s
  File.open(path, "w") { |f|
    f.puts "--"
    f.puts "-- This file is auto-generated by prick(1). Please don't touch"
    f.puts COPY_STMT
    f.print \
        "1\t",
        FIELDS[..-2].map { |f| version.send(f.to_sym) || '\N' }.join("\t"),
        "\t#{version_string}\n"
    f.puts "\\."
  }
  Git.add(path)
end