Module: Lightning::Config
- Included in:
- Lightning
- Defined in:
- lib/lightning/config.rb
Instance Method Summary collapse
- #add_command_paths(config) ⇒ Object
- #command_to_path_key(map_to_command, new_command) ⇒ Object
- #config ⇒ Object
- #config_command(name) ⇒ Object
-
#globbable_paths_by_key(key) ⇒ Object
should return array of globbable paths.
- #ignore_paths ⇒ Object
- #path_key_to_command(path_key) ⇒ Object
- #read_config(config_file = nil) ⇒ Object
Instance Method Details
#add_command_paths(config) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lightning/config.rb', line 34 def add_command_paths(config) config[:paths] ||= {} config[:commands].each do |e| #mapping a referenced path if e['paths'].is_a?(String) e['path_key'] = e['paths'].dup e['paths'] = config[:paths][e['paths'].strip] || [] end #create a path entry + key if none exists if e['path_key'].nil? #extract command in case it has options after it e['map_to'] =~ /\s*(\w+)/ path_key = command_to_path_key($1, e['name']) e['path_key'] = path_key config[:paths][path_key] = e['paths'] end end end |
#command_to_path_key(map_to_command, new_command) ⇒ Object
26 27 28 |
# File 'lib/lightning/config.rb', line 26 def command_to_path_key(map_to_command, new_command) "#{map_to_command}-#{new_command}" end |
#config ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/lightning/config.rb', line 2 def config unless @config @config = read_config add_command_paths(@config) end @config end |
#config_command(name) ⇒ Object
22 23 24 |
# File 'lib/lightning/config.rb', line 22 def config_command(name) config[:commands].find {|e| e['name'] == name} || {} end |
#globbable_paths_by_key(key) ⇒ Object
should return array of globbable paths
18 19 20 |
# File 'lib/lightning/config.rb', line 18 def globbable_paths_by_key(key) config[:paths][key] || [] end |
#ignore_paths ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/lightning/config.rb', line 53 def ignore_paths unless @ignore_paths @ignore_paths = [] @ignore_paths += config[:ignore_paths] if config[:ignore_paths] && !config[:ignore_paths].empty? end @ignore_paths end |
#path_key_to_command(path_key) ⇒ Object
30 31 32 |
# File 'lib/lightning/config.rb', line 30 def path_key_to_command(path_key) path_key.split("-")[1] end |
#read_config(config_file = nil) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/lightning/config.rb', line 10 def read_config(config_file=nil) default_config = {:shell=>'bash', :generated_file=>File.(File.join('~', '.lightning_completions'))} config_file ||= File.exists?('lightning.yml') ? 'lightning.yml' : File.(File.join("~",".lightning.yml")) hash = YAML::load(File.new(config_file)) default_config.merge(hash.symbolize_keys) end |