Sha256: 16bc265bb169da39bd12e91dea87604290895c0c932619749b28645f789a1c83

Contents?: true

Size: 760 Bytes

Versions: 4

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

module Tangle
  module Mixin
    #
    # Mixin to initialize the dynamic mixin system
    #
    module Initialize
      attr_reader :mixins

      private

      def initialize_mixins(mixins: nil, **kwargs)
        @mixins = mixins
        extend_with_mixins unless @mixins.nil?
        initialize_kwargs(**kwargs) unless kwargs.empty?
      end

      def extend_with_mixins
        klass = self.class.name[/[^:]+$/].to_sym
        @mixins.each do |mixin|
          extend(mixin.const_get(klass)) if mixin.const_defined?(klass)
        end
      end

      def initialize_kwargs(**kwargs)
        kwargs.each do |keyword, argument|
          send("initialize_kwarg_#{keyword}", argument)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tangle-0.11.0 lib/tangle/mixin.rb
tangle-0.10.2 lib/tangle/mixin.rb
tangle-0.10.1 lib/tangle/mixin.rb
tangle-0.10.0 lib/tangle/mixin.rb