Class: Capistrano::Template::Helpers::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/template/helpers/uploader.rb

Overview

rubocop: disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#digestObject

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

Parameters:

  • value

    the value to set the attribute digest_cmd to.



9
10
11
# File 'lib/capistrano/template/helpers/uploader.rb', line 9

def digest_cmd=(value)
  @digest_cmd = value
end

#full_to_pathObject

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

#groupObject

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

Parameters:

  • value

    the value to set the attribute group_test_cmd to.



9
10
11
# File 'lib/capistrano/template/helpers/uploader.rb', line 9

def group_test_cmd=(value)
  @group_test_cmd = value
end

#ioObject

Returns the value of attribute io.



9
10
11
# File 'lib/capistrano/template/helpers/uploader.rb', line 9

def io
  @io
end

#modeObject

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

Parameters:

  • value

    the value to set the attribute mode_test_cmd to.



9
10
11
# File 'lib/capistrano/template/helpers/uploader.rb', line 9

def mode_test_cmd=(value)
  @mode_test_cmd = value
end

#remote_handlerObject

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

#userObject

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

Parameters:

  • value

    the value to set the attribute user_test_cmd to.



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

#callObject



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

Returns:

  • (Boolean)


101
102
103
# File 'lib/capistrano/template/helpers/uploader.rb', line 101

def file_changed?
  !__check__(digest_cmd)
end

#group_changed?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/capistrano/template/helpers/uploader.rb', line 113

def group_changed?
  group && __check__(group_test_cmd)
end

#hostObject



68
69
70
# File 'lib/capistrano/template/helpers/uploader.rb', line 68

def host
  remote_handler.host
end

#permission_changed?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/capistrano/template/helpers/uploader.rb', line 105

def permission_changed?
  __check__(mode_test_cmd)
end

#set_groupObject



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_modeObject



72
73
74
75
76
77
78
79
# File 'lib/capistrano/template/helpers/uploader.rb', line 72

def set_mode
  if permission_changed?
    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_userObject



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_fileObject



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

Returns:

  • (Boolean)


109
110
111
# File 'lib/capistrano/template/helpers/uploader.rb', line 109

def user_changed?
  user && __check__(user_test_cmd)
end