diff --git a/bin/mpw-wallet b/bin/mpw-wallet index e575c0d..bcc3fc2 100644 --- a/bin/mpw-wallet +++ b/bin/mpw-wallet @@ -66,7 +66,7 @@ cli = MPW::Cli.new(config) cli.load_config -if not options[:list].nil? +if !options[:list].nil? cli.list_wallet else cli.get_wallet(options[:wallet]) diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 83b9af3..9571fec 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -103,7 +103,7 @@ class Cli # Request the GPG password and decrypt the file def decrypt - if not defined?(@mpw) + unless defined?(@mpw) @password = ask(I18n.t('display.gpg_password')) {|q| q.echo = false} @mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe) end @@ -451,9 +451,7 @@ class Cli item = get_item(items) confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s - if not confirm =~ /^(y|yes|YES|Yes|Y)$/ - return false - end + return false unless confirm =~ /^(y|yes|YES|Yes|Y)$/ item.delete @mpw.write_data @@ -516,7 +514,7 @@ class Cli # @args: file -> the import file def import(file) raise I18n.t('form.import.file_empty') if file.to_s.empty? - raise I18n.t('form.import.file_not_exist') if not File.exist?(file) + raise I18n.t('form.import.file_not_exist') unless File.exist?(file) YAML::load_file(file).each_value do |row| item = Item.new(group: row['group'], @@ -530,8 +528,8 @@ class Cli next if item.empty? @mpw.add(item) - @mpw.set_password(item.id, row['password']) if not row['password'].to_s.empty? - @mpw.set_otp_key(item.id, row['otp_key']) if not row['otp_key'].to_s.empty? + @mpw.set_password(item.id, row['password']) unless row['password'].to_s.empty? + @mpw.set_otp_key(item.id, row['otp_key']) unless row['otp_key'].to_s.empty? end @mpw.write_data diff --git a/lib/mpw/config.rb b/lib/mpw/config.rb index 298ba61..8ec8e3a 100644 --- a/lib/mpw/config.rb +++ b/lib/mpw/config.rb @@ -73,7 +73,7 @@ class Config end end - if not gpg_key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/ + unless gpg_key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/ raise I18n.t('error.config.key_bad_format') end diff --git a/lib/mpw/item.rb b/lib/mpw/item.rb index 469af15..7c2547e 100644 --- a/lib/mpw/item.rb +++ b/lib/mpw/item.rb @@ -68,7 +68,7 @@ class Item @port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty? @otp = options[:otp] if options.has_key?(:otp) @comment = options[:comment] if options.has_key?(:comment) - @last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit) + @last_edit = Time.now.to_i unless options.has_key?(:no_update_last_edit) end # Delete all data diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 9147648..bb4e38b 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -33,7 +33,7 @@ class MPW @gpg_exe = gpg_exe @wallet_file = wallet_file - if not @gpg_exe.to_s.empty? + unless @gpg_exe.to_s.empty? GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg") end end @@ -48,7 +48,7 @@ class MPW data = nil - return if not File.exists?(@wallet_file) + return unless File.exists?(@wallet_file) Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar| tar.each do |f| @@ -80,7 +80,7 @@ class MPW end end - if not data.nil? and not data.empty? + unless data.to_s.empty? YAML.load(data).each_value do |d| @data.push(Item.new(id: d['id'], group: d['group'], @@ -254,14 +254,12 @@ class MPW @data.each do |item| next if item.empty? - next if not group.empty? and not group.eql?(item.group.to_s.downcase) + next unless group.empty? or group.eql?(item.group.to_s.downcase) host = item.host.to_s.downcase comment = item.comment.to_s.downcase - if not host =~ /^.*#{search}.*$/ and not comment =~ /^.*#{search}.*$/ - next - end + next unless host =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/ result.push(item) end @@ -284,9 +282,7 @@ class MPW # args: id -> the item id # key -> the new key def set_otp_key(id, key) - if not key.to_s.empty? - @otp_keys[id] = encrypt(key.to_s) - end + @otp_keys[id] = encrypt(key.to_s) unless key.to_s.empty? end # Get an opt key @@ -305,7 +301,7 @@ class MPW # @args: id -> the item id # @rtrn: an otp code def get_otp_code(id) - if not @otp_keys.has_key?(id) + unless @otp_keys.has_key?(id) return 0 else return ROTP::TOTP.new(decrypt(@otp_keys[id])).now diff --git a/templates/add_form.erb b/templates/add_form.erb index c2d6d73..bb81787 100644 --- a/templates/add_form.erb +++ b/templates/add_form.erb @@ -2,7 +2,7 @@ host: # <%= I18n.t('form.add_item.host') %> user: # <%= I18n.t('form.add_item.login') %> group: # <%= I18n.t('form.add_item.group') %> -protocol: # <%= I18n.t('form.add_item.protocol') %><% if not password %> +protocol: # <%= I18n.t('form.add_item.protocol') %><% unless password %> password: # <%= I18n.t('form.add_item.password') %><% end %> port: # <%= I18n.t('form.add_item.port') %> comment: # <%= I18n.t('form.add_item.comment') %> diff --git a/templates/update_form.erb b/templates/update_form.erb index e5363f8..f27da0b 100644 --- a/templates/update_form.erb +++ b/templates/update_form.erb @@ -2,7 +2,7 @@ # <%= I18n.t('form.update_item.host') %> host: <%= item.host %> # <%= I18n.t('form.update_item.login') %> -user: <%= item.user %><% if not password %> +user: <%= item.user %><% unless password %> # <%= I18n.t('form.update_item.password') %> password: <% end %> # <%= I18n.t('form.update_item.group') %>