class Medoc
Public Class Methods
config_file()
click to toggle source
Returns path to config file
# File lib/medoc.rb, line 42 def self.config_file @@config_file end
init()
click to toggle source
Creates default config file
# File lib/medoc.rb, line 49 def self.init if !File.exists? @@config_file f = File.new @@config_file, "w" f.puts '#############################################' f.puts '### Medoc config file ###' f.puts '### ###' f.puts '### Visit https://github.com/acadet/medoc ###' f.puts '### to know more about this file ###' f.puts '#############################################' else raise MedocError.new "Error: config file is already existing." end end
run(keyword)
click to toggle source
Main method. Returns full path matching provided alias
# File lib/medoc.rb, line 66 def self.run(keyword) if !Medoc.load_config # No existing config file raise MedocError.new 'Error: no config file found. You should run medoc --init.' end if !@@config # No alias raise MedocError.new 'Error: no alias defined in config file. Visit https://github.com/acadet/medoc to know how to define aliases.' end if @@config.has_key? keyword instructions = @@config[keyword] target = '' # Instructions can either be a simple directory # or a list of aliases and directories if instructions.kind_of? Array instructions.each do |e| if @@config.has_key?(e) && e != keyword # Instruction is an existing alias target = append target, Medoc.run(e) else # Simple directory target = append target, e end end else # Only a directory target = instructions end return target else raise MedocError.new "Error: no '#{keyword}' alias in config file." end end
version()
click to toggle source
Returns current version
# File lib/medoc.rb, line 35 def self.version '1.0.2' end
Private Class Methods
append(path, dir)
click to toggle source
Appends a path to new dir
# File lib/medoc.rb, line 109 def self.append(path, dir) if path.size > 0 && path[path.size - 1] != '/' # Append '/' if missing "#{path}/#{dir}" else "#{path}#{dir}" end end
load_config()
click to toggle source
Loads Medoc
config file
# File lib/medoc.rb, line 121 def self.load_config if !@@config.nil? # File already loaded return true end # Test if file exists if !File.exists? @@config_file return false end @@config = YAML.load_file @@config_file true end