class Serverspec::Type::File

Attributes

content[RW]

Public Instance Methods

block_device?() click to toggle source
# File lib/serverspec/type/file.rb, line 15
def block_device?
  @runner.check_file_is_block_device(@name)
end
character_device?() click to toggle source
# File lib/serverspec/type/file.rb, line 19
def character_device?
  @runner.check_file_is_character_device(@name)
end
contain(pattern, from, to) click to toggle source
# File lib/serverspec/type/file.rb, line 39
def contain(pattern, from, to)
  if pattern.is_a?(Array)
    @runner.check_file_contains_lines(@name, pattern, from, to)
  else
    if (from || to).nil?
      @runner.check_file_contains(@name, pattern)
    else
      @runner.check_file_contains_within(@name, pattern, from, to)
    end
  end
end
content_as_json() click to toggle source
# File lib/serverspec/type/file.rb, line 118
def content_as_json
  @content_as_json = MultiJson.load(content) if @content_as_json.nil?
  @content_as_json
end
content_as_yaml() click to toggle source
# File lib/serverspec/type/file.rb, line 123
def content_as_yaml
  if @content_as_yaml.nil?
    @content_as_yaml = if YAML.respond_to?(:unsafe_load)
                         YAML.unsafe_load(content)
                       else
                         YAML.load(content)
                       end
  end
  @content_as_yaml
end
directory?() click to toggle source
# File lib/serverspec/type/file.rb, line 27
def directory?
  @runner.check_file_is_directory(@name)
end
executable?(by_whom, by_user) click to toggle source
# File lib/serverspec/type/file.rb, line 83
def executable?(by_whom, by_user)
  if by_user != nil
    @runner.check_file_is_accessible_by_user(@name, by_user, 'x')
  else
    @runner.check_file_is_executable(@name, by_whom)
  end
end
exists?() click to toggle source
# File lib/serverspec/type/file.rb, line 99
def exists?
  @runner.check_file_exists(@name)
end
file?() click to toggle source
# File lib/serverspec/type/file.rb, line 9
def file?
  cmd = Specinfra.command.get(:check_file_is_file, @name)
  @inspection = Specinfra.backend.build_command(cmd.to_s)
  @runner.check_file_is_file(@name)
end
group() click to toggle source
# File lib/serverspec/type/file.rb, line 134
def group
  @runner.get_file_owner_group(@name).stdout.strip
end
grouped_into?(group) click to toggle source
# File lib/serverspec/type/file.rb, line 59
def grouped_into?(group)
  @runner.check_file_is_grouped(@name, group)
end
immutable?() click to toggle source
# File lib/serverspec/type/file.rb, line 95
def immutable?
  @runner.check_file_is_immutable(@name)
end
linked_to?(target) click to toggle source
# File lib/serverspec/type/file.rb, line 63
def linked_to?(target)
  @runner.check_file_is_linked_to(@name, target)
end
md5sum() click to toggle source
# File lib/serverspec/type/file.rb, line 103
def md5sum
  @runner.get_file_md5sum(@name).stdout.strip
end
mode() click to toggle source
# File lib/serverspec/type/file.rb, line 146
def mode
  @runner.get_file_mode(@name).stdout.strip
end
mode?(mode) click to toggle source
# File lib/serverspec/type/file.rb, line 51
def mode?(mode)
  @runner.check_file_has_mode(@name, mode)
end
mounted?(attr, only_with) click to toggle source
# File lib/serverspec/type/file.rb, line 91
def mounted?(attr, only_with)
  @runner.check_file_is_mounted(@name, attr, only_with)
end
mtime() click to toggle source
# File lib/serverspec/type/file.rb, line 150
def mtime
  d = @runner.get_file_mtime(@name).stdout.strip
  DateTime.strptime(d, '%s').new_offset(DateTime.now.offset)
end
owned_by?(owner) click to toggle source
# File lib/serverspec/type/file.rb, line 55
def owned_by?(owner)
  @runner.check_file_is_owned_by(@name, owner)
end
owner() click to toggle source
# File lib/serverspec/type/file.rb, line 155
def owner
  @runner.get_file_owner_user(@name).stdout.strip
end
pipe?() click to toggle source
# File lib/serverspec/type/file.rb, line 35
def pipe?
  @runner.check_file_is_pipe(@name)
end
readable?(by_whom, by_user) click to toggle source
# File lib/serverspec/type/file.rb, line 67
def readable?(by_whom, by_user)
  if by_user != nil
    @runner.check_file_is_accessible_by_user(@name, by_user, 'r')
  else
    @runner.check_file_is_readable(@name, by_whom)
  end
end
selinux_label() click to toggle source
# File lib/serverspec/type/file.rb, line 163
def selinux_label
  @runner.get_file_selinuxlabel(@name).stdout.strip
end
sha256sum() click to toggle source
# File lib/serverspec/type/file.rb, line 107
def sha256sum
  @runner.get_file_sha256sum(@name).stdout.strip
end
size() click to toggle source
# File lib/serverspec/type/file.rb, line 159
def size
  @runner.get_file_size(@name).stdout.strip.to_i
end
socket?() click to toggle source
# File lib/serverspec/type/file.rb, line 23
def socket?
  @runner.check_file_is_socket(@name)
end
version?(version) click to toggle source
# File lib/serverspec/type/file.rb, line 138
def version?(version)
  @runner.check_file_has_version(@name, version)
end
writable?(by_whom, by_user) click to toggle source
# File lib/serverspec/type/file.rb, line 75
def writable?(by_whom, by_user)
  if by_user != nil
    @runner.check_file_is_accessible_by_user(@name, by_user, 'w')
  else
    @runner.check_file_is_writable(@name, by_whom)
  end
end