Class: PgTrigger::Generator::Migration
- Inherits:
-
Object
- Object
- PgTrigger::Generator::Migration
- Defined in:
- lib/pg_trigger/generator.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #generate_output ⇒ Object
-
#initialize(plan) ⇒ Migration
constructor
A new instance of Migration.
- #save_to_file ⇒ Object
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
#name ⇒ Object (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_output ⇒ Object
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) end |
#save_to_file ⇒ Object
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 |