Sha256: fac7756ddfe07924ff25e75d5c8e2f236895d8c9bf80e2afbca62de345b15d7e

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 Bytes

Contents

# encoding: utf-8
require 'rails_best_practices/core/check'

module RailsBestPractices
  module Prepares
    # Check all initializers
    class InitializerPrepare < Core::Check
      interesting_nodes :method_add_arg, :class
      interesting_files INITIALIZER_FILES

      def initialize
        @configs = Prepares.configs
      end

      # check if AR include ActiveModel::ForbiddenAttributesProtection
      add_callback :start_method_add_arg do |node|
        if include_forbidden_attributes_protection?(node)
          @configs["railsbp.include_forbidden_attributes_protection"] = "true"
        end
      end

      # check if the node is
      #     ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
      def include_forbidden_attributes_protection?(node)
        "ActiveRecord::Base" == node.receiver.to_s &&
          "send" == node.message.to_s &&
          ["include", "ActiveModel::ForbiddenAttributesProtection"] == node.arguments.all.map(&:to_s)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_best_practices-1.13.8 lib/rails_best_practices/prepares/initializer_prepare.rb