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

DEFAULT_CONTROLLERS_PATTERN =
"**/*_controller.rb".freeze
DEFAULT_EXCLUSION_PATTERN =
"vendor/**/*_controller.rb".freeze
VERSION =
"1.4.1"

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chusaku.rb', line 22

def call(flags = {})
  @flags = flags
  @routes = Chusaku::Routes.call
  @changed_files = []
  controllers_pattern = @flags[:controllers_pattern] || DEFAULT_CONTROLLERS_PATTERN
  exclusion_pattern = @flags[:exclusion_pattern] || DEFAULT_EXCLUSION_PATTERN
  controllers_paths = FileList
    .new(Rails.root.join(controllers_pattern))
    .exclude(Rails.root.join(exclusion_pattern))

  source_paths_map.each do |source_path, actions|
    next unless controllers_paths.include?(source_path)

    annotate_file(path: source_path, actions: actions)
  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`.



44
45
46
47
48
# File 'lib/chusaku.rb', line 44

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