Class: Zodra::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/zodra/contract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ Contract

Returns a new instance of Contract.



7
8
9
10
11
# File 'lib/zodra/contract.rb', line 7

def initialize(name:)
  @name = name
  @actions = {}
  @types = TypeRegistry.new
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



5
6
7
# File 'lib/zodra/contract.rb', line 5

def actions
  @actions
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/zodra/contract.rb', line 5

def name
  @name
end

#typesObject (readonly)

Returns the value of attribute types.



5
6
7
# File 'lib/zodra/contract.rb', line 5

def types
  @types
end

Instance Method Details

#add_action(action_name) ⇒ Object



13
14
15
16
17
# File 'lib/zodra/contract.rb', line 13

def add_action(action_name)
  action = Action.new(name: action_name, contract: self)
  @actions[action_name.to_sym] = action
  action
end

#find(type_name) ⇒ Object



29
30
31
# File 'lib/zodra/contract.rb', line 29

def find(type_name)
  types.find(type_name) || TypeRegistry.global.find(type_name)
end

#find_action(action_name) ⇒ Object



19
20
21
# File 'lib/zodra/contract.rb', line 19

def find_action(action_name)
  @actions[action_name.to_sym]
end

#resolve_type(type_name) ⇒ Object Also known as: find!



23
24
25
# File 'lib/zodra/contract.rb', line 23

def resolve_type(type_name)
  types.find(type_name) || TypeRegistry.global.find!(type_name)
end