Class: ActiveInteraction::HashFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/mtk_framework/gem_extensions/active_interaction/filters/hash_filter.rb

Instance Method Summary collapse

Instance Method Details

#import_filters(klass, options = {}) ⇒ Object

Import filters from another interaction.

Parameters:

  • klass (Class)

    The other interaction.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :only (Array<Symbol>, nil)

    Import only these filters.

  • :except (Array<Symbol>, nil)

    Import all filters except for these.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mtk_framework/gem_extensions/active_interaction/filters/hash_filter.rb', line 23

def import_filters(klass, options = {}) # rubocop:disable Metrics/AbcSize
  only = options[:only]
  except = options[:except]
  groups = options[:groups] || [klass.to_s.demodulize.underscore.to_sym]

  klass.filters.each do |name, filter|
    next if only && ![*only].include?(name)
    next if except && [*except].include?(name)

    options = filter.options.merge(groups: groups)
    filter_copy = filter.class.new(name, options)
    filters[name] = filter_copy
  end
end