chef-zero 14.0.12 → 15.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -6
  3. data/Rakefile +9 -1
  4. data/bin/chef-zero +5 -4
  5. data/chef-zero.gemspec +2 -5
  6. data/lib/chef_zero.rb +1 -1
  7. data/lib/chef_zero/chef_data/cookbook_data.rb +2 -2
  8. data/lib/chef_zero/chef_data/data_normalizer.rb +9 -7
  9. data/lib/chef_zero/chef_data/default_creator.rb +8 -5
  10. data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
  11. data/lib/chef_zero/data_store/data_error.rb +1 -1
  12. data/lib/chef_zero/data_store/data_not_found_error.rb +1 -1
  13. data/lib/chef_zero/data_store/default_facade.rb +4 -4
  14. data/lib/chef_zero/data_store/interface_v2.rb +1 -1
  15. data/lib/chef_zero/data_store/memory_store.rb +3 -3
  16. data/lib/chef_zero/data_store/memory_store_v2.rb +22 -14
  17. data/lib/chef_zero/data_store/raw_file_store.rb +7 -5
  18. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +11 -1
  19. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +1 -1
  20. data/lib/chef_zero/dist.rb +9 -0
  21. data/lib/chef_zero/endpoints/acl_endpoint.rb +4 -3
  22. data/lib/chef_zero/endpoints/acls_endpoint.rb +6 -5
  23. data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +2 -1
  24. data/lib/chef_zero/endpoints/actor_endpoint.rb +4 -4
  25. data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
  26. data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +3 -2
  27. data/lib/chef_zero/endpoints/actors_endpoint.rb +2 -2
  28. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +3 -2
  29. data/lib/chef_zero/endpoints/container_endpoint.rb +3 -3
  30. data/lib/chef_zero/endpoints/containers_endpoint.rb +3 -3
  31. data/lib/chef_zero/endpoints/controls_endpoint.rb +3 -2
  32. data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
  33. data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +3 -3
  34. data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +1 -1
  35. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +1 -1
  36. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +8 -6
  37. data/lib/chef_zero/endpoints/cookbooks_base.rb +5 -3
  38. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +1 -1
  39. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +4 -4
  40. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +4 -4
  41. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +3 -3
  42. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +2 -2
  43. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +14 -11
  44. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +2 -2
  45. data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
  46. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +2 -2
  47. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +2 -2
  48. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +2 -2
  49. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +1 -1
  50. data/lib/chef_zero/endpoints/group_endpoint.rb +3 -3
  51. data/lib/chef_zero/endpoints/groups_endpoint.rb +2 -2
  52. data/lib/chef_zero/endpoints/license_endpoint.rb +2 -2
  53. data/lib/chef_zero/endpoints/node_endpoint.rb +3 -3
  54. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +2 -2
  55. data/lib/chef_zero/endpoints/nodes_endpoint.rb +3 -3
  56. data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
  57. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +3 -2
  58. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +2 -2
  59. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +2 -2
  60. data/lib/chef_zero/endpoints/organization_endpoint.rb +4 -3
  61. data/lib/chef_zero/endpoints/organization_user_base.rb +2 -2
  62. data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +1 -1
  63. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +2 -2
  64. data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +2 -2
  65. data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +1 -1
  66. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +3 -3
  67. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +2 -2
  68. data/lib/chef_zero/endpoints/organizations_endpoint.rb +2 -2
  69. data/lib/chef_zero/endpoints/policies_endpoint.rb +1 -1
  70. data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
  71. data/lib/chef_zero/endpoints/policy_group_endpoint.rb +3 -3
  72. data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +4 -4
  73. data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +3 -3
  74. data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +1 -1
  75. data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +1 -1
  76. data/lib/chef_zero/endpoints/principal_endpoint.rb +3 -3
  77. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +3 -3
  78. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +4 -3
  79. data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
  80. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +2 -2
  81. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +4 -4
  82. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +2 -2
  83. data/lib/chef_zero/endpoints/search_endpoint.rb +9 -9
  84. data/lib/chef_zero/endpoints/searches_endpoint.rb +1 -1
  85. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +1 -1
  86. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +4 -4
  87. data/lib/chef_zero/endpoints/universe_endpoint.rb +3 -3
  88. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +3 -2
  89. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +2 -2
  90. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +2 -2
  91. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +2 -2
  92. data/lib/chef_zero/endpoints/version_endpoint.rb +3 -2
  93. data/lib/chef_zero/rest_base.rb +20 -16
  94. data/lib/chef_zero/rest_request.rb +10 -6
  95. data/lib/chef_zero/rest_router.rb +3 -3
  96. data/lib/chef_zero/rspec.rb +6 -5
  97. data/lib/chef_zero/server.rb +100 -95
  98. data/lib/chef_zero/socketless_server_map.rb +4 -2
  99. data/lib/chef_zero/solr/query/phrase.rb +2 -2
  100. data/lib/chef_zero/solr/query/range_query.rb +3 -3
  101. data/lib/chef_zero/solr/query/term.rb +1 -1
  102. data/lib/chef_zero/solr/solr_parser.rb +12 -10
  103. data/lib/chef_zero/version.rb +1 -1
  104. data/spec/run_oc_pedant.rb +8 -6
  105. data/spec/search_spec.rb +2 -2
  106. data/spec/server_spec.rb +2 -2
  107. data/spec/socketless_server_map_spec.rb +1 -1
  108. data/spec/support/oc_pedant.rb +1 -1
  109. metadata +7 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18556b1f6a192914d736e3477f8ae1813a92c9635c812a3fad3ea13936730fc2
