Module: Lightning::Config
- Included in:
- Lightning
- Defined in:
- lib/lightning/config.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
Instance Method Summary collapse
- #commands_to_bolt_key(map_to_command, new_command) ⇒ Object
- #config ⇒ Object
- #config=(value) ⇒ Object
- #config_command(name) ⇒ Object
- #configure_commands_and_paths(hash) ⇒ Object
- #ignore_paths ⇒ Object
- #load_config ⇒ Object
- #read_config_file(file = nil) ⇒ Object
- #setup_config ⇒ Object
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
2 3 4 |
# File 'lib/lightning/config.rb', line 2 def config_file @config_file end |
Instance Method Details
#commands_to_bolt_key(map_to_command, new_command) ⇒ Object
33 34 35 |
# File 'lib/lightning/config.rb', line 33 def commands_to_bolt_key(map_to_command, new_command) "#{map_to_command}-#{new_command}" end |
#config ⇒ Object
7 8 9 |
# File 'lib/lightning/config.rb', line 7 def config @config ||= setup_config end |
#config=(value) ⇒ Object
11 12 13 |
# File 'lib/lightning/config.rb', line 11 def config=(value) @config = value end |
#config_command(name) ⇒ Object
29 30 31 |
# File 'lib/lightning/config.rb', line 29 def config_command(name) config[:commands].find {|e| e['name'] == name} || {} end |
#configure_commands_and_paths(hash) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lightning/config.rb', line 37 def configure_commands_and_paths(hash) hash[:paths] ||= {} hash[:commands].each do |e| #mapping a referenced path if e['paths'].is_a?(String) e['bolt_key'] = e['paths'].dup end #create a path entry + key if none exists if e['bolt_key'].nil? #extract command in case it has options after it e['map_to'] =~ /\s*(\w+)/ bolt_key = commands_to_bolt_key($1, e['name']) e['bolt_key'] = bolt_key hash[:paths][bolt_key] = e['paths'] || [] end end hash end |
#ignore_paths ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/lightning/config.rb', line 56 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 |
#load_config ⇒ Object
3 4 5 |
# File 'lib/lightning/config.rb', line 3 def load_config @config = setup_config end |
#read_config_file(file = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/lightning/config.rb', line 21 def read_config_file(file=nil) default_config = {:shell=>'bash', :generated_file=>File.(File.join('~', '.lightning_completions')), :complete_regex=>true} @config_file = file || @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 |
#setup_config ⇒ Object
15 16 17 18 19 |
# File 'lib/lightning/config.rb', line 15 def setup_config hash = read_config_file configure_commands_and_paths(hash) hash end |