class Rbk::Configuration
Public Class Methods
create(argv)
click to toggle source
# File lib/rbk/configuration.rb, line 8 def self.create(argv) self.load.parse(argv) end
load()
click to toggle source
# File lib/rbk/configuration.rb, line 12 def self.load if File.exists?('.rbk.yml') config = YAML.load_file('.rbk.yml') elsif File.exists?(File.join(Dir.home, '.rbk.yml')) config = YAML.load_file(File.join(Dir.home, '.rbk.yml')) else config = {} end new(config) end
new(config={})
click to toggle source
# File lib/rbk/configuration.rb, line 23 def initialize(config={}) @config = defaults.merge(config) @parser = create_parser end
Public Instance Methods
aws_credentials()
click to toggle source
# File lib/rbk/configuration.rb, line 60 def aws_credentials { access_key_id: @config['aws_access_key_id'], secret_access_key: @config['aws_secret_access_key'] } end
help?()
click to toggle source
# File lib/rbk/configuration.rb, line 48 def help? !!@config['show_help'] end
method_missing(m, *args, &block)
click to toggle source
Calls superclass method
# File lib/rbk/configuration.rb, line 40 def method_missing(m, *args, &block) if @config.key?(m.to_s) @config[m.to_s] else super end end
parse(argv)
click to toggle source
# File lib/rbk/configuration.rb, line 28 def parse(argv) @parser.parse(argv) self end
quiet?()
click to toggle source
# File lib/rbk/configuration.rb, line 52 def quiet? !!@config['quiet'] end
usage()
click to toggle source
# File lib/rbk/configuration.rb, line 56 def usage @parser.to_s end
validate()
click to toggle source
# File lib/rbk/configuration.rb, line 33 def validate invalid_option?(@config['bucket'], 'Missing S3 bucket') invalid_option?(@config['github_access_token'], 'Missing GitHub access token') invalid_option?(@config['organization'], 'Missing organization') self end
Private Instance Methods
create_parser()
click to toggle source
# File lib/rbk/configuration.rb, line 87 def create_parser OptionParser.new do |opt| opt.on('-o', '--organization=NAME', '(GitHub) Organization name') do |o| @config['organization'] = o end opt.on('-b', '--bucket=NAME', 'S3 bucket where to store backups') do |b| @config['bucket'] = b end opt.on('-G TOKEN', '--github-access-token=TOKEN', 'GitHub access token') do |token| @config['github_access_token'] = token end opt.on('-A KEY', '--access-key-id=KEY', 'AWS access key id') do |key| @config['aws_access_key_id'] = key end opt.on('-S KEY', '--secret-access-key=KEY', 'AWS secret access key') do |key| @config['aws_secret_access_key'] = key end opt.on('-q', '--quiet', 'Be quiet and mind your own business') do |key| @config['quiet'] = key end opt.on('-h', '--help', 'Display this screen') do @config['show_help'] = true end end end
defaults()
click to toggle source
# File lib/rbk/configuration.rb, line 75 def defaults { 'aws_access_key_id' => nil, 'aws_secret_access_key' => nil, 'bucket' => nil, 'github_access_token' => ENV['GITHUB_ACCESS_TOKEN'], 'organization' => nil, 'quiet' => false, 'show_help' => false, } end
invalid_option?(value, message)
click to toggle source
# File lib/rbk/configuration.rb, line 69 def invalid_option?(value, message) if !help? && (!value || value.empty?) raise InsufficientOptionsError, message end end