Top Level Namespace

Defined Under Namespace

Modules: Admin, Initial, Teleporter Classes: WelcomeController

Instance Method Summary collapse

Instance Method Details

#smart_template(from, to = nil) ⇒ Object

will first try and copy the file: config/deploy/#full_app_name/#from.erb to: shared/config/to if the original source path doesn exist then it will search in: config/deploy/shared/#from.erb this allows files which are common to all enviros to come from a single source while allowing specific ones to be over-ridden if the target file name is the same as the source then the second parameter can be left out



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/initial/templates/capistrano/lib/template.rb', line 13

def smart_template(from, to=nil)
  to ||= from
  full_to_path = "#{shared_path}/config/#{to}"
  if from_erb_path = template_file(from)
    from_erb = StringIO.new(ERB.new(File.read(from_erb_path)).result(binding))
    upload! from_erb, full_to_path
    info "copying: #{from_erb} to: #{full_to_path}"
  else
    error "error #{from} not found"
  end
end

#sub_strings(input_string) ⇒ Object

we often want to refer to variables which are defined in subsequent stage files. This let’s us use the {var} to represent fetch(:var) in strings which are only evaluated at runtime.



6
7
8
9
10
11
12
# File 'lib/generators/initial/templates/capistrano/lib/substitute_strings.rb', line 6

def sub_strings(input_string)
  output_string = input_string
  input_string.scan(/{{(\w*)}}/).each do |var|
    output_string.gsub!("{{#{var[0]}}}", fetch(var[0].to_sym))
  end
  output_string
end

#template_file(name) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/generators/initial/templates/capistrano/lib/template.rb', line 25

def template_file(name)
  if File.exist?((file = "config/deploy/#{fetch(:full_app_name)}/#{name}.erb"))
    return file
  elsif File.exist?((file = "config/deploy/shared/#{name}.erb"))
    return file
  end
  return nil
end