Top Level Namespace

Defined Under Namespace

Modules: AppDirectory, Negroku, SSHKit

Instance Method Summary collapse

Instance Method Details

#all_required?(arr) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/negroku/helpers/tasks.rb', line 11

def all_required?(arr)
  arr.all? { |file| required?(file) }
end

#any_required?(arr) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/negroku/helpers/tasks.rb', line 7

def any_required?(arr)
  arr.any? { |file| required?(file) }
end

#build_set_var_cmd(vars_file, key, value) ⇒ Object

helper to build the set VAR cmd



2
3
4
5
6
7
8
9
# File 'lib/negroku/helpers/env.rb', line 2

def build_set_var_cmd(vars_file, key, value)
  puts "#{vars_file} #{key} #{value}"
  cmd = "if awk < #{vars_file} -F= '{print $1}' | grep --quiet -w #{key}; then "
  cmd += "sed -i 's/^#{key}=.*/#{key}=#{value.gsub("\/", "\\/")}/g' #{vars_file};"
  cmd += "else echo '#{key}=#{value}' >> #{vars_file};"
  cmd += "fi"
  cmd
end

#build_template(template, destination, binding) ⇒ Object

Build the template



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/negroku/helpers/templates.rb', line 4

def build_template(template, destination, binding)

  template_file = get_template_file(template)

  result = ERB.new(template_file, nil, '-').result(binding)

  if destination
    File.open(destination.to_s, 'w+') do |f|
      f.write(result)
    end
  else
    return StringIO.new(result)
  end
end

#define_logs(namespace, hash) ⇒ Object

Define los



3
4
5
6
7
8
9
# File 'lib/negroku/helpers/logs.rb', line 3

def define_logs(namespace, hash)
  logs = fetch(:negroku_logs, {})

  logs[namespace] = hash

  set :negroku_logs, logs
end

#get_template_file(filename) ⇒ Object

Get the template file from the project and fallback to the gem



26
27
28
29
30
31
32
33
34
# File 'lib/negroku/helpers/templates.rb', line 26

def get_template_file(filename)
  if File.exists?(filename)
    templateFile = filename
  else
    templateFile = File.expand_path("../../#{filename}", __FILE__)
  end

  File.read(templateFile)
end

#load_task(name, dependencies = []) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/negroku/helpers/tasks.rb', line 15

def load_task(name, dependencies = [])
  if all_required? dependencies
    load File.join(File.dirname(__FILE__), '..', 'capistrano', 'tasks', "#{name}.rake")
  else
    fail "To load #{name} you need to include #{dependencies.join ", "}"
  end
end

#partial(filename, binding) ⇒ Object

Render one nested error partial



20
21
22
23
# File 'lib/negroku/helpers/templates.rb', line 20

def partial(filename, binding)
  template_file = get_template_file(filename)
  ERB.new(template_file, nil, '-', '_erbout2').result(binding)
end

#required?(file) ⇒ Boolean

Find out if a specific library file was already required

Returns:

  • (Boolean)


2
3
4
5
# File 'lib/negroku/helpers/tasks.rb', line 2

def required?(file)
  rex = Regexp.new("/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
  $LOADED_FEATURES.find { |f| f =~ rex }
end

#watch_process(name, options = {}) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/negroku/helpers/watch.rb', line 1

def watch_process(name, options = {})
  processes = fetch(:eye_watched_processes, {})

  options[:name] ||= name

  options[:template] ||= name.to_sym

  if options[:template].kind_of?(Symbol)
    options[:template] = "capistrano/templates/eye/_#{options[:template]}.erb"
  end

  processes[name] = options

  set :eye_watched_processes, processes
end