Object
# File lib/chef_zero/data_store/memory_store.rb, line 29 def clear @data = {} # Create containers create_dir([], 'clients') create_dir([], 'cookbooks') create_dir([], 'data') create_dir([], 'environments') create_dir([], 'file_store') create_dir(['file_store'], 'checksums') create_dir([], 'nodes') create_dir([], 'roles') create_dir([], 'sandboxes') create_dir([], 'users') # Set defaults create(['clients'], 'chef-validator', '{ "validator": true }') create(['clients'], 'chef-webui', '{ "admin": true }') create(['environments'], '_default', '{ "description": "The default Chef environment" }') create(['users'], 'admin', '{ "admin": true }') end
# File lib/chef_zero/data_store/memory_store.rb, line 63 def create(path, name, data, *options) if !data.is_a?(String) raise "set only works with strings" end parent = _get(path, options.include?(:create_dir)) if parent.has_key?(name) raise DataAlreadyExistsError.new(path + [name]) end parent[name] = data end
# File lib/chef_zero/data_store/memory_store.rb, line 51 def create_dir(path, name, *options) parent = _get(path, options.include?(:recursive)) if parent.has_key?(name) if !options.include?(:recursive) raise DataAlreadyExistsError.new(path + [name]) end else parent[name] = {} end end
# File lib/chef_zero/data_store/memory_store.rb, line 98 def delete(path) parent = _get(path[0,path.length-1]) if !parent.has_key?(path[-1]) raise DataNotFoundError.new(path) end if !parent[path[-1]].is_a?(String) raise "delete only works with strings: #{path}" end parent.delete(path[-1]) end
# File lib/chef_zero/data_store/memory_store.rb, line 109 def delete_dir(path, *options) parent = _get(path[0,path.length-1]) if !parent.has_key?(path[-1]) raise DataNotFoundError.new(path) end if !parent[path[-1]].is_a?(Hash) raise "delete_dir only works with directories: #{path}" end parent.delete(path[-1]) end
# File lib/chef_zero/data_store/memory_store.rb, line 128 def exists?(path) begin get(path) return true rescue DataNotFoundError return false end end
# File lib/chef_zero/data_store/memory_store.rb, line 137 def exists_dir?(path) begin dir = _get(path) if !dir.is_a? Hash raise "exists_dir? only works with directories (#{path} = #{dir.class}" end return true rescue DataNotFoundError return false end end
# File lib/chef_zero/data_store/memory_store.rb, line 76 def get(path, request=nil) value = _get(path) if value.is_a?(Hash) raise "get() called on directory #{path.join('/')}" end value end
# File lib/chef_zero/data_store/memory_store.rb, line 120 def list(path) dir = _get(path) if !dir.is_a? Hash raise "list only works with directories (#{path} = #{dir.class}" end dir.keys.sort end
# File lib/chef_zero/data_store/memory_store.rb, line 84 def set(path, data, *options) if !data.is_a?(String) raise "set only works with strings: #{path} = #{data.inspect}" end # Get the parent parent = _get(path[0..-2], options.include?(:create_dir)) if !options.include?(:create) && !parent[path[-1]] raise DataNotFoundError.new(path) end parent[path[-1]] = data end
Generated with the Darkfish Rdoc Generator 2.