Class: Monocle::DropCommand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ DropCommand

Returns a new instance of DropCommand.



5
6
7
# File 'lib/monocle/drop_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/drop_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/drop_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
  drop_directive = ["-- Drop\n"]
  # Put it back together
  new_sql = (drop_directive + 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