Sha256: 2154a5b78d0bb47b97661a18276f97f10419f5efb3e9272ee6d48499959c6bbb
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
require 'uri' module Glman module Commands module Configs class GitlabConfig class GitlabConfigurationError < StandardError; end include InitRequired attr_required :config_manager DEFAULT = { url: '', private_token: '' } def set(hash={}) raise GitlabConfigurationError.new('incorrect data') unless hash.kind_of? Hash raise GitlabConfigurationError.new "url is incorrect" unless valid_url?(hash[:url]) raise GitlabConfigurationError.new "private_token missing" if hash[:private_token].to_s.strip.empty? gitlab = {url: hash[:url], private_token: hash[:private_token]} config_manager.set(gitlab: gitlab) end def get (config_manager.get || {})[:gitlab] || DEFAULT end def clear config_manager.set(gitlab: DEFAULT) end private def valid_url?(url) url = URI.parse(url) rescue false url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems