Class: CheckEverything

Inherits:
Object
  • Object
show all
Defined in:
lib/check_everything.rb

Constant Summary collapse

KNOWN_TAGS =
{
  :help => ['-h','--help'],
  :links => ['-l','--links'],
  :ruby => ['-r','--ruby'],
  :categories => ['-c', '--categories'],
  :all => ['-a', '--all']
}
LINKPATH =
"#{File.expand_path('~')}/.check_everything_links"
LINKFILE =
"#{LINKPATH}/links.txt"
RUBYFILE =
"#{LINKPATH}/ruby.txt"

Class Method Summary collapse

Class Method Details

.runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/check_everything.rb', line 16

def self.run
  @argv = ARGV.map(&:downcase)
  until ARGV.empty?
    ARGV.pop
  end
  # Only assemble Ruby development library if requested to.
  @ruby_dev_assemble = false
  # Create a new link file if none has been created yet
  if !File.exists?(LINKFILE)
    # If a previous version created a file rather than a directory, move it into
    # the new directory.
    if File.exists?(LINKPATH)
      system("mv #{LINKPATH} #{LINKPATH}2")
      system("mkdir #{LINKPATH}")
      system("mv #{LINKPATH}2 #{LINKFILE}")
    else
      system("mkdir #{LINKPATH}")
      system("cp #{File.dirname(__FILE__)}/check_everything/links.txt #{LINKFILE}")
    end
    @argv = ["-l"]
    print "Are you a Ruby Dev who will want documentation-checking ",
      "functionality? [Y/n] "
    @ruby_dev_assemble = true unless gets.strip.downcase == 'n'
    puts "\nPlease customize your installation.",
      "This message will only be shown once.",
      "To open again and customize, just enter 'check_everything -l' to open",
      "the link file."
  end
  # Assume no problems with the link file.
  @category_space, @category_dash = false, false

  extract_links

  # First check for unknown arguments and print out a helpful message.
  known_tags = KNOWN_TAGS.values.flatten + @links.keys + @ruby_links
  unmatched_args = @argv.select do |arg|
    !known_tags.any?{|known_tag| known_tag.downcase == arg.downcase}
  end
  if !unmatched_args.empty?
    puts "\nUnknown option#{@argv.size > 1 ? "s" : nil}: " +
      "#{unmatched_args.join(" ")}"
    print "usage: check_everything"
    KNOWN_TAGS.values.flatten.each {|tag| print " [#{tag}]"}
    puts "\n\nHint: Enter 'check_everything --help' to see the options!"
    puts "\n"
  
  # Print out a help message.
  elsif @argv.any? {|arg| KNOWN_TAGS[:help].include?(arg)}
    help

  # Edit the tags and links.
  elsif @argv.any? {|arg| KNOWN_TAGS[:links].include?(arg)}
    # If asked to build the Ruby Dev file, build it!
    assemble_ruby_docs_file if @ruby_dev_assemble

    system("open #{LINKFILE}")
  
  elsif @argv.any? {|arg| KNOWN_TAGS[:ruby].include?(arg)}
    assemble_ruby_docs_file

  # Check for errors; don't allow the user to see bad categories or open up
  # websites if the categories are not formatted properly.
  elsif @category_space
      puts "Your link file includes a category with a space in it; " +
        "please fix by entering 'check_everything -l' into your command line."
  elsif @category_dash
      puts "Your link file includes a category with a dash, which is " +
        "not allowed; please fix by entering 'check_everything -l' into your command line."

  # View the categories the user has defined.
  elsif @argv.any? {|arg| KNOWN_TAGS[:categories].include?(arg)}
    view_categories
  
  # Open up the websites!
  else
    open_links
  end
end