-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow callers from some files to be ignored
- Loading branch information
1 parent
b912cb3
commit 1527f80
Showing
6 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'yaml' | ||
|
||
module MetaRequest | ||
module Config | ||
def self.ignored_path?(file_path) | ||
ingore_paths.any? { |ignore_path| ignore_path.match(file_path) } | ||
end | ||
|
||
def self.config_file | ||
@@config_file ||= load_and_parse_config_file | ||
end | ||
|
||
private | ||
|
||
def self.ingore_paths | ||
config_file[:ignore_paths] | ||
end | ||
|
||
def self.load_and_parse_config_file | ||
@@config_file = load_config_file | ||
@@config_file[:ignore_paths] ||= [] | ||
@@config_file[:ignore_paths].map! do |ignore_path| | ||
Regexp.new(ignore_path) | ||
end | ||
@@config_file.freeze | ||
end | ||
|
||
def self.load_config_file | ||
YAML.load_file("#{MetaRequest.rails_root}/config/meta_request.yml") || {} | ||
rescue Errno::ENOENT | ||
{} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module MetaRequest | ||
VERSION = '0.4.2' | ||
VERSION = '0.4.3' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'test_helper' | ||
require 'tempfile' | ||
require 'fileutils' | ||
|
||
describe MetaRequest::Config do | ||
CONFIG_DIRECTORY = "#{MetaRequest.rails_root}/config" | ||
CONFIG_FILE_PATH = "#{CONFIG_DIRECTORY}/meta_request.yml" | ||
|
||
def write_config_file(config) | ||
file = File.new(CONFIG_FILE_PATH, "w") | ||
file.write(config.to_yaml) | ||
file.close | ||
end | ||
|
||
before(:each) do | ||
FileUtils.mkdir_p(CONFIG_DIRECTORY) | ||
end | ||
|
||
after(:each) do | ||
FileUtils.remove_dir(CONFIG_DIRECTORY, force: true) | ||
MetaRequest::Config.class_variable_set(:@@config_file, nil) | ||
end | ||
|
||
describe 'config_file' do | ||
it 'provides default config when config file is not present' do | ||
assert_equal [], MetaRequest::Config.config_file[:ignore_paths] | ||
end | ||
|
||
it 'provides default config when config file is empty' do | ||
write_config_file(nil) | ||
assert_equal [], MetaRequest::Config.config_file[:ignore_paths] | ||
end | ||
|
||
it 'converts ignore paths array to regexs' do | ||
config = { | ||
ignore_paths: ['.*files', 'notaregex'] | ||
} | ||
expected_ignore_paths = config[:ignore_paths].map { |p| Regexp.new(p) } | ||
write_config_file(config) | ||
assert_equal expected_ignore_paths, MetaRequest::Config.config_file[:ignore_paths] | ||
end | ||
end | ||
|
||
describe 'ignored_path?' do | ||
it 'does not ignore files if the ignore_paths option is empty' do | ||
assert_equal [], MetaRequest::Config.config_file[:ignore_paths] | ||
assert_equal false, MetaRequest::Config.ignored_path?('this/file/is/not/ignored.txt') | ||
end | ||
|
||
it 'ignores files that match the ignore_paths' do | ||
config = { | ||
ignore_paths: ['.*ignored.*', 'notaregex'] | ||
} | ||
expected_ignore_paths = config[:ignore_paths].map { |p| Regexp.new(p) } | ||
write_config_file(config) | ||
assert_equal true, MetaRequest::Config.ignored_path?('this/file/is/ignored.txt') | ||
assert_equal true, MetaRequest::Config.ignored_path?('notaregex') | ||
assert_equal false, MetaRequest::Config.ignored_path?('this/file/is/included.txt') | ||
end | ||
|
||
end | ||
end | ||
|