Class: Contracts::Engine::Target
- Inherits:
-
Object
- Object
- Contracts::Engine::Target
- Defined in:
- lib/contracts-ruby2/lib/contracts/engine/target.rb,
lib/contracts-ruby3/lib/contracts/engine/target.rb
Overview
Represents class in question
Instance Method Summary collapse
-
#applied? ⇒ Bool
Returns true if target has contracts engine already.
-
#apply(engine_class = Base) ⇒ Object
Enable contracts engine for target - it is no-op if contracts engine is already enabled - it automatically enables contracts engine for its eigenclass - it sets owner class to target for its eigenclass.
-
#engine ⇒ Engine::Base or Engine::Eigenclass
Returns contracts engine of target.
-
#initialize(target) ⇒ Target
constructor
Creates new instance of Target.
Constructor Details
#initialize(target) ⇒ Target
Creates new instance of Target
8 9 10 |
# File 'lib/contracts-ruby2/lib/contracts/engine/target.rb', line 8 def initialize(target) @target = target end |
Instance Method Details
#applied? ⇒ Bool
Returns true if target has contracts engine already
36 37 38 |
# File 'lib/contracts-ruby2/lib/contracts/engine/target.rb', line 36 def applied? target.respond_to?(:__contracts_engine) end |
#apply(engine_class = Base) ⇒ Object
Enable contracts engine for target
-
it is no-op if contracts engine is already enabled
-
it automatically enables contracts engine for its eigenclass
-
it sets owner class to target for its eigenclass
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/contracts-ruby2/lib/contracts/engine/target.rb', line 19 def apply(engine_class = Base) return if applied? apply_to_eigenclass eigenclass.class_eval do define_method(:__contracts_engine) do @__contracts_engine ||= engine_class.new(self) end end engine.set_eigenclass_owner end |
#engine ⇒ Engine::Base or Engine::Eigenclass
Returns contracts engine of target
43 44 45 |
# File 'lib/contracts-ruby2/lib/contracts/engine/target.rb', line 43 def engine applied? && target.__contracts_engine end |