Class: Monocle::BumpCommand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ BumpCommand

Returns a new instance of BumpCommand.



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

def initialize(view)
  @view = view
end

Instance Attribute Details

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#callObject



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

def call
  # Get the SQL from the file, skipping the timestamp row
  # Drop the newlines too
  sql = File.readlines(view.path_for_sql)[1..-1]
  # Generate the new timestamp line
  timestamp = ["-- Timestamp: #{Time.now}\n"]
  # Put it back together
  new_sql = (timestamp + sql).join
  # Open the file for writing (no w+, we want to clear it up)
  File.open(view.path_for_sql, "w") do |f|
    f << new_sql
  end
end