Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Check for Rails >= 2.0.0, automatically install assets on startup

  • Loading branch information...
commit b9e7a32a63cf2b097bee9ffbe4c5801c400cd130 1 parent a11bb5d
@bruce bruce authored
Showing with 44 additions and 31 deletions.
  1. +3 −8 install.rb
  2. +22 −5 lib/fiveruns/tuneup.rb
  3. +19 −18 rails/init.rb
View
11 install.rb
@@ -1,18 +1,13 @@
-# Allow linking (for development)
-method = ENV['LINK'] ? :ln_s : :cp
installed = false
Dir[File.dirname(__FILE__) << "/assets/*"].each do |location|
directory = File.basename(location)
destination = File.join(RAILS_ROOT, 'public', directory, 'tuneup')
- FileUtils.mkdir_p(destination) rescue nil
+ FileUtils.rm_rf(destination) rescue nil
+ FileUtils.mkdir_p(destination)
Dir[File.join(location, '*')].each do |file|
new_filename = File.join(destination, File.basename(file))
unless File.exists?(new_filename)
- FileUtils.send(method, file, new_filename)
- installed = true
+ FileUtils.cp file, new_filename
end
end
-end
-if installed
- STDERR.puts "FiveRuns TuneUp: Installed assets in public/"
end
View
27 lib/fiveruns/tuneup.rb
@@ -78,20 +78,37 @@ def recording?
end
def start
- log :info, "Starting..."
- install_instrumentation
- log :debug, "Using collector at #{collector_url}"
- log :debug, "Using frontend at #{frontend_url}"
+ if supports_rails?
+ yield
+ log :info, "Starting..."
+ install_instrumentation
+ log :debug, "Using collector at #{collector_url}"
+ log :debug, "Using frontend at #{frontend_url}"
+ end
end
def log(level, text)
- LOGGER.send(level, "FiveRuns TuneUp (v#{Fiveruns::Tuneup::Version::STRING}): #{text}")
+ message = "FiveRuns TuneUp (v#{Fiveruns::Tuneup::Version::STRING}): #{text}"
+ LOGGER.send(level, message)
+ STDERR.puts message if level == :error
end
#######
private
#######
+ def supports_rails?
+ version = Rails::VERSION rescue nil
+ return true unless version
+ if version::MAJOR < 2
+ log :error, "Sorry, FiveRuns TuneUp does not currently support Rails < 2.0.0; aborting load."
+ false
+ else
+ log :info, "Rails version #{version::STRING} is supported, loading..."
+ true
+ end
+ end
+
def clear_stack
@stack = nil
@exclusion_stack = nil
View
37 rails/init.rb
@@ -1,20 +1,21 @@
-require 'dispatcher'
-Dispatcher.to_prepare :tuneup_route do
- ActionController::Routing::Routes.add_route '/tuneup', :controller => 'tuneup', :action => 'show'
- ActionController::Routing::Routes.add_route '/tuneup/:action', :controller => 'tuneup'
- 2.times do
- route = ActionController::Routing::Routes.routes.pop
- ActionController::Routing::Routes.routes.unshift(route)
+Fiveruns::Tuneup.start do
+ require 'dispatcher'
+ Dispatcher.to_prepare :tuneup_route do
+ ActionController::Routing::Routes.add_route '/tuneup', :controller => 'tuneup', :action => 'show'
+ ActionController::Routing::Routes.add_route '/tuneup/:action', :controller => 'tuneup'
+ 2.times do
+ route = ActionController::Routing::Routes.routes.pop
+ ActionController::Routing::Routes.routes.unshift(route)
+ end
+ end
+ Dispatcher.to_prepare :tuneup_controller_filters do
+ TuneupController.filter_chain.clear
+ TuneupController.before_filter :find_config, :except => :index
+ end
+ [ActionController::Base, ActiveRecord::Base, ActionView::Base].each do |target|
+ target.extend Fiveruns::Tuneup::CustomMethods
end
-end
-Dispatcher.to_prepare :tuneup_controller_filters do
- TuneupController.filter_chain.clear
- TuneupController.before_filter :find_config, :except => :index
-end
-[ActionController::Base, ActiveRecord::Base, ActionView::Base].each do |target|
- target.extend Fiveruns::Tuneup::CustomMethods
-end
-ActionController::Base.append_view_path(File.dirname(__FILE__) << "/../views")
-require File.dirname(__FILE__) << "/../install" # Check for assets
-Fiveruns::Tuneup.start
+ ActionController::Base.append_view_path(File.dirname(__FILE__) << "/../views")
+ require File.dirname(__FILE__) << "/../install" # Check for assets
+end
Please sign in to comment.
Something went wrong with that request. Please try again.