changed properties and the name of hyperchad to selectricity
[selectricity-live] / vendor / plugins / engines / tasks / engines.rake
1 module Engines
2   module RakeTasks
3     def self.all_engines
4       # An engine is informally defined as any subdirectory in vendor/plugins
5       # which ends in '_engine', '_bundle', or contains an 'init_engine.rb' file.
6       engine_base_dirs = ['vendor/plugins']
7       # The engine root may be different; if possible try to include
8       # those directories too
9       if Engines.const_defined?(:CONFIG)
10         engine_base_dirs << Engines::CONFIG[:root]
11       end
12       engine_base_dirs.map! {|d| [d + '/*_engine/*', 
13                                   d + '/*_bundle/*',
14                                   d + '/*/init_engine.rb']}.flatten!
15       engine_dirs = FileList.new(*engine_base_dirs)
16       engine_dirs.map do |engine| 
17         File.basename(File.dirname(engine))
18       end.uniq       
19     end
20   end
21 end
22
23
24 namespace :engines do
25   desc "Display version information about active engines"
26   task :info => :environment do
27     if ENV["ENGINE"]
28       e = Engines.get(ENV["ENGINE"])
29       header = "Details for engine '#{e.name}':"
30       puts header
31       puts "-" * header.length
32       puts "Version: #{e.version}"
33       puts "Details: #{e.info}"
34     else
35       puts "Engines plugin: #{Engines.version}"
36       Engines.each do |e|
37         puts "#{e.name}: #{e.version}"
38       end
39     end
40   end
41 end
42
43 namespace :db do  
44   namespace :fixtures do
45     namespace :engines do
46       
47       desc "Load plugin/engine fixtures into the current environment's database."
48       task :load => :environment do
49         require 'active_record/fixtures'
50         ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
51         plugin = ENV['ENGINE'] || '*'
52         Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', plugin, 'test', 'fixtures', '*.yml')).each do |fixture_file|
53           Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
54         end
55       end
56       
57     end
58   end
59
60
61   namespace :migrate do
62     
63     desc "Migrate all engines. Target specific version with VERSION=x, specific engine with ENGINE=x"
64     task :engines => :environment do
65       engines_to_migrate = ENV["ENGINE"] ? [Engines.get(ENV["ENGINE"])].compact : Engines.active
66       if engines_to_migrate.empty?
67         puts "Couldn't find an engine called '#{ENV["ENGINE"]}'"
68       else
69         if ENV["VERSION"] && !ENV["ENGINE"]
70           # ignore the VERSION, since it makes no sense in this context; we wouldn't
71           # want to revert ALL engines to the same version because of a misttype
72           puts "Ignoring the given version (#{ENV["VERSION"]})."
73           puts "To control individual engine versions, use the ENGINE=<engine> argument"
74         else
75           engines_to_migrate.each do |engine| 
76             Engines::EngineMigrator.current_engine = engine
77             migration_directory = File.join(engine.root, 'db', 'migrate')
78             if File.exist?(migration_directory)
79               puts "Migrating engine '#{engine.name}'"
80               Engines::EngineMigrator.migrate(migration_directory, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
81             else
82               puts "The db/migrate directory for engine '#{engine.name}' appears to be missing."
83               puts "Should be: #{migration_directory}"
84             end
85           end
86           if ActiveRecord::Base.schema_format == :ruby && !engines_to_migrate.empty?
87             Rake::Task[:db_schema_dump].invoke
88           end
89         end
90       end
91     end
92
93     namespace :engines do
94       Engines::RakeTasks.all_engines.each do |engine_name|
95         desc "Migrate the '#{engine_name}' engine. Target specific version with VERSION=x"
96         task engine_name => :environment do
97           ENV['ENGINE'] = engine_name; Rake::Task['db:migrate:engines'].invoke
98         end
99       end
100     end
101     
102   end
103 end
104
105
106 # this is just a rip-off from the plugin stuff in railties/lib/tasks/documentation.rake, 
107 # because the default plugindoc stuff doesn't support subdirectories like <engine>/app or
108 # <engine>/component.
109 namespace :doc do
110
111   desc "Generate documation for all installed engines"
112   task :engines => Engines::RakeTasks.all_engines.map {|engine| "doc:engines:#{engine}"}
113
114   namespace :engines do
115     # Define doc tasks for each engine
116     Engines::RakeTasks.all_engines.each do |engine_name|
117       desc "Generation documentation for the '#{engine_name}' engine"
118       task engine_name => :environment do
119         engine_base   = "vendor/plugins/#{engine_name}"
120         options       = []
121         files         = Rake::FileList.new
122         options << "-o doc/plugins/#{engine_name}"
123         options << "--title '#{engine_name.titlecase} Documentation'"
124         options << '--line-numbers --inline-source'
125         options << '--all' # include protected methods
126         options << '-T html'
127
128         files.include("#{engine_base}/lib/**/*.rb")
129         files.include("#{engine_base}/app/**/*.rb") # include the app directory
130         files.include("#{engine_base}/components/**/*.rb") # include the components directory
131         if File.exists?("#{engine_base}/README")
132           files.include("#{engine_base}/README")    
133           options << "--main '#{engine_base}/README'"
134         end
135         files.include("#{engine_base}/CHANGELOG") if File.exists?("#{engine_base}/CHANGELOG")
136
137         options << files.to_s
138
139         sh %(rdoc #{options * ' '})
140       end
141     end
142   end
143 end
144
145 namespace :test do
146   desc "Run the engine tests in vendor/plugins/**/test (or specify with ENGINE=name)"
147   # NOTE: we're using the Rails 1.0 non-namespaced task here, just to maintain
148   # compatibility with Rails 1.0
149   # TODO: make this work with Engines.config(:root)
150   
151   namespace :engines do
152     Engines::RakeTasks.all_engines.each do |engine_name|
153       desc "Run the engine tests for '#{engine_name}'"
154       Rake::TestTask.new(engine_name => :prepare_test_database) do |t|
155         t.libs << 'test'
156         t.pattern = "vendor/plugins/#{engine_name}/test/**/*_test.rb"
157         t.verbose = true
158       end
159     end    
160   end
161   
162   Rake::TestTask.new(:engines => [:warn_about_multiple_engines_testing, :prepare_test_database]) do |t|
163     t.libs << "test"
164     engines = ENV['ENGINE'] || '**'
165     t.pattern = "vendor/plugins/#{engines}/test/**/*_test.rb"
166     t.verbose = true
167   end
168   
169   task :warn_about_multiple_engines_testing do
170     puts %{-~============== A Moste Polite Warninge ==================~-
171 You may experience issues testing multiple engines at once. 
172 Please test engines individual for the moment.
173 -~===============( ... as you were ... )===================~-
174 }
175   end
176 end

Benjamin Mako Hill || Want to submit a patch?