-
Notifications
You must be signed in to change notification settings - Fork 222
/
configuration.rb
103 lines (86 loc) · 3.04 KB
/
configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# frozen_string_literal: true
require 'rubycritic/source_control_systems/base'
module RubyCritic
class Configuration
attr_reader :root
attr_accessor :source_control_system, :mode, :formats, :formatters, :deduplicate_symlinks,
:suppress_ratings, :open_with, :no_browser, :base_branch,
:feature_branch, :base_branch_score, :feature_branch_score,
:base_root_directory, :feature_root_directory,
:compare_root_directory, :threshold_score, :base_branch_collection,
:feature_branch_collection, :churn_after, :ruby_extensions, :paths
def set(options)
self.mode = options[:mode] || :default
self.root = options[:root] || 'tmp/rubycritic'
self.deduplicate_symlinks = options[:deduplicate_symlinks]
self.suppress_ratings = options[:suppress_ratings]
self.open_with = options[:open_with]
self.no_browser = options[:no_browser]
self.threshold_score = options[:threshold_score].to_i
setup_paths_for_targets(options) if options[:paths]
setup_analysis_targets(options)
setup_version_control(options)
setup_formats(options)
end
def setup_paths_for_targets(options)
options[:paths] = find_directories(options[:paths])
end
def setup_analysis_targets(options)
self.paths = options[:paths] || ['.']
self.ruby_extensions = options[:ruby_extensions] || %w[.rb .rake .thor]
end
def setup_version_control(options)
self.base_branch = options[:base_branch]
self.feature_branch = options[:feature_branch]
self.churn_after = options[:churn_after]
end
def setup_formats(options)
formats = options[:formats].to_a
self.formats = formats.empty? ? [:html] : formats
self.formatters = options[:formatters] || []
end
def root=(path)
@root = File.expand_path(path)
end
def source_control_present?
source_control_system &&
!source_control_system.is_a?(SourceControlSystem::Double)
end
private
def find_directories(paths)
expanded_paths = paths.flat_map do |path|
if path.include?('**')
search_pattern = File.join(path)
Dir.glob(search_pattern).select { |tmp_path| File.directory?(tmp_path) && !tmp_path.start_with?('tmp') }
else
path
end
end
expanded_paths
end
end
module Config
def self.configuration
@configuration ||= Configuration.new
end
def self.set(options = {})
configuration.set(options)
end
def self.compare_branches_mode?
%i[compare_branches ci].include?(Config.mode)
end
def self.build_mode?
!Config.no_browser && %i[compare_branches ci].include?(Config.mode)
end
def self.method_missing(method, *args, &block)
if configuration.respond_to?(method)
configuration.public_send(method, *args, &block)
else
super
end
end
def self.respond_to_missing?(symbol, include_all = false)
configuration.respond_to?(symbol) || super
end
end
end