Class: Serverspec::Type::File

Inherits:
Base
  • Object
show all
Defined in:
lib/serverspec/type/file.rb

Direct Known Subclasses

JsonFile

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#initialize, #inspect, #to_ary, #to_s

Constructor Details

This class inherits a constructor from Serverspec::Type::Base

Instance Attribute Details

#content ⇒ Object

Returns the value of attribute content.



6
7
8
# File 'lib/serverspec/type/file.rb', line 6

def content
  @content
end

Instance Method Details

#block_device? ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/serverspec/type/file.rb', line 14

def block_device?
  @runner.check_file_is_block_device(@name)
end

#character_device? ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/serverspec/type/file.rb', line 18

def character_device?
  @runner.check_file_is_character_device(@name)
end

#contain(pattern, from, to) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/serverspec/type/file.rb', line 38

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 ⇒ Object



117
118
119
120
121
122
123
# File 'lib/serverspec/type/file.rb', line 117

def content_as_json
  if @content_as_json.nil?
    @content = @runner.get_file_content(@name).stdout if @content.nil?
    @content_as_json = MultiJson.load(@content)
  end
  @content_as_json
end

#directory? ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/serverspec/type/file.rb', line 26

def directory?
  @runner.check_file_is_directory(@name)
end

#executable?(by_whom, by_user) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
# File 'lib/serverspec/type/file.rb', line 82

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? ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/serverspec/type/file.rb', line 98

def exists?
  @runner.check_file_exists(@name)
end

#file? ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/serverspec/type/file.rb', line 8

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 ⇒ Object



125
126
127
# File 'lib/serverspec/type/file.rb', line 125

def group
  @runner.get_file_owner_group(@name).stdout.strip
end

#grouped_into?(group) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/serverspec/type/file.rb', line 58

def grouped_into?(group)
  @runner.check_file_is_grouped(@name, group)
end

#immutable? ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/serverspec/type/file.rb', line 94

def immutable?
  @runner.check_file_is_immutable(@name)
end


133
134
135
# File 'lib/serverspec/type/file.rb', line 133

def link_target
  @runner.get_file_link_target(@name).stdout.strip
end

#linked_to?(target) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/serverspec/type/file.rb', line 62

def linked_to?(target)
  @runner.check_file_is_linked_to(@name, target)
end

#md5sum ⇒ Object



102
103
104
# File 'lib/serverspec/type/file.rb', line 102

def md5sum
  @runner.get_file_md5sum(@name).stdout.strip
end

#mode ⇒ Object



137
138
139
# File 'lib/serverspec/type/file.rb', line 137

def mode
  @runner.get_file_mode(@name).stdout.strip
end

#mode?(mode) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/serverspec/type/file.rb', line 50

def mode?(mode)
  @runner.check_file_has_mode(@name, mode)
end

#mounted?(attr, only_with) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/serverspec/type/file.rb', line 90

def mounted?(attr, only_with)
  @runner.check_file_is_mounted(@name, attr, only_with)
end

#mtime ⇒ Object



141
142
143
144
# File 'lib/serverspec/type/file.rb', line 141

def mtime
  d = @runner.get_file_mtime(@name).stdout.strip
  DateTime.strptime(d, '%s').new_offset(DateTime.now.offset)
end

#owned_by?(owner) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/serverspec/type/file.rb', line 54

def owned_by?(owner)
  @runner.check_file_is_owned_by(@name, owner)
end

#owner ⇒ Object



146
147
148
# File 'lib/serverspec/type/file.rb', line 146

def owner
  @runner.get_file_owner_user(@name).stdout.strip
end

#pipe? ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/serverspec/type/file.rb', line 34

def pipe?
  @runner.check_file_is_pipe(@name)
end

#readable?(by_whom, by_user) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/serverspec/type/file.rb', line 66

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 ⇒ Object



154
155
156
# File 'lib/serverspec/type/file.rb', line 154

def selinux_label
  @runner.get_file_selinuxlabel(@name).stdout.strip
end

#sha256sum ⇒ Object



106
107
108
# File 'lib/serverspec/type/file.rb', line 106

def sha256sum
  @runner.get_file_sha256sum(@name).stdout.strip
end

#size ⇒ Object



150
151
152
# File 'lib/serverspec/type/file.rb', line 150

def size
  @runner.get_file_size(@name).stdout.strip.to_i
end

#socket? ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/serverspec/type/file.rb', line 22

def socket?
  @runner.check_file_is_socket(@name)
end

#symlink? ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/serverspec/type/file.rb', line 30

def symlink?
  @runner.check_file_is_symlink(@name)
end

#version?(version) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/serverspec/type/file.rb', line 129

def version?(version)
  @runner.check_file_has_version(@name, version)
end

#writable?(by_whom, by_user) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/serverspec/type/file.rb', line 74

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