Module: Countless::Extensions::ConfigurationHandling

Extended by:
ActiveSupport::Concern
Included in:
Countless
Defined in:
lib/countless/extensions/configuration_handling.rb

Overview

A top-level gem-module extension to handle configuration needs.

rubocop:disable Metrics/BlockLength because this is how

an +ActiveSupport::Concern+ looks like

Class Method Summary collapse

Class Method Details

.configurationConfiguration

Retrieve the current configuration object.

Returns:



16
17
18
# File 'lib/countless/extensions/configuration_handling.rb', line 16

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Configure the concern by providing a block which takes care of this task. Example:

Countless.configure do |conf|
  # conf.xyz = [..]
end

Yields:



26
27
28
# File 'lib/countless/extensions/configuration_handling.rb', line 26

def configure
  yield(configuration)
end

.reset_configuration!Object

Reset the current configuration with the default one.



31
32
33
# File 'lib/countless/extensions/configuration_handling.rb', line 31

def reset_configuration!
  @configuration = Configuration.new
end

.statistic_directoriesArray<Hash{Symbol => Mixed}>

Get an assembled list of directories which should be checked for code statistics.

rubocop:disable Metrics/MethodLength because of the

configuration assembling

rubocop:disable Metrics/AbcSize dito rubocop:disable Metrics/CyclomaticComplexity dito

Returns:

  • (Array<Hash{Symbol => Mixed}>)

    the statistics directories



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/countless/extensions/configuration_handling.rb', line 47

def statistic_directories
  conf = configuration
  pattern_suffix = "/**/*.{#{conf.stats_file_extensions.join(',')}}"

  res = conf.stats_base_directories.deep_dup
  conf.stats_app_object_types.each do |type|
    one_type = type.singularize.titleize
    many_types = type.pluralize.titleize

    res << { name: many_types, dir: "app/#{type}" }
    res << { name: "#{one_type} tests",
             dir: "test/#{type}", test: true }
    res << { name: "#{one_type} specs",
             dir: "specs/#{type}", test: true }
  end

  res.each do |cur|
    # Add the configured base dir, when we hit a relative dir config
    cur[:dir] = "#{conf.base_path}/#{cur[:dir]}" \
      unless (cur[:dir] || '').start_with? '/'
    # Add the default pattern, when no user configured pattern
    # is present
    cur[:pattern] ||= "#{cur[:dir]}#{pattern_suffix}"
    # Fallback to regular code, when not otherwise configured
    cur[:test] ||= false
  end

  res.sort_by { |cur| [cur[:test].to_s, cur[:name]] }
end