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

Instance Method Details

#load_selection(name) ⇒ Object

Raises:



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_selectionsObject



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

Yields:

  • (sel)


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