Class: Maximus::Railsbp

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

Overview

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

#check_default_config_path, #edit_yaml, #file_count, #file_list, #is_rails?, #lines_added_to_range, #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
36
37
38
39
40
41
42
43
# File 'lib/maximus/lints/railsbp.rb', line 8

def result

  return unless is_rails?

  @task = 'railsbp'

  return unless temp_config(@task)

  @path = @settings[:root_dir] if @path.blank?

  return unless 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|
      if file
        # This crazy gsub grapbs scrubs the absolute path from the filename
        railsbp[file.gsub(Rails.root.to_s, '')[1..-1].to_sym] = errors.map { |o| hash_for_railsbp(o) }
      end
    end
    # The output of railsbp is a mix of strings and symbols
    #   but resetting the JSON like this standardizes everything.
    # @todo Better way to get around this?
    railsbp = JSON.parse(railsbp.to_json)
  end

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