Class: Contracts::Engine::Eigenclass

Inherits:
Base
  • Object
show all
Defined in:
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



9
10
11
# File 'lib/contracts/engine/eigenclass.rb', line 9

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:



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/contracts/engine/eigenclass.rb', line 19

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



35
36
37
# File 'lib/contracts/engine/eigenclass.rb', line 35

def all_decorators
  pop_decorators
end

#set_eigenclass_ownerObject

No-op for eigenclasses



32
# File 'lib/contracts/engine/eigenclass.rb', line 32

def set_eigenclass_owner; end