diff options
author | John Keiser <jkeiser@opscode.com> | 2014-04-21 15:35:34 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-04-21 15:35:34 -0700 |
commit | 16ee59c619a0f40f17b9c64a0e2be6a19140df9d (patch) | |
tree | e858cf9c92428c54d15e16d2e8136643bab2d797 /lib/chef_zero/data_store/v2_to_v1_adapter.rb | |
parent | 30a1b6b918902fa526ed77c185a2928cb2a3f640 (diff) | |
download | chef-zero-16ee59c619a0f40f17b9c64a0e2be6a19140df9d.tar.gz |
Add ability to run specs against existing Chef::ChefFS
Diffstat (limited to 'lib/chef_zero/data_store/v2_to_v1_adapter.rb')
-rw-r--r-- | lib/chef_zero/data_store/v2_to_v1_adapter.rb | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/chef_zero/data_store/v2_to_v1_adapter.rb b/lib/chef_zero/data_store/v2_to_v1_adapter.rb new file mode 100644 index 0000000..6bc72c0 --- /dev/null +++ b/lib/chef_zero/data_store/v2_to_v1_adapter.rb @@ -0,0 +1,107 @@ +# +# Author:: John Keiser (<jkeiser@opscode.com>) +# Copyright:: Copyright (c) 2014 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef_zero/data_store/interface_v1' + +module ChefZero + module DataStore + class V2ToV1Adapter < ChefZero::DataStore::InterfaceV1 + def initialize + @single_org = 'chef' + end + + attr_reader :real_store + attr_reader :single_org + + def clear + real_store.clear + real_store.create_dir([ 'organizations' ], single_org) + end + + def create_dir(path, name, *options) + fix_exceptions do + real_store.create_dir(fix_path(path), name, *options) + end + end + + def create(path, name, data, *options) + fix_exceptions do + real_store.create(fix_path(path), name, data, *options) + end + end + + def get(path, request=nil) + fix_exceptions do + real_store.get(fix_path(path), request) + end + end + + def set(path, data, *options) + fix_exceptions do + real_store.set(fix_path(path), data, *options) + end + end + + def delete(path) + fix_exceptions do + real_store.delete(fix_path(path)) + end + end + + def delete_dir(path, *options) + fix_exceptions do + real_store.delete_dir(fix_path(path), *options) + end + end + + def list(path) + fix_exceptions do + real_store.list(fix_path(path)) + end + end + + def exists?(path) + fix_exceptions do + real_store.exists?(fix_path(path)) + end + end + + def exists_dir?(path) + fix_exceptions do + real_store.exists_dir?(fix_path(path)) + end + end + + protected + + def fix_exceptions + begin + yield + rescue DataAlreadyExistsError => e + raise DataAlreadyExistsError.new(e.path[2..-1], e) + rescue DataNotFoundError => e + raise DataNotFoundError.new(e.path[2..-1], e) + end + end + + def fix_path(path) + [ 'organizations', single_org ] + path + end + end + end +end |