Sha256: bcb8f4442bac5518f352507b16c48a7bcbd711916c44f9e867323bc44f852505

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'chef_fs/file_system/base_fs_dir'
require 'chef_fs/file_system/rest_list_entry'

# TODO: take environment into account

module ChefFS
  module FileSystem
    class RestListDir < BaseFSDir
      def initialize(name, parent, api_path = nil)
        super(name, parent)
        @api_path = api_path || (parent.api_path == "" ? name : "#{parent.api_path}/#{name}")
      end

      attr_reader :api_path

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

      def children
        begin
          @children ||= rest.get_rest(api_path).keys.map { |key| RestListEntry.new("#{key}.json", self, true) }
        rescue Net::HTTPServerException
          if $!.response.code == "404"
            raise ChefFS::FileSystem::NotFoundException, $!
          else
            raise
          end
        end
      end

      def environment
        parent.environment
      end

      def rest
        parent.rest
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
knife-essentials-0.1.1 lib/chef_fs/file_system/rest_list_dir.rb
knife-essentials-0.1 lib/chef_fs/file_system/rest_list_dir.rb