Module: Metrical::Options

Defined in:
lib/metrical/options.rb

Class Method Summary collapse

Class Method Details

.defaultsObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/metrical/options.rb', line 6

def self.defaults

  defaults = {
    :open => true,
    :metrics => Hash.new(true)
  }
  defaults[:metrics][:saikuro] = version(ruby) < version("1.9")
  defaults[:metrics][:rcov]    = version(ruby) < version("1.9")
  defaults
end

.metricsObject



25
26
27
# File 'lib/metrical/options.rb', line 25

def self.metrics
  MetricFu.configuration.metrics.sort_by(&:to_s)
end

.parse(argv) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/metrical/options.rb', line 29

def self.parse(argv)
  options = defaults.dup

  opts = OptionParser.new do |opts|

    opts.version = Metrical::VERSION

    metrics.each do |metric|

      opts.on "--[no-]#{metric}", "Enables or disables #{metric.to_s.titleize} (default: #{options[:metrics][metric]})" do |option|
        options[:metrics][metric] = option
      end

    end

    opts.on "--[no-]open", "Open report in browser" do |open|
      options[:open] = open
    end

  end

  begin
    opts.parse!(argv)
  rescue OptionParser::InvalidOption => error
    puts error.message
    puts opts
    exit 1
  end
  options
end

.rubyObject



21
22
23
# File 'lib/metrical/options.rb', line 21

def self.ruby
  RUBY_VERSION.dup
end

.version(version) ⇒ Object



17
18
19
# File 'lib/metrical/options.rb', line 17

def self.version(version)
  Gem::Version.new(version)
end