Files

Class/Module Index [+]

Quicksearch

Chef::ChefFS::FileSystem::RestListDir

Attributes

api_path[R]
data_handler[R]

Public Class Methods

new(name, parent, api_path = nil, data_handler = nil) click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 27
def initialize(name, parent, api_path = nil, data_handler = nil)
  super(name, parent)
  @api_path = api_path || (parent.api_path == "" ? name : "#{parent.api_path}/#{name}")
  @data_handler = data_handler
end

Public Instance Methods

_make_child_entry(name, exists = nil) click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 109
def _make_child_entry(name, exists = nil)
  RestListEntry.new(name, self, exists)
end
can_have_child?(name, is_dir) click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 42
def can_have_child?(name, is_dir)
  name =~ /\.json$/ && !is_dir
end
child(name) click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 36
def child(name)
  result = @children.select { |child| child.name == name }.first if @children
  result ||= can_have_child?(name, false) ?
             _make_child_entry(name) : NonexistentFSObject.new(name, self)
end
children() click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 46
def children
  begin
    @children ||= root.get_json(api_path).keys.sort.map do |key|
      _make_child_entry("#{key}.json", true)
    end
  rescue Timeout::Error => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e), "Timeout retrieving children: #{e}"
  rescue Net::HTTPServerException => e
    if $!.response.code == "404"
      raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
    else
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e), "HTTP error retrieving children: #{e}"
    end
  end
end
create_child(name, file_contents) click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 62
def create_child(name, file_contents)
  begin
    object = JSON.parse(file_contents, :create_additions => false)
  rescue JSON::ParserError => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Parse error reading JSON creating child '#{name}': #{e}"
  end

  result = _make_child_entry(name, true)

  if data_handler
    object = data_handler.normalize_for_post(object, result)
    data_handler.verify_integrity(object, result) do |error|
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self), "Error creating '#{name}': #{error}"
    end
  end

  begin
    rest.post(api_path, object)
  rescue Timeout::Error => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Timeout creating '#{name}': #{e}"
  rescue Net::HTTPServerException => e
    if e.response.code == "404"
      raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
    elsif $!.response.code == "409"
      raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e), "Failure creating '#{name}': #{path}/#{name} already exists"
    else
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Failure creating '#{name}': #{e.message}"
    end
  end

  @children = nil

  result
end
environment() click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 101
def environment
  parent.environment
end
org() click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 97
def org
  parent.org
end
rest() click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 105
def rest
  parent.rest
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.