Class: Contracts::Engine::Eigenclass

Inherits:
Base
  • Object
show all
Defined in:
lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb,
lib/contracts-ruby3/lib/contracts/engine/eigenclass.rb

Overview

Special case of contracts engine for eigenclasses We don’t care about eigenclass of eigenclass at this point

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_method_decorator, applied?, apply, #decorate, #decorated_methods?, #decorated_methods_for, fetch_from, #initialize, #nearest_decorated_ancestor

Constructor Details

This class inherits a constructor from Contracts::Engine::Base

Instance Attribute Details

#owner_classObject

Class that owns this eigenclass



7
8
9
# File 'lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb', line 7

def owner_class
  @owner_class
end

Class Method Details

.lift(eigenclass, owner) ⇒ Engine::Eigenclass

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

Parameters:

  • eigenclass (Class)
    • class in question

  • owner (Class)
    • owner of eigenclass

Returns:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb', line 17

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

Instance Method Details

#all_decoratorsObject

Fetches just eigenclasses decorators



34
35
36
# File 'lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb', line 34

def all_decorators
  pop_decorators
end

#set_eigenclass_ownerObject

No-op for eigenclasses



30
31
# File 'lib/contracts-ruby2/lib/contracts/engine/eigenclass.rb', line 30

def set_eigenclass_owner
end