rubocop 0.14.0 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +15 -0
- data/README.md +1 -1
- data/config/default.yml +4 -0
- data/config/enabled.yml +16 -8
- data/lib/rubocop.rb +3 -0
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/config.rb +3 -160
- data/lib/rubocop/config_loader.rb +156 -0
- data/lib/rubocop/config_store.rb +6 -6
- data/lib/rubocop/cop/style/align_hash.rb +15 -11
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +46 -0
- data/lib/rubocop/cop/style/class_length.rb +27 -4
- data/lib/rubocop/cop/style/documentation.rb +23 -25
- data/lib/rubocop/cop/style/raise_args.rb +6 -1
- data/lib/rubocop/cop/style/space_after_not.rb +37 -0
- data/lib/rubocop/cop/util.rb +18 -1
- data/lib/rubocop/formatter/clang_style_formatter.rb +11 -2
- data/lib/rubocop/options.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/spec/project_spec.rb +2 -2
- data/spec/rubocop/cli_spec.rb +1 -1
- data/spec/rubocop/config_loader_spec.rb +314 -0
- data/spec/rubocop/config_spec.rb +1 -308
- data/spec/rubocop/config_store_spec.rb +9 -9
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +3 -3
- data/spec/rubocop/cop/style/align_hash_spec.rb +17 -20
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +193 -0
- data/spec/rubocop/cop/style/class_length_spec.rb +64 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +10 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +0 -7
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +1 -1
- data/spec/rubocop/cop/style/raise_args_spec.rb +5 -0
- data/spec/rubocop/cop/style/space_after_not_spec.rb +22 -0
- data/spec/rubocop/cop/team_spec.rb +1 -1
- data/spec/rubocop/cop/util_spec.rb +49 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +42 -16
- data/spec/rubocop/options_spec.rb +3 -2
- data/spec/spec_helper.rb +1 -1
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac71ab74e5b7b997ffbc58dec68eaf2946ecbe5a
|
4
|
+
data.tar.gz: 6d0cc8550c439423260381ac3fddd57150ccb2ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b185443b7dd173d210470487fc30ac302a07678831a6db7072a52763e975f566cc1204a180925e59cff6437376f1bc8ce71da294dbf1f7f9a23e8545377aa4
|
7
|
+
data.tar.gz: b726196458275a3bb7d20270dac674c953b764bb0eb5f219b2b8540ff9cd579dd6c9adf573292828c73e6821710f0c65f49085764a51044f7d21834740154af4
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.14.1 (10/10/2013)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* [#551](https://github.com/bbatsov/rubocop/pull/551) - New cop `BracesAroundHashParameters` checks for braces in function calls with hash parameters.
|
10
|
+
* New cop `SpaceAfterNot` tracks redundant space after the `!` operator.
|
11
|
+
|
12
|
+
### Bugs fixed
|
13
|
+
|
14
|
+
* Fix bug concerning table and separator alignment of multi-line hash with multiple keys on the same line.
|
15
|
+
* Fix a bug where `ClassLength` counted lines of inner classes/modules
|
16
|
+
* Fix a false positive for namespace class in `Documentation`
|
17
|
+
* Fix "Parser::Source::Range spans more than one line" bug in clang formatter
|
18
|
+
* [#552](https://github.com/bbatsov/rubocop/pull/552) - `RaiseArgs` allows exception constructor calls with more than one 1 argument.
|
19
|
+
|
5
20
|
## 0.14.0 (07/10/2013)
|
6
21
|
|
7
22
|
### New features
|
data/README.md
CHANGED
@@ -302,7 +302,7 @@ W: 4: 5: end at 4, 4 is not aligned with if at 2, 2
|
|
302
302
|
1 file inspected, 3 offences detected
|
303
303
|
```
|
304
304
|
|
305
|
-
### File List
|
305
|
+
### File List Formatter
|
306
306
|
|
307
307
|
Sometimes you might want to just open all files with offences in your
|
308
308
|
favorite editor. This formatter outputs just the names of the files
|
data/config/default.yml
CHANGED
data/config/enabled.yml
CHANGED
@@ -384,26 +384,30 @@ SpaceInsideBrackets:
|
|
384
384
|
Description: 'No spaces after [ or before ].'
|
385
385
|
Enabled: true
|
386
386
|
|
387
|
+
SpaceAfterColon:
|
388
|
+
Description: 'Use spaces after colons.'
|
389
|
+
Enabled: true
|
390
|
+
|
387
391
|
SpaceAfterComma:
|
388
392
|
Description: 'Use spaces after commas.'
|
389
393
|
Enabled: true
|
390
394
|
|
395
|
+
SpaceAfterControlKeyword:
|
396
|
+
Description: 'Use spaces after if/elsif/unless/while/until/case/when.'
|
397
|
+
Enabled: true
|
398
|
+
|
391
399
|
SpaceAfterMethodName:
|
392
400
|
Description: >
|
393
401
|
Never put a space between a method name and the opening
|
394
402
|
parenthesis.
|
395
403
|
Enabled: true
|
396
404
|
|
397
|
-
|
398
|
-
Description:
|
399
|
-
Enabled: true
|
400
|
-
|
401
|
-
SpaceAfterColon:
|
402
|
-
Description: 'Use spaces after colons.'
|
405
|
+
SpaceAfterNot:
|
406
|
+
Description: Tracks redundant space after the ! operator.
|
403
407
|
Enabled: true
|
404
408
|
|
405
|
-
|
406
|
-
Description: 'Use spaces after
|
409
|
+
SpaceAfterSemicolon:
|
410
|
+
Description: 'Use spaces after semicolons.'
|
407
411
|
Enabled: true
|
408
412
|
|
409
413
|
SpaceAroundEqualsInParameterDefault:
|
@@ -482,6 +486,10 @@ WhileUntilDo:
|
|
482
486
|
Description: 'Checks for redundant do after while or until.'
|
483
487
|
Enabled: true
|
484
488
|
|
489
|
+
BracesAroundHashParameters:
|
490
|
+
Description: 'Enforce braces style inside hash parameters.'
|
491
|
+
Enabled: true
|
492
|
+
|
485
493
|
#################### Lint ################################
|
486
494
|
### Warnings
|
487
495
|
|
data/lib/rubocop.rb
CHANGED
@@ -125,6 +125,7 @@ require 'rubocop/cop/style/single_line_methods'
|
|
125
125
|
require 'rubocop/cop/style/space_after_comma_etc'
|
126
126
|
require 'rubocop/cop/style/space_after_control_keyword'
|
127
127
|
require 'rubocop/cop/style/space_after_method_name'
|
128
|
+
require 'rubocop/cop/style/space_after_not'
|
128
129
|
require 'rubocop/cop/style/special_global_vars'
|
129
130
|
require 'rubocop/cop/style/space_before_modifier_keyword'
|
130
131
|
require 'rubocop/cop/style/string_literals'
|
@@ -142,6 +143,7 @@ require 'rubocop/cop/style/variable_name'
|
|
142
143
|
require 'rubocop/cop/style/when_then'
|
143
144
|
require 'rubocop/cop/style/while_until_do'
|
144
145
|
require 'rubocop/cop/style/word_array'
|
146
|
+
require 'rubocop/cop/style/braces_around_hash_parameters'
|
145
147
|
|
146
148
|
require 'rubocop/cop/rails/has_and_belongs_to_many'
|
147
149
|
require 'rubocop/cop/rails/read_attribute'
|
@@ -159,6 +161,7 @@ require 'rubocop/formatter/offence_count_formatter'
|
|
159
161
|
require 'rubocop/formatter/formatter_set'
|
160
162
|
|
161
163
|
require 'rubocop/config'
|
164
|
+
require 'rubocop/config_loader'
|
162
165
|
require 'rubocop/config_store'
|
163
166
|
require 'rubocop/target_finder'
|
164
167
|
require 'rubocop/token'
|
data/lib/rubocop/cli.rb
CHANGED
data/lib/rubocop/config.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'delegate'
|
4
|
-
require 'yaml'
|
5
4
|
require 'pathname'
|
6
5
|
|
7
6
|
module Rubocop
|
@@ -13,165 +12,9 @@ module Rubocop
|
|
13
12
|
class Config < DelegateClass(Hash)
|
14
13
|
class ValidationError < StandardError; end
|
15
14
|
|
16
|
-
DOTFILE = '.rubocop.yml'
|
17
|
-
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
18
|
-
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
|
19
|
-
AUTO_GENERATED_FILE = 'rubocop-todo.yml'
|
20
|
-
|
21
15
|
attr_reader :loaded_path
|
22
16
|
attr_accessor :contains_auto_generated_config
|
23
17
|
|
24
|
-
class << self
|
25
|
-
attr_accessor :debug
|
26
|
-
alias_method :debug?, :debug
|
27
|
-
|
28
|
-
def load_file(path)
|
29
|
-
path = File.absolute_path(path)
|
30
|
-
hash = YAML.load_file(path)
|
31
|
-
puts "configuration from #{path}" if debug?
|
32
|
-
contains_auto_generated_config = false
|
33
|
-
|
34
|
-
base_configs(path, hash['inherit_from']).reverse_each do |base_config|
|
35
|
-
if File.basename(base_config.loaded_path) == DOTFILE
|
36
|
-
make_excludes_absolute(base_config)
|
37
|
-
end
|
38
|
-
base_config.each do |key, value|
|
39
|
-
if value.is_a?(Hash)
|
40
|
-
hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
|
41
|
-
end
|
42
|
-
end
|
43
|
-
if base_config.loaded_path.include?(AUTO_GENERATED_FILE)
|
44
|
-
contains_auto_generated_config = true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
hash.delete('inherit_from')
|
49
|
-
config = new(hash, path)
|
50
|
-
config.warn_unless_valid
|
51
|
-
config.contains_auto_generated_config = contains_auto_generated_config
|
52
|
-
config
|
53
|
-
end
|
54
|
-
|
55
|
-
def make_excludes_absolute(config)
|
56
|
-
if config['AllCops'] && config['AllCops']['Excludes']
|
57
|
-
config['AllCops']['Excludes'].map! do |exclude_elem|
|
58
|
-
if exclude_elem.is_a?(String) && !exclude_elem.start_with?('/')
|
59
|
-
File.join(File.dirname(config.loaded_path), exclude_elem)
|
60
|
-
else
|
61
|
-
exclude_elem
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def relative_path(path, base)
|
68
|
-
path_name = Pathname.new(File.expand_path(path))
|
69
|
-
path_name.relative_path_from(Pathname.new(base)).to_s
|
70
|
-
end
|
71
|
-
|
72
|
-
# Return an extended merge of two hashes. That is, a normal hash merge,
|
73
|
-
# with the addition that any value that is a hash, and occurs in both
|
74
|
-
# arguments (i.e., cop names), will also be merged.
|
75
|
-
def merge(base_hash, derived_hash)
|
76
|
-
result = {}
|
77
|
-
base_hash.each do |key, value|
|
78
|
-
result[key] = if derived_hash.key?(key)
|
79
|
-
if value.is_a?(Hash)
|
80
|
-
value.merge(derived_hash[key])
|
81
|
-
else
|
82
|
-
derived_hash[key]
|
83
|
-
end
|
84
|
-
else
|
85
|
-
base_hash[key]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
derived_hash.each do |key, value|
|
89
|
-
result[key] = value unless base_hash.key?(key)
|
90
|
-
end
|
91
|
-
result
|
92
|
-
end
|
93
|
-
|
94
|
-
def base_configs(path, inherit_from)
|
95
|
-
base_files = case inherit_from
|
96
|
-
when nil then []
|
97
|
-
when String then [inherit_from]
|
98
|
-
when Array then inherit_from
|
99
|
-
end
|
100
|
-
base_files.map do |f|
|
101
|
-
f = File.join(File.dirname(path), f) unless f.start_with?('/')
|
102
|
-
print 'Inheriting ' if debug?
|
103
|
-
load_file(f)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Returns the path of .rubocop.yml searching upwards in the
|
108
|
-
# directory structure starting at the given directory where the
|
109
|
-
# inspected file is. If no .rubocop.yml is found there, the
|
110
|
-
# user's home directory is checked. If there's no .rubocop.yml
|
111
|
-
# there either, the path to the default file is returned.
|
112
|
-
def configuration_file_for(target_dir)
|
113
|
-
config_files_in_path(target_dir).first || DEFAULT_FILE
|
114
|
-
end
|
115
|
-
|
116
|
-
def configuration_from_file(config_file)
|
117
|
-
config = load_file(config_file)
|
118
|
-
found_files = config_files_in_path(config_file)
|
119
|
-
if found_files.any? && found_files.last != config_file
|
120
|
-
print 'AllCops/Excludes ' if debug?
|
121
|
-
add_excludes_from_higher_level(config, load_file(found_files.last))
|
122
|
-
end
|
123
|
-
make_excludes_absolute(config)
|
124
|
-
merge_with_default(config, config_file)
|
125
|
-
end
|
126
|
-
|
127
|
-
def add_excludes_from_higher_level(config, highest_config)
|
128
|
-
if highest_config['AllCops'] && highest_config['AllCops']['Excludes']
|
129
|
-
config['AllCops'] ||= {}
|
130
|
-
config['AllCops']['Excludes'] ||= []
|
131
|
-
highest_config['AllCops']['Excludes'].each do |path|
|
132
|
-
unless path.is_a?(Regexp) || path.start_with?('/')
|
133
|
-
path = File.join(File.dirname(highest_config.loaded_path), path)
|
134
|
-
end
|
135
|
-
config['AllCops']['Excludes'] << path
|
136
|
-
end
|
137
|
-
config['AllCops']['Excludes'].uniq!
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def default_configuration
|
142
|
-
@default_configuration ||= begin
|
143
|
-
print 'Default ' if debug?
|
144
|
-
load_file(DEFAULT_FILE)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def merge_with_default(config, config_file)
|
149
|
-
result = new(merge(default_configuration, config), config_file)
|
150
|
-
result.contains_auto_generated_config =
|
151
|
-
config.contains_auto_generated_config
|
152
|
-
result
|
153
|
-
end
|
154
|
-
|
155
|
-
private
|
156
|
-
|
157
|
-
def config_files_in_path(target)
|
158
|
-
possible_config_files = dirs_to_search(target).map do |dir|
|
159
|
-
File.join(dir, DOTFILE)
|
160
|
-
end
|
161
|
-
possible_config_files.select { |config_file| File.exist?(config_file) }
|
162
|
-
end
|
163
|
-
|
164
|
-
def dirs_to_search(target_dir)
|
165
|
-
dirs_to_search = []
|
166
|
-
target_dir_pathname = Pathname.new(File.expand_path(target_dir))
|
167
|
-
target_dir_pathname.ascend do |dir_pathname|
|
168
|
-
dirs_to_search << dir_pathname.to_s
|
169
|
-
end
|
170
|
-
dirs_to_search << Dir.home
|
171
|
-
dirs_to_search
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
18
|
def initialize(hash = {}, loaded_path = nil)
|
176
19
|
@hash = hash
|
177
20
|
@loaded_path = loaded_path
|
@@ -196,9 +39,9 @@ module Rubocop
|
|
196
39
|
# TODO: This should be a private method
|
197
40
|
def validate
|
198
41
|
# Don't validate RuboCop's own files. Avoids inifinite recursion.
|
199
|
-
return if @loaded_path.start_with?(RUBOCOP_HOME)
|
42
|
+
return if @loaded_path.start_with?(ConfigLoader::RUBOCOP_HOME)
|
200
43
|
|
201
|
-
default_config =
|
44
|
+
default_config = ConfigLoader.default_configuration
|
202
45
|
|
203
46
|
valid_cop_names, invalid_cop_names = @hash.keys.partition do |key|
|
204
47
|
default_config.key?(key)
|
@@ -244,7 +87,7 @@ module Rubocop
|
|
244
87
|
|
245
88
|
def relative_path_to_loaded_dir(file)
|
246
89
|
return file unless loaded_path
|
247
|
-
|
90
|
+
ConfigLoader.relative_path(file, loaded_dir_pathname)
|
248
91
|
end
|
249
92
|
|
250
93
|
def loaded_dir_pathname
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module Rubocop
|
7
|
+
# This class represents the configuration of the RuboCop application
|
8
|
+
# and all its cops. A Config is associated with a YAML configuration
|
9
|
+
# file from which it was read. Several different Configs can be used
|
10
|
+
# during a run of the rubocop program, if files in several
|
11
|
+
# directories are inspected.
|
12
|
+
class ConfigLoader
|
13
|
+
DOTFILE = '.rubocop.yml'
|
14
|
+
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
15
|
+
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
|
16
|
+
AUTO_GENERATED_FILE = 'rubocop-todo.yml'
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :debug
|
20
|
+
alias_method :debug?, :debug
|
21
|
+
|
22
|
+
def load_file(path)
|
23
|
+
path = File.absolute_path(path)
|
24
|
+
hash = YAML.load_file(path)
|
25
|
+
puts "configuration from #{path}" if debug?
|
26
|
+
contains_auto_generated_config = false
|
27
|
+
|
28
|
+
base_configs(path, hash['inherit_from']).reverse_each do |base_config|
|
29
|
+
if File.basename(base_config.loaded_path) == DOTFILE
|
30
|
+
make_excludes_absolute(base_config)
|
31
|
+
end
|
32
|
+
base_config.each do |key, value|
|
33
|
+
if value.is_a?(Hash)
|
34
|
+
hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
if base_config.loaded_path.include?(AUTO_GENERATED_FILE)
|
38
|
+
contains_auto_generated_config = true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
hash.delete('inherit_from')
|
43
|
+
config = Config.new(hash, path)
|
44
|
+
config.warn_unless_valid
|
45
|
+
config.contains_auto_generated_config = contains_auto_generated_config
|
46
|
+
config
|
47
|
+
end
|
48
|
+
|
49
|
+
def make_excludes_absolute(config)
|
50
|
+
if config['AllCops'] && config['AllCops']['Excludes']
|
51
|
+
config['AllCops']['Excludes'].map! do |exclude_elem|
|
52
|
+
if exclude_elem.is_a?(String) && !exclude_elem.start_with?('/')
|
53
|
+
File.join(File.dirname(config.loaded_path), exclude_elem)
|
54
|
+
else
|
55
|
+
exclude_elem
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def relative_path(path, base)
|
62
|
+
path_name = Pathname.new(File.expand_path(path))
|
63
|
+
path_name.relative_path_from(Pathname.new(base)).to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
# Return an extended merge of two hashes. That is, a normal hash merge,
|
67
|
+
# with the addition that any value that is a hash, and occurs in both
|
68
|
+
# arguments (i.e., cop names), will also be merged.
|
69
|
+
def merge(base_hash, derived_hash)
|
70
|
+
result = base_hash.merge(derived_hash)
|
71
|
+
keys_appearing_in_both = base_hash.keys & derived_hash.keys
|
72
|
+
keys_appearing_in_both.each do |key|
|
73
|
+
if base_hash[key].is_a?(Hash)
|
74
|
+
result[key] = base_hash[key].merge(derived_hash[key])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
def base_configs(path, inherit_from)
|
81
|
+
Array(inherit_from).map do |f|
|
82
|
+
f = File.join(File.dirname(path), f) unless f.start_with?('/')
|
83
|
+
print 'Inheriting ' if debug?
|
84
|
+
load_file(f)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns the path of .rubocop.yml searching upwards in the
|
89
|
+
# directory structure starting at the given directory where the
|
90
|
+
# inspected file is. If no .rubocop.yml is found there, the
|
91
|
+
# user's home directory is checked. If there's no .rubocop.yml
|
92
|
+
# there either, the path to the default file is returned.
|
93
|
+
def configuration_file_for(target_dir)
|
94
|
+
config_files_in_path(target_dir).first || DEFAULT_FILE
|
95
|
+
end
|
96
|
+
|
97
|
+
def configuration_from_file(config_file)
|
98
|
+
config = load_file(config_file)
|
99
|
+
found_files = config_files_in_path(config_file)
|
100
|
+
if found_files.any? && found_files.last != config_file
|
101
|
+
print 'AllCops/Excludes ' if debug?
|
102
|
+
add_excludes_from_higher_level(config, load_file(found_files.last))
|
103
|
+
end
|
104
|
+
make_excludes_absolute(config)
|
105
|
+
merge_with_default(config, config_file)
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_excludes_from_higher_level(config, highest_config)
|
109
|
+
if highest_config['AllCops'] && highest_config['AllCops']['Excludes']
|
110
|
+
config['AllCops'] ||= {}
|
111
|
+
config['AllCops']['Excludes'] ||= []
|
112
|
+
highest_config['AllCops']['Excludes'].each do |path|
|
113
|
+
unless path.is_a?(Regexp) || path.start_with?('/')
|
114
|
+
path = File.join(File.dirname(highest_config.loaded_path), path)
|
115
|
+
end
|
116
|
+
config['AllCops']['Excludes'] << path
|
117
|
+
end
|
118
|
+
config['AllCops']['Excludes'].uniq!
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def default_configuration
|
123
|
+
@default_configuration ||= begin
|
124
|
+
print 'Default ' if debug?
|
125
|
+
load_file(DEFAULT_FILE)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def merge_with_default(config, config_file)
|
130
|
+
result = Config.new(merge(default_configuration, config), config_file)
|
131
|
+
result.contains_auto_generated_config =
|
132
|
+
config.contains_auto_generated_config
|
133
|
+
result
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def config_files_in_path(target)
|
139
|
+
possible_config_files = dirs_to_search(target).map do |dir|
|
140
|
+
File.join(dir, DOTFILE)
|
141
|
+
end
|
142
|
+
possible_config_files.select { |config_file| File.exist?(config_file) }
|
143
|
+
end
|
144
|
+
|
145
|
+
def dirs_to_search(target_dir)
|
146
|
+
dirs_to_search = []
|
147
|
+
target_dir_pathname = Pathname.new(File.expand_path(target_dir))
|
148
|
+
target_dir_pathname.ascend do |dir_pathname|
|
149
|
+
dirs_to_search << dir_pathname.to_s
|
150
|
+
end
|
151
|
+
dirs_to_search << Dir.home
|
152
|
+
dirs_to_search
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|