Class: Maximus::Railsbp

Inherits:
Lint
  • Object
show all
Defined in:
lib/maximus/lints/railsbp.rb

Overview

Evaluates quality of Rails methods

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from Lint

#output

Instance Method Summary collapse

Methods inherited from Lint

#initialize, #refine

Methods included from Helper

#discover_path, #edit_yaml, #file_count, #file_list, #is_middleman?, #is_rails?, #node_module_exists, #path_exists?, #prompt, #reporter_path, #root_dir, #truthy?

Constructor Details

This class inherits a constructor from Maximus::Lint

Instance Method Details

#resultObject

rails_best_practice (requires Rails)

See Also:

Since:

  • 0.1.0



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/maximus/lints/railsbp.rb', line 8

def result
  @task = 'railsbp'
  @path = discover_path

  return unless is_rails? && temp_config(@task) && path_exists?(@path)

  tmp = Tempfile.new('railsbp')
  `rails_best_practices #{@path} -f json --output-file #{tmp.path}`
  railsbp = tmp.read
  tmp.close
  tmp.unlink

  unless railsbp.blank?
    rbj = JSON.parse(railsbp).group_by { |s| s['filename'] }
    railsbp = {}
    rbj.each do |file, errors|
      next unless file

      # This crazy gsub scrubs the absolute path from the filename
      filename = file.gsub(Rails.root.to_s, '')[1..-1]
      railsbp[filename] = errors.map { |o| hash_for_railsbp(o) }

    end
  end

  @output[:files_inspected] ||= files_inspected('rb', ' ')
  refine railsbp
end