Class: Medoc
- Inherits:
-
Object
- Object
- Medoc
- Defined in:
- lib/medoc.rb
Constant Summary collapse
- @@config_file =
Path to config file
File. '~/.medoc.yml'
- @@config =
Loaded config
nil
Class Method Summary collapse
-
.config_file ⇒ Object
Returns path to config file.
-
.init ⇒ Object
Creates default config file.
-
.run(keyword) ⇒ Object
Main method.
-
.version ⇒ Object
Returns current version.
Class Method Details
.config_file ⇒ Object
Returns path to config file
42 43 44 |
# File 'lib/medoc.rb', line 42 def self.config_file @@config_file end |
.init ⇒ Object
Creates default config file
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
Main method. Returns full path matching provided alias
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 94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
Returns current version
35 36 37 |
# File 'lib/medoc.rb', line 35 def self.version '1.0.2' end |