Module: Lightning::Util
- Extends:
- Lightning::Util
- Defined in:
- lib/lightning/util.rb
Instance Method Summary
- - (String) find_home Cross-platform way to determine a user’s home.
- - (Object) load_plugins(base_dir, sub_dir) Loads *.rb plugins in given directory and sub directory under it.
- - (Boolean) shell_command_exists?(command) Determines if a shell command exists by searching for it in ENV[‘PATH’].
- - (Hash) symbolize_keys(hash) Symbolizes keys of given hash.
Instance Method Details
- (String) find_home
Cross-platform way to determine a user’s home. From Rubygems.
33 34 35 36 37 38 39 |
# File 'lib/lightning/util.rb', line 33 def find_home ['HOME', 'USERPROFILE'].each {|e| return ENV[e] if ENV[e] } return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] File.("~") rescue File::ALT_SEPARATOR ? "C:/" : "/" end |
- (Object) load_plugins(base_dir, sub_dir)
Loads *.rb plugins in given directory and sub directory under it
55 56 57 58 59 60 |
# File 'lib/lightning/util.rb', line 55 def load_plugins(base_dir, sub_dir) if File.exists?(dir = File.join(base_dir, sub_dir)) plugin_type = sub_dir.sub(/s$/, '') Dir[dir + '/*.rb'].each {|file| load_plugin(file, plugin_type) } end end |
- (Boolean) shell_command_exists?(command)
Determines if a shell command exists by searching for it in ENV[‘PATH’].
42 43 44 45 |
# File 'lib/lightning/util.rb', line 42 def shell_command_exists?(command) (@path ||= ENV['PATH'].split(File::PATH_SEPARATOR)). any? {|d| File.exists? File.join(d, command) } end |
- (Hash) symbolize_keys(hash)
Symbolizes keys of given hash
48 49 50 51 52 |
# File 'lib/lightning/util.rb', line 48 def symbolize_keys(hash) hash.inject({}) do |h, (key, value)| h[key.to_sym] = value; h end end |