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.
Class Method Summary collapse
-
.configuration ⇒ Configuration
Retrieve the current configuration object.
-
.configure {|configuration| ... } ⇒ Object
Configure the concern by providing a block which takes care of this task.
-
.reset_configuration! ⇒ Object
Reset the current configuration with the default one.
-
.statistic_directories ⇒ Array<Hash{Symbol => Mixed}>
Get an assembled list of directories which should be checked for code statistics.
Class Method Details
.configuration ⇒ Configuration
Retrieve the current configuration object.
13 14 15 |
# File 'lib/countless/extensions/configuration_handling.rb', line 13 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
23 24 25 |
# File 'lib/countless/extensions/configuration_handling.rb', line 23 def configure yield(configuration) end |
.reset_configuration! ⇒ Object
Reset the current configuration with the default one.
28 29 30 |
# File 'lib/countless/extensions/configuration_handling.rb', line 28 def reset_configuration! @configuration = Configuration.new end |
.statistic_directories ⇒ Array<Hash{Symbol => Mixed}>
Get an assembled list of directories which should be checked for code statistics.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/countless/extensions/configuration_handling.rb', line 39 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 |