class Policial::StyleGuides::Ruby
Public: Determine Ruby
style guide violations per-line.
Constants
- KEY
Public Instance Methods
default_config_file()
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 27 def default_config_file RuboCop::ConfigLoader::DOTFILE end
exclude_file?(filename)
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 19 def exclude_file?(filename) config.file_to_exclude?(filename) end
filename_pattern()
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 23 def filename_pattern /.+\.rb\z/ end
violations_in_file(file)
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 11 def violations_in_file(file) offenses = team.inspect_file(parsed_source(file)) offenses.reject(&:disabled?).map do |offense| Violation.new(file, offense.line, offense.message, offense.cop_name) end end
Private Instance Methods
config()
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 54 def config @config ||= RuboCop::ConfigLoader.merge_with_default(custom_config, '') end
custom_config()
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 58 def custom_config content = @config_loader.yaml(config_file) filter(content) tempfile_from(config_file, content.to_yaml) do |tempfile| RuboCop::ConfigLoader.load_file(tempfile.path) end end
filter(config_hash)
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 77 def filter(config_hash) config_hash.delete('require') config_hash.delete('inherit_gem') config_hash['inherit_from'] = Array(config_hash['inherit_from']).select do |value| value =~ /\A#{URI.regexp(%w(http https))}\z/ end end
parsed_source(file)
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 43 def parsed_source(file) absolute_path = File.join(config.base_dir_for_path_parameters, file.filename) RuboCop::ProcessedSource.new( file.content, config['AllCops']['TargetRubyVersion'], absolute_path ) end
team()
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 33 def team cop_classes = if config['Rails']['Enabled'] RuboCop::Cop::Cop.all else RuboCop::Cop::Cop.non_rails end RuboCop::Cop::Team.new(cop_classes, config) end
tempfile_from(filename, content) { |tempfile| ... }
click to toggle source
# File lib/policial/style_guides/ruby.rb, line 67 def tempfile_from(filename, content) filename = File.basename(filename) Tempfile.create(File.basename(filename), Dir.pwd) do |tempfile| tempfile.write(content) tempfile.rewind yield(tempfile) end end