Sha256: 30bc4ab2710edec425d0ba775a1090a223c5ba0805999e89dc8b74df6def745a

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

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

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.
      def start_module(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" => 10, "unused" => false},
      #         "update_time" => {"file" => "app/helpers/posts_helper.rb", "line" => 10, "unused" => false}
      #       }
      #     }
      def start_def(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" => node.line}, current_access_control)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
rails_best_practices-1.10.1 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-gorgeouscode-1.0.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.10.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.9.1 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.9.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.8.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.7.2 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.7.1 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.7.0 lib/rails_best_practices/prepares/helper_prepare.rb
rails_best_practices-1.6.0 lib/rails_best_practices/prepares/helper_prepare.rb