Sha256: 7a034a36ddc27ff9ea74134e4247176a32d31aec588f083ed9fc91e858e167d8

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

module Satisfactory
  # Finds the upstream record of a given type.
  #
  # @api private
  class UpstreamRecordFinder
    def initialize(upstream:)
      @upstream = upstream
    end

    # @api private
    attr_accessor :upstream

    # @!method create
    #   Delegates to the upstream record.
    #   @return (see Satisfactory::Record#create)
    #   @see Satisfactory::Record#create
    # @!method with_new
    #   Delegates to the upstream record.
    #   @return (see Satisfactory::Record#with_new)
    #   @see Satisfactory::Record#with_new
    # @!method to_plan
    #   Delegates to the upstream record.
    #   @return (see Satisfactory::Record#with_new)
    #   @see Satisfactory::Record#with_new
    delegate :create, :with_new, :to_plan, to: :upstream

    # Find the upstream record of the given type.
    #
    # @api private
    # @param type [Symbol] The type of upstream record to find.
    # @return [Satisfactory::Record, Satisfactory::Collection, Satisfactory::Root]
    def find(type)
      raise MissingUpstreamRecordError, type if upstream.nil?

      if type == upstream.type
        self
      else
        self.upstream = upstream.upstream
        find(type)
      end
    end

    # (see Satisfactory::Record#with)
    def with(*args, **kwargs)
      upstream.with(*args, force: true, **kwargs)
    end

    # @api private
    class MissingUpstreamRecordError < StandardError; end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
satisfactory-0.3.2 lib/satisfactory/upstream_record_finder.rb