class Permutation::Config

Constants

ACCOUNT_CONFIG_FILE
REPOSITORY_CONFIG_FILE

Public Class Methods

account() click to toggle source
# File lib/tools/config.rb, line 7
def account
  Permutation::Config.read(ACCOUNT_CONFIG_FILE) || init
end
host() click to toggle source
# File lib/tools/config.rb, line 35
def host
  if config = Permutation::Config.read(ACCOUNT_CONFIG_FILE)
    config['host']
  else
    nil
  end
end
init() click to toggle source
# File lib/tools/config.rb, line 11
def init
  access_token = nil
  json = {}

  puts "Log In to Permutation"
  email  = ask("Email: ")
  password = ask("Password: ") {|q| q.echo = false}

  response = Permutation::API.post '/api/session.json', { email: email, password: password }

  if response.status == 201
    session = response.body.slice("email","access_token")
    json.merge! session
    json.merge! host: Permutation::API.host unless Permutation::API.host == Permutation::API::DEFAULT_HOST

    write(json, ACCOUNT_CONFIG_FILE)
    json
  else
    puts
    puts "Invalid login credentials"
    exit
  end
end
read(file) click to toggle source
# File lib/tools/config.rb, line 54
def read(file)
  return JSON.parse( IO.read(file), symbolize_names: false )
rescue
  nil
end
version() click to toggle source
# File lib/tools/config.rb, line 60
def version
  read["version"]
end
write(json, file) click to toggle source
# File lib/tools/config.rb, line 46
def write(json, file)
  puts "Writing to #{file}" if DEBUG

  _file = File.open( file, "w+" )
  _file.write(JSON.pretty_generate(json))
  _file.close
end

Private Class Methods

not_setup!() click to toggle source
# File lib/tools/config.rb, line 66
def not_setup!
  puts "Permutation is not setup, please run 'permutation init'"
  exit 1
end