Sha256: 282b54e158b73639f619130887acd8da1777a8d2ed689c47adf49e1d1a8fc64f

Contents?: true

Size: 1.28 KB

Versions: 15

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8
module RailsBestPractices
  module Prepares
    # Remember helper methods.
    class HelperPrepare < Core::Check
      include Core::Check::Moduleable
      include Core::Check::Accessable

      interesting_nodes :def, :command
      interesting_files HELPER_FILES, CONTROLLER_FILES

      def initialize
        @helpers = Prepares.helpers
        @methods = Prepares.helper_methods
      end

      # check module node to remember the module name.
      add_callback :start_module do |node|
        @helpers << Core::Mod.new(current_module_name, [])
      end

      # check def node to remember all methods.
      #
      # the remembered methods (@methods) are like
      #     {
      #       "PostsHelper" => {
      #         "create_time" => {"file" => "app/helpers/posts_helper.rb", "line_number" => 10, "unused" => false},
      #         "update_time" => {"file" => "app/helpers/posts_helper.rb", "line_number" => 10, "unused" => false}
      #       }
      #     }
      add_callback :start_def do |node|
        if node.file =~ HELPER_FILES
          method_name = node.method_name.to_s
          @methods.add_method(current_module_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rails_best_practices-1.19.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.18.1 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.18.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.17.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.16.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.15.7 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.15.6 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.15.4 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.15.3 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.15.2 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.15.1 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.14.4 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.14.3 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.14.2 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.14.1 lib/rails_best_practices/prepares/helper_prepare.rb