module RailsBestPractices::Core::Check::InheritedResourcesable

Helper to indicate if the controller is inherited from InheritedResources.

Public Class Methods

included(base) click to toggle source
# File lib/rails_best_practices/core/check.rb, line 322
def self.included(base)
  base.class_eval do
    interesting_nodes :class, :var_ref, :vcall
    interesting_files CONTROLLER_FILES

    # check if the controller is inherit from InheritedResources::Base.
    add_callback :start_class do |_node|
      if current_extend_class_name == 'InheritedResources::Base'
        @inherited_resources = true
      end
    end

    # check if there is a DSL call inherit_resources.
    add_callback :start_var_ref do |node|
      if node.to_s == 'inherit_resources'
        @inherited_resources = true
      end
    end

    # check if there is a DSL call inherit_resources.
    add_callback :start_vcall do |node|
      if node.to_s == 'inherit_resources'
        @inherited_resources = true
      end
    end
  end
end