lib/chusaku.rb in chusaku-0.1.2 vs lib/chusaku.rb in chusaku-0.1.3

- old
+ new

@@ -1,26 +1,33 @@ # frozen_string_literal: true +require 'ruby-progressbar' require 'chusaku/version' require 'chusaku/parser' require 'chusaku/routes' module Chusaku # The main method to run Chusaku. Annotate all actions in your Rails project # as follows: # - # # @route GET /waterlilies/:id (waterlilies) + # # @route [GET] /waterlilies/:id (waterlilies) # def show # # ... # end def self.call - puts 'Chusaku starting...' routes = Chusaku::Routes.call - controllers = 'app/controllers/**/*_controller.rb' + controller_pattern = 'app/controllers/**/*_controller.rb' + controller_paths = Dir.glob(Rails.root.join(controller_pattern)) + # Start progress bar. + progressbar = ProgressBar.create \ + title: 'Chusaku', + total: controller_paths.count + # Loop over all controller file paths. - Dir.glob(Rails.root.join(controllers)).each do |path| + controller_paths.each do |path| + progressbar.increment controller = /controllers\/(.*)_controller\.rb/.match(path)[1] actions = routes[controller] next if actions.nil? # Parse the file and iterate over the parsed content, two entries at a @@ -44,14 +51,11 @@ end # Write to file. parsed_content = parsed_file.map { |pf| pf[:body] } write(path, parsed_content.join) - puts "Annotated #{controller}" end - - puts 'Chusaku finished!' end # Write given content to a file. If we're using an overridden version of File, # then use its method instead for testing purposes. # @@ -68,10 +72,10 @@ end end # Given a hash describing an action, generate an annotation in the form: # - # @route GET /waterlilies/:id (waterlilies) + # @route [GET] /waterlilies/:id (waterlilies) # # @param {Hash} action_info # @return {String} def self.annotate(action_info) verbs = action_info[:verbs]