Module: Chusaku

Defined in:
lib/chusaku.rb,
lib/chusaku/cli.rb,
lib/chusaku/parser.rb,
lib/chusaku/routes.rb,
lib/chusaku/version.rb

Overview

Handles core functionality of annotating projects.

Defined Under Namespace

Modules: Parser Classes: CLI, Routes

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.call(flags = {}) ⇒ Integer

The main method to run Chusaku. Annotate all actions in a Rails project as follows:

# @route GET /waterlilies/:id (waterlilies)
def show
  # ...
end

Parameters:

  • flags (Hash) (defaults to: {})

    CLI flags

Returns:

  • (Integer)

    0 on success, 1 on error



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chusaku.rb', line 18

def call(flags = {})
  @flags = flags
  @routes = Chusaku::Routes.call
  @changed_files = []
  controllers_pattern = @flags[:controllers_pattern] || "app/controllers/**/*_controller.rb"

  Dir.glob(Rails.root.join(controllers_pattern)).each do |path|
    controller = %r{controllers/(.*)_controller\.rb}.match(path)[1]
    actions = @routes[controller]
    next if actions.nil?

    annotate_file(path: path, controller: controller, actions: actions.keys)
  end

  output_results
end

.load_tasksvoid

This method returns an undefined value.

Load Rake tasks for Chusaku. Should be called in your project’s ‘Rakefile`.



38
39
40
41
42
# File 'lib/chusaku.rb', line 38

def load_tasks
  Dir[File.join(File.dirname(__FILE__), "tasks", "**/*.rake")].each do |task|
    load(task)
  end
end