module Crate::Hook
Public Instance Methods
_hook_check_undefined_keys(**options)
click to toggle source
# File lib/crate/hook.rb, line 68 def _hook_check_undefined_keys(**options) _log(**_options, name: _fullname, **options, severity: Logger::DEBUG) undefined_keys = _raw.keys - self.class._names return if undefined_keys.empty? _log(**_options, name: _fullname, severity: Logger::WARN, **options) do "has undefined keys: #{undefined_keys.inspect}" end end
_hook_convert(name, **options, &block)
click to toggle source
# File lib/crate/hook.rb, line 21 def _hook_convert(name, **options, &block) _hook_convert_impl(name, **options, &block) end
_hook_convert_impl(name, **options, &block)
click to toggle source
# File lib/crate/hook.rb, line 7 def _hook_convert_impl(name, **options, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength _log(**_options, name: _name(name), **options, severity: Logger::DEBUG) before_value = _raw[name] after_value = instance_exec(before_value, &block) return if before_value == after_value not_set = !_raw.key?(name) _raw[name] = after_value before_message = not_set ? 'not set' : before_value.inspect _log(**_options, name: _name(name), tag: 'convert', severity: Logger::INFO, **options) do "was #{before_message} and is now #{after_value.inspect}" end end
_hook_default(name, *args, **options, &block)
click to toggle source
# File lib/crate/hook.rb, line 25 def _hook_default(name, *args, **options, &block) default, = args block ||= proc { default } _hook_convert_impl(name, **options) do |before| _raw.key?(name) ? before : instance_exec(&block) end end
_hook_must_be(name, klass, **options)
click to toggle source
# File lib/crate/hook.rb, line 59 def _hook_must_be(name, klass, **options) _log(**_options, name: _name(name), **options, severity: Logger::DEBUG) return if _raw[name].is_a?(klass) _log(**_options, name: _name(name), severity: Logger::FATAL, **options) do "must be #{klass} but is #{_raw[name].class}" end exit 1 end
_hook_required(name, **options)
click to toggle source
# File lib/crate/hook.rb, line 50 def _hook_required(name, **options) _log(**_options, name: _name(name), **options, severity: Logger::DEBUG) return if _raw.key?(name) _log(**_options, name: _name(name), severity: Logger::FATAL, **options) do 'is not set' end exit 1 end
_hook_strip(name, **options)
click to toggle source
# File lib/crate/hook.rb, line 43 def _hook_strip(name, **options) # The bug on ruby 2.4.0 # rubocop:disable Style/SymbolProc _hook_convert_impl(name, **options) { |before| before.strip } # rubocop:enable Style/SymbolProc end
_hook_type(name, klass, **options)
click to toggle source
# File lib/crate/hook.rb, line 37 def _hook_type(name, klass, **options) _hook_convert_impl(name, **options) do |before| _type_convert(klass).call(before) end end
_type_convert(klass)
click to toggle source
# File lib/crate/hook.rb, line 33 def _type_convert(klass) Kernel.method(klass.to_s.to_sym) end