Sha256: af0ccb91b9cdb9b879559b5d212707484b47fbaa3f2780709c3c9b706a44a32a

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Magicka
  class Aggregator
    # Class methods for {Magicka::Aggregator}
    module ClassMethods
      # (see Aggregator.with_element)
      def with_element(element_class, method_name = nil, template: nil)
        MethodBuilder
          .new(self, element_class, method_name, template: template)
          .prepare
          .build
      end

      # Set and return the type of the aggregator
      #
      # When new_type is ommited, returns the last value
      #
      # @param new_type [Symbol,String] The value to be set
      #
      # @return [Symbol] the type of the aggregator
      def type(new_type = nil)
        return @type ||= default_type unless new_type

        @type = new_type.to_sym
      end

      private

      # @private
      # @api private
      #
      # Default type when type is not defined
      #
      # Default type is extracted from class name
      #
      # @return [Symbol]
      def default_type
        name&.demodulize&.underscore&.to_sym
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
magicka-1.1.0 lib/magicka/aggregator/class_methods.rb
magicka-1.0.0 lib/magicka/aggregator/class_methods.rb
magicka-0.6.0 lib/magicka/aggregator/class_methods.rb