diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5a41892..3478096 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2022-06-28 10:15:51 UTC using RuboCop version 1.31.0. +# on 2022-07-27 14:47:27 UTC using RuboCop version 1.32.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -61,7 +61,7 @@ Style/OptionalBooleanParameter: Exclude: - 'lib/onlyoffice_gmail_helper.rb' -# Offense count: 3 +# Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. # URISchemes: http, https diff --git a/CHANGELOG.md b/CHANGELOG.md index fde7edd..7f0fae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Fix `markdownlint` failure because of old `nodejs` in CI * Remove `codeclimate` support since we don't use it any more +* If there is no config fail on initialize level, not on `require` level ### Changes diff --git a/Gemfile.lock b/Gemfile.lock index 6832734..e8b224c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,4 +110,4 @@ DEPENDENCIES yard (~> 0, >= 0.9.20) BUNDLED WITH - 2.3.16 + 2.3.18 diff --git a/lib/onlyoffice_gmail_helper.rb b/lib/onlyoffice_gmail_helper.rb index 20554aa..d368910 100644 --- a/lib/onlyoffice_gmail_helper.rb +++ b/lib/onlyoffice_gmail_helper.rb @@ -21,9 +21,9 @@ class Gmail_helper # @return [String] default label attr_accessor :label - def initialize(user = EmailAccount::GMAIL_DEFAULT.login, password = EmailAccount::GMAIL_DEFAULT.password, timeout_for_mail = 10, label = nil) - @user = user - @password = password + def initialize(user = nil, password = nil, timeout_for_mail = 10, label = nil) + @user = user || EmailAccount.default_account.login + @password = password || EmailAccount.default_account.password @gmail = Gmail.new(user, password) @imap = @gmail.instance_variable_get(:@imap) @timeout_for_mail = timeout_for_mail diff --git a/lib/onlyoffice_gmail_helper/email_account.rb b/lib/onlyoffice_gmail_helper/email_account.rb index 1a0992d..269ef11 100644 --- a/lib/onlyoffice_gmail_helper/email_account.rb +++ b/lib/onlyoffice_gmail_helper/email_account.rb @@ -26,7 +26,9 @@ def self.read_env_defaults # rubocop:enable Style/FetchEnvVar end - # @return [MailAccount] default account - GMAIL_DEFAULT = MailAccount.new(read_defaults[:user], read_defaults[:password]) + # @return [MailAccount] default account for GMail + def self.default_account + @default_account ||= MailAccount.new(read_defaults[:user], read_defaults[:password]) + end end end