Sha256: 3440625fe9ee73f91793372ebb85000398a5f2583b266a02175087738adbfe6b

Contents?: true

Size: 905 Bytes

Versions: 4

Compression:

Stored size: 905 Bytes

Contents

require 'chef_fs/file_system/rest_list_dir'
require 'chef_fs/file_system/data_bag_dir'

module ChefFS
  module FileSystem
    class DataBagsDir < RestListDir
      def initialize(parent)
        super("data_bags", parent, "data")
      end

      def child(name)
        result = @children.select { |child| child.name == name }.first if @children
        result || DataBagDir.new(name, self)
      end

      def children
        @children ||= rest.get_rest(api_path).keys.map { |entry| DataBagDir.new(entry, self, true) }
      end

      def can_have_child?(name, is_dir)
        is_dir
      end

      def create_child(name, file_contents)
        begin
          rest.post_rest(api_path, { 'name' => name })
        rescue Net::HTTPServerException
          if $!.response.code != "409"
            raise
          end
        end
        DataBagDir.new(name, self, true)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
knife-essentials-0.5.3 lib/chef_fs/file_system/data_bags_dir.rb
knife-essentials-0.5.2 lib/chef_fs/file_system/data_bags_dir.rb
knife-essentials-0.5.1 lib/chef_fs/file_system/data_bags_dir.rb
knife-essentials-0.5 lib/chef_fs/file_system/data_bags_dir.rb