Sha256: 4ffa8e33950b6d71f054c5b1f732a38a95f69c89376428de7d34f48daf82cc83

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

class Sinclair
  # @api private
  # @author darthjee
  #
  # Enumerator holding all method definitions
  class MethodDefinitions
    delegate :each, to: :definitions

    # Builds and adds new definition
    #
    # The type is decided based in the arguments
    #
    # @param name [String,Symbol] method name
    # @param options [Hash] Options of construction
    # @option options cached [Boolean] Flag telling to create
    #   a method with cache
    #
    # @overload add(definition_class, name, code = nil, **options)
    #   @param code [String] code to be evaluated when the method is ran
    #
    # @overload add(definition_class, name, **options, &block)
    #   @param block [Proc]  block to be ran as method
    #
    # @return [Array<MethodDefinition>]
    def add(name, code = nil, **options, &block)
      definitions << MethodDefinition.from(name, code, **options, &block)
    end

    # Builds and adds new definition
    #
    # The type is decided based on the argument +type+
    #
    # @param type [Symbol] type of definition
    #   - :string -> {MethodDefinition::StringDefinition}
    #   - :block -> {MethodDefinition::BlockDefinition}
    #   - :call -> {MethodDefinition::CallDefinition}
    # @param options [Hash] Options of construction
    # @option options cached [Boolean] Flag telling to create
    #   a method with cache
    # @param block [Proc]  block to be ran as method
    #
    # @return [Array<MethodDefinition>]
    def add_definition(type, *args, **options, &block)
      definitions << MethodDefinition.for(type, *args, **options, &block)
    end

    private

    # @private
    #
    # All definitions
    #
    # @return [Array<MethodDefinition>]
    def definitions
      @definitions ||= []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinclair-1.10.0 lib/sinclair/method_definitions.rb