lib/metric_fu/base.rb in p8-metric_fu-0.9.0.2 vs lib/metric_fu/base.rb in p8-metric_fu-0.9.0.3
- old
+ new
@@ -1,20 +1,123 @@
require 'erb'
module MetricFu
TEMPLATE_DIR = File.join(File.dirname(__FILE__), '..', 'templates')
BASE_DIRECTORY = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
- RAILS = File.exist?("config/environment.rb")
- if RAILS
- CODE_DIRS = ['app', 'lib']
- DEFAULT_METRICS = [:coverage, :churn, :flog, :flay, :reek, :roodi, :stats, :saikuro ]
- else
- CODE_DIRS = ['lib']
- DEFAULT_METRICS = [:coverage, :churn, :flog, :flay, :reek, :roodi, :saikuro ]
- end
+ class << self
+ # The Configuration instance used to configure the Rails environment
+ def configuration
+ @@configuration ||= Configuration.new
+ end
+ def churn
+ configuration.churn
+ end
+
+ def coverage
+ configuration.coverage
+ end
+
+ def flay
+ configuration.flay
+ end
+
+ def flog
+ configuration.flog
+ end
+
+ def metrics
+ configuration.metrics
+ end
+
+ def open_in_browser?
+ configuration.general[:open_in_browser] && PLATFORM['darwin'] && !run_by_cruise_control?
+ end
+
+ def saikuro
+ configuration.saikuro
+ end
+
+ def reek
+ configuration.reek
+ end
+
+ def roodi
+ configuration.roodi
+ end
+
+ def run_by_cruise_control?
+ !!ENV['CC_BUILD_ARTIFACTS']
+ end
+
+ def uses_git?
+ File.exist?(".git")
+ end
+
+ def uses_svn?
+ File.exist?(".svn")
+ end
+
+ def can_churn?
+ uses_git? || uses_svn?
+ end
+
+ def is_rails?
+ File.exist?("config/environment.rb")
+ end
+
+ def code_dirs
+ dirs = ['lib']
+ dirs << 'app' if is_rails?
+ dirs.sort{|v1, v2| v1.to_s <=> v2.to_s}
+ end
+
+ def default_metrics
+ metrics = [:coverage, :flog, :flay, :reek, :roodi, :saikuro ]
+ metrics << :stats if is_rails?
+ # Churning requires a subversion or git repo
+ metrics << :churn if can_churn?
+ metrics.sort{|v1, v2| v1.to_s <=> v2.to_s}
+ end
+
+ end
+
+ class Configuration
+ 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
+ end
+
+ def self.run()
+ yield MetricFu.configuration
+ end
+
+ def reset
+ @general = { :open_in_browser => true }
+ @churn = {}
+ rcov_opts = ["--sort coverage", "--html", "--exclude /gems/,/Library/,spec"]
+ rcov_opts << "--rails" if MetricFu.is_rails?
+ @coverage = { :test_files => ['test/**/*_test.rb', 'spec/**/*_spec.rb'],
+ :rcov_opts => rcov_opts }
+ @flay = { :dirs_to_flay => MetricFu.code_dirs}
+ @flog = { :dirs_to_flog => MetricFu.code_dirs}
+ @reek = { :dirs_to_reek => MetricFu.code_dirs}
+ @roodi = { :dirs_to_roodi => MetricFu.code_dirs}
+ @metrics = MetricFu.default_metrics
+ @saikuro = {}
+ end
+
+ def saikuro=(options)
+ raise "saikuro need to be a Hash" unless options.is_a?(Hash)
+ @saikuro = options
+ end
+ end
+
module Base
######################################################################
# Base class for report Generators
#
@@ -99,85 +202,6 @@
end
end
end
end
- class << self
- # The Configuration instance used to configure the Rails environment
- def configuration
- @@configuration ||= Configuration.new
- end
-
- def churn
- configuration.churn
- end
-
- def coverage
- configuration.coverage
- end
-
- def flay
- configuration.flay
- end
-
- def flog
- configuration.flog
- end
-
- def metrics
- configuration.metrics
- end
-
- def open_in_browser?
- configuration.general[:open_in_browser] && PLATFORM['darwin'] && !run_by_cruise_control?
- end
-
- def saikuro
- configuration.saikuro
- end
-
- def reek
- configuration.reek
- end
-
- 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, :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
- end
-
- 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}
- @reek = { :dirs_to_reek => CODE_DIRS}
- @roodi = { :dirs_to_roodi => CODE_DIRS}
- @metrics = DEFAULT_METRICS
- @saikuro = {}
- end
-
- def saikuro=(options)
- raise "saikuro need to be a Hash" unless options.is_a?(Hash)
- @saikuro = options
- end
- end
end
\ No newline at end of file