Sha256: d7fd4f36dc01ba1ed4fa9aeb881ae3891e87cf3987e2b68de36803cea8560044

Contents?: true

Size: 684 Bytes

Versions: 19

Compression:

Stored size: 684 Bytes

Contents

# -*- coding: utf-8 -*-

module Magellan
  module Cli
    module FileAccess

      class NotSelected < StandardError
      end

      def load_selections
        File.readable?(".magellan-cli") ? YAML.load_file(".magellan-cli") : {}
      end

      def load_selection(name)
        sel = load_selections
        s = sel[name]
        raise NotSelected, "No #{name} selected" unless s
        return s
      end

      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
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
magellan-cli-0.2.18 lib/magellan/cli/file_access.rb
magellan-cli-0.2.17 lib/magellan/cli/file_access.rb
magellan-cli-0.2.16 lib/magellan/cli/file_access.rb
magellan-cli-0.2.15 lib/magellan/cli/file_access.rb
magellan-cli-0.2.14 lib/magellan/cli/file_access.rb
magellan-cli-0.2.13 lib/magellan/cli/file_access.rb
magellan-cli-0.2.12 lib/magellan/cli/file_access.rb
magellan-cli-0.2.11 lib/magellan/cli/file_access.rb
magellan-cli-0.2.10 lib/magellan/cli/file_access.rb
magellan-cli-0.2.9 lib/magellan/cli/file_access.rb
magellan-cli-0.2.8 lib/magellan/cli/file_access.rb
magellan-cli-0.2.7 lib/magellan/cli/file_access.rb
magellan-cli-0.2.6 lib/magellan/cli/file_access.rb
magellan-cli-0.2.5 lib/magellan/cli/file_access.rb
magellan-cli-0.2.4 lib/magellan/cli/file_access.rb
magellan-cli-0.2.3 lib/magellan/cli/file_access.rb
magellan-cli-0.2.2 lib/magellan/cli/file_access.rb
magellan-cli-0.2.1 lib/magellan/cli/file_access.rb
magellan-cli-0.2.0 lib/magellan/cli/file_access.rb