Class: ActiveRecord::MigrationNotes::Handler

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/active_record/migration_notes/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHandler

Returns a new instance of Handler.



10
11
12
# File 'lib/active_record/migration_notes/handler.rb', line 10

def initialize
  @notes = []
end

Instance Attribute Details

#notesObject

Returns the value of attribute notes.



8
9
10
# File 'lib/active_record/migration_notes/handler.rb', line 8

def notes
  @notes
end

Instance Method Details

#add(version, name, content, direction = :up) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/active_record/migration_notes/handler.rb', line 14

def add(version, name, content, direction = :up)
  content = '   ' + content.split("\n").map(&:strip).join("\n   ")
  notes << { version: version, name: name, content: content,
             direction: direction }
rescue
  nil
end

#outputObject



22
23
24
25
# File 'lib/active_record/migration_notes/handler.rb', line 22

def output
  migration_notes unless notes.empty?
  @notes = []
end