Module: Yac

Extended by:
Yac
Included in:
Yac
Defined in:
lib/yac.rb

Constant Summary collapse

YACRC =
File.join("#{ENV['HOME']}",".yacrc")
CONFIG =
YAML.load_file(File.join(ENV['HOME'],".yacrc"))

Instance Method Summary collapse

Instance Method Details

#edit(args) ⇒ Object



60
61
62
# File 'lib/yac.rb', line 60

def edit(args)
  args.each {|x| edit_single(x)}
end

#helpObject



68
69
70
# File 'lib/yac.rb', line 68

def help
  format_file(File.dirname(__FILE__)+"/../README.rdoc")
end

#new(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/yac.rb', line 15

def new(args)
  unless File.exist?(@main_path) && File.exist?(@pri_path)
    return unless init
  end
  @all_result = []
  (help && exit) if args.empty?
  case args.first
  when "show" then show(args[1,args.size])
  when "name" then search(args[1,args.size],"name")
  when "content" then search(args[1,args.size],"content")
  when "update" then update(args[1,args.size])
  when /^(add|edit)$/ then edit(args[1,args.size])
  when /^(help|-h|yac|--help)$/ then help
  when /^(sh|shell)$/ then shell(args[1,args.size])
  when "rm" then rm(args[1,args.size])
  when "init" then init
  else show(args)
  end
  show_possible_result
rescue
end

#rm(args) ⇒ Object



64
65
66
# File 'lib/yac.rb', line 64

def rm(args)
  args.each {|x| rm_single(x)}
end

#search(args, type = "name") ⇒ Object



41
42
43
# File 'lib/yac.rb', line 41

def search(args,type = "name")
  args.each {|x| search_single(x,type)}
end

#shell(args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/yac.rb', line 72

def shell(args)
  case args.to_s
  when /main/
    puts "\033[31m Welcome To The Main Yac Repository \033[0m"
    system "cd #{@main_path}; sh"
  else
    puts "\033[31m Welcome To The Private Yac Repository \033[0m"
    system "cd #{@pri_path}; sh"
  end
end

#show(args) ⇒ Object



37
38
39
# File 'lib/yac.rb', line 37

def show(args)
  args.each {|x| show_single(x)}
end

#update(args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/yac.rb', line 45

def update(args)
  begin
    unless args.empty?
      @pri_git.pull if args.to_s =~ /pri/
      @main_git.pull if args.to_s =~ /main/
    else
      @main_git.pull
      @pri_git.pull
    end
  rescue
    puts "ERROR: can not update the repository,"
    puts $!
  end
end