summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs/data_handler/environment_data_handler.rb
blob: 4191575d7db2f938147b33a43e0f2ea45bb0b2f3 (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 "chef/chef_fs/data_handler/data_handler_base"
require "chef/environment"

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

        def preserve_key?(key)
          return 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