summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs/file_system/repository
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-04-20 17:41:46 +0100
committerThom May <thom@chef.io>2016-05-05 14:35:10 +0100
commitf4e7711817ff704286bcde22a9ca95415028e58f (patch)
treed79748b0c537877b592852c6ec22e5cdfb52bc89 /lib/chef/chef_fs/file_system/repository
parent0f5e73eebbb509750a380ccddfaf112ba415dd4a (diff)
downloadchef-f4e7711817ff704286bcde22a9ca95415028e58f.tar.gz
properly deal with loading ruby files
Diffstat (limited to 'lib/chef/chef_fs/file_system/repository')
-rw-r--r--lib/chef/chef_fs/file_system/repository/base_file.rb17
1 files changed, 14 insertions, 3 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 d5ef26887e..514ffc9584 100644
--- a/lib/chef/chef_fs/file_system/repository/base_file.rb
+++ b/lib/chef/chef_fs/file_system/repository/base_file.rb
@@ -41,11 +41,15 @@ class Chef
end
def is_json_file?
- File.extname(name) == ".json"
+ File.extname(file_path) == ".json"
+ end
+
+ def is_ruby_file?
+ File.extname(file_path) == ".rb"
end
def name_valid?
- !name.start_with?(".") && is_json_file?
+ !name.start_with?(".") && (is_json_file? || is_ruby_file?)
end
def fs_entry_valid?
@@ -91,12 +95,19 @@ class Chef
end
def read
- File.open(file_path, "rb") { |f| f.read }
+ if is_ruby_file?
+ data_handler.from_ruby(file_path).to_json
+ else
+ File.open(file_path, "rb") { |f| f.read }
+ end
rescue Errno::ENOENT
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end
def write(content)
+ if is_ruby_file?
+ raise Chef::ChefFS::FileSystem::RubyFileError.new(:write, self)
+ end
if content && write_pretty_json && is_json_file?
content = minimize(content, self)
end