Class: L5MTools::Application

Inherits:
Object
  • Object
show all
Includes:
Tools
Defined in:
lib/l5m-tools.rb,
lib/l5m-tools/application.rb

Instance Method Summary collapse

Methods included from Tools

#ask, #change_directory, #copy_with_replace, #copy_with_replace_without_puts, #duplicate_and_replace, #replace, #send_mail, #to_file, #user_home

Instance Method Details

#del(*args) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/l5m-tools/application.rb', line 56

def del(*args)
    p = ->(file){
        rm(file, :force => true)
        puts file
    }
    if File.exist?(args[0])
        read_files(args[0], &p)
    else
        search_files(args[0], args[1], &p)
    end
end

#dupObject



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

alias :dup :duplicate_app

#duplicate_app(*args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/l5m-tools/application.rb', line 42

def duplicate_app(*args)
    delete = args.delete('-d')
    replacements  = {args[1] => args[2]}
    p = ->(line){
        rm(line, :force => true) if duplicate_and_replace( line.chomp ,  replacements )[1] != line && delete
    }
    if File.exist?(args[0])
        read_files(args[0], &p)
    else
        search_files(args[0], args[1], &p)
    end
end

#helpObject



92
93
94
95
96
# File 'lib/l5m-tools/application.rb', line 92

def help
    puts <<-EOF
        Please go to https://github.com/RONGHAI/l5m-tools
    EOF
end

#makeObject



21
22
23
24
25
26
# File 'lib/l5m-tools.rb', line 21

def make_app(*args, &block)
    package = ask("rem","Please input package name").downcase
    application = ask("","Please input application name") 
    use_base_worker = ask("true","Use AbstractBaseWorker?").to_boolean
    old_make_app(package, application, use_base_worker, &block)
end

#make_app(package, application, use_base_worker, &block) ⇒ Object



15
16
17
18
19
20
# File 'lib/l5m-tools.rb', line 15

def make_app(*args, &block)
    package = ask("rem","Please input package name").downcase
    application = ask("","Please input application name") 
    use_base_worker = ask("true","Use AbstractBaseWorker?").to_boolean
    old_make_app(package, application, use_base_worker, &block)
end

#old_make_appObject



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

alias old_make_app make_app

#read_files(csvfile) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/l5m-tools/application.rb', line 31

def read_files(csvfile)
    File.open(csvfile, "r") do |infile|
        while (line = infile.gets)
            line = line.chomp.strip
            if line.length > 0 && line[0] != '#'
                yield line if block_given?
            end
        end
    end
end

#rm(file, options) ⇒ Object

that is svn remove



11
12
13
14
15
16
17
18
19
# File 'lib/l5m-tools/application.rb', line 11

def rm(file, options)
    #FileUtils.rm(file, :force => true)
    # remove file from svn
    package = file[(WORKSPACE.length+1)..(-1)]
    svnfile = package[(package.index(/[\/\\]/) + 1)..(-1)]
    package = package[0...(package.index(/[\/\\]/))]
    require 'l5m-tools/l5m-tools-module'
    L5MTools.svn.delete([package], {}, [ "--force", svnfile])
end

#run(*args, &block) ⇒ Object



23
24
25
# File 'lib/l5m-tools.rb', line 23

def run(*args, &block)
    send args.shift, *args, &block
end

#search_files(package, application) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/l5m-tools/application.rb', line 22

def search_files(package, application)
    Dir.glob("#{WORKSPACE}/#{package}/{src,WebContent}/**/#{application}*.*", File::FNM_CASEFOLD).each{|line|  
        bn = File.basename(line, ".*")
        unless(bn[application.length] =~ /[a-z0-9]/)
            yield line if block_given?
        end              
    }
end

#versionObject



88
89
90
91
# File 'lib/l5m-tools/application.rb', line 88

def version
    file = Pathname.new(__FILE__).parent.parent.parent.to_s + "/VERSION"
    puts(File.exist?(file) ? File.read(file) : "") 
end