class ChefZero::DataStore::DefaultFacade
The DefaultFacade exists to layer defaults on top of an existing data store. When you create an org, you just create the directory itself: the rest of the org (such as environments/_default) will not actually exist anywhere, but when you get(/organizations/org/environments/_default), the DefaultFacade will create one for you on the fly.
acls in particular are instantiated on the fly using this method.
Attributes
default_creator[R]
real_store[R]
Public Class Methods
new(real_store, single_org, osc_compat, superusers = nil)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 16 def initialize(real_store, single_org, osc_compat, superusers = nil) @real_store = real_store @default_creator = ChefData::DefaultCreator.new(self, single_org, osc_compat, superusers) clear end
Public Instance Methods
clear()
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 25 def clear real_store.clear if real_store.respond_to?(:clear) default_creator.clear end
create(path, name, data, *options)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 49 def create(path, name, data, *options) if default_creator.exists?(path + [ name ]) && !options.include?(:create_dir) raise DataAlreadyExistsError.new(path + [name]) end begin real_store.create(path, name, data, *options) rescue DataNotFoundError if default_creator.exists?(path) real_store.create(path, name, data, :create_dir, *options) else raise end end options_hash = options.last.is_a?(Hash) ? options.last : {} default_creator.created(path + [ name ], options_hash[:requestor], options.include?(:create_dir)) end
create_dir(path, name, *options)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 30 def create_dir(path, name, *options) if default_creator.exists?(path + [ name ]) && !options.include?(:recursive) raise DataAlreadyExistsError.new(path + [name]) end begin real_store.create_dir(path, name, *options) rescue DataNotFoundError if default_creator.exists?(path) real_store.create_dir(path, name, :recursive, *options) else raise end end options_hash = options.last.is_a?(Hash) ? options.last : {} default_creator.created(path + [ name ], options_hash[:requestor], options.include?(:recursive)) end
delete(path, *options)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 98 def delete(path, *options) deleted = default_creator.deleted(path) begin real_store.delete(path) rescue DataNotFoundError if !deleted raise end end end
delete_dir(path, *options)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 109 def delete_dir(path, *options) deleted = default_creator.deleted(path) begin real_store.delete_dir(path, *options) rescue DataNotFoundError if !deleted raise end end end
exists?(path)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 138 def exists?(path) real_store.exists?(path) || default_creator.exists?(path) end
exists_dir?(path)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 142 def exists_dir?(path) real_store.exists_dir?(path) || default_creator.exists?(path) end
get(path, request = nil)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 68 def get(path, request = nil) real_store.get(path, request) rescue DataNotFoundError result = default_creator.get(path) if result FFI_Yajl::Encoder.encode(result, :pretty => true) else raise end end
list(path)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 120 def list(path) default_results = default_creator.list(path) begin real_results = real_store.list(path) if default_results (real_results + default_results).uniq else real_results end rescue DataNotFoundError if default_results default_results else raise end end end
set(path, data, *options)
click to toggle source
# File lib/chef_zero/data_store/default_facade.rb, line 79 def set(path, data, *options) begin real_store.set(path, data, *options) rescue DataNotFoundError if options.include?(:create_dir) || options.include?(:create) && default_creator.exists?(path[0..-2]) || default_creator.exists?(path) real_store.set(path, data, :create, :create_dir, *options) else raise end end if options.include?(:create) options_hash = options.last.is_a?(Hash) ? options.last : {} default_creator.created(path, options_hash[:requestor], options.include?(:create_dir)) end end