class Serverkit::Resources::Entry
Abstract class for file and directory
Public Instance Methods
apply()
click to toggle source
@note Override
# File lib/serverkit/resources/entry.rb, line 16 def apply update_entry unless has_correct_entry? update_group unless has_correct_group? update_mode unless has_correct_mode? update_owner unless has_correct_owner? end
check()
click to toggle source
@note Override
# File lib/serverkit/resources/entry.rb, line 24 def check has_correct_entry? && has_correct_group? && has_correct_mode? && has_correct_owner? end
Private Instance Methods
destination()
click to toggle source
@note Override me @return [String] Path to the entry on remote side
# File lib/serverkit/resources/entry.rb, line 32 def destination raise NotImplementedError end
has_correct_content?()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 36 def has_correct_content? content.nil? || remote_file_sha256sum == local_content_sha256sum end
has_correct_entry?()
click to toggle source
@note Override me
# File lib/serverkit/resources/entry.rb, line 41 def has_correct_entry? raise NotImplementedError end
has_correct_group?()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 45 def has_correct_group? group.nil? || check_command_from_identifier(:check_file_is_grouped, destination, group) end
has_correct_mode?()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 49 def has_correct_mode? mode.nil? || check_command_from_identifier(:check_file_has_mode, destination, mode_in_octal_notation) end
has_correct_owner?()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 53 def has_correct_owner? owner.nil? || check_command_from_identifier(:check_file_is_owned_by, destination, owner) end
has_remote_file?()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 57 def has_remote_file? check_command_from_identifier(:check_file_is_file, destination) end
local_content_sha256sum()
click to toggle source
@return [String]
# File lib/serverkit/resources/entry.rb, line 62 def local_content_sha256sum ::Digest::SHA256.hexdigest(content) end
mode_in_octal_notation()
click to toggle source
@return [String] @example “755” # for 0755
# File lib/serverkit/resources/entry.rb, line 68 def mode_in_octal_notation if mode.is_a?(Integer) mode.to_s(8) else mode end end
remote_file_sha256sum()
click to toggle source
@return [String]
# File lib/serverkit/resources/entry.rb, line 77 def remote_file_sha256sum run_command_from_identifier(:get_file_sha256sum, destination).stdout.rstrip end
send_content_to_destination()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 81 def send_content_to_destination ::Tempfile.open("") do |file| file.write(content || "") file.close backend.send_file(file.path, destination) end end
update_entry()
click to toggle source
@note Override me
# File lib/serverkit/resources/entry.rb, line 90 def update_entry raise NotImplementedError end
update_group()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 94 def update_group run_command_from_identifier(:change_file_group, destination, group) end
update_mode()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 98 def update_mode run_command_from_identifier(:change_file_mode, destination, mode_in_octal_notation) end
update_owner()
click to toggle source
# File lib/serverkit/resources/entry.rb, line 102 def update_owner run_command_from_identifier(:change_file_owner, destination, owner) end