Module: L5MTools::Tools
- Includes:
- FileUtils
- Included in:
- Application, SVN
- Defined in:
- lib/l5m-tools.rb,
lib/l5m-tools/tools.rb
Instance Method Summary collapse
- #ask(default_answer, *question_lines) ⇒ Object
- #change_directory(dir, &operation) ⇒ Object
- #copy_with_replace(from, to, replacements) ⇒ Object (also: #copy_silently)
- #copy_with_replace_without_puts ⇒ Object
- #duplicate_and_replace(file, replacements = {}) {|to| ... } ⇒ Object
- #replace(in_file, replacements) ⇒ Object
- #send_mail(to, subject = "", body = "") ⇒ Object
- #to_file(file, replacements = {}) ⇒ Object
- #user_home ⇒ Object
Instance Method Details
#ask(default_answer, *question_lines) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/l5m-tools/tools.rb', line 39 def ask(default_answer, *question_lines) puts question_lines print "[#{default_answer}] => " answer = STDIN.readline.strip answer == '' ? default_answer.to_s : answer.to_s end |
#change_directory(dir, &operation) ⇒ Object
36 37 38 |
# File 'lib/l5m-tools/tools.rb', line 36 def change_directory(dir, &operation) return Dir::chdir(dir, &operation) if File.exists? dir end |
#copy_with_replace(from, to, replacements) ⇒ Object Also known as: copy_silently
8 9 10 11 |
# File 'lib/l5m-tools.rb', line 8 def copy_with_replace(from, to, replacements) puts to copy_with_replace_without_puts(from, to, replacements) end |
#copy_with_replace_without_puts ⇒ Object
7 |
# File 'lib/l5m-tools.rb', line 7 alias :copy_with_replace_without_puts :copy_with_replace |
#duplicate_and_replace(file, replacements = {}) {|to| ... } ⇒ Object
56 57 58 59 60 |
# File 'lib/l5m-tools/tools.rb', line 56 def duplicate_and_replace(file, replacements = {}) to = to_file(file, replacements) yield to if block_given? copy_with_replace(file, to, replacements) end |
#replace(in_file, replacements) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/l5m-tools/tools.rb', line 20 def replace(in_file, replacements) contents = IO.read(in_file) changed = false replacements.each do | key, value | if(contents.gsub!(key, value)) changed = true; end end File.open(in_file, 'w') { | io | io.puts(contents) } return changed end |
#send_mail(to, subject = "", body = "") ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/l5m-tools/tools.rb', line 3 def send_mail to, subject="", body="" require 'win32ole' outlook = WIN32OLE.new('Outlook.Application') mapi = outlook.GetNameSpace('MAPI') = outlook.CreateItem(0) .Subject = subject .Body = body .To = to .Save .Send mapi.SyncObjects end |
#to_file(file, replacements = {}) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/l5m-tools/tools.rb', line 47 def to_file(file, replacements = {}) dirname = File.dirname(file) basename = File.basename(file) replacements.each do | key, value | basename.gsub!(key, value) end dirname + File::SEPARATOR + basename; end |
#user_home ⇒ Object
64 65 66 |
# File 'lib/l5m-tools/tools.rb', line 64 def user_home File.('~') end |