4
- data.tar.gz: 29565bf8101772bc167f881f85f61b53535e542b2eef15c87e9e27c7d95ee319
3
+ metadata.gz: 517f7eb63557ab1b885ee828fcd9c9a4bd68dbe1302aa6259fbee124df3a77c2
4
+ data.tar.gz: bae60b71f5c08e1fdfc057486c4194f88e3dd3d62d1a39066d58f428b1abecc2
5
5
  SHA512:
6
- metadata.gz: e72fd5c1e0f749c4d5437a9e29daa60f6704eba864414dad242eb755f0c9466f9771de45d61670d82121a775cb0110e1e4872118391cc80ef419c280abb2d688
7
- data.tar.gz: 14c97ab83e709f967fe5ca74537fbb1667672220810901c82d81f0d2b3150d92f55cdfaf39eb4a5a2eb852ff8f7b19adafbc49b0189e81587507abe7dd01dc69
6
+ metadata.gz: 4c7b374ef151f182b10da552a52cc69c638940c1fe289d5d1adb67878755e81c645506727716fe7d7abcc20fd26ef4fd9a049dfe17f78c536dd646347f84c4bb
7
+ data.tar.gz: 2a0de3a9db40d37c66ee38bcebda62cd664a365872f7f7e7116551edfa88c46ab366c2aca7b468fdec94cde55df9977358fd3ce61f73231d063e95cb6c83fee2
data/Gemfile CHANGED
@@ -9,11 +9,13 @@ group :pedant do
9
9
  end
10
10
 
11
11
  group :development, :test do
12
- gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
12
+ gem "chefstyle"
13
+ gem "rake"
14
+ gem "rspec", "~> 3.0"
13
15
  end
14
16
 
15
17
  if ENV["GEMFILE_MOD"]
16
- puts "GEMFILE_MOD: #{ENV['GEMFILE_MOD']}"
18
+ puts "GEMFILE_MOD: #{ENV["GEMFILE_MOD"]}"
17
19
  instance_eval(ENV["GEMFILE_MOD"])
18
20
  else
19
21
  gem "chef", "~> 14.0"
@@ -25,7 +27,3 @@ group :debug do
25
27
  gem "pry-byebug"
26
28
  gem "pry-stack_explorer"
27
29
  end
28
-
29
- # If you want to load debugging tools into the bundle exec sandbox,
30
- # add these additional dependencies into Gemfile.local
31
- eval_gemfile(__FILE__ + ".local") if File.exist?(__FILE__ + ".local")
data/Rakefile CHANGED
@@ -52,9 +52,17 @@ end
52
52
  begin
