Module: Babushka::RunHelpers
Instance Method Summary
collapse
-
#_by_babushka ⇒ Object
-
#added_by_babushka(nlines) ⇒ Object
-
#append_to_file(text, file, opts = {}) ⇒ Object
-
#babushka_config?(path) ⇒ Boolean
-
#bundle_rake(cmd, &block) ⇒ Object
-
#change_line(line, replacement, filename) ⇒ Object
-
#change_with_sed(keyword, from, to, file) ⇒ Object
-
#check_file(file_name, method_name) ⇒ Object
-
#edited_by_babushka ⇒ Object
-
#erb_path_for(erb) ⇒ Object
-
#grep(pattern, file) ⇒ Object
-
#hostname ⇒ Object
-
#insert_into_file(insert_before, path, lines, opts = {}) ⇒ Object
-
#log_and_open(message, url) ⇒ Object
-
#mysql(cmd, username = 'root', include_password = true) ⇒ Object
-
#rake(cmd, &block) ⇒ Object
-
#render_erb(erb, opts = {}) ⇒ Object
-
#yaml(path) ⇒ Object
cd, in_build_dir, in_download_dir
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_babushka ⇒ Object
43
44
45
|
# File 'lib/babushka/helpers/run_helpers.rb', line 43
def _by_babushka
"by babushka-#{VERSION} at #{Time.now}"
end
|
#added_by_babushka(nlines) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/babushka/helpers/run_helpers.rb', line 51
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
39
40
41
|
# File 'lib/babushka/helpers/run_helpers.rb', line 39
def append_to_file text, file, opts = {}
removed! :instead => 'Fancypath#append', :example => "'#{file}'.p.append(#{text.inspect})"
end
|
#babushka_config?(path) ⇒ Boolean
59
60
61
62
63
64
65
66
67
|
# File 'lib/babushka/helpers/run_helpers.rb', line 59
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
|
#bundle_rake(cmd, &block) ⇒ Object
15
16
17
|
# File 'lib/babushka/helpers/run_helpers.rb', line 15
def bundle_rake cmd, &block
removed! :instead => "#shell directly", :example => "shell({'RAILS_ENV' => 'env'}, 'bundle exec #{cmd}')"
end
|
#change_line(line, replacement, filename) ⇒ Object
27
28
29
|
# File 'lib/babushka/helpers/run_helpers.rb', line 27
def change_line line, replacement, filename
removed! :instead => "sed via #shell", :example => "shell(\"sed -i'' -e 's/^#{Regexp.escape(line)}$/#{replacement}/' '#{filename}'\")"
end
|
#change_with_sed(keyword, from, to, file) ⇒ Object
35
36
37
|
# File 'lib/babushka/helpers/run_helpers.rb', line 35
def change_with_sed keyword, from, to, file
removed! :instead => "sed via #shell", :example => "shell(\"sed -i'' -e 's/^#{Regexp.escape(keyword)}\\s+#{Regexp.escape(from)}\\b/#{keyword} #{to}/' '#{file}'\")"
end
|
#check_file(file_name, method_name) ⇒ Object
19
20
21
|
# File 'lib/babushka/helpers/run_helpers.rb', line 19
def check_file file_name, method_name
removed! :instead => "Fancypath##{method_name}", :example => "path.p.#{method_name}"
end
|
#edited_by_babushka ⇒ Object
47
48
49
|
# File 'lib/babushka/helpers/run_helpers.rb', line 47
def edited_by_babushka
"This line edited #{_by_babushka}"
end
|
#erb_path_for(erb) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/babushka/helpers/run_helpers.rb', line 89
def erb_path_for erb
if erb.to_s.starts_with? '/'
erb elsif load_path
File.dirname(load_path) / erb end
end
|
#grep(pattern, file) ⇒ Object
23
24
25
|
# File 'lib/babushka/helpers/run_helpers.rb', line 23
def grep pattern, file
removed! :instead => 'Fancypath#grep', :example => "#{file.inspect}.p.grep(#{pattern.inspect})"
end
|
7
8
9
|
# File 'lib/babushka/helpers/run_helpers.rb', line 7
def hostname
removed! :instead => "#shell directly", :example => "shell('hostname -f')"
end
|
#insert_into_file(insert_before, path, lines, opts = {}) ⇒ Object
31
32
33
|
# File 'lib/babushka/helpers/run_helpers.rb', line 31
def insert_into_file insert_before, path, lines, opts = {}
removed! :instead => "a template with #render_erb"
end
|
#log_and_open(message, url) ⇒ Object
97
98
99
|
# File 'lib/babushka/helpers/run_helpers.rb', line 97
def log_and_open message, url
removed! :instead => "a plain #log with the URL", :example => "log('Download here: http://website.org')"
end
|
#mysql(cmd, username = 'root', include_password = true) ⇒ Object
101
102
103
|
# File 'lib/babushka/helpers/run_helpers.rb', line 101
def mysql cmd, username = 'root', include_password = true
removed! :instead => "#shell directly", :example => "shell('mysql', '-u', username, :input => cmd.end_with(';'))"
end
|
#rake(cmd, &block) ⇒ Object
11
12
13
|
# File 'lib/babushka/helpers/run_helpers.rb', line 11
def rake cmd, &block
removed! :instead => "#shell directly", :example => "shell({'RAILS_ENV' => env}, 'rake #{cmd}')"
end
|
#render_erb(erb, opts = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/babushka/helpers/run_helpers.rb', line 73
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
|
#yaml(path) ⇒ Object
69
70
71
|
# File 'lib/babushka/helpers/run_helpers.rb', line 69
def yaml path
removed! :instead => 'Fancypath#yaml', :example => "'#{path}'.p.yaml"
end
|