From c738b0c5667e114b86b912cba429b64b342836ff Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 1 Oct 2015 23:32:17 -0700 Subject: [PATCH] Abstract conf parsing to class --- lib/vmfloaty.rb | 14 ++------------ lib/vmfloaty/conf.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 lib/vmfloaty/conf.rb diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index ca9c7de..2359815 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -2,10 +2,10 @@ require 'rubygems' require 'commander' -require 'yaml' require 'vmfloaty/auth' require 'vmfloaty/pooler' require 'vmfloaty/version' +require 'vmfloaty/conf' class Vmfloaty include Commander::Methods @@ -14,7 +14,7 @@ class Vmfloaty program :version, Version.get program :description, 'A CLI helper tool for Puppet Labs vmpooler to help you stay afloat' - config = read_config + config = Conf.read_config command :get do |c| c.syntax = 'floaty get [hostname,...]' @@ -235,14 +235,4 @@ class Vmfloaty run! end - - def read_config - conf = {} - begin - conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml") - rescue - STDERR.puts "WARNING: There was no config file at #{Dir.home}/.vmfloaty.yml" - end - conf - end end diff --git a/lib/vmfloaty/conf.rb b/lib/vmfloaty/conf.rb new file mode 100644 index 0000000..2f04e61 --- /dev/null +++ b/lib/vmfloaty/conf.rb @@ -0,0 +1,14 @@ +require 'yaml' + +class Conf + + def self.read_config + conf = {} + begin + conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml") + rescue + STDERR.puts "WARNING: There was no config file at #{Dir.home}/.vmfloaty.yml" + end + conf + end +end