Sha256: 82770f456d71cb1b5d41f281241b16edf99c66552572705a66b518ab4230a211

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module ActiveRecord
  class AssociationRelation
    undef :new
    undef :create
    undef :create!

    def build(attributes = nil, options = {}, &block)
      block = protected_attributes_scope_block('new', block)
      scoping { @association.build(attributes, options, &block) }
    end
    alias new build

    def create(attributes = nil, options = {}, &block)
      block = protected_attributes_scope_block('create', block)
      scoping { @association.create(attributes, options, &block) }
    end

    def create!(attributes = nil, options = {}, &block)
      block = protected_attributes_scope_block('create!', block)
      scoping { @association.create!(attributes, options, &block) }
    end

    private

    if ActiveRecord.gem_version < Gem::Version.new('6.0')

      def protected_attributes_scope_block(_label, block)
        block
      end

    elsif ActiveRecord.gem_version < Gem::Version.new('6.1')

      def protected_attributes_scope_block(label, block)
        _deprecated_scope_block(label, &block)
      end

    else

      def protected_attributes_scope_block(_label, block)
        current_scope_restoring_block(&block)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
protected_attributes_continued-1.9.0 lib/active_record/mass_assignment_security/association_relation.rb
protected_attributes_continued-1.8.2 lib/active_record/mass_assignment_security/association_relation.rb
protected_attributes_continued-1.8.1 lib/active_record/mass_assignment_security/association_relation.rb