From 0f7510b6e6b61dfb898328eb6c161b2583dbff83 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 30 Mar 2017 19:44:32 +0200 Subject: [PATCH] multiple fix on syntax --- lib/mpw/cli.rb | 6 ++---- lib/mpw/config.rb | 7 ++----- lib/mpw/item.rb | 2 +- lib/mpw/mpw.rb | 8 ++------ 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 0536108..cc452cf 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -70,9 +70,7 @@ class Cli password = ask(I18n.t('form.setup_gpg_key.password')) { |q| q.echo = false } confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) { |q| q.echo = false } - if password != confirm - raise I18n.t('form.setup_gpg_key.error_password') - end + raise I18n.t('form.setup_gpg_key.error_password') if password != confirm @password = password.to_s @@ -378,7 +376,7 @@ class Cli opts = YAML.load_file(tmp_file) end - opts.delete_if { |k, v| v.to_s.empty? } + opts.delete_if { |_, v| v.to_s.empty? } opts.each do |k, v| options[k.to_sym] = v diff --git a/lib/mpw/config.rb b/lib/mpw/config.rb index a6c102e..d691559 100644 --- a/lib/mpw/config.rb +++ b/lib/mpw/config.rb @@ -101,11 +101,8 @@ class Config # expire -> the time of expire to GPG key # @rtrn: true if the GPG key is create, else false def setup_gpg_key(password, name, length = 4096, expire = 0) - if name.to_s.empty? - raise I18n.t('error.config.genkey_gpg.name') - elsif password.to_s.empty? - raise I18n.t('error.config.genkey_gpg.password') - end + raise I18n.t('error.config.genkey_gpg.name') if name.to_s.empty? + raise I18n.t('error.config.genkey_gpg.password') if password.to_s.empty? param = '' param << '' + "\n" diff --git a/lib/mpw/item.rb b/lib/mpw/item.rb index 1534cc4..cd24168 100644 --- a/lib/mpw/item.rb +++ b/lib/mpw/item.rb @@ -96,7 +96,7 @@ class Item # Generate an random id def generate_id - ([*('A'..'Z'), *('a'..'z'), *('0'..'9')]).sample(16).join + [*('A'..'Z'), *('a'..'z'), *('0'..'9')].sample(16).join end end end diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 557d572..daf04ff 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -32,9 +32,7 @@ class MPW @gpg_exe = gpg_exe @wallet_file = wallet_file - unless @gpg_exe.to_s.empty? - GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg") - end + GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg") unless @gpg_exe.to_s.empty? end # Read mpw file @@ -204,9 +202,7 @@ class MPW data = GPGME::Key.export(key, armor: true).read end - if data.to_s.empty? - raise I18n.t('error.export_key') - end + raise I18n.t('error.export_key') if data.to_s.empty? @keys[key] = data @passwords.each_key { |id| set_password(id, get_password(id)) }