class SPath::ConfigFile
Attributes
options[RW]
path[RW]
shortcuts[RW]
Public Class Methods
load(path = DEFAULT_CONFIG_PATH)
click to toggle source
# File lib/spath.rb, line 37 def self.load(path = DEFAULT_CONFIG_PATH) path = File.expand_path(path) return new unless File.exists?(File.expand_path(path)) data = YAML.load(File.read(path)) # If config file returns empty, use the default return new unless data shortcuts = data[:shortcuts].map { |sdata| Shortcut[sdata] } new(path, shortcuts, data[:options]) end
new(path = DEFAULT_CONFIG_PATH, shortcuts = [], options = {})
click to toggle source
# File lib/spath.rb, line 11 def initialize(path = DEFAULT_CONFIG_PATH, shortcuts = [], options = {}) @path = File.expand_path(path) @shortcuts = shortcuts @options = options end
Public Instance Methods
<<(shortcut)
click to toggle source
# File lib/spath.rb, line 17 def <<(shortcut) raise ArgumentError "#{shortcut} is not a SPath::Shortcut" \ unless shortcut.is_a? Shortcut # Make room for new shortcuts @shortcuts.delete_if { |old_shortcut| shortcut.nickname == old_shortcut.nickname } # Append to the array @shortcuts << shortcut end
Also aliased as: add_shortcut
path_for(nickname)
click to toggle source
# File lib/spath.rb, line 51 def path_for(nickname) raise ArgumentError, "path does not exist for shortcut #{nickname}" unless \ (shortcut = @shortcuts.select { |s| s.nickname.to_s == nickname }.first) shortcut.path end
to_hash()
click to toggle source
# File lib/spath.rb, line 29 def to_hash { shortcuts: @shortcuts.map(&:to_hash), options: @options } end
write!()
click to toggle source
# File lib/spath.rb, line 33 def write! File.open(@path, "w") { |f| f.write(to_hash.to_yaml) } end