lib/metric_fu/base.rb in p8-metric_fu-0.9.0 vs lib/metric_fu/base.rb in p8-metric_fu-0.9.0.1

- old
+ new

@@ -66,22 +66,40 @@ def inline_css(css) open(File.join(MetricFu::TEMPLATE_DIR, css)) { |f| f.read } end def link_to_filename(name, line = nil) - filename = File.expand_path(name) - if PLATFORM['darwin'] - %{<a href="txmt://open/?url=file://#{filename}&line=#{line}">#{name}:#{line}</a>} + if MetricFu.run_by_cruise_control? + cc_link_to_filename(name, line) else - %{<a href="file://#{filename}">#{name}:#{line}</a>} + system_link_to_filename(name, line) end end def cycle(first_value, second_value, iteration) return first_value if iteration % 2 == 0 return second_value end + + private + def cc_link_to_filename(name, line = nil) + if MetricFu.configuration.general[:url_prefix] + MetricFu.configuration.general[:url_prefix] += '/' unless MetricFu.configuration.general[:url_prefix] =~ /\/$/ + %{<a href="#{MetricFu.configuration.general[:url_prefix]}#{name}?line=#{line}##{line}">#{name}</a>} + else + %{"#{name}"} # No link for cruise control without a prefix + end + end + + def system_link_to_filename(name, line = nil) + filename = File.expand_path(name) + if PLATFORM['darwin'] + %{<a href="txmt://open/?url=file://#{filename}&line=#{line}">#{name}</a>} + else + %{<a href="file://#{filename}">#{name}</a>} + end + end end end class << self # The Configuration instance used to configure the Rails environment @@ -108,11 +126,11 @@ def metrics configuration.metrics end def open_in_browser? - PLATFORM['darwin'] && !ENV['CC_BUILD_ARTIFACTS'] + configuration.general[:open_in_browser] && PLATFORM['darwin'] && !run_by_cruise_control? end def saikuro configuration.saikuro end @@ -123,14 +141,18 @@ def roodi configuration.roodi end + def run_by_cruise_control? + !!ENV['CC_BUILD_ARTIFACTS'] + end + end class Configuration - attr_accessor :churn, :coverage, :flay, :flog, :metrics, :reek, :roodi, :saikuro + attr_accessor :churn, :coverage, :flay, :flog, :metrics, :reek, :roodi, :saikuro, :general def initialize raise "Use config.churn instead of MetricFu::CHURN_OPTIONS" if defined? ::MetricFu::CHURN_OPTIONS raise "Use config.flog[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG" if defined? ::MetricFu::DIRECTORIES_TO_FLOG raise "Use config.saikuro instead of MetricFu::SAIKURO_OPTIONS" if defined? ::MetricFu::SAIKURO_OPTIONS reset @@ -139,9 +161,10 @@ def self.run() yield MetricFu.configuration end def reset + @general = { :open_in_browser => true } @churn = {} @coverage = { :test_files => ['test/**/*_test.rb', 'spec/**/*_spec.rb'], :rcov_opts => ["--sort coverage", "--html", "--rails", "--exclude /gems/,/Library/,spec"] } @flay = { :dirs_to_flay => CODE_DIRS} @flog = { :dirs_to_flog => CODE_DIRS} \ No newline at end of file