Module: Babushka::RunHelpers

Includes:
LogHelpers, PathHelpers, ShellHelpers
Included in:
DepDefiner, DepDefiner, Renderable
Defined in:
lib/babushka/helpers/run_helpers.rb

Instance Method Summary collapse

Methods included from PathHelpers

cd, in_build_dir, in_download_dir

Methods included from ShellHelpers

cmd_dir, current_username, log_shell, login_shell, raw_shell, shell, shell!, shell?, shell_cmd, sudo, which

Methods included from LogHelpers

debug, deprecated!, log, log_block, log_error, log_ok, log_stderr, log_warn, removed!

Instance Method Details

#_by_babushkaObject



13
14
15
# File 'lib/babushka/helpers/run_helpers.rb', line 13

def _by_babushka
  "by babushka-#{VERSION} at #{Time.now}"
end

#added_by_babushka(nlines) ⇒ Object



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

def added_by_babushka nlines
  if nlines == 1
    "This line added #{_by_babushka}"
  else
    "These #{nlines} lines added #{_by_babushka}"
  end
end

#append_to_file(text, file, opts = {}) ⇒ Object



7
8
9
10
11
# File 'lib/babushka/helpers/run_helpers.rb', line 7

def append_to_file text, file, opts = {}
  deprecated! '2012-09-01', :instead => 'Fancypath#append', :example => "'#{file}'.p.append(#{text.inspect})"
  text = text.to_s
  shell %Q{echo "\n# #{added_by_babushka(text.split("\n").length)}\n#{text.gsub('"', '\"')}" >> #{file}}, opts
end

#babushka_config?(path) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
# File 'lib/babushka/helpers/run_helpers.rb', line 29

def babushka_config? path
  if !path.p.exists?
    unmet "the config hasn't been generated yet"
  elsif !grep(/Generated by babushka/, path)
    unmet "the config needs to be regenerated"
  else
    true
  end
end

#edited_by_babushkaObject



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

def edited_by_babushka
  "This line edited #{_by_babushka}"
end

#erb_path_for(erb) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/babushka/helpers/run_helpers.rb', line 55

def erb_path_for erb
  if erb.to_s.starts_with? '/'
    erb # absolute path
  elsif load_path
    File.dirname(load_path) / erb # directory this dep is in, plus relative path
  end
end

#render_erb(erb, opts = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/babushka/helpers/run_helpers.rb', line 39

def render_erb erb, opts = {}
  if (path = erb_path_for(erb)).nil?
    log_error "If you use #render_erb within a dynamically defined dep, you have to give the full path to the erb template."
  elsif !File.exists?(path)
    log_error "Couldn't find erb to render at #{path}."
  elsif File.exists?(path)
    Renderable.new(opts[:to]).render(path, opts.merge(:context => self)).tap {|result|
      if result
        log "Rendered #{opts[:to]}."
      else
        log_error "Couldn't render #{opts[:to]}."
      end
    }
  end
end