Class: MandateClaw::DSL::ContractBuilder

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

Overview

Internal builder — keeps the Contract class clean

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ ContractBuilder

Returns a new instance of ContractBuilder.



70
71
72
# File 'lib/mandate_claw/dsl/contract.rb', line 70

def initialize(target)
  @target = target
end

Instance Method Details

#agent_bounds(party_name, &block) ⇒ Object



90
91
92
93
94
# File 'lib/mandate_claw/dsl/contract.rb', line 90

def agent_bounds(party_name, &block)
  bounds = DSL::AgentBounds.new(party_name)
  bounds.instance_eval(&block) if block_given?
  @target._agent_bounds[party_name] = bounds
end

#attestation(&block) ⇒ Object



102
103
104
105
106
# File 'lib/mandate_claw/dsl/contract.rb', line 102

def attestation(&block)
  att = DSL::Attestation.new
  att.instance_eval(&block) if block_given?
  @target._attestation = att
end

#obligation(name, on:, within: nil, breach: nil) ⇒ Object



78
79
80
# File 'lib/mandate_claw/dsl/contract.rb', line 78

def obligation(name, on:, within: nil, breach: nil)
  @target._obligations << DSL::Obligation.new(name, on: on, within: within, breach: breach)
end

#party(name, identifies_by:, kind: :human) ⇒ Object



74
75
76
# File 'lib/mandate_claw/dsl/contract.rb', line 74

def party(name, identifies_by:, kind: :human)
  @target._parties[name] = DSL::Party.new(name, identifies_by: identifies_by, kind: kind)
end

#permission(name, on:, within: nil, event: nil) ⇒ Object



82
83
84
# File 'lib/mandate_claw/dsl/contract.rb', line 82

def permission(name, on:, within: nil, event: nil)
  @target._permissions << DSL::Permission.new(name, on: on, within: within, event: event)
end

#prohibition(name, on:, breach: nil) ⇒ Object



86
87
88
# File 'lib/mandate_claw/dsl/contract.rb', line 86

def prohibition(name, on:, breach: nil)
  @target._prohibitions << DSL::Prohibition.new(name, on: on, breach: breach)
end

#rule(name, &block) ⇒ Object



96
97
98
99
100
# File 'lib/mandate_claw/dsl/contract.rb', line 96

def rule(name, &block)
  dr = DSL::DecisionRule.new(name)
  dr.instance_eval(&block) if block_given?
  @target._rules << dr
end