Class: PreCommit::Configuration::Providers

Inherits:
Object
  • Object
show all
Includes:
Pluginator::Extensions::Conversions
Defined in:
lib/pre-commit/configuration/providers.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

Classes: Default, Env, Git, GitOld, Yaml

Instance Method Summary collapse

Constructor Details

#initialize(pluginator, plugins = nil) ⇒ Providers

Returns a new instance of Providers.


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

def initialize(pluginator, plugins = nil)
  @pluginator = pluginator
  @plugins    = plugins
end

Instance Method Details

#[](name) ⇒ Object


19
20
21
# File 'lib/pre-commit/configuration/providers.rb', line 19

def [](name)
  plugins.map{|plugin| plugin[name] }.compact.last
end

#default(name) ⇒ Object


23
24
25
# File 'lib/pre-commit/configuration/providers.rb', line 23

def default(name)
  plugins[0][name]
end

#listObject


36
37
38
# File 'lib/pre-commit/configuration/providers.rb', line 36

def list
  plugins.map{|plugin| "#{class2string(class2name(plugin.class))}(#{plugin.class.priority})" }
end

#update(plugin_name, name, operation, list) ⇒ Object


27
28
29
30
31
32
33
34
# File 'lib/pre-commit/configuration/providers.rb', line 27

def update(plugin_name, name, operation, list)
  plugin = find_update_plugin(plugin_name)
  name   = name.to_sym
  value = plugin[name] || []
  raise PreCommit::NotAnArray.new unless Array === value
  value = value.send(operation, list)
  plugin.update(name, value)
end