Class: Yardstick::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/yardstick/config.rb

Overview

Handles Yardstick configuration

Constant Summary collapse

InvalidRule =
Class.new(StandardError)
NAMESPACE_PREFIX =
'Yardstick::Rules::'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|config| ... } ⇒ Yardstick::Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes new config

Parameters:

  • options (Hash) (defaults to: {})

    optional configuration

Yield Parameters:



101
102
103
104
105
# File 'lib/yardstick/config.rb', line 101

def initialize(options = {}, &block)
  self.defaults = options

  yield(self) if block_given?
end

Instance Attribute Details

#outputYardstick::ReportOutput

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The path to the file where the measurements will be written



58
59
60
# File 'lib/yardstick/config.rb', line 58

def output
  @output
end

#pathString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List of paths to measure

Returns:

  • (String)


44
45
46
# File 'lib/yardstick/config.rb', line 44

def path
  @path
end

#require_exact_threshold=(value) ⇒ undefined (writeonly)

Specify if the threshold should match the coverage

Returns:

  • (undefined)


30
31
32
# File 'lib/yardstick/config.rb', line 30

def require_exact_threshold=(value)
  @require_exact_threshold = value
end

#thresholdInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Threshold value

Returns:

  • (Integer)


23
24
25
# File 'lib/yardstick/config.rb', line 23

def threshold
  @threshold
end

#verbose=(value) ⇒ undefined (writeonly)

Specify if the coverage summary should be displayed

Returns:

  • (undefined)


51
52
53
# File 'lib/yardstick/config.rb', line 51

def verbose=(value)
  @verbose = value
end

Class Method Details

.coerce(hash) {|config| ... } ⇒ Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerces hash into a config object

Parameters:

  • hash (Hash)

Yield Parameters:

Returns:



70
71
72
# File 'lib/yardstick/config.rb', line 70

def self.coerce(hash, &block)
  new(normalize_hash(hash), &block)
end

.normalize_hash(hash) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts string keys into symbol keys

Parameters:

  • hash (Hash)

Returns:

  • (Hash)

    normalized hash



82
83
84
85
86
87
88
# File 'lib/yardstick/config.rb', line 82

def self.normalize_hash(hash)
  hash.reduce({}) do |normalized_hash, (key, value)|
    normalized_value = value.is_a?(Hash) ? normalize_hash(value) : value
    normalized_hash[key.to_sym] = normalized_value
    normalized_hash
  end
end

Instance Method Details

#for_rule(rule_class) ⇒ RuleConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return config for given rule

Parameters:

  • rule_class (Class)

Returns:



114
115
116
117
118
119
120
121
122
# File 'lib/yardstick/config.rb', line 114

def for_rule(rule_class)
  key = rule_class.to_s[NAMESPACE_PREFIX.length..-1]

  if key
    RuleConfig.new(@rules.fetch(key.to_sym, {}))
  else
    fail InvalidRule, "every rule must begin with #{NAMESPACE_PREFIX}"
  end
end

#require_exact_threshold?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return if the threshold should match the coverage

Returns:

  • (Boolean)


138
139
140
# File 'lib/yardstick/config.rb', line 138

def require_exact_threshold?
  @require_exact_threshold
end

#verbose?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Specify if the coverage summary should be displayed

Returns:

  • (Boolean)


129
130
131
# File 'lib/yardstick/config.rb', line 129

def verbose?
  @verbose
end