Module: L5MTools::Tools

Includes:
FileUtils
Included in:
Application, SVN
Defined in:
lib/l5m-tools.rb,
lib/l5m-tools/tools.rb

Instance Method Summary collapse

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_putsObject



7
# File 'lib/l5m-tools.rb', line 7

alias :copy_with_replace_without_puts :copy_with_replace

#duplicate_and_replace(file, replacements = {}) {|to| ... } ⇒ Object

Yields:

  • (to)


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), to]
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')
    message = outlook.CreateItem(0) 
    message.Subject =   subject
    message.Body = body
    message.To = to
    message.Save
    message.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_homeObject



64
65
66
# File 'lib/l5m-tools/tools.rb', line 64

def user_home
    File.expand_path('~')
end