Class: Serverspec::Type::File
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::File
show all
- Defined in:
- lib/serverspec/type/file.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#name
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #inspect, #to_ary, #to_s
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
7
8
9
|
# File 'lib/serverspec/type/file.rb', line 7
def content
@content
end
|
Instance Method Details
#block_device? ⇒ Boolean
15
16
17
|
# File 'lib/serverspec/type/file.rb', line 15
def block_device?
@runner.check_file_is_block_device(@name)
end
|
#character_device? ⇒ Boolean
19
20
21
|
# File 'lib/serverspec/type/file.rb', line 19
def character_device?
@runner.check_file_is_character_device(@name)
end
|
#contain(pattern, from, to) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# 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 ⇒ Object
118
119
120
121
|
# 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 ⇒ Object
123
124
125
126
|
# File 'lib/serverspec/type/file.rb', line 123
def content_as_yaml
@content_as_yaml = YAML.load(content) if @content_as_yaml.nil?
@content_as_yaml
end
|
#directory? ⇒ Boolean
27
28
29
|
# File 'lib/serverspec/type/file.rb', line 27
def directory?
@runner.check_file_is_directory(@name)
end
|
#executable?(by_whom, by_user) ⇒ Boolean
83
84
85
86
87
88
89
|
# 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? ⇒ Boolean
99
100
101
|
# File 'lib/serverspec/type/file.rb', line 99
def exists?
@runner.check_file_exists(@name)
end
|
#file? ⇒ Boolean
9
10
11
12
13
|
# 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 ⇒ Object
128
129
130
|
# File 'lib/serverspec/type/file.rb', line 128
def group
@runner.get_file_owner_group(@name).stdout.strip
end
|
#grouped_into?(group) ⇒ Boolean
59
60
61
|
# File 'lib/serverspec/type/file.rb', line 59
def grouped_into?(group)
@runner.check_file_is_grouped(@name, group)
end
|
#immutable? ⇒ Boolean
95
96
97
|
# File 'lib/serverspec/type/file.rb', line 95
def immutable?
@runner.check_file_is_immutable(@name)
end
|
#link_target ⇒ Object
136
137
138
|
# File 'lib/serverspec/type/file.rb', line 136
def link_target
@runner.get_file_link_target(@name).stdout.strip
end
|
#linked_to?(target) ⇒ Boolean
63
64
65
|
# File 'lib/serverspec/type/file.rb', line 63
def linked_to?(target)
@runner.check_file_is_linked_to(@name, target)
end
|
#md5sum ⇒ Object
103
104
105
|
# File 'lib/serverspec/type/file.rb', line 103
def md5sum
@runner.get_file_md5sum(@name).stdout.strip
end
|
#mode ⇒ Object
140
141
142
|
# File 'lib/serverspec/type/file.rb', line 140
def mode
@runner.get_file_mode(@name).stdout.strip
end
|
#mode?(mode) ⇒ Boolean
51
52
53
|
# File 'lib/serverspec/type/file.rb', line 51
def mode?(mode)
@runner.check_file_has_mode(@name, mode)
end
|
#mounted?(attr, only_with) ⇒ Boolean
91
92
93
|
# File 'lib/serverspec/type/file.rb', line 91
def mounted?(attr, only_with)
@runner.check_file_is_mounted(@name, attr, only_with)
end
|
#mtime ⇒ Object
144
145
146
147
|
# File 'lib/serverspec/type/file.rb', line 144
def mtime
d = @runner.get_file_mtime(@name).stdout.strip
DateTime.strptime(d, '%s').new_offset(DateTime.now.offset)
end
|
#owned_by?(owner) ⇒ Boolean
55
56
57
|
# File 'lib/serverspec/type/file.rb', line 55
def owned_by?(owner)
@runner.check_file_is_owned_by(@name, owner)
end
|
#owner ⇒ Object
149
150
151
|
# File 'lib/serverspec/type/file.rb', line 149
def owner
@runner.get_file_owner_user(@name).stdout.strip
end
|
#pipe? ⇒ Boolean
35
36
37
|
# File 'lib/serverspec/type/file.rb', line 35
def pipe?
@runner.check_file_is_pipe(@name)
end
|
#readable?(by_whom, by_user) ⇒ Boolean
67
68
69
70
71
72
73
|
# 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 ⇒ Object
157
158
159
|
# File 'lib/serverspec/type/file.rb', line 157
def selinux_label
@runner.get_file_selinuxlabel(@name).stdout.strip
end
|
#sha256sum ⇒ Object
107
108
109
|
# File 'lib/serverspec/type/file.rb', line 107
def sha256sum
@runner.get_file_sha256sum(@name).stdout.strip
end
|
#size ⇒ Object
153
154
155
|
# File 'lib/serverspec/type/file.rb', line 153
def size
@runner.get_file_size(@name).stdout.strip.to_i
end
|
#socket? ⇒ Boolean
23
24
25
|
# File 'lib/serverspec/type/file.rb', line 23
def socket?
@runner.check_file_is_socket(@name)
end
|
#symlink? ⇒ Boolean
31
32
33
|
# File 'lib/serverspec/type/file.rb', line 31
def symlink?
@runner.check_file_is_symlink(@name)
end
|
#version?(version) ⇒ Boolean
132
133
134
|
# File 'lib/serverspec/type/file.rb', line 132
def version?(version)
@runner.check_file_has_version(@name, version)
end
|
#writable?(by_whom, by_user) ⇒ Boolean
75
76
77
78
79
80
81
|
# 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
|