Sha256: ce0da328838a97c77e849db9612a149c73a4f413c9b7717d7695cc2203febb48

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

class Sinclair
  # @api private
  # @author darthjee
  #
  # Class responsible for building methods
  class MethodBuilder
    autoload :Base,                'sinclair/method_builder/base'
    autoload :StringMethodBuilder, 'sinclair/method_builder/string_method_builder'
    autoload :BlockMethodBuilder,  'sinclair/method_builder/block_method_builder'

    CLASS_METHOD = :class
    INSTANCE_METHOD = :instance

    # @param klass [Class] class to receive the method
    def initialize(klass)
      @klass = klass
    end

    # Builds methods
    #
    # @param definitions [MethodDefinitions] all methods
    #   definitions to be built
    # @param type [Symbol] type of method to be built
    #
    # @return [MethodDefinitions]
    def build_methods(definitions, type)
      definitions.each do |definition|
        build_from_definition(definition, type)
      end
    end

    private

    attr_reader :klass
    # @method klass
    # @private
    # @api private
    #
    # class to receive the method
    #
    # @return [Class]

    # @private
    #
    # Build one method from definition
    #
    # @param definition [MethodDefinition] the method definition
    # @param type [Symbol] type of method to be built
    #
    # @return (see Base#build)
    def build_from_definition(definition, type)
      if definition.string?
        StringMethodBuilder.new(klass, definition, type: type).build
      else
        BlockMethodBuilder.new(klass, definition, type: type).build
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sinclair-1.9.0 lib/sinclair/method_builder.rb
sinclair-1.8.0 lib/sinclair/method_builder.rb
sinclair-1.7.0 lib/sinclair/method_builder.rb
sinclair-1.6.7 lib/sinclair/method_builder.rb
sinclair-1.6.6 lib/sinclair/method_builder.rb
sinclair-1.6.5 lib/sinclair/method_builder.rb
sinclair-1.6.4 lib/sinclair/method_builder.rb
sinclair-1.6.3 lib/sinclair/method_builder.rb
sinclair-1.6.2 lib/sinclair/method_builder.rb
sinclair-1.6.1 lib/sinclair/method_builder.rb
sinclair-1.6.0 lib/sinclair/method_builder.rb
sinclair-1.5.2 lib/sinclair/method_builder.rb
sinclair-1.5.1 lib/sinclair/method_builder.rb
sinclair-1.5.0 lib/sinclair/method_builder.rb