Sha256: 09cc370cc09e06e88cb6b3fd9b36c6efdfdeae4f7fa34b24c0dea0131f19f27b

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Solidus
      # This cop finds reimbursement_success_hooks and reimbursement_failed_hooks calls and
      # asks to remove them and subscribe to reimbursement_reimbursed event instead.
      #
      # @example
      #
      #   # bad
      #   reimbursement_success_hooks.each { |h| h.call self }
      #   reimbursement_failed_hooks.each { |h| h.call self }
      #
      #   # good
      #
      # @example
      #
      #   # bad
      #   reimbursement_success_hooks.any?
      #   reimbursement_failed_hooks.any?
      #
      #   # good
      #
      class ReimbursementHookDeprecated < Base
        include TargetSolidusVersion
        minimum_solidus_version 2.11

        MSG = 'Please remove reimbursement_success_hooks and reimbursement_failed_hooks. ' \
              'Subscribe to reimbursement_reimbursed event instead.'

        def_node_matcher :success_hook?, <<~PATTERN
          (send (send nil? :reimbursement_success_hooks) ...)
        PATTERN

        def_node_matcher :fail_hook?, <<~PATTERN
          (send (send nil? :reimbursement_failed_hooks) ...)
        PATTERN

        def on_send(node)
          return unless success_hook?(node) || fail_hook?(node)

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-solidus-0.2.0 lib/rubocop/cop/solidus/reimbursement_hook_deprecated.rb
rubocop-solidus-0.1.4 lib/rubocop/cop/solidus/reimbursement_hook_deprecated.rb