diff --git a/.rubocop.yml b/.rubocop.yml index 064022d..fa26a9e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,34 +1,38 @@ AllCops: DisplayCopNames: true Exclude: - 'lib/capistrano/**/*' - 'vendor/**/*' - 'unicorn.conf.rb' Metrics/LineLength: Max: 120 Metrics/ParameterLists: Max: 6 Documentation: Enabled: false Style/NegatedIf: Enabled: false Style/Not: Enabled: false Style/WordArray: Enabled: false Style/TrailingComma: Enabled: false Style/BlockDelimiters: Enabled: false Style/TrailingBlankLines: Enabled: false Style/EmptyLinesAroundClassBody: Enabled: false Style/EmptyLinesAroundModuleBody: Enabled: false Lint/HandleExceptions: Enabled: false Metrics/AbcSize: Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/MethodLength: + Enabled: false diff --git a/lib/notification.rb b/lib/notification.rb index ec8063c..43c401e 100644 --- a/lib/notification.rb +++ b/lib/notification.rb @@ -1,93 +1,93 @@ require 'singleton' class Notification include Singleton # Send out a notification about notable record changes def notify_record(user, record, context) ActiveSupport::Notifications.instrument( 'webdns.record', user: user, context: context, object: record) end # Send out a notification about notable domain changes def notify_domain(user, domain, context) ActiveSupport::Notifications.instrument( 'webdns.domain', user: user, context: context, object: domain) end # Subscribe to domain/record notifications def hook hook_record hook_domain end private def hook_record ActiveSupport::Notifications .subscribe 'webdns.record' do |_name, _started, _finished, _unique_id, data| handle_record(data) end end def hook_domain ActiveSupport::Notifications .subscribe 'webdns.domain' do |_name, _started, _finished, _unique_id, data| handle_domain(data) end end - def handle_record(data) # rubocop:disable Metrics/MethodLength + def handle_record(data) record, context, user = data.values_at(:object, :context, :user) domain = record.domain changes = record.previous_changes # Nobody is interested in those changes.delete('updated_at') changes.delete('created_at') return if changes.empty? others = domain.group.users.where.not(id: user.id).pluck(:email) return if others.empty? admin_action = !user.groups.exists?(domain.group_id) NotificationMailer.notify_record( record: record, context: context, user: user, admin: admin_action, others: others, changes: changes ).deliver end - def handle_domain(data) # rubocop:disable Metrics/MethodLength + def handle_domain(data) domain, context, user = data.values_at(:object, :context, :user) changes = domain.previous_changes # Nobody is interested in those changes.delete('updated_at') changes.delete('created_at') return if changes.empty? others = domain.group.users.where.not(id: user.id).pluck(:email) return if others.empty? admin_action = !user.groups.exists?(domain.group_id) NotificationMailer.notify_domain( domain: domain, context: context, user: user, admin: admin_action, others: others, changes: changes ).deliver end end