/
annotate_models_migrate.rake
59 lines (51 loc) · 1.69 KB
/
annotate_models_migrate.rake
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# These tasks are added to the project if you install annotate as a Rails plugin.
# (They are not used to build annotate itself.)
# Append annotations to Rake tasks for ActiveRecord, so annotate automatically gets
# run after doing db:migrate.
namespace :db do
annotation_options_task = if Rake::Task.task_defined?('app:set_annotation_options')
'app:set_annotation_options'
else
'set_annotation_options'
end
[:migrate, :rollback].each do |cmd|
task cmd do
Rake::Task[annotation_options_task].invoke
Annotate::Migration.update_annotations
end
namespace cmd do
[:change, :up, :down, :reset, :redo].each do |t|
task t do
Rake::Task[annotation_options_task].invoke
Annotate::Migration.update_annotations
end
end
end
end
end
module Annotate
class Migration
@@working = false
def self.update_annotations
unless @@working || Annotate.skip_on_migration?
@@working = true
self.update_models if Annotate.include_models?
self.update_routes if Annotate.include_routes?
end
end
def self.update_models
if Rake::Task.task_defined?("annotate_models")
Rake::Task["annotate_models"].invoke
elsif Rake::Task.task_defined?("app:annotate_models")
Rake::Task["app:annotate_models"].invoke
end
end
def self.update_routes
if Rake::Task.task_defined?("annotate_routes")
Rake::Task["annotate_routes"].invoke
elsif Rake::Task.task_defined?("app:annotate_routes")
Rake::Task["app:annotate_routes"].invoke
end
end
end
end