Module: NitroKit::Variants::ClassMethods

Defined in:
lib/nitro_kit/variants.rb

Instance Method Summary collapse

Instance Method Details

#automatic_variants(variants, method_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/nitro_kit/variants.rb', line 4

def automatic_variants(variants, method_name)
  _, prefix, original = method_name.match(/(nk_)(.+)/).to_a

  variants.each do |variant, class_name|
    variant_method_name = "#{prefix}#{variant}_#{original}"

    define_method(variant_method_name) do |*args, **kwargs, &block|
      send(method_name, *args, variant:, **kwargs, &block)
    end
  end
end