Sha256: 5e492a4b49a9ad32e220f0390bcd9cfb59fa80afb0586a18d2affc899f52fbae

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 Bytes

Contents

module Trailblazer::V2_1
  # This is copied from the Declarative gem. This might get removed in favor of a real heritage gem.
  class Operation
    class Heritage < Array
      # Record inheritable assignments for replay in an inheriting class.
      def record(method, *args, &block)
        self << { method: method, args: args, block: block }
      end

      # Replay the recorded assignments on inheritor.
      # Accepts a block that will allow processing the arguments for every recorded statement.
      def call(inheritor, &block)
        each { |cfg| call!(inheritor, cfg, &block) }
      end

    private
      def call!(inheritor, cfg)
        yield cfg if block_given? # allow messing around with recorded arguments.

        inheritor.send(cfg[:method], *cfg[:args], &cfg[:block])
      end

      module Accessor
        def heritage
          @heritage ||= Heritage.new
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-future-2.1.0.rc1 lib/trailblazer/v2_1/operation/heritage.rb