# class Chef::ChefFS::DataHandler::DataBagItemDataHandler

### Public Instance Methods

chef_class() click to toggle source

    # File lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb, line 41
    def chef_class
      Chef::DataBagItem
    end

normalize(data_bag_item, entry) click to toggle source

    # File lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb, line 8
    def normalize(data_bag_item, entry)
      # If it's wrapped with raw_data, unwrap it.
      if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
        data_bag_item = data_bag_item['raw_data']
      end
      # chef_type and data_bag come back in PUT and POST results, but we don't
      # use those in knife-essentials.
      normalize_hash(data_bag_item, {
        'id' => remove_dot_json(entry.name)
      })
    end

normalize_for_post(data_bag_item, entry) click to toggle source

    # File lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb, line 20
    def normalize_for_post(data_bag_item, entry)
      if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
        data_bag_item = data_bag_item['raw_data']
      end
      {
        "name" => "data_bag_item_#{entry.parent.name}_#{remove_dot_json(entry.name)}",
        "json_class" => "Chef::DataBagItem",
        "chef_type" => "data_bag_item",
        "data_bag" => entry.parent.name,
        "raw_data" => normalize(data_bag_item, entry)
      }
    end

normalize_for_put(data_bag_item, entry) click to toggle source

    # File lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb, line 33
    def normalize_for_put(data_bag_item, entry)
      normalize_for_post(data_bag_item, entry)
    end

preserve_key(key) click to toggle source

    # File lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb, line 37
    def preserve_key(key)
      return key == 'id'
    end

verify_integrity(object, entry, &on_error) click to toggle source

    # File lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb, line 45
    def verify_integrity(object, entry, &on_error)
      base_name = remove_dot_json(entry.name)
      if object['raw_data']['id'] != base_name
        on_error.call("ID in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['raw_data']['id']}')")
      end
    end