Module: Capistrano::MagicRecipes::BaseHelpers

Defined in:
lib/capistrano/magic_recipes/base_helpers.rb

Instance Method Summary collapse

Instance Method Details

#generate_secrect_keyObject



33
34
35
# File 'lib/capistrano/magic_recipes/base_helpers.rb', line 33

def generate_secrect_key
  SecureRandom.hex(82)
end

#get_template_file(from) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/capistrano/magic_recipes/base_helpers.rb', line 43

def get_template_file( from )
  [
      File.join('config', 'deploy', 'templates', "#{from}.rb.erb"),
      File.join('config', 'deploy', 'templates', "#{from}.rb"),
      File.join('config', 'deploy', 'templates', "#{from}.erb"),
      File.join('config', 'deploy', 'templates', "#{from}"),
      File.join('lib', 'capistrano', 'templates', "#{from}.rb.erb"),
      File.join('lib', 'capistrano', 'templates', "#{from}.rb"),
      File.join('lib', 'capistrano', 'templates', "#{from}.erb"),
      File.join('lib', 'capistrano', 'templates', "#{from}"),
      File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}.rb.erb", __FILE__),
      File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}.rb", __FILE__),
      File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}.erb", __FILE__),
      File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}", __FILE__)
  ].each do |path|
    return File.read(path) if File.file?(path)
  end
  # false
  raise "File '#{from}' was not found!!!"
end

#magic_render(tmpl) ⇒ Object



27
28
29
30
# File 'lib/capistrano/magic_recipes/base_helpers.rb', line 27

def magic_render(tmpl)
  erb = get_template_file(tmpl)
  ERB.new(erb).result(binding)
end

#magic_template(from, to) ⇒ Object



21
22
23
24
# File 'lib/capistrano/magic_recipes/base_helpers.rb', line 21

def magic_template(from, to)
  erb = get_template_file(from)
  upload! StringIO.new( ERB.new(erb).result(binding) ), to
end

#template(from, to) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/capistrano/magic_recipes/base_helpers.rb', line 8

def template(from, to)
  # => erb = File.read(File.expand_path("../../../../config/deploy/templates/#{from}", __FILE__))
  # => upload ERB.new(erb).result(binding), to, via: :scp
  # on hosts do |host|
  #   upload! ERB.new(erb).result(binding), to
  # end
  # => erb = File.read(File.expand_path("../../../../config/deploy/templates/#{from}", __FILE__))
  if File.file?(from)
    config = ERB.new( File.read(from) ).result(binding)
    upload! StringIO.new(config), to
  end
end

#template_with_role(from, to, role = nil) ⇒ Object



37
38
39
40
# File 'lib/capistrano/magic_recipes/base_helpers.rb', line 37

def template_with_role(from, to, role = nil)
  erb = get_template_file(from)
  upload! StringIO.new(ERB.new(erb).result(binding)), to
end