class Renv::CLI

Public Instance Methods

del(*keys) click to toggle source
# File lib/renv/cli.rb, line 23
def del(*keys)
  _engine.del(keys)
end
dump() click to toggle source
# File lib/renv/cli.rb, line 28
def dump
  puts _engine.dump
end
get(key) click to toggle source
# File lib/renv/cli.rb, line 12
def get(key)
  puts _engine.get(key)
end
load() click to toggle source
# File lib/renv/cli.rb, line 33
def load
  _engine.load(STDIN.read)
end
set(*pairs) click to toggle source
# File lib/renv/cli.rb, line 17
def set(*pairs)
  hash = _parse_pairs(pairs)
  _engine.set(hash)
end

Private Instance Methods

_engine() click to toggle source
# File lib/renv/cli.rb, line 39
def _engine
  connection = Connection.new(
    app:        options[:app],
    bucket:     options[:bucket]
  )
  Engine.new(
    name:       options[:name],
    connection: connection)
end
_parse_pairs(pairs) click to toggle source

Transforms an array of KEY=VALUE pairs into a { KEY => VALUE } hash. The key is the part at the left of the first equals sign.

# File lib/renv/cli.rb, line 51
def _parse_pairs(pairs)
  Hash.new.tap do |h|
    pairs.each do |p|
      if p !~ /^([^=]+)=(.*)$/ # left/right of the first equals sign
        $stderr.puts "Not a valid key-value: '#{p}'"
        exit 1
      end
      h[$1] = $2
    end
  end
end