Sha256: 9dc8326d736cbc07bac01d102c9060855c56afb0de30b513d4f661c21f8de6c3

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

module Contracts
  module Engine
    # Special case of contracts engine for eigenclasses
    # We don't care about eigenclass of eigenclass at this point
    class Eigenclass < Base
      # Class that owns this eigenclass
      attr_accessor :owner_class

      # Automatically enables eigenclass engine if it is not
      # Returns its engine
      # NOTE: Required by jruby in 1.9 mode. Otherwise inherited
      # eigenclasses don't have their engines
      #
      # @param [Class] eigenclass - class in question
      # @param [Class] owner - owner of eigenclass
      # @return [Engine::Eigenclass]
      def self.lift(eigenclass, owner)
        return Engine.fetch_from(eigenclass) if Engine.applied?(eigenclass)

        Target.new(eigenclass).apply(Eigenclass)
        Engine.fetch_from(owner).set_eigenclass_owner
        Engine.fetch_from(eigenclass)
      end

      # No-op for eigenclasses
      def set_eigenclass_owner
      end

      # Fetches just eigenclasses decorators
      def all_decorators
        pop_decorators
      end

      private

      # Fails when contracts are not included in owner class
      def validate!
        fail ContractsNotIncluded unless owner?
      end

      def owner?
        !!owner_class
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contracts-0.12.0 lib/contracts/engine/eigenclass.rb
contracts-0.11.0 lib/contracts/engine/eigenclass.rb
contracts-0.10.1 lib/contracts/engine/eigenclass.rb
contracts-0.10 lib/contracts/engine/eigenclass.rb