diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2016-02-24 20:23:48 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2016-02-24 21:27:18 -0800 |
commit | 3077de7bd41ffd55895276f61fa968f0f0de8c70 (patch) | |
tree | cedca4b1f736d78223d67a84945fc806d89fcc1f | |
parent | b5b94dc98bca9e0158b6ddab29e14ca4edf5ac02 (diff) | |
download | chef-3077de7bd41ffd55895276f61fa968f0f0de8c70.tar.gz |
Refactor dot_d loading for workstation_config_loader to use mixin
-rw-r--r-- | chef-config/lib/chef-config/mixin/dot_d.rb | 38 | ||||
-rw-r--r-- | chef-config/lib/chef-config/workstation_config_loader.rb | 22 |
2 files changed, 41 insertions, 19 deletions
diff --git a/chef-config/lib/chef-config/mixin/dot_d.rb b/chef-config/lib/chef-config/mixin/dot_d.rb new file mode 100644 index 0000000000..dc751f8964 --- /dev/null +++ b/chef-config/lib/chef-config/mixin/dot_d.rb @@ -0,0 +1,38 @@ +# +# Copyright:: Copyright 2016, Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "chef-config/path_helper" + +module ChefConfig + module Mixin + module DotD + def load_dot_d(path) + dot_d_files = + begin + entries = Array.new + entries << Dir.glob(File.join( + ChefConfig::PathHelper.escape_glob_dir(path), "*.rb")) + entries.flatten.select do |entry| + File.file?(entry) + end + end + dot_d_files.sort.map do |conf| + read_config(IO.read(conf), conf) + end + end + end + end +end diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb index efc7049ec1..89e703ff8c 100644 --- a/chef-config/lib/chef-config/workstation_config_loader.rb +++ b/chef-config/lib/chef-config/workstation_config_loader.rb @@ -21,9 +21,11 @@ require "chef-config/exceptions" require "chef-config/logger" require "chef-config/path_helper" require "chef-config/windows" +require "chef-config/mixin/dot_d" module ChefConfig class WorkstationConfigLoader + include ChefConfig::Mixin::DotD # Path to a config file requested by user, (e.g., via command line option). Can be nil attr_accessor :explicit_config_file @@ -72,7 +74,7 @@ module ChefConfig read_config(IO.read(config_location), config_location) end - load_conf_d_directory + load_dot_d(Config[:conf_d_dir]) if Config[:conf_d_dir] end # (Private API, public for test purposes) @@ -126,24 +128,6 @@ module ChefConfig end end - def load_conf_d_directory - conf_d_files.sort.map do |conf| - read_config(IO.read(conf), conf) - end - end - - def conf_d_files - @conf_d_files ||= - begin - entries = Array.new - entries << Dir.glob(File.join(PathHelper.escape_glob_dir( - Config[:conf_d_dir]), "*.rb")) if Config[:conf_d_dir] - entries.flatten.select do |entry| - File.file?(entry) - end - end - end - def working_directory a = if ChefConfig.windows? env["CD"] |