Class: Itamae::Resource::File
- Inherits:
-
Base
- Object
- Base
- Itamae::Resource::File
show all
- Defined in:
- lib/itamae/resource/file.rb
Instance Attribute Summary
Attributes inherited from Base
#attributes, #current_attributes, #notifications, #recipe, #resource_name, #subscriptions, #updated
Instance Method Summary
collapse
Methods inherited from Base
#action_nothing, define_attribute, inherited, #initialize, #resource_type, #run
Instance Method Details
#action_create(options) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/itamae/resource/file.rb', line 56
def action_create(options)
if attributes.mode
run_specinfra(:change_file_mode, @temppath, attributes.mode)
end
if attributes.owner || attributes.group
run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group)
end
if run_specinfra(:check_file_is_file, attributes.path)
unless check_command(["diff", "-q", @temppath, attributes.path])
updated!
end
else
updated!
end
run_specinfra(:move_file, @temppath, attributes.path)
end
|
#action_delete(options) ⇒ Object
77
78
79
80
81
|
# File 'lib/itamae/resource/file.rb', line 77
def action_delete(options)
if run_specinfra(:check_file_is_file, attributes.path)
run_specinfra(:remove_file, attributes.path)
end
end
|
#action_edit(options) ⇒ Object
83
84
85
86
87
|
# File 'lib/itamae/resource/file.rb', line 83
def action_edit(options)
run_command(['chmod', '--reference', attributes.path, @temppath])
run_command(['chown', '--reference', attributes.path, @temppath])
run_specinfra(:move_file, @temppath, attributes.path)
end
|
#pre_action ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/itamae/resource/file.rb', line 14
def pre_action
case @current_action
when :create
attributes.exist = true
when :delete
attributes.exist = false
when :edit
attributes.exist = true
content = backend.receive_file(attributes.path)
attributes.block.call(content)
attributes.content = content
end
send_tempfile
end
|
#set_current_attributes ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/itamae/resource/file.rb', line 31
def set_current_attributes
current.exist = run_specinfra(:check_file_is_file, attributes.path)
if current.exist
current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
else
current.mode = nil
current.owner = nil
current.group = nil
end
end
|
#show_differences ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/itamae/resource/file.rb', line 45
def show_differences
current.mode = current.mode.rjust(4, '0') if current.mode
attributes.mode = attributes.mode.rjust(4, '0') if attributes.mode
super
if current.exist
show_file_diff
end
end
|