Class: MetricFu::Metric
- Inherits:
-
Object
- Object
- MetricFu::Metric
- Defined in:
- lib/metric_fu/metric.rb
Direct Known Subclasses
MetricCane, MetricChurn, MetricFlay, MetricFlog, MetricHotspots, MetricRailsBestPractices, MetricRcov, MetricReek, MetricRoodi, MetricSaikuro, MetricStats
Instance Attribute Summary collapse
-
#activated ⇒ Object
Returns the value of attribute activated.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
Class Method Summary collapse
- .enabled_metrics ⇒ Object
- .get_metric(name) ⇒ Object
-
.metrics ⇒ Object
ensure :hotspots runs last.
Instance Method Summary collapse
-
#activate ⇒ Object
TODO: Confirm this catches load errors from requires in subclasses, such as for flog.
- #configured_run_options ⇒ Object
- #default_run_args ⇒ Object
-
#default_run_options ⇒ Hash
Default metric run options.
- #enable ⇒ Object
- #gem_name ⇒ Object
-
#has_graph? ⇒ Hash
Metric_options.
-
#initialize ⇒ Metric
constructor
A new instance of Metric.
-
#name ⇒ Object
Metric name [Symbol].
- #run ⇒ Object
- #run_external(args = default_run_args) ⇒ Object
-
#run_options ⇒ Object
Metric run options [Hash].
Constructor Details
#initialize ⇒ Metric
Returns a new instance of Metric.
9 10 11 12 13 |
# File 'lib/metric_fu/metric.rb', line 9 def initialize self.enabled = false @libraries = Set.new @configured_run_options = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (protected)
Enable using a syntax such as metric.foo = ‘foo’
by catching the missing method here,
checking if :foo is a key in the default_run_options, and
setting the key/value in the @configured_run_options hash
TODO: See if we can do this without a method_missing
110 111 112 113 114 115 116 117 |
# File 'lib/metric_fu/metric.rb', line 110 def method_missing(method, *args) key = method_to_attr(method) if .has_key?(key) [key] = args.first else raise "#{key} is not a valid configuration option" end end |
Instance Attribute Details
#activated ⇒ Object
Returns the value of attribute activated.
7 8 9 |
# File 'lib/metric_fu/metric.rb', line 7 def activated @activated end |
#enabled ⇒ Object
Returns the value of attribute enabled.
7 8 9 |
# File 'lib/metric_fu/metric.rb', line 7 def enabled @enabled end |
Class Method Details
.enabled_metrics ⇒ Object
91 92 93 |
# File 'lib/metric_fu/metric.rb', line 91 def self.enabled_metrics metrics.select { |metric| metric.enabled && metric.activated }.sort_by { |metric| metric.name == :hotspots ? 1 : 0 } end |
.get_metric(name) ⇒ Object
95 96 97 |
# File 'lib/metric_fu/metric.rb', line 95 def self.get_metric(name) metrics.find { |metric|metric.name.to_s == name.to_s } end |
.metrics ⇒ Object
ensure :hotspots runs last
87 88 89 |
# File 'lib/metric_fu/metric.rb', line 87 def self.metrics @metrics end |
Instance Method Details
#activate ⇒ Object
TODO: Confirm this catches load errors from requires in subclasses, such as for flog
20 21 22 23 24 25 26 |
# File 'lib/metric_fu/metric.rb', line 20 def activate MetricFu.metrics_require { default_metric_library_paths } @libraries.each { |library| require(library) } self.activated = true rescue LoadError => e mf_log "#{name} metric not activated, #{e.}" end |
#configured_run_options ⇒ Object
70 71 72 |
# File 'lib/metric_fu/metric.rb', line 70 def @configured_run_options end |
#default_run_args ⇒ Object
42 43 44 |
# File 'lib/metric_fu/metric.rb', line 42 def default_run_args .map { |k, v| "--#{k} #{v}" }.join(" ") end |
#default_run_options ⇒ Hash
Returns default metric run options.
75 76 77 |
# File 'lib/metric_fu/metric.rb', line 75 def not_implemented end |
#enable ⇒ Object
15 16 17 |
# File 'lib/metric_fu/metric.rb', line 15 def enable self.enabled = true end |
#gem_name ⇒ Object
33 34 35 |
# File 'lib/metric_fu/metric.rb', line 33 def gem_name name end |
#has_graph? ⇒ Hash
Returns metric_options.
80 81 82 |
# File 'lib/metric_fu/metric.rb', line 80 def has_graph? not_implemented end |
#name ⇒ Object
Returns metric name [Symbol].
29 30 31 |
# File 'lib/metric_fu/metric.rb', line 29 def name not_implemented end |
#run ⇒ Object
46 47 48 |
# File 'lib/metric_fu/metric.rb', line 46 def run not_implemented end |
#run_external(args = default_run_args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/metric_fu/metric.rb', line 50 def run_external(args = default_run_args) runner = GemRun.new( gem_name: gem_name.to_s, metric_name: name.to_s, # version: , args: args, ) stdout, stderr, status = runner.run # TODO: do something with the stderr # for now, just acknowledge we got it unless stderr.empty? STDERR.puts "STDERR from #{gem_name}:\n#{stderr}" end # TODO: status.success? is not reliable for distinguishing # between a successful run of the metric and problems # found by the metric. Talk to other metrics about this. MetricFu.logger.debug "#{gem_name} ran with #{status.success? ? 'success' : 'failure'} code #{status.exitstatus}" stdout end |
#run_options ⇒ Object
Returns metric run options [Hash].
38 39 40 |
# File 'lib/metric_fu/metric.rb', line 38 def .merge() end |