Top Level Namespace

Defined Under Namespace

Modules: TSRails

Instance Method Summary collapse

Instance Method Details

#action_mailer_host(rails_env, host) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/helpers.rb', line 77

def action_mailer_host(rails_env, host)
  inject_into_file(
    "config/environments/#{rails_env}.rb",
    "\n\n  config.action_mailer.default_url_options = { :host => '#{host}' }",
    :before => "\nend"
  )
end

#apache_name_taken?(project_name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/helpers.rb', line 59

def apache_name_taken?(project_name)
  remote_dir_exists?(TSRails::Constants.get(:staging_server), TSRails::Constants.get(:staging_ssh_user), "#{TSRails::Constants.get(:remote_apache_dir)}/#{project_name}.taylored-software.com")
end

#ask_with_default(prompt, default_value) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/helpers.rb', line 21

def ask_with_default(prompt, default_value)
  msg = "#{prompt} [#{default_value}]"
  result = ask(msg)
  if result.nil?
    result = default_value
  end
  result
end

#concat_file(source, destination) ⇒ Object



63
64
65
66
# File 'lib/helpers.rb', line 63

def concat_file(source, destination)
  contents = IO.read(find_in_source_paths(source))
  append_file destination, contents
end

#get_file(http_location, file) ⇒ Object

Helper functions



11
12
13
14
15
# File 'lib/helpers.rb', line 11

def get_file(http_location, file)
  uri = URI.parse(http_location)
  contents = Net::HTTP.get(uri)
  File.open(file, "w") { |f| f.write(contents) }
end

#git_name_taken?(project_name) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/helpers.rb', line 55

def git_name_taken?(project_name)
  remote_dir_exists?(TSRails::Constants.get(:staging_server), TSRails::Constants.get(:staging_ssh_user), "#{TSRails::Constants.get(:remote_git_dir)}/#{project_name}.git")
end

#msg(mtype, message) ⇒ Object



17
18
19
# File 'lib/helpers.rb', line 17

def msg(message)
  msg :info, message
end

#remote_dir_exists?(hostname, username, dir_path) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/helpers.rb', line 47

def remote_dir_exists?(hostname, username, dir_path)
  output = ""
  Net::SSH.start(hostname, username) do |ssh|
    output = ssh.exec!("ls -d #{dir_path} 2>/dev/null | wc -l").chomp.strip
  end
  output == "1"
end

#replace_file(filename, content) ⇒ Object



90
91
92
93
# File 'lib/helpers.rb', line 90

def replace_file (filename, content)
  remove_file filename
  file filename, content
end

#replace_in_file(relative_path, find, replace) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/helpers.rb', line 68

def replace_in_file(relative_path, find, replace)
  path = File.join(destination_root, relative_path)
  contents = IO.read(path)
  unless contents.gsub!(find, replace)
    raise "#{find.inspect} not found in #{relative_path}"
  end
  File.open(path, "w") { |file| file.write(contents) }
end

#section(descr) ⇒ Object



85
86
87
88
# File 'lib/helpers.rb', line 85

def section(descr)
  printf "\n"
  msg :info, descr
end