diff options
author | ytti <saku@ytti.fi> | 2018-06-22 19:25:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 19:25:10 +0300 |
commit | 428708ef376884c3dc35aee1951cb8e1c55fac9f (patch) | |
tree | 8e209bdceb34385373f11796178b8706ba7e55c9 /lib/oxidized/source/csv.rb | |
parent | f0947761b46e4ee6cdadd866b1cf3cf25bdfeedd (diff) |
Refactor smells
* reduce no/resolve_repo smell
* reduce input/ssh/connect smell
* reduce source/http load smell
* reduce node/worker smell
* reduce source/csv smell
* reduce output/http smell
Get's code climate from B to A, so I'm sure it's super duper important.
Diffstat (limited to 'lib/oxidized/source/csv.rb')
-rw-r--r-- | lib/oxidized/source/csv.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index 7b771f6..769b1f7 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -20,14 +20,7 @@ module Oxidized def load _node_want = nil nodes = [] - file = File.expand_path(@cfg.file) - file = if @cfg.gpg? - crypto = GPGME::Crypto.new password: @cfg.gpg_password - file = crypto.decrypt(File.open(file)).to_s - else - open(file) - end - file.each_line do |line| + get_file.each_line do |line| next if line.match(/^\s*#/) data = line.chomp.split(@cfg.delimiter, -1) next if data.empty? @@ -49,5 +42,17 @@ module Oxidized end nodes end + + private + + def get_file + file = File.expand_path(@cfg.file) + if @cfg.gpg? + crypto = GPGME::Crypto.new password: @cfg.gpg_password + crypto.decrypt(File.open(file)).to_s + else + open(file) + end + end end end |