Class: ChefZero::DataStore::V1ToV2Adapter
- Inherits:
-
InterfaceV2
- Object
- InterfaceV1
- InterfaceV2
- ChefZero::DataStore::V1ToV2Adapter
- Defined in:
- lib/chef_zero/data_store/v1_to_v2_adapter.rb
Instance Attribute Summary collapse
-
#real_store ⇒ Object
readonly
Returns the value of attribute real_store.
-
#single_org ⇒ Object
readonly
Returns the value of attribute single_org.
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, options = {}) ⇒ V1ToV2Adapter
constructor
A new instance of V1ToV2Adapter.
- #list(path) ⇒ Object
- #set(path, data, *options) ⇒ Object
Methods inherited from InterfaceV2
Methods inherited from InterfaceV1
Constructor Details
#initialize(real_store, single_org, options = {}) ⇒ V1ToV2Adapter
Returns a new instance of V1ToV2Adapter.
6 7 8 9 10 11 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 6 def initialize(real_store, single_org, = {}) @real_store = real_store @single_org = single_org @options = clear end |
Instance Attribute Details
#real_store ⇒ Object (readonly)
Returns the value of attribute real_store.
13 14 15 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 13 def real_store @real_store end |
#single_org ⇒ Object (readonly)
Returns the value of attribute single_org.
14 15 16 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 14 def single_org @single_org end |
Instance Method Details
#clear ⇒ Object
16 17 18 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 16 def clear real_store.clear if real_store.respond_to?(:clear) end |
#create(path, name, data, *options) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 30 def create(path, name, data, *) raise DataNotFoundError.new(path) if skip_organizations?(path) raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name) raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2 fix_exceptions do real_store.create(path[2..-1], name, data, *) end end |
#create_dir(path, name, *options) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 20 def create_dir(path, name, *) raise DataNotFoundError.new(path) if skip_organizations?(path) raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name) raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2 fix_exceptions do real_store.create_dir(path[2..-1], name, *) end end |
#delete(path, *options) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 65 def delete(path, *) raise DataNotFoundError.new(path) if skip_organizations?(path) && !.include?(:recursive) fix_exceptions do real_store.delete(path[2..-1]) end end |
#delete_dir(path, *options) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 73 def delete_dir(path, *) raise DataNotFoundError.new(path) if skip_organizations?(path) && !.include?(:recursive) fix_exceptions do real_store.delete_dir(path[2..-1], *) end end |
#exists?(path) ⇒ Boolean
95 96 97 98 99 100 101 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 95 def exists?(path) return false if skip_organizations?(path) fix_exceptions do real_store.exists?(path[2..-1]) end end |
#exists_dir?(path) ⇒ Boolean
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 103 def exists_dir?(path) return false if skip_organizations?(path) if path == [] true elsif path == [ "organizations" ] || path == [ "users" ] true else return false if skip_organizations?(path) fix_exceptions do real_store.exists_dir?(path[2..-1]) end end end |
#get(path, request = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 40 def get(path, request = nil) raise DataNotFoundError.new(path) if skip_organizations?(path) fix_exceptions do # Make it so build_uri will include /organizations/ORG inside the V1 data store if request && request.rest_base_prefix.size == 0 old_base_uri = request.base_uri request.base_uri = File.join(request.base_uri, "organizations", single_org) end begin real_store.get(path[2..-1], request) ensure request.base_uri = old_base_uri if request && request.rest_base_prefix.size == 0 end end end |
#list(path) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 81 def list(path) raise DataNotFoundError.new(path) if skip_organizations?(path) if path == [] [ "organizations" ] elsif path == [ "organizations" ] [ single_org ] else fix_exceptions do real_store.list(path[2..-1]) end end end |
#set(path, data, *options) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/chef_zero/data_store/v1_to_v2_adapter.rb', line 57 def set(path, data, *) raise DataNotFoundError.new(path) if skip_organizations?(path) fix_exceptions do real_store.set(path[2..-1], data, *) end end |