Class: PgTrigger::Generator::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_trigger/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plan) ⇒ Migration

Returns a new instance of Migration.



26
27
28
29
30
31
32
# File 'lib/pg_trigger/generator.rb', line 26

def initialize(plan)
  @plan = plan
  @output = nil

  number = ActiveRecord::Migration.next_migration_number(0)
  @name = "#{number}_#{plan.name}.rb"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/pg_trigger/generator.rb', line 24

def name
  @name
end

Instance Method Details

#generate_outputObject



43
44
45
46
47
48
49
50
# File 'lib/pg_trigger/generator.rb', line 43

def generate_output
  @output = ""
  header
  add_direction(:up)
  @output << "\n"
  add_direction(:down)
  footer
end

#save_to_fileObject



34
35
36
37
38
39
40
41
# File 'lib/pg_trigger/generator.rb', line 34

def save_to_file
  generate_output if @output.nil?

  filename = name
  File.binwrite(File.join(PgTrigger.migrations_path, filename), @output)

  filename
end