Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#_cset(name, *args, &block) ⇒ Object

Accepts a parameter name and value and registers it as a default within Capistrano. Params: name args block



6
7
8
9
10
# File 'lib/ash/common.rb', line 6

def _cset(name, *args, &block)
  unless exists?(name)
    set(name, *args, &block)
  end
end

#local_dir_exists?(full_path) ⇒ Boolean

Check if a directory exists by providing the full path to the expected location

Returns:

  • (Boolean)


25
26
27
# File 'lib/ash/common.rb', line 25

def local_dir_exists?(full_path)
  File.directory?(full_path)
end

#local_file_exists?(full_path) ⇒ Boolean

Check if a file exists by providing the full path to the expected file location

Returns:

  • (Boolean)


20
21
22
# File 'lib/ash/common.rb', line 20

def local_file_exists?(full_path)
  File.exists?(full_path)
end

#remote_dir_exists?(dir_path) ⇒ Boolean

Test to see if a directory exists on a remote server by providing the full path to the expected directory

Params:

+dir_path+

Returns:

  • (Boolean)


41
42
43
# File 'lib/ash/common.rb', line 41

def remote_dir_exists?(dir_path)
  'true' == capture("if [[ -d #{dir_path} ]]; then echo 'true'; fi").strip
end

#remote_file_exists?(full_path) ⇒ Boolean

Test to see if a file exists by providing the full path to the expected file location

Returns:

  • (Boolean)


31
32
33
# File 'lib/ash/common.rb', line 31

def remote_file_exists?(full_path)
  'true' ==  capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end

#set_perms(path, perm = 644) ⇒ Object

set permission on specific file or directory path instead of doing it with a big hammer like set_perms_files or set_perms_dir



81
82
83
84
85
86
87
88
# File 'lib/ash/common.rb', line 81

def set_perms(path, perm = 644)
  begin
    try_sudo "chmod #{perm} #{path}" if remote_file_exists?(path) || remote_dir_exists?(path)
  rescue Exception => e
    logger.important "FAILED to set permission of #{perm} on #{path}"
    logger.important e.message
  end
end

#set_perms_dirs(dir_path, perm = 755) ⇒ Object

set the permissions for directories recursively from the starting directory (dir_path)



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ash/common.rb', line 63

def set_perms_dirs(dir_path, perm = 755)
  begin
    run "find #{dir_path} -type d -print0 | xargs -0 -L 500 #{try_sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
  rescue Exception => e
    logger.important "FAILED to set permissions of #{perm} on directories within #{dir_path}!"
    logger.important e.message
    logger.important "Trying to set permissions without using xargs"
    begin
      run "find #{dir_path} -type d -exec #{try_sudo} chmod #{perm} {} \\;"  if remote_dir_exists?(dir_path)
    rescue Exception => e
      logger.important "FAILED second attempt to set permissions of #{perm} on directories within #{dir_path}!"
      logger.important e.message
    end
  end
end

#set_perms_files(dir_path, perm = 644) ⇒ Object

set the permissions for files recurisvely from the starting directory (dir_path)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ash/common.rb', line 46

def set_perms_files(dir_path, perm = 644)
  begin
    run "find #{dir_path} -type f -print0 | xargs -0 -L 500 #{try_sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
  rescue Exception => e
    logger.important "FAILED to set permissions of #{perm} on files within #{dir_path}!"
    logger.important e.message
    logger.important "Trying to set permissions without using xargs"
    begin
      run "find #{dir_path} -type f -exec #{try_sudo} chmod #{perm} {} \\;"  if remote_dir_exists?(dir_path)
    rescue Exception => e
      logger.important "FAILED second attempt to set permissions of #{perm} on files within #{dir_path}!"
      logger.important e.message
    end
  end
end

#text_prompt(prompt = "Value: ") ⇒ Object

Prompts user entry Params: prompt



15
16
17
# File 'lib/ash/common.rb', line 15

def text_prompt(prompt="Value: ")
  Capistrano::CLI.ui.ask(prompt) { |q| q.echo = true }
end