module NliPipeline::AbstractUtil::ClassMethods

methods to be loaded as static/class methods in class that extends AbstractUtil

Public Instance Methods

get_allowed_kwargs(**kwargs) click to toggle source

@return [Hash] args that can be converted into instance vars for class

# File lib/nli_pipeline/abstract_util/init_attrs.rb, line 95
def get_allowed_kwargs(**kwargs)
  kwargs.select { |k, _v| supported_args.key?(k) }
end
get_forbidden_kwargs(**kwargs) click to toggle source

@return [Hash] args that can't be converted into instance vars for class

# File lib/nli_pipeline/abstract_util/init_attrs.rb, line 100
def get_forbidden_kwargs(**kwargs)
  kwargs.reject { |k, _v| supported_args.key?(k) }
end
method_missing(method, *args) click to toggle source

:nocov: use method_missing to force classes that use AbstractUtil to implement

supported_args and required_args.

@param method [String] @param args [Array]

Calls superclass method
# File lib/nli_pipeline/abstract_util/init_attrs.rb, line 76
def method_missing(method, *args)
  # cast methods to array of symbols, compare to current missing method
  if %i[supported_args required_args].include?(method.to_sym)
    message = "Method #{method} must be implemented in #{self.class} "\
      'in order to use AbstractUtil'
    raise ArgumentError, message
  end
  super
end
required_args?(**kwargs) click to toggle source

@return [Boolean] have all required args been passed?

# File lib/nli_pipeline/abstract_util/init_attrs.rb, line 105
def required_args?(**kwargs)
  required_args.all? { |key| kwargs.key?(key) }
end
respond_to_missing?(method, *args) click to toggle source

support for method_missing robots.thoughtbot.com/always-define-respond-to-missing-when-overriding

Calls superclass method
# File lib/nli_pipeline/abstract_util/init_attrs.rb, line 90
def respond_to_missing?(method, *args)
  %i[supported_args required_args].include?(method.to_sym) || super
end