Parent

Files

Class/Module Index [+]

Quicksearch

Chef::ChefFS::FileSystem::ChefRepositoryFileSystemEntry

ChefRepositoryFileSystemEntry works just like FileSystemEntry, except can inflate Chef objects

Public Class Methods

new(name, parent, file_path = nil, data_handler = nil) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 29
def initialize(name, parent, file_path = nil, data_handler = nil)
  super(name, parent, file_path)
  @data_handler = data_handler
end

Public Instance Methods

can_have_child?(name, is_dir) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 51
def can_have_child?(name, is_dir)
  !is_dir && name[-5..-1] == '.json'
end
chef_object() click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 42
def chef_object
  begin
    return data_handler.chef_object(JSON.parse(read, :create_additions => false))
  rescue
    Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}")
  end
  nil
end
children() click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 69
def children
  # Except cookbooks and data bag dirs, all things must be json files
  begin
    Dir.entries(file_path).sort.
        select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
        map { |child_name| make_child(child_name) }
  rescue Errno::ENOENT
    raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
  end
end
data_handler() click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 38
def data_handler
  @data_handler || parent.data_handler
end
minimize(file_contents, entry) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 62
def minimize(file_contents, entry)
  object = JSONCompat.from_json(file_contents, :create_additions => false)
  object = data_handler.normalize(object, entry)
  object = data_handler.minimize(object, entry)
  JSONCompat.to_json_pretty(object)
end
write(file_contents) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 55
def write(file_contents)
  if file_contents && write_pretty_json && name[-5..-1] == '.json'
    file_contents = minimize(file_contents, self)
  end
  super(file_contents)
end
write_pretty_json() click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 34
def write_pretty_json
  root.write_pretty_json
end

Protected Instance Methods

make_child(child_name) click to toggle source
# File lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb, line 82
def make_child(child_name)
  ChefRepositoryFileSystemEntry.new(child_name, self)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.