53
53
  require "chefstyle"
54
54
  require "rubocop/rake_task"
55
+ desc "Run Chefstyle tests"
55
56
  RuboCop::RakeTask.new(:style) do |task|
56
57
  task.options += ["--display-cop-names", "--no-color"]
57
58
  end
58
59
  rescue LoadError
59
- puts "chefstyle/rubocop is not available. bundle install first to make sure all dependencies are installed."
60
+ puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed."
61
+ end
62
+
63
+ begin
64
+ require "yard" unless defined?(YARD)
65
+ YARD::Rake::YardocTask.new(:docs)
66
+ rescue LoadError
67
+ puts "yard is not available. bundle install first to make sure all dependencies are installed."
60
68
  end
@@ -3,14 +3,15 @@
3
3
  # Trap interrupts to quit cleanly.
4
4
  Signal.trap("INT") { exit 1 }
5
5
 
6
- require "rubygems"
6
+ require "rubygems" unless defined?(Gem)
7
7
  $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
8
8
 
9
9
  require "chef_zero/log"
10
+ require "chef_zero/dist"
10
11
  require "chef_zero/version"
11
12
  require "chef_zero/server"
12
13
  require "chef_zero/data_store/raw_file_store"
13
- require "optparse"
14
+ require "optparse" unless defined?(OptionParser)
14
15
 
15
16
  def parse_port(port)
16
17
  array = []
@@ -28,7 +29,7 @@ end
28
29
  options = {}
29
30
 
30
31
  OptionParser.new do |opts|
31
- opts.banner = "Usage: chef-zero [ARGS]"
32
+ opts.banner = "Usage: #{ChefZero::Dist::CLIENT} [ARGS]"
32
33
 
33
34
  opts.on("-H", "--host HOST", "Host to bind to (default: 127.0.0.1)") do |value|
34
35
  options[:host] ||= []
@@ -100,7 +101,7 @@ if options[:daemon]
100
101
  server.start(true)
101
102
  else
102
103
  if ENV["OS"] == "Windows_NT"
103
- abort "Daemonization is not supported on Windows. Running 'start chef-zero' will fork the process."
104
+ abort "Daemonization is not supported on Windows. Running 'start #{ChefZero::Dist::CLIENT}' will fork the process."
104
105
  else
105
106
  abort "Process.daemon requires Ruby >= 1.9"
106
107
  end
@@ -11,17 +11,14 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "https://github.com/chef/chef-zero"
12
12
  s.license = "Apache-2.0"
13
13
 
14
- s.required_ruby_version = ">= 2.4.0"
14
+ s.required_ruby_version = ">= 2.6"
15
15
 
16
16
  s.add_dependency "mixlib-log", ">= 2.0", "< 4.0"
17
- s.add_dependency "hashie", ">= 2.0", "< 4.0"
17
+ s.add_dependency "hashie", ">= 2.0", "< 5.0"
18
18
  s.add_dependency "uuidtools", "~> 2.1"
19
19
  s.add_dependency "ffi-yajl", "~> 2.2"
20
20
  s.add_dependency "rack", "~> 2.0", ">= 2.0.6"
21
21
 
22
- s.add_development_dependency "rake"
23
- s.add_development_dependency "rspec"
24
-
25
22
  s.bindir = "bin"
26
23
  s.executables = ["chef-zero"]
27
24
  s.require_path = "lib"
@@ -1,5 +1,5 @@
1
1
  module ChefZero
2
- require "chef_zero/log"
2
+ require_relative "chef_zero/log"
3
3
 
4
4
  MIN_API_VERSION = 0
5
5
  MAX_API_VERSION = 2
@@ -1,4 +1,4 @@
1
- require "digest/md5"
1
+ require "digest/md5" unless defined?(Digest::MD5)
2
2
  require "hashie"
3
3
 
4
4
  module ChefZero
@@ -107,7 +107,7 @@ module ChefZero
107
107
  if directory.is_a?(Hash)
108
108
  directory.keys
109
109
  else
