summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-05-03 12:02:48 +0100
committerThom May <thom@chef.io>2016-05-05 14:35:33 +0100
commitdb3567feabbb4ab6de40ab22ce44559129c63532 (patch)
treeb2985169da0d72d4fcb4f7009bc64c4d343584c4
parent5023c4348652cdac96dcd4119a36b908dfa3faef (diff)
downloadchef-db3567feabbb4ab6de40ab22ce44559129c63532.tar.gz
Repository files need to figure out their extension
Signed-off-by: Thom May <thom@may.lt>
-rw-r--r--lib/chef/chef_fs/file_system/repository/base_file.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb
index 514ffc9584..344f9e6085 100644
--- a/lib/chef/chef_fs/file_system/repository/base_file.rb
+++ b/lib/chef/chef_fs/file_system/repository/base_file.rb
@@ -31,9 +31,22 @@ class Chef
def initialize(name, parent)
@parent = parent
+
+ if %w{ .rb .json }.include? File.extname(name)
+ name = File.basename(name, ".*")
+ end
+
+ file_path = "#{parent.file_path}/#{name}"
+
+ Chef::Log.debug "BaseFile: Detecting file extension for #{name}"
+ ext = File.exist?(file_path + ".rb") ? ".rb" : ".json"
+ name += ext
+ file_path += ext
+
+ Chef::Log.debug "BaseFile: got a file path of #{file_path} for #{name}"
@name = name
@path = Chef::ChefFS::PathUtils.join(parent.path, name)
- @file_path = "#{parent.file_path}/#{name}"
+ @file_path = file_path
end
def dir?