diff options
author | Mal Graty <mal.graty@googlemail.com> | 2013-03-06 09:33:48 +0000 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-05-24 07:12:45 -0700 |
commit | 1c004dc6f1320cd0b2d2c785e197e599e22115dd (patch) | |
tree | bc44136d86e2c300053966422d0ff92d46720b14 /lib/chef/cookbook | |
parent | 2de2f4a4cde5a58247caaf1d2b8a1a10c8d3a024 (diff) | |
download | chef-1c004dc6f1320cd0b2d2c785e197e599e22115dd.tar.gz |
Lazy load metadata
Diffstat (limited to 'lib/chef/cookbook')
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 77db236eca..44782bd7bf 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -19,16 +19,13 @@ class Chef attr_reader :cookbook_pathname - attr_reader :cookbook_name attr_reader :cookbook_settings attr_reader :metadata_filenames def initialize(path, chefignore=nil) @cookbook_path = File.expand_path( path ) @cookbook_pathname = File.basename( path ) - @cookbook_name = @cookbook_pathname @chefignore = chefignore - @metadata = Hash.new @relative_path = /#{Regexp.escape(@cookbook_path)}\/(.+)$/ @cookbook_settings = { :attribute_filenames => {}, @@ -66,14 +63,15 @@ class Chef if empty? Chef::Log.warn "found a directory #{cookbook_name} in the cookbook path, but it contains no cookbook files. skipping." - else - metadata = @metadata.is_a?(Metadata) ? @metadata : metadata(nil) - @cookbook_name = metadata.name.to_sym unless metadata.name.nil? end @cookbook_settings end + def cookbook_name + metadata.name || @cookbook_pathname + end + def cookbook_version return nil if empty? @@ -89,13 +87,16 @@ class Chef c.provider_filenames = cookbook_settings[:provider_filenames].values c.root_filenames = cookbook_settings[:root_filenames].values c.metadata_filenames = @metadata_filenames - c.metadata = metadata(c) - c.name = c.metadata.name.to_sym + c.metadata = load_metadata(c) end end + def metadata + @metadata ||= load_metadata(nil) + end + # Generates the Cookbook::Metadata object - def metadata(cookbook_version) + def load_metadata(cookbook_version) @metadata = Chef::Cookbook::Metadata.new(cookbook_version) @metadata_filenames.each do |metadata_file| case metadata_file @@ -158,18 +159,18 @@ class Chef def apply_ruby_metadata(file) begin - @metadata.from_file(file) + metadata.from_file(file) rescue JSON::ParserError - Chef::Log.error("Error evaluating metadata.rb for #@cookbook_name in " + file) + Chef::Log.error("Error evaluating metadata.rb for #{cookbook_name} in " + file) raise end end def apply_json_metadata(file) begin - @metadata.from_json(IO.read(file)) + metadata.from_json(IO.read(file)) rescue JSON::ParserError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #@cookbook_name in " + file) + Chef::Log.error("Couldn't parse cookbook metadata JSON for #{cookbook_name} in " + file) raise end end |