110
- directory.children.map { |c| c.name }
110
+ directory.children.map(&:name)
111
111
  end
112
112
  end
113
113
 
@@ -1,6 +1,6 @@
1
- require "chef_zero"
2
- require "chef_zero/rest_base"
3
- require "chef_zero/chef_data/default_creator"
1
+ require_relative "../../chef_zero"
2
+ require_relative "../rest_base"
3
+ require_relative "default_creator"
4
4
 
5
5
  module ChefZero
6
6
  module ChefData
@@ -53,7 +53,7 @@ module ChefZero
53
53
  user["admin"] ||= false
54
54
  user["admin"] = !!user["admin"]
55
55
  user["openid"] ||= nil
56
- if !osc_compat
56
+ unless osc_compat
57
57
  if method == "GET"
58
58
  user.delete("admin")
59
59
  user.delete("password")
@@ -69,7 +69,7 @@ module ChefZero
69
69
  def self.normalize_data_bag_item(data_bag_item, data_bag_name, id, method)
70
70
  if method == "DELETE"
71
71
  # TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
72
- if !(data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"])
72
+ unless data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
73
73
  data_bag_item["id"] ||= id
74
74
  data_bag_item = { "raw_data" => data_bag_item }
75
75
  data_bag_item["chef_type"] ||= "data_bag_item"
@@ -93,14 +93,15 @@ module ChefZero
93
93
  end
94
94
 
95
95
  def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method,
96
- is_cookbook_artifact = false, api_version: 2)
96
+ is_cookbook_artifact = false, api_version: 2)
97
97
  # TODO I feel dirty
98
98
  if method == "PUT" && api_version < 2
99
99
  cookbook["all_files"] = cookbook.delete(["root_files"]) { [] }
100
100
  COOKBOOK_SEGMENTS.each do |segment|
101
101
  next unless cookbook.key? segment
102
+
102
103
  cookbook[segment].each do |file|
103
- file["name"] = "#{segment}/#{file['name']}"
104
+ file["name"] = "#{segment}/#{file["name"]}"
104
105
  cookbook["all_files"] << file
105
106
  end
106
107
  cookbook.delete(segment)
@@ -131,6 +132,7 @@ module ChefZero
131
132
 
132
133
  file.delete("full_path")
133
134
  next unless COOKBOOK_SEGMENTS.include? segment
135
+
134
136
  file["name"] = name
135
137
  cookbook[segment] << file
136
138
  end
@@ -1,4 +1,4 @@
1
- require "chef_zero/chef_data/acl_path"
1
+ require_relative "acl_path"
2
2
 
3
3
  module ChefZero
4
4
  module ChefData
@@ -140,6 +140,7 @@ module ChefZero
140
140
 
141
141
  def exists?(path)
142
142
  return true if path.size == 0
143
+
143
144
  parent_list = list(path[0..-2])
144
145
  parent_list && parent_list.include?(path[-1])
145
146
  end
@@ -184,7 +185,8 @@ module ChefZero
184
185
  value = DEFAULT_ORG_SPINE
185
186
  2.upto(path.size - 1) do |index|
186
187
  value = nil if @deleted[path[0..index]]
187
- break if !value
188
+ break unless value
189
+
188
190
  value = value[path[index]]
189
191
  end
190
192
 
@@ -272,7 +274,8 @@ module ChefZero
272
274
  object_path = AclPath.get_object_path(path)
273
275
  # The actual things containers correspond to don't have to exist, as
274
276
  # long as the container does
275
- return nil if !data_exists?(object_path)
277
+ return nil unless data_exists?(object_path)
278
+
276
279
  basic_acl =
277
280
  case path[3..-1].join("/")
278
281
  when "root", "containers/containers", "containers/groups"
@@ -350,7 +353,7 @@ module ChefZero
350
353
  if path.size == 4 && path[0] == "organizations" && path[2] == "clients"
351
354
  begin
352
355
  client = FFI_Yajl::Parser.parse(data.get(path))
353
- if !client["validator"]
356
+ unless client["validator"]
354
357
  unknown_owners |= [ path[3] ]
355
358
  end
356
359
  rescue
