class PreCommit::Checks::Plugin::ConfigFile

Attributes

alternate_location[R]
config[R]
name[R]

Public Class Methods

new(name, config, alternate_location) click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 5
def initialize(name, config, alternate_location)
  @name = name
  @config = config
  @alternate_location = alternate_location
end

Public Instance Methods

location() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 11
def location
  return @location if defined?(@location)

  @location = location_from_config || location_from_alternate
end

Private Instance Methods

config_location() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 39
def config_location
  @config_location ||= config.get(property_name)
end
environment_variable_name() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 47
def environment_variable_name
  "#{name.upcase}_CONFIG"
end
location_from(location, show_usage = false) click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 28
def location_from(location, show_usage = false)
  if location && !location.empty?
    if File.exist?(location)
      location
    else
      usage if show_usage
      nil
    end
  end
end
location_from_alternate() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 24
def location_from_alternate
  location_from(alternate_location)
end
location_from_config() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 20
def location_from_config
  location_from(config_location, true)
end
property_name() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 43
def property_name
  "#{name}.config"
end
usage() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 55
def usage
  $stderr.puts "Warning: #{name} config file '#{config_location}' does not exist"
  $stderr.puts "Set the path to the config file using:"
  $stderr.puts "\tgit config pre-commit.#{property_name} 'path/relative/to/git/dir/#{name}.config'"
  $stderr.puts "Or in 'config/pre_commit.yml':"
  $stderr.puts "\t#{yaml_property_name}: path/relative/to/git/dir/#{name}.config"
  $stderr.puts "Or set the environment variable:"
  $stderr.puts "\texport #{environment_variable_name}='path/relative/to/git/dir/#{name}.config'"
  $stderr.puts "#{name} will look for a configuration file in the project root or use its default behavior.\n\n"
end
yaml_property_name() click to toggle source
# File lib/pre-commit/checks/plugin/config_file.rb, line 51
def yaml_property_name
  property_name.gsub(/_/, '.')
end