class Policial::StyleChecker

Public: Filters files to reviewable subset, builds style guide based on file extension and delegates to style guide for line violations.

Public Class Methods

new(pull_request, options = {}) click to toggle source
# File lib/policial/style_checker.rb, line 7
def initialize(pull_request, options = {})
  @pull_request = pull_request
  @style_guides = {}
  @options = options
end

Public Instance Methods

violations() click to toggle source
# File lib/policial/style_checker.rb, line 13
def violations
  @violations ||= violations_in_checked_files.select(&:on_changed_line?)
end

Private Instance Methods

config_loader() click to toggle source
# File lib/policial/style_checker.rb, line 42
def config_loader
  @config_loader ||= ConfigLoader.new(@pull_request.head_commit)
end
files_to_check() click to toggle source
# File lib/policial/style_checker.rb, line 31
def files_to_check
  @pull_request.files.reject(&:removed?)
end
style_guides() click to toggle source
# File lib/policial/style_checker.rb, line 35
def style_guides
  Policial.style_guides.map do |klass|
    @style_guides[klass] ||= klass.new(
      config_loader, @options[klass::KEY] || {})
  end
end
violations_in_checked_files() click to toggle source
# File lib/policial/style_checker.rb, line 19
def violations_in_checked_files
  files_to_check.flat_map do |file|
    style_guides.flat_map do |style_guide|
      if style_guide.investigate?(file.filename)
        style_guide.violations_in_file(file)
      else
        []
      end
    end
  end
end