Module: Magellan::Cli::FileAccess
- Included in:
- Login, Resources::Base
- Defined in:
- lib/magellan/cli/file_access.rb
Defined Under Namespace
Classes: NotSelected
Instance Method Summary collapse
- #load_selection(name) ⇒ Object
- #load_selections ⇒ Object
- #update_selections(hash = nil) {|sel| ... } ⇒ Object
Instance Method Details
#load_selection(name) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/magellan/cli/file_access.rb', line 14 def load_selection(name) sel = load_selections s = sel[name] raise NotSelected, "No #{name} selected" unless s return s end |
#load_selections ⇒ Object
10 11 12 |
# File 'lib/magellan/cli/file_access.rb', line 10 def load_selections File.readable?(".magellan-cli") ? YAML.load_file(".magellan-cli") : {} end |
#update_selections(hash = nil) {|sel| ... } ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/magellan/cli/file_access.rb', line 21 def update_selections(hash = nil) sel = load_selections sel.update(hash) if hash yield(sel) if block_given? open(".magellan-cli", "w") do |f| f.chmod 0600 YAML.dump(sel, f) end end |