Sha256: 5e5f41651390436b90cfc2ce969a64ea28cfa721dfea8fc87f3cd9c9d33e84f6

Contents?: true

Size: 1.81 KB

Versions: 16

Compression:

Stored size: 1.81 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
    #
    # @overload add(definition_class, name, code = nil, **options)
    #   @param name [String,Symbol] method name
    #   @param code [String] code to be evaluated when the method is ran
    #   @param options [Hash] Options of construction
    #   @option options cached [Boolean] Flag telling to create
    #     a method with cache
    #
    # @overload add(definition_class, name, **options, &block)
    #   @param name [String,Symbol] method name
    #   @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
    #
    # @overload add(type, *args, **options, &block)
    #   @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
    #
    # @see MethodDefinition.for
    # @see MethodDefinition.from
    #
    # @return [Array<MethodDefinition>]
    def add(*args, type: nil, **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

16 entries across 16 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/method_definitions.rb
sinclair-2.1.0 lib/sinclair/method_definitions.rb
sinclair-2.0.1 lib/sinclair/method_definitions.rb
sinclair-2.0.0 lib/sinclair/method_definitions.rb
sinclair-1.16.3 lib/sinclair/method_definitions.rb
sinclair-1.16.2 lib/sinclair/method_definitions.rb
sinclair-1.16.1 lib/sinclair/method_definitions.rb
sinclair-1.16.0 lib/sinclair/method_definitions.rb
sinclair-1.15.0 lib/sinclair/method_definitions.rb
sinclair-1.14.2 lib/sinclair/method_definitions.rb
sinclair-1.14.1 lib/sinclair/method_definitions.rb
sinclair-1.14.0 lib/sinclair/method_definitions.rb
sinclair-1.13.0 lib/sinclair/method_definitions.rb
sinclair-1.12.1 lib/sinclair/method_definitions.rb
sinclair-1.12.0 lib/sinclair/method_definitions.rb
sinclair-1.11.0 lib/sinclair/method_definitions.rb