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
# File 'lib/monocle/version_generator.rb', line 10

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