Class: ChefZero::DataStore::DefaultFacade
- Inherits:
-
InterfaceV2
- Object
- InterfaceV1
- InterfaceV2
- ChefZero::DataStore::DefaultFacade
- Defined in:
- lib/chef_zero/data_store/default_facade.rb
Overview
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.
Instance Attribute Summary collapse
-
#default_creator ⇒ Object
readonly
Returns the value of attribute default_creator.
-
#real_store ⇒ Object
readonly
Returns the value of attribute real_store.
Instance Method Summary collapse
- #clear ⇒ Object
- #create(path, name, data, *options) ⇒ Object
- #create_dir(path, name, *options) ⇒ Object
- #delete(path, *options) ⇒ Object
- #delete_dir(path, *options) ⇒ Object
- #exists?(path) ⇒ Boolean
- #exists_dir?(path) ⇒ Boolean
- #get(path, request = nil) ⇒ Object
-
#initialize(real_store, single_org, osc_compat, superusers = nil) ⇒ DefaultFacade
constructor
A new instance of DefaultFacade.
- #list(path) ⇒ Object
- #set(path, data, *options) ⇒ Object
Methods inherited from InterfaceV2
Methods inherited from InterfaceV1
Constructor Details
#initialize(real_store, single_org, osc_compat, superusers = nil) ⇒ DefaultFacade
Returns a new instance of DefaultFacade.
16 17 18 19 20 |
# 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 |
Instance Attribute Details
#default_creator ⇒ Object (readonly)
Returns the value of attribute default_creator.
23 24 25 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 23 def default_creator @default_creator end |
#real_store ⇒ Object (readonly)
Returns the value of attribute real_store.
22 23 24 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 22 def real_store @real_store end |
Instance Method Details
#clear ⇒ Object
25 26 27 28 |
# 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) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 49 def create(path, name, data, *) if default_creator.exists?(path + [ name ]) && !.include?(:create_dir) raise DataAlreadyExistsError.new(path + [name]) end begin real_store.create(path, name, data, *) rescue DataNotFoundError if default_creator.exists?(path) real_store.create(path, name, data, :create_dir, *) else raise end end = .last.is_a?(Hash) ? .last : {} default_creator.created(path + [ name ], [:requestor], .include?(:create_dir)) end |
#create_dir(path, name, *options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 30 def create_dir(path, name, *) if default_creator.exists?(path + [ name ]) && !.include?(:recursive) raise DataAlreadyExistsError.new(path + [name]) end begin real_store.create_dir(path, name, *) rescue DataNotFoundError if default_creator.exists?(path) real_store.create_dir(path, name, :recursive, *) else raise end end = .last.is_a?(Hash) ? .last : {} default_creator.created(path + [ name ], [:requestor], .include?(:recursive)) end |
#delete(path, *options) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 98 def delete(path, *) deleted = default_creator.deleted(path) begin real_store.delete(path) rescue DataNotFoundError unless deleted raise end end end |
#delete_dir(path, *options) ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 109 def delete_dir(path, *) deleted = default_creator.deleted(path) begin real_store.delete_dir(path, *) rescue DataNotFoundError unless deleted raise end end end |
#exists?(path) ⇒ Boolean
138 139 140 |
# 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) ⇒ Boolean
142 143 144 |
# 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) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# 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) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# 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) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/chef_zero/data_store/default_facade.rb', line 79 def set(path, data, *) begin real_store.set(path, data, *) rescue DataNotFoundError if .include?(:create_dir) || .include?(:create) && default_creator.exists?(path[0..-2]) || default_creator.exists?(path) real_store.set(path, data, :create, :create_dir, *) else raise end end if .include?(:create) = .last.is_a?(Hash) ? .last : {} default_creator.created(path, [:requestor], .include?(:create_dir)) end end |