summaryrefslogtreecommitdiff
path: root/lib/chef_zero/data_store
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef_zero/data_store')
-rw-r--r--lib/chef_zero/data_store/default_facade.rb16
-rw-r--r--lib/chef_zero/data_store/memory_store_v2.rb28
-rw-r--r--lib/chef_zero/data_store/raw_file_store.rb28
-rw-r--r--lib/chef_zero/data_store/v1_to_v2_adapter.rb20
-rw-r--r--lib/chef_zero/data_store/v2_to_v1_adapter.rb12
5 files changed, 44 insertions, 60 deletions
diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb
index 5e932d5..d906446 100644
--- a/lib/chef_zero/data_store/default_facade.rb
+++ b/lib/chef_zero/data_store/default_facade.rb
@@ -66,15 +66,13 @@ module ChefZero
end
def get(path, request = nil)
- begin
- real_store.get(path, request)
- rescue DataNotFoundError
- result = default_creator.get(path)
- if result
- FFI_Yajl::Encoder.encode(result, :pretty => true)
- else
- raise
- end
+ 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
diff --git a/lib/chef_zero/data_store/memory_store_v2.rb b/lib/chef_zero/data_store/memory_store_v2.rb
index c2f2d8e..b35d490 100644
--- a/lib/chef_zero/data_store/memory_store_v2.rb
+++ b/lib/chef_zero/data_store/memory_store_v2.rb
@@ -111,27 +111,23 @@ module ChefZero
end
def exists?(path, options = {})
- begin
- value = _get(path)
- if value.is_a?(Hash) && !options[:allow_dirs]
- raise "exists? does not work with directories (#{path} = #{value.class})"
- end
- return true
- rescue DataNotFoundError
- return false
+ value = _get(path)
+ if value.is_a?(Hash) && !options[:allow_dirs]
+ raise "exists? does not work with directories (#{path} = #{value.class})"
end
+ return true
+ rescue DataNotFoundError
+ return false
end
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
+ 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
private
diff --git a/lib/chef_zero/data_store/raw_file_store.rb b/lib/chef_zero/data_store/raw_file_store.rb
index 120fc1b..8b4c442 100644
--- a/lib/chef_zero/data_store/raw_file_store.rb
+++ b/lib/chef_zero/data_store/raw_file_store.rb
@@ -80,11 +80,9 @@ module ChefZero
end
def get(path, request = nil)
- begin
- return IO.read(path_to(path))
- rescue Errno::ENOENT
- raise DataNotFoundError.new(path)
- end
+ return IO.read(path_to(path))
+ rescue Errno::ENOENT
+ raise DataNotFoundError.new(path)
end
def set(path, data, *options)
@@ -105,11 +103,9 @@ module ChefZero
end
def delete(path)
- begin
- File.delete(path_to(path))
- rescue Errno::ENOENT
- raise DataNotFoundError.new(path)
- end
+ File.delete(path_to(path))
+ rescue Errno::ENOENT
+ raise DataNotFoundError.new(path)
end
def delete_dir(path, *options)
@@ -128,19 +124,17 @@ module ChefZero
end
def list(path)
- begin
- Dir.entries(path_to(path)).select { |entry| entry != "." && entry != ".." }.to_a
- rescue Errno::ENOENT
- raise DataNotFoundError.new(path)
- end
+ Dir.entries(path_to(path)).select { |entry| entry != "." && entry != ".." }.to_a
+ rescue Errno::ENOENT
+ raise DataNotFoundError.new(path)
end
def exists?(path, options = {})
- File.exists?(path_to(path))
+ File.exist?(path_to(path))
end
def exists_dir?(path)
- File.exists?(path_to(path))
+ File.exist?(path_to(path))
end
end
end
diff --git a/lib/chef_zero/data_store/v1_to_v2_adapter.rb b/lib/chef_zero/data_store/v1_to_v2_adapter.rb
index dba35b3..874c05a 100644
--- a/lib/chef_zero/data_store/v1_to_v2_adapter.rb
+++ b/lib/chef_zero/data_store/v1_to_v2_adapter.rb
@@ -109,17 +109,15 @@ module ChefZero
private
def fix_exceptions
- begin
- yield
- rescue DataAlreadyExistsError => e
- err = DataAlreadyExistsError.new([ "organizations", single_org ] + e.path, e)
- err.set_backtrace(e.backtrace)
- raise err
- rescue DataNotFoundError => e
- err = DataNotFoundError.new([ "organizations", single_org ] + e.path, e)
- err.set_backtrace(e.backtrace)
- raise e
- end
+ yield
+ rescue DataAlreadyExistsError => e
+ err = DataAlreadyExistsError.new([ "organizations", single_org ] + e.path, e)
+ err.set_backtrace(e.backtrace)
+ raise err
+ rescue DataNotFoundError => e
+ err = DataNotFoundError.new([ "organizations", single_org ] + e.path, e)
+ err.set_backtrace(e.backtrace)
+ raise e
end
def skip_organizations?(path, name = nil)
diff --git a/lib/chef_zero/data_store/v2_to_v1_adapter.rb b/lib/chef_zero/data_store/v2_to_v1_adapter.rb
index f2cbce0..38f2bc1 100644
--- a/lib/chef_zero/data_store/v2_to_v1_adapter.rb
+++ b/lib/chef_zero/data_store/v2_to_v1_adapter.rb
@@ -90,13 +90,11 @@ module ChefZero
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
+ yield
+ rescue DataAlreadyExistsError => e
+ raise DataAlreadyExistsError.new(e.path[2..-1], e)
+ rescue DataNotFoundError => e
+ raise DataNotFoundError.new(e.path[2..-1], e)
end
def fix_path(path)