Parent

Files

Class/Module Index [+]

Quicksearch

Chef::ChefFS::FileSystem::BaseFSObject

Attributes

name[R]
parent[R]
path[R]

Public Class Methods

new(name, parent) click to toggle source
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 25
def initialize(name, parent)
  @parent = parent
  @name = name
  if parent
    @path = Chef::ChefFS::PathUtils::join(parent.path, name)
  else
    if name != ''
      raise ArgumentError, "Name of root object must be empty string: was '#{name}' instead"
    end
    @path = '/'
  end
end

Public Instance Methods

can_have_child?(name, is_dir) click to toggle source

Override can_have_child? to report whether a given file could be added to this directory. (Some directories can't have subdirs, some can only have .json files, etc.)

# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 74
def can_have_child?(name, is_dir)
  false
end
child(name) click to toggle source
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 67
def child(name)
  NonexistentFSObject.new(name, self)
end
compare_to(other) click to toggle source

Override this if you have a special comparison algorithm that can tell you whether this entry is the same as another--either a quicker or a more reliable one. Callers will use this to decide whether to upload, download or diff an object.

You should not override this if you're going to do the standard +self.read == other.read+. If you return nil, the caller will call +other.compare_to(you)+ instead. Give them a chance :)

Parameters

  • other - the entry to compare to

Returns

  • +[ are_same, value, other_value ]+ are_same may be true, false or nil (which means "don't know"). value and other_value must either be the text of self or other, :none (if the entry does not exist or has no value) or nil if the value was not retrieved.

  • nil if a definitive answer cannot be had and nothing was retrieved.

Example

are_same, value, other_value = entry.compare_to(other)
if are_same.nil?
  are_same, other_value, value = other.compare_to(entry)
end
if are_same.nil?
  value = entry.read if value.nil?
  other_value = entry.read if other_value.nil?
  are_same = (value == other_value)
end
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 111
def compare_to(other)
  return nil
end
dir?() click to toggle source
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 59
def dir?
  false
end
exists?() click to toggle source
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 63
def exists?
  true
end
path_for_printing() click to toggle source
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 46
def path_for_printing
  if parent
    parent_path = parent.path_for_printing
    if parent_path == '.'
      name
    else
      Chef::ChefFS::PathUtils::join(parent.path_for_printing, name)
    end
  else
    name
  end
end
root() click to toggle source
# File lib/chef/chef_fs/file_system/base_fs_object.rb, line 42
def root
  parent ? parent.root : self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.