Class: Ree::Contracts::Engine

Inherits:
Object
  • Object
show all
Includes:
Args
Defined in:
lib/ree/contracts/engine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Args

#check_arg, #check_arg_any, #check_arg_array_of, #check_bool, #not_nil

Constructor Details

#initialize(target) ⇒ Engine

Returns a new instance of Engine.



21
22
23
24
# File 'lib/ree/contracts/engine.rb', line 21

def initialize(target)
  check_arg_any(target, :target, [Class, Module])
  @target = target
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



19
20
21
# File 'lib/ree/contracts/engine.rb', line 19

def target
  @target
end

Class Method Details

.fetch_for(target) ⇒ Object



6
7
8
# File 'lib/ree/contracts/engine.rb', line 6

def fetch_for(target)
  engines[target.object_id] ||= new(target)
end

Instance Method Details

#add_contract(*args) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ree/contracts/engine.rb', line 26

def add_contract(*args)
  if @contract
    raise Ree::Error.new('Another active contract definition found', :invalid_dsl_usage)
  end

  @contract = ContractDefinition.new(args)
end

#add_doc(str) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ree/contracts/engine.rb', line 34

def add_doc(str)
  check_arg(str, :str, String)

  if @doc
    raise Ree::Error.new('Another active contract definition found', :invalid_dsl_usage)
  end

  @doc = str
end

#add_errors(*errors) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ree/contracts/engine.rb', line 44

def add_errors(*errors)
  if @errors
    raise Ree::Error.new('Another active contract definition found', :invalid_dsl_usage)
  end

  errors.each do |e|
    check_arg(e, :errors, Class)
  end

  @errors = errors
end

#fetch_contractObject



61
62
63
64
# File 'lib/ree/contracts/engine.rb', line 61

def fetch_contract
  contract, @contract = @contract, nil
  contract
end

#fetch_docObject



56
57
58
59
# File 'lib/ree/contracts/engine.rb', line 56

def fetch_doc
  doc, @doc = @doc, nil
  doc
end

#fetch_errorsObject



66
67
68
69
# File 'lib/ree/contracts/engine.rb', line 66

def fetch_errors
  errors, @errors = @errors, nil
  errors
end