Class: Capistrano::Template::Helpers::Uploader
- Inherits:
-
Object
- Object
- Capistrano::Template::Helpers::Uploader
- Defined in:
- lib/capistrano/template/helpers/uploader.rb
Overview
rubocop: disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#digest_cmd ⇒ Object
writeonly
Sets the attribute digest_cmd.
-
#full_to_path ⇒ Object
Returns the value of attribute full_to_path.
-
#group ⇒ Object
Returns the value of attribute group.
-
#group_test_cmd ⇒ Object
writeonly
Sets the attribute group_test_cmd.
-
#io ⇒ Object
Returns the value of attribute io.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#mode_test_cmd ⇒ Object
writeonly
Sets the attribute mode_test_cmd.
-
#remote_handler ⇒ Object
Returns the value of attribute remote_handler.
-
#user ⇒ Object
Returns the value of attribute user.
-
#user_test_cmd ⇒ Object
writeonly
Sets the attribute user_test_cmd.
Instance Method Summary collapse
- #call ⇒ Object
- #file_changed? ⇒ Boolean
- #group_changed? ⇒ Boolean
- #host ⇒ Object
-
#initialize(full_to_path, remote_handler, mode: 0640, mode_test_cmd: nil, user: nil, user_test_cmd: nil, group: nil, group_test_cmd: nil, digest: nil, digest_cmd: nil, io: nil) ⇒ Uploader
constructor
A new instance of Uploader.
- #permission_changed? ⇒ Boolean
- #set_group ⇒ Object
- #set_mode ⇒ Object
- #set_user ⇒ Object
- #upload_as_file ⇒ Object
- #user_changed? ⇒ Boolean
Constructor Details
#initialize(full_to_path, remote_handler, mode: 0640, mode_test_cmd: nil, user: nil, user_test_cmd: nil, group: nil, group_test_cmd: nil, digest: nil, digest_cmd: nil, io: nil) ⇒ Uploader
Returns a new instance of Uploader.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 21 def initialize(full_to_path, remote_handler, mode: 0640, mode_test_cmd: nil, user: nil, user_test_cmd: nil, group: nil, group_test_cmd: nil, digest: nil, digest_cmd: nil, io: nil ) self.remote_handler = remote_handler self.full_to_path = full_to_path self.digest_cmd = digest_cmd self.mode = mode self.mode_test_cmd = mode_test_cmd self.user = user self.user_test_cmd = user_test_cmd self.group = group self.group_test_cmd = group_test_cmd self.io = io self.digest = digest end |
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def digest @digest end |
#digest_cmd=(value) ⇒ Object
Sets the attribute digest_cmd
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def digest_cmd=(value) @digest_cmd = value end |
#full_to_path ⇒ Object
Returns the value of attribute full_to_path.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def full_to_path @full_to_path end |
#group ⇒ Object
Returns the value of attribute group.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def group @group end |
#group_test_cmd=(value) ⇒ Object
Sets the attribute group_test_cmd
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def group_test_cmd=(value) @group_test_cmd = value end |
#io ⇒ Object
Returns the value of attribute io.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def io @io end |
#mode ⇒ Object
Returns the value of attribute mode.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def mode @mode end |
#mode_test_cmd=(value) ⇒ Object
Sets the attribute mode_test_cmd
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def mode_test_cmd=(value) @mode_test_cmd = value end |
#remote_handler ⇒ Object
Returns the value of attribute remote_handler.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def remote_handler @remote_handler end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def user @user end |
#user_test_cmd=(value) ⇒ Object
Sets the attribute user_test_cmd
9 10 11 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 9 def user_test_cmd=(value) @user_test_cmd = value end |
Instance Method Details
#call ⇒ Object
48 49 50 51 52 53 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 48 def call upload_as_file set_mode set_user set_group end |
#file_changed? ⇒ Boolean
101 102 103 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 101 def file_changed? !__check__(digest_cmd) end |
#group_changed? ⇒ Boolean
113 114 115 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 113 def group_changed? group && __check__(group_test_cmd) end |
#host ⇒ Object
68 69 70 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 68 def host remote_handler.host end |
#permission_changed? ⇒ Boolean
105 106 107 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 105 def __check__(mode_test_cmd) end |
#set_group ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 91 def set_group if group_changed? remote_handler.info "group changed for file #{full_to_path} on #{host} set new group" remote_handler.execute 'sudo', 'chgrp', group, full_to_path else remote_handler.info "group not changed for file #{full_to_path} on #{host}" end end |
#set_mode ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 72 def set_mode if remote_handler.info "permission changed for file #{full_to_path} on #{host} set new permissions" remote_handler.execute 'chmod', octal_mode_str, full_to_path else remote_handler.info "permission not changed for file #{full_to_path} on #{host}" end end |
#set_user ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 81 def set_user if user_changed? remote_handler.info "user changed for file #{full_to_path} on #{host} set new user" remote_handler.execute 'sudo', 'chown', user, full_to_path else remote_handler.info "user not changed for file #{full_to_path} on #{host}" end end |
#upload_as_file ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 55 def upload_as_file if file_changed? remote_handler.info "copying to: #{full_to_path}" # just in case owner changed remote_handler.execute 'rm', '-f', full_to_path remote_handler.upload! io, full_to_path else remote_handler.info "File #{full_to_path} on host #{host} not changed" end end |
#user_changed? ⇒ Boolean
109 110 111 |
# File 'lib/capistrano/template/helpers/uploader.rb', line 109 def user_changed? user && __check__(user_test_cmd) end |