@@ -453,7 +456,7 @@ module ChefZero
453
456
  def is_dir?(path)
454
457
  case path.size
455
458
  when 0, 1
456
- return true
459
+ true
457
460
  when 2
458
461
  path[0] == "organizations" || (path[0] == "acls" && path[1] != "root")
459
462
  when 3
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_error"
19
+ require_relative "data_error"
20
20
 
21
21
  module ChefZero
22
22
  module DataStore
@@ -24,7 +24,7 @@ module ChefZero
24
24
  def initialize(path, cause = nil)
25
25
  @path = path
26
26
  @cause = cause
27
- path_for_msg = path.nil? ? "nil" : "/#{path.join('/')}"
27
+ path_for_msg = path.nil? ? "nil" : "/#{path.join("/")}"
28
28
  super "Data path: #{path_for_msg}"
29
29
  end
30
30
  end
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_error"
19
+ require_relative "data_error"
20
20
 
21
21
  module ChefZero
22
22
  module DataStore
@@ -1,5 +1,5 @@
1
- require "chef_zero/data_store/interface_v2"
2
- require "chef_zero/chef_data/default_creator"
1
+ require_relative "interface_v2"
2
+ require_relative "../chef_data/default_creator"
3
3
 
4
4
  module ChefZero
5
5
  module DataStore
@@ -100,7 +100,7 @@ module ChefZero
100
100
  begin
101
101
  real_store.delete(path)
102
102
  rescue DataNotFoundError
103
- if !deleted
103
+ unless deleted
104
104
  raise
105
105
  end
106
106
  end
@@ -111,7 +111,7 @@ module ChefZero
111
111
  begin
112
112
  real_store.delete_dir(path, *options)
113
113
  rescue DataNotFoundError
114
- if !deleted
114
+ unless deleted
115
115
  raise
116
116
  end
117
117
  end
@@ -1,4 +1,4 @@
1
- require "chef_zero/data_store/interface_v1"
1
+ require_relative "interface_v1"
2
2
 
3
3
  module ChefZero
4
4
  module DataStore
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/v2_to_v1_adapter"
20
- require "chef_zero/data_store/memory_store_v2"
21
- require "chef_zero/data_store/default_facade"
19
+ require_relative "v2_to_v1_adapter"
20
+ require_relative "memory_store_v2"
21
+ require_relative "default_facade"
22
22
 
23
23
  module ChefZero
24
24
  module DataStore
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_already_exists_error"
20
- require "chef_zero/data_store/data_not_found_error"
21
- require "chef_zero/data_store/interface_v2"
19
+ require_relative "data_already_exists_error"
20
+ require_relative "data_not_found_error"
21
+ require_relative "interface_v2"
22
22
 
23
23
  module ChefZero
24
24
  module DataStore
@@ -37,7 +37,7 @@ module ChefZero
37
37
  parent = _get(path, options.include?(:recursive))
38
38
 
39
39
  if parent.key?(name)
40
- if !options.include?(:recursive)
40
+ unless options.include?(:recursive)
41
41
  raise DataAlreadyExistsError.new(path + [name])
42
42
  end
43
43
  else
@@ -46,7 +46,7 @@ module ChefZero
46
46
  end
47
47
 
48
48
  def create(path, name, data, *options)
49
- if !data.is_a?(String)
49
+ unless data.is_a?(String)
50
50
  raise "set only works with strings (given data: #{data.inspect})"
51
51
  end
52
52
 
@@ -55,19 +55,21 @@ module ChefZero
55
55
  if parent.key?(name)
56
56
  raise DataAlreadyExistsError.new(path + [name])
57
57
  end
58
+
58
59
  parent[name] = data
59
60
  end
60
61
 
61
62
  def get(path, request = nil)
62
63
  value = _get(path)
63
64
  if value.is_a?(Hash)
64
- raise "get() called on directory #{path.join('/')}"
65
+ raise "get() called on directory #{path.join("/")}"
65
66
  end
67
+
66
68
  value
67
69
  end
68
70
 
69
71
  def set(path, data, *options)
