Class: Overcommit::Configuration
- Inherits:
-
Object
- Object
- Overcommit::Configuration
- Defined in:
- lib/overcommit/configuration.rb
Overview
Stores configuration for Overcommit and the hooks it runs.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#apply_environment!(hook_context, env) ⇒ Object
Applies additional configuration settings based on the provided environment variables.
-
#enabled_builtin_hooks(hook_context) ⇒ Object
Returns the built-in hooks that have been enabled for a hook type.
-
#for_hook(hook, hook_type = nil) ⇒ Object
Returns a non-modifiable configuration for a hook.
-
#initialize(hash) ⇒ Configuration
constructor
Creates a configuration from the given hash.
-
#merge(config) ⇒ Object
Merges the given configuration with this one, returning a new Configuration.
-
#plugin_directory ⇒ Object
Returns absolute path to the directory that external hook plugins should be loaded from.
- #verify_plugin_signatures? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ Configuration
Creates a configuration from the given hash.
5 6 7 |
# File 'lib/overcommit/configuration.rb', line 5 def initialize(hash) @hash = ConfigurationValidator.new.validate(hash) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
9 10 11 |
# File 'lib/overcommit/configuration.rb', line 9 def ==(other) super || @hash == other.hash end |
#apply_environment!(hook_context, env) ⇒ Object
Applies additional configuration settings based on the provided environment variables.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/overcommit/configuration.rb', line 53 def apply_environment!(hook_context, env) skipped_hooks = "#{env['SKIP']} #{env['SKIP_CHECKS']} #{env['SKIP_HOOKS']}".split(/[:, ]/) hook_type = hook_context.hook_class_name if skipped_hooks.include?('all') || skipped_hooks.include?('ALL') @hash[hook_type]['ALL']['skip'] = true else skipped_hooks.select { |hook_name| hook_exists?(hook_context, hook_name) }. map { |hook_name| Overcommit::Utils.camel_case(hook_name) }. each do |hook_name| @hash[hook_type][hook_name] ||= {} @hash[hook_type][hook_name]['skip'] = true end end end |
#enabled_builtin_hooks(hook_context) ⇒ Object
Returns the built-in hooks that have been enabled for a hook type.
25 26 27 28 29 30 |
# File 'lib/overcommit/configuration.rb', line 25 def enabled_builtin_hooks(hook_context) @hash[hook_context.hook_class_name].keys. select { |hook_name| hook_name != 'ALL' }. select { |hook_name| built_in_hook?(hook_context, hook_name) }. select { |hook_name| hook_enabled?(hook_context, hook_name) } end |
#for_hook(hook, hook_type = nil) ⇒ Object
Returns a non-modifiable configuration for a hook.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/overcommit/configuration.rb', line 33 def for_hook(hook, hook_type = nil) unless hook_type components = hook.class.name.split('::') hook = components.last hook_type = components[-2] end # Merge hook configuration with special 'ALL' config smart_merge(@hash[hook_type]['ALL'], @hash[hook_type][hook] || {}).freeze end |
#merge(config) ⇒ Object
Merges the given configuration with this one, returning a new Overcommit::Configuration. The provided configuration will either add to or replace any options defined in this configuration.
47 48 49 |
# File 'lib/overcommit/configuration.rb', line 47 def merge(config) self.class.new(smart_merge(@hash, config.hash)) end |
#plugin_directory ⇒ Object
Returns absolute path to the directory that external hook plugins should be loaded from.
16 17 18 |
# File 'lib/overcommit/configuration.rb', line 16 def plugin_directory File.join(Overcommit::Utils.repo_root, @hash['plugin_directory'] || '.githooks') end |
#verify_plugin_signatures? ⇒ Boolean
20 21 22 |
# File 'lib/overcommit/configuration.rb', line 20 def verify_plugin_signatures? @hash['verify_plugin_signatures'] != false end |