summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs/data_handler/environment_data_handler.rb
blob: e3aa242fc9a165cfc8929690cd6a07fc54ecb708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require_relative "data_handler_base"
require_relative "../../environment"

class Chef
  module ChefFS
    module DataHandler
      class EnvironmentDataHandler < DataHandlerBase
        def normalize(environment, entry)
          normalize_hash(environment, {
            "name" => remove_file_extension(entry.name),
            "description" => "",
            "cookbook_versions" => {},
            "default_attributes" => {},
            "override_attributes" => {},
            "json_class" => "Chef::Environment",
            "chef_type" => "environment",
          })
        end

        def preserve_key?(key)
          key == "name"
        end

        def chef_class
          Chef::Environment
        end

        def to_ruby(object)
          result = to_ruby_keys(object, %w{name description default_attributes override_attributes})
          if object["cookbook_versions"]
            object["cookbook_versions"].each_pair do |name, version|
              result << "cookbook #{name.inspect}, #{version.inspect}"
            end
          end
          result
        end
      end
    end
  end
end