70
- if !data.is_a?(String)
72
+ unless data.is_a?(String)
71
73
  raise "set only works with strings: #{path} = #{data.inspect}"
72
74
  end
73
75
 
@@ -77,36 +79,40 @@ module ChefZero
77
79
  if !options.include?(:create) && !parent[path[-1]]
78
80
  raise DataNotFoundError.new(path)
79
81
  end
82
+
80
83
  parent[path[-1]] = data
81
84
  end
82
85
 
83
86
  def delete(path)
84
87
  parent = _get(path[0, path.length - 1])
85
- if !parent.key?(path[-1])
88
+ unless parent.key?(path[-1])
86
89
  raise DataNotFoundError.new(path)
87
90
  end
88
- if !parent[path[-1]].is_a?(String)
91
+ unless parent[path[-1]].is_a?(String)
89
92
  raise "delete only works with strings: #{path}"
90
93
  end
94
+
91
95
  parent.delete(path[-1])
92
96
  end
93
97
 
94
98
  def delete_dir(path, *options)
95
99
  parent = _get(path[0, path.length - 1])
96
- if !parent.key?(path[-1])
100
+ unless parent.key?(path[-1])
97
101
  raise DataNotFoundError.new(path)
98
102
  end
99
- if !parent[path[-1]].is_a?(Hash)
103
+ unless parent[path[-1]].is_a?(Hash)
100
104
  raise "delete_dir only works with directories: #{path}"
101
105
  end
106
+
102
107
  parent.delete(path[-1])
103
108
  end
104
109
 
105
110
  def list(path)
106
111
  dir = _get(path)
107
- if !dir.is_a? Hash
112
+ unless dir.is_a? Hash
108
113
  raise "list only works with directories (#{path} = #{dir.class})"
109
114
  end
115
+
110
116
  dir.keys.sort
111
117
  end
112
118
 
@@ -115,6 +121,7 @@ module ChefZero
115
121
  if value.is_a?(Hash) && !options[:allow_dirs]
116
122
  raise "exists? does not work with directories (#{path} = #{value.class})"
117
123
  end
124
+
118
125
  true
119
126
  rescue DataNotFoundError
120
127
  false
@@ -122,9 +129,10 @@ module ChefZero
122
129
 
123
130
  def exists_dir?(path)
124
131
  dir = _get(path)
125
- if !dir.is_a? Hash
132
+ unless dir.is_a? Hash
126
133
  raise "exists_dir? only works with directories (#{path} = #{dir.class})"
127
134
  end
135
+
128
136
  true
129
137
  rescue DataNotFoundError
130
138
  false
@@ -135,7 +143,7 @@ module ChefZero
135
143
  def _get(path, create_dir = false)
136
144
  value = @data
137
145
  path.each_with_index do |path_part, index|
138
- if !value.key?(path_part)
146
+ unless value.key?(path_part)
139
147
  if create_dir
140
148
  value[path_part] = {}
141
149
  else
@@ -16,10 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_already_exists_error"
20
- require "chef_zero/data_store/data_not_found_error"
21
- require "chef_zero/data_store/interface_v2"
22
- require "fileutils"
19
+ require_relative "data_already_exists_error"
20
+ require_relative "data_not_found_error"
21
+ require_relative "interface_v2"
22
+ require "fileutils" unless defined?(FileUtils)
23
23
 
24
24
  module ChefZero
25
25
  module DataStore
@@ -44,6 +44,7 @@ module ChefZero
44
44
  if destructible
45
45
  Dir.entries(root).each do |entry|
46
46
  next if entry == "." || entry == ".."
47
+
47
48
  FileUtils.rm_rf(Path.join(root, entry))
48
49
  end
49
50
  end
@@ -110,9 +111,10 @@ module ChefZero
110
111
 
111
112
  def delete_dir(path, *options)
112
113
  if options.include?(:recursive)
113
- if !File.exist?(path_to(path))
114
+ unless File.exist?(path_to(path))
114
115
  raise DataNotFoundError.new(path)
115
116
  end
117
+
116
118
  FileUtils.rm_rf(path_to(path))
117
119
  else
118
120
  begin