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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/itamae/resource/file.rb', line 60
def action_create(options)
if !current.exist && !@temppath
run_command(["touch", attributes.path])
end
change_target = attributes.modified ? @temppath : attributes.path
if attributes.mode
run_specinfra(:change_file_mode, change_target, attributes.mode)
end
if attributes.owner || attributes.group
run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group)
end
if attributes.modified
run_specinfra(:move_file, @temppath, attributes.path)
end
end
|
#action_delete(options) ⇒ Object
80
81
82
83
84
|
# File 'lib/itamae/resource/file.rb', line 80
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/itamae/resource/file.rb', line 86
def action_edit(options)
change_target = attributes.modified ? @temppath : attributes.path
if attributes.mode || attributes.modified
mode = attributes.mode || run_specinfra(:get_file_mode, attributes.path).stdout.chomp
run_specinfra(:change_file_mode, change_target, mode)
end
if attributes.owner || attributes.group || attributes.modified
owner = attributes.owner || run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
group = attributes.group || run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
run_specinfra(:change_file_owner, change_target, owner, group)
end
if attributes.modified
run_specinfra(:move_file, @temppath, attributes.path)
end
end
|
#pre_action ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/itamae/resource/file.rb', line 14
def pre_action
current.exist = run_specinfra(:check_file_is_file, attributes.path)
case @current_action
when :create
attributes.exist = true
when :delete
attributes.exist = false
when :edit
attributes.exist = true
if !runner.dry_run? || current.exist
content = backend.receive_file(attributes.path)
attributes.block.call(content)
attributes.content = content
end
end
send_tempfile
compare_file
end
|
#set_current_attributes ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/itamae/resource/file.rb', line 36
def set_current_attributes
current.modified = false
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
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/itamae/resource/file.rb', line 49
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 @temppath && @current_action != :delete
show_content_diff
end
end
|