Class: Yay::Lister

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

Overview

Lists installed .yay files See also: Rimmer, Cat

Instance Method Summary collapse

Instance Method Details

#get_all_filesObject

returns {dir=>



23
24
25
26
27
28
29
30
# File 'lib/yay/lister.rb', line 23

def get_all_files
  paths  = Yay::Paths.new
  result = {}
  paths.yay_paths.each { |path| 
    result[path] = get_files_in_dir path
  }
  return result
end

#get_files_in_dir(dir) ⇒ Object

returns [[name, path],..]



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/yay/lister.rb', line 9

def get_files_in_dir dir
  results = []
  Dir.glob("#{dir}/*.yay").each { |path| 
    matches = /\/(\w*)?\.yay$/.match(path)
    if matches[1]
      results.unshift [matches[1], path]
    else
      puts "Eh.. #{path} isn't quite right"
    end
  }
  return results
end

print all paths and files we find in them



53
54
55
56
57
# File 'lib/yay/lister.rb', line 53

def print
  print_paths
  puts
  print_files
end

print the files we can use and the command that can be typed to use it



42
43
44
45
46
47
48
49
50
# File 'lib/yay/lister.rb', line 42

def print_files
  puts "Installed styles:"
  get_all_files.each_pair { |dir, files| 
    #puts "#{dir}:"
    files.each { |file| 
      puts "#{file[0]}#{' '*(20-file[0].length)}#{file[1]}"
    }
  }      
end

print the search paths we’ll use when looking for yay files



33
34
35
36
37
38
39
# File 'lib/yay/lister.rb', line 33

def print_paths
  puts "Search paths: (in order of precedence)"
  paths = Yay::Paths.new
  paths.yay_paths.each { |dir| 
    puts dir
  }
end