Sha256: 0522febb018a127ca96c6497df3d009db35f4a2c54b1ee3640df739a4f155c8d

Contents?: true

Size: 1.44 KB

Versions: 17

Compression:

Stored size: 1.44 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)
        eigenclass.extend(MethodDecorators)
        # FIXME; this should detect what user uses `include Contracts` or
        # `include Contracts;;Core`
        eigenclass.send(:include, Contracts)
        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

17 entries across 17 versions & 6 rubygems

Version Path
entitlements-app-1.1.0 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-app-1.0.0 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-app-0.3.4 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-app-0.3.1 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-app-0.3.0 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-0.2.1 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-app-0.2.1 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-0.2.0 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
entitlements-app-0.2.0 lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb
contracts-0.16.1 lib/contracts/engine/eigenclass.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/contracts-0.13.0/lib/contracts/engine/eigenclass.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/contracts-0.16.0/lib/contracts/engine/eigenclass.rb
contracts-0.16.0 lib/contracts/engine/eigenclass.rb
contracts-0.15.0 lib/contracts/engine/eigenclass.rb
contracts-lite-0.14.0 lib/contracts/engine/eigenclass.rb
contracts-0.14.0 lib/contracts/engine/eigenclass.rb
contracts-0.13.0 lib/contracts/engine/eigenclass.rb