Sha256: 9d9d3e0886a7355150efba075e042e8cb33de080b0863fb0bfe316cfad9bcfad

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

module HoundConfig
  extend self

  CONFIG_FILE_REPOSITORY = "https://raw.githubusercontent.com/platanus/la-guia/master/"

  def content
    @@content ||= load_content
  end

  def enabled_for?(linter_name)
    # disabled if linter_name key does not exist in .hound.yml
    return false unless content.key?(linter_name)
    options = options_for(linter_name)
    # enabled if linter_name key exists and enabled key is not defined.
    return true unless options.keys.select { |k| k.downcase === "enabled" }.any?
    # enabled "enabled" or "Enabled" keys are true.
    !!options["enabled"] || !!options["Enabled"]
  end

  def options_for(linter_name)
    return content[linter_name] if content.respond_to?(:key?) && content.key?(linter_name)
    Hash.new
  end

  def rules_url_for(linter_name)
    path_in_repo = options_for(linter_name)["config_file"].to_s
    HoundConfig::CONFIG_FILE_REPOSITORY + path_in_repo
  end

  private

  def config_file_url
    CONFIG_FILE_REPOSITORY + ".hound.yml"
  end

  def load_content
    Hound::Parser.yaml(RestClient.get(config_file_url))
  rescue RestClient::ResourceNotFound
    inform_config_not_found(config_file_url)
    Hash.new
  end

  def inform_config_not_found(url)
    puts "config file not found in #{url}".red
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hound-cli-0.4.1 lib/hound/hound_config.rb
hound-cli-0.4.0 lib/hound/hound_config.rb
hound-cli-0.3.0 lib/hound/hound_config.rb
hound-cli-0.2.2 lib/hound/hound_config.rb