Class: Monocle::VersionGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/monocle/version_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ VersionGenerator

Returns a new instance of VersionGenerator.



5
6
7
8
# File 'lib/monocle/version_generator.rb', line 5

def initialize(path)
  @path = path
  @view = File.basename(path, ".sql")
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/monocle/version_generator.rb', line 3

def path
  @path
end

#viewObject (readonly)

Returns the value of attribute view.



3
4
5
# File 'lib/monocle/version_generator.rb', line 3

def view
  @view
end

Instance Method Details

#generateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/monocle/version_generator.rb', line 10

def generate
  timestamp = File.open path, &:readline
  case timestamp
  when /^-- Timestamp:/
    # Get only the digits out of the timestamp line
    timestamp.gsub!(/[^\d]/, '')
    return "#{view}_#{timestamp}"
  when /^-- Drop/
    return :drop
  else
    fail "can't read timestamp of #{path}! Aborting..."
  end
end