Class: PreCommit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pre-commit/configuration.rb,
lib/pre-commit/configuration/providers.rb,
lib/pre-commit/configuration/top_level.rb,
lib/plugins/pre_commit/configuration/providers/env.rb,
lib/plugins/pre_commit/configuration/providers/git.rb,
lib/plugins/pre_commit/configuration/providers/yaml.rb,
lib/plugins/pre_commit/configuration/providers/default.rb,
lib/plugins/pre_commit/configuration/providers/git_old.rb

Defined Under Namespace

Modules: TopLevel Classes: Providers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pluginator, providers = nil) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
# File 'lib/pre-commit/configuration.rb', line 9

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

Instance Attribute Details

#pluginatorObject (readonly)

Returns the value of attribute pluginator.



7
8
9
# File 'lib/pre-commit/configuration.rb', line 7

def pluginator
  @pluginator
end

#providersObject (readonly)

Returns the value of attribute providers.



7
8
9
# File 'lib/pre-commit/configuration.rb', line 7

def providers
  @providers
end

Instance Method Details

#disable(plugin_name, type, check1, *checks) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/pre-commit/configuration.rb', line 42

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

#enable(plugin_name, type, check1, *checks) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/pre-commit/configuration.rb', line 31

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

#get(name) ⇒ Object



14
15
16
# File 'lib/pre-commit/configuration.rb', line 14

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

#get_arr(name) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pre-commit/configuration.rb', line 18

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

#get_combined(name) ⇒ Object



27
28
29
# File 'lib/pre-commit/configuration.rb', line 27

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