Files

Class/Module Index [+]

Quicksearch

Chef::ChefFS::FileSystem::RestListDir

Attributes

api_path[R]

Public Class Methods

new(name, parent, api_path = 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)
  super(name, parent)
  @api_path = api_path || (parent.api_path == "" ? name : "#{parent.api_path}/#{name}")
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 78
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 40
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 34
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 44
def children
  begin
    @children ||= rest.get_rest(api_path).keys.map do |key|
      _make_child_entry("#{key}.json", true)
    end
  rescue Net::HTTPServerException
    if $!.response.code == "404"
      raise Chef::ChefFS::FileSystem::NotFoundError.new($!), "#{path_for_printing} not found"
    else
      raise
    end
  end
end
create_child(name, file_contents) click to toggle source

NOTE if you change this significantly, you will likely need to change DataBagDir.create_child as well.

# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 60
def create_child(name, file_contents)
  json = Chef::JSONCompat.from_json(file_contents).to_hash
  base_name = name[0,name.length-5]
  if json.include?('name') && json['name'] != base_name
    raise "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{json['name']}')"
  end
  rest.post_rest(api_path, json)
  _make_child_entry(name, true)
end
environment() click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 70
def environment
  parent.environment
end
rest() click to toggle source
# File lib/chef/chef_fs/file_system/rest_list_dir.rb, line 74
def rest
  parent.rest
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.