diff options
author | Thom May <thom@chef.io> | 2016-04-20 17:41:46 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-05-05 14:35:10 +0100 |
commit | f4e7711817ff704286bcde22a9ca95415028e58f (patch) | |
tree | d79748b0c537877b592852c6ec22e5cdfb52bc89 /lib/chef/chef_fs/data_handler | |
parent | 0f5e73eebbb509750a380ccddfaf112ba415dd4a (diff) | |
download | chef-f4e7711817ff704286bcde22a9ca95415028e58f.tar.gz |
properly deal with loading ruby files
Diffstat (limited to 'lib/chef/chef_fs/data_handler')
-rw-r--r-- | lib/chef/chef_fs/data_handler/data_handler_base.rb | 21 | ||||
-rw-r--r-- | lib/chef/chef_fs/data_handler/environment_data_handler.rb | 2 | ||||
-rw-r--r-- | lib/chef/chef_fs/data_handler/role_data_handler.rb | 2 |
3 files changed, 13 insertions, 12 deletions
diff --git a/lib/chef/chef_fs/data_handler/data_handler_base.rb b/lib/chef/chef_fs/data_handler/data_handler_base.rb index b30ae9c708..b34aff4b98 100644 --- a/lib/chef/chef_fs/data_handler/data_handler_base.rb +++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb @@ -24,15 +24,14 @@ class Chef object end - # - # Takes a name like blah.json and removes the .json from it. - # - def remove_dot_json(name) - if name.length < 5 || name[-5, 5] != ".json" - raise "Invalid name #{path}: must end in .json" + def remove_file_extension(name, ext = ".*") + if %w{ .rb .json }.include?(File.extname(name)) + File.basename(name, ext) + else + name end - name[0, name.length - 5] end + alias_method :remove_dot_json, :remove_file_extension # # Return true if minimize() should preserve a key even if it is the same @@ -109,8 +108,10 @@ class Chef # # Bring in an instance of this object from Ruby. (Like roles/x.rb) # - def from_ruby(ruby) - chef_class.from_file(ruby).to_hash + def from_ruby(path) + r = chef_class.new + r.from_file(path) + r.to_hash end # @@ -192,7 +193,7 @@ class Chef # @yield [s] callback to handle errors # @yieldparam [s<string>] error message def verify_integrity(object, entry) - base_name = remove_dot_json(entry.name) + base_name = remove_file_extension(entry.name) if object["name"] != base_name yield("Name must be '#{base_name}' (is '#{object['name']}')") end diff --git a/lib/chef/chef_fs/data_handler/environment_data_handler.rb b/lib/chef/chef_fs/data_handler/environment_data_handler.rb index 8d066764be..68f6daee9a 100644 --- a/lib/chef/chef_fs/data_handler/environment_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/environment_data_handler.rb @@ -7,7 +7,7 @@ class Chef class EnvironmentDataHandler < DataHandlerBase def normalize(environment, entry) normalize_hash(environment, { - "name" => remove_dot_json(entry.name), + "name" => remove_file_extension(entry.name), "description" => "", "cookbook_versions" => {}, "default_attributes" => {}, diff --git a/lib/chef/chef_fs/data_handler/role_data_handler.rb b/lib/chef/chef_fs/data_handler/role_data_handler.rb index 74533cff05..b09c146a5d 100644 --- a/lib/chef/chef_fs/data_handler/role_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/role_data_handler.rb @@ -7,7 +7,7 @@ class Chef class RoleDataHandler < DataHandlerBase def normalize(role, entry) result = normalize_hash(role, { - "name" => remove_dot_json(entry.name), + "name" => remove_file_extension(entry.name), "description" => "", "json_class" => "Chef::Role", "chef_type" => "role", |