Sha256: 3e97859fd331e03ed96183cd0a73403671b78b3e60b124b4642baae619d9a246

Contents?: true

Size: 1.43 KB

Versions: 32

Compression:

Stored size: 1.43 KB

Contents

require 'pluginator'
require 'pre-commit/configuration/providers'
require 'pre-commit/plugins_list'

module PreCommit
  class Configuration
    attr_reader :pluginator, :providers

    def initialize(pluginator, providers = nil)
      @pluginator = (pluginator or PreCommit.pluginator)
      @providers  = (providers  or Providers.new(@pluginator))
    end

    def get(name)
      @providers[name.to_sym]
    end

    def get_arr(name)
      value = get(name)
      case value
      when nil   then []
      when Array then value
      else raise PreCommit::NotAnArray.new
      end
    end

    def get_combined(name)
      get_arr(name) + get_arr("#{name}_add")
    end

    def enable(plugin_name, type, check1, *checks)
      checks.unshift(check1) # check1 is ArgumentError triger
      checks.map!(&:to_sym)
      @providers.update( plugin_name, "#{type}_remove", :-, checks )
      @providers.update( plugin_name, "#{type}_add",    :+, (checks or []) - (@providers.default(type) or []) )
      true
    rescue PreCommit::PluginNotFound => e
      $stderr.puts e
      false
    end

    def disable(plugin_name, type, check1, *checks)
      checks.unshift(check1) # check1 is ArgumentError triger
      checks.map!(&:to_sym)
      @providers.update( plugin_name, "#{type}_add",    :-, checks )
      @providers.update( plugin_name, "#{type}_remove", :+, checks )
      true
    rescue PreCommit::PluginNotFound => e
      warn e
      false
    end

  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
pre-commit-0.38.1 lib/pre-commit/configuration.rb
pre-commit-0.38.0 lib/pre-commit/configuration.rb
pre-commit-0.37.0 lib/pre-commit/configuration.rb
pre-commit-0.36.0 lib/pre-commit/configuration.rb
pre-commit-0.35.0 lib/pre-commit/configuration.rb
pre-commit-0.34.0 lib/pre-commit/configuration.rb
pre-commit-0.33.0 lib/pre-commit/configuration.rb
pre-commit-0.32.0 lib/pre-commit/configuration.rb
pre-commit-0.31.0 lib/pre-commit/configuration.rb
pre-commit-0.30.0 lib/pre-commit/configuration.rb
pre-commit-0.29.0 lib/pre-commit/configuration.rb
pre-commit-0.28.0 lib/pre-commit/configuration.rb
pre-commit-0.27.0 lib/pre-commit/configuration.rb
pre-commit-0.26.0 lib/pre-commit/configuration.rb
pre-commit-0.25.0 lib/pre-commit/configuration.rb
pre-commit-0.24.0 lib/pre-commit/configuration.rb
pre-commit-0.23.0 lib/pre-commit/configuration.rb
pre-commit-0.22.1 lib/pre-commit/configuration.rb
pre-commit-0.22.0 lib/pre-commit/configuration.rb
pre-commit-0.21.0 lib/pre-commit/configuration.rb