Class: Localtower::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/localtower/status.rb

Instance Method Summary collapse

Instance Method Details

#runObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/localtower/status.rb', line 3

def run
  files = Dir["#{Rails.root}/db/migrate/*.rb"].sort.reverse
  db_migrations = begin
    ActiveRecord::Base.connection.execute("select * from schema_migrations;")
  rescue => e
    []
  end

  db_migrations = db_migrations.map { |e| e["version"].to_s }

  files.map do |file_full_path|
    name = file_full_path.split("/")[-1] # add_email_to_user.rb
    time = name.split("_")[0] # 201203890987
    status = db_migrations.include?(time) ? :done : :todo
    content = File.open(file_full_path).read

    {
      "file_full_path" => file_full_path,
      "name" => name,
      "time" => time.to_i,
      "status" => status,
      "content" => content
    }
  end
end