Sha256: b219325c199a82bd6c8fed6355c1693233725912745f1390161aad1a18ff2eaf

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'forwardable'

module Democritus
  class ClassBuilder
    # @api public
    #
    # An abstract class useful in composing additional Democritus::Commands
    #
    # The expected interface for a Democritus::Command is as follows:
    #
    # * Its #initialize method must accept a :builder keyword (i.e. `#initialize`)
    # * It responds to #call and #call does not accept any parameters
    class Command
      # @api public
      #
      # @param builder [Democritus::ClassBuilder] The context in which we are leveraging this building command.
      def initialize(*, builder:)
        self.builder = builder
      end

      # @api public
      # @abstract Subclass and override #call to implement
      #
      # Responsible for applying changes to the class that is being built.
      #
      # @return void
      def call
        fail(NotImplementedError, 'Method #call should be overriden in child classes')
      end

      extend Forwardable
      def_delegator :builder, :defer

      private

      attr_accessor :builder
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
democritus-0.2.1 lib/democritus/class_builder/command.rb