diff options
Diffstat (limited to 'lib/chef/chef_fs/file_system/repository')
-rw-r--r-- | lib/chef/chef_fs/file_system/repository/base_file.rb | 17 |
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 |