diff options
author | danielsdeleo <dan@chef.io> | 2016-02-05 13:38:51 -0800 |
---|---|---|
committer | danielsdeleo <dan@chef.io> | 2016-02-16 15:26:43 -0800 |
commit | bc439749f1ab1382a822b1e5f58b2bbf64cd315d (patch) | |
tree | 370598e6df9196cad9481669778b29e697d537ae | |
parent | ee563defc6281e1e75b66edae147c1efa23d605e (diff) | |
download | chef-bc439749f1ab1382a822b1e5f58b2bbf64cd315d.tar.gz |
Inline cheffs data bag dir all the way
-rw-r--r-- | lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb | 133 |
1 files changed, 129 insertions, 4 deletions
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb index 427af31cee..ced97439e2 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb @@ -34,7 +34,12 @@ class Chef # class ChefRepositoryFileSystemDataBagsDir < BaseFSDir # With BaseFSDir inlined - class ChefRepositoryFileSystemDataBagsDir < BaseFSObject + # class ChefRepositoryFileSystemDataBagsDir < BaseFSObject + + # With BaseFSObject inlined + class ChefRepositoryFileSystemDataBagsDir + + attr_reader :data_handler # Original ## def initialize(name, parent, path = nil) @@ -53,16 +58,39 @@ class Chef ## @file_path = file_path || "#{parent.file_path}/#{name}" ## end + # BaseFSObject#initialize + ## def initialize(name, parent) + ## @parent = parent + ## @name = name + ## if parent + ## @path = Chef::ChefFS::PathUtils::join(parent.path, name) + ## else + ## if name != "" + ## raise ArgumentError, "Name of root object must be empty string: was '#{name}' instead" + ## end + ## @path = "/" + ## end + ## end + # inlined initialize # # original method signature: def initialize(name, parent, file_path = nil) # # the only caller of this should never give a nil path def initialize(name, parent, file_path) - super(name, parent) + @parent = parent + @name = name + # We are not root, don't need to handle that case + ##if parent + @path = Chef::ChefFS::PathUtils::join(parent.path, name) + ##else + ## if name != "" + ## raise ArgumentError, "Name of root object must be empty string: was '#{name}' instead" + ## end + ## @path = "/" + ##end @file_path = file_path # || "#{parent.file_path}/#{name}" - # Seems like this has to be important, but where is it used? - #@data_handler = Chef::ChefFS::DataHandler::DataBagItemDataHandler.new + @data_handler = Chef::ChefFS::DataHandler::DataBagItemDataHandler.new end @@ -286,6 +314,103 @@ class Chef def empty? children.empty? end + + ############################## + # Inlined from BaseFSObject + ############################## + + attr_reader :name + attr_reader :parent + attr_reader :path + + # unused? + ## def compare_to(other) + ## nil + ## end + + # overridden in subclass + ## def can_have_child?(name, is_dir) + ## false + ## end + + def child(name) + if can_have_child?(name, true) || can_have_child?(name, false) + result = make_child_entry(name) + end + result || NonexistentFSObject.new(name, self) + end + + + # overridden in subclass + ## def children + ## raise NotFoundError.new(self) if !exists? + ## [] + ## end + + # Seems unused + ## def chef_object + ## raise NotFoundError.new(self) if !exists? + ## nil + ## end + + # overridden in subclass + ##def create_child(name, file_contents) + ## raise NotFoundError.new(self) if !exists? + ## raise OperationNotAllowedError.new(:create_child, self) + ##end + + # overridden in subclass + ## def delete(recurse) + ## raise NotFoundError.new(self) if !exists? + ## raise OperationNotAllowedError.new(:delete, self) + ## end + + # overridden in subclass, seems unused? + ##def dir? + ## false + ##end + + # overridden in subclass + ## def exists? + ## true + ## end + + # overridden in subclass + ## def path_for_printing + ## if parent + ## parent_path = parent.path_for_printing + ## if parent_path == "." + ## name + ## else + ## Chef::ChefFS::PathUtils::join(parent.path_for_printing, name) + ## end + ## else + ## name + ## end + ## end + + # Cannot hit all of these cases + ## def root + ## parent ? parent.root : self + ## end + + # the only branch we can hit + def root + parent.root + end + + # unused + ## def read + ## raise NotFoundError.new(self) if !exists? + ## raise OperationNotAllowedError.new(:read, self) + ## end + + # unused + ## def write(file_contents) + ## raise NotFoundError.new(self) if !exists? + ## raise OperationNotAllowedError.new(:write, self) + ## end + end end |