<commit_before>require 'active_record'
require 'dependent_restrict/delete_restriction_error'

module DependentRestrict
  VERSION = '0.1.0'

  def self.included(base)
    super
    base.extend(ClassMethods)

    base.class_eval do
      class << self
        alias_method_chain :has_one, :restrict
        alias_method_chain :has_many, :restrict
        alias_method_chain :has_and_belongs_to_many, :restrict
      end
    end
  end

  module ClassMethods
    # We should be aliasing configure_dependency_for_has_many but that method
    # is private so we can't. We alias has_many instead trying to be as fair
    # as we can to the original behaviour.
    def has_one_with_restrict(*args) #:nodoc:
      reflection = if active_record_4?
        association_id, options, scope, extension = *args
        create_reflection(:has_one, association_id, options || {}, scope || {}, self)
      else
        association_id, options, extension = *args
        create_reflection(:has_one, association_id, options || {}, self)
      end
      add_dependency_callback!(reflection, options)
      has_one_without_restrict(*args) #association_id, options, &extension)
    end

    def has_many_with_restrict(association_id, options = {}, &extension) #:nodoc:
      reflection = if active_record_4?
        create_reflection(:has_many, association_id, options, scope ||= {}, self)
      else
        create_reflection(:has_many, association_id, options, self)
      end
      add_dependency_callback!(reflection, options)
      has_many_without_restrict(association_id, options, &extension)
    end

    def has_and_belongs_to_many_with_restrict(association_id, options = {}, &extension)
      reflection = create_reflection(:has_and_belongs_to_many, association_id, options, self)
      add_dependency_callback!(reflection, options)
      options.delete(:dependent)
      has_and_belongs_to_many_without_restrict(association_id, options, &extension)
    end
<commit_msg>Make sure option hash is present when adding dependency callback<commit_after>require 'active_record'
require 'dependent_restrict/delete_restriction_error'

module DependentRestrict
  VERSION = '0.1.0'

  def self.included(base)
    super
    base.extend(ClassMethods)

    base.class_eval do
      class << self
        alias_method_chain :has_one, :restrict
        alias_method_chain :has_many, :restrict
        alias_method_chain :has_and_belongs_to_many, :restrict
      end
    end
  end

  module ClassMethods
    # We should be aliasing configure_dependency_for_has_many but that method
    # is private so we can't. We alias has_many instead trying to be as fair
    # as we can to the original behaviour.
    def has_one_with_restrict(*args) #:nodoc:
      reflection = if active_record_4?
        association_id, options, scope, extension = *args
        create_reflection(:has_one, association_id, options || {}, scope || {}, self)
      else
        association_id, options, extension = *args
        create_reflection(:has_one, association_id, options || {}, self)
      end
      add_dependency_callback!(reflection, options || {})
      has_one_without_restrict(*args) #association_id, options, &extension)
    end

    def has_many_with_restrict(association_id, options = {}, &extension) #:nodoc:
      reflection = if active_record_4?
        create_reflection(:has_many, association_id, options, scope ||= {}, self)
      else
        create_reflection(:has_many, association_id, options, self)
      end
      add_dependency_callback!(reflection, options)
      has_many_without_restrict(association_id, options, &extension)
    end

    def has_and_belongs_to_many_with_restrict(association_id, options = {}, &extension)
      reflection = create_reflection(:has_and_belongs_to_many, association_id, options, self)
      add_dependency_callback!(reflection, options)
      options.delete(:dependent)
      has_and_belongs_to_many_without_restrict(association_id, options, &extension)
    end

{'fraction_non_alphanumeric': 0.08108788718207001, 'fraction_numerical': 0.0025182573659027953, 'mean_word_length': 3.9158415841584158, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1748426', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1179, 'n_words': 275}