Class: Finitio::Contract

Inherits:
Object
  • Object
show all
Includes:
Metadata
Defined in:
lib/finitio/support/contract.rb

Constant Summary

Constants included from Metadata

Metadata::EMPTY_METADATA

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Metadata

#metadata, #metadata=, #metadata?

Constructor Details

#initialize(infotype, dresser, undresser, name = nil, metadata = nil) ⇒ Contract

Returns a new instance of Contract.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/finitio/support/contract.rb', line 5

def initialize(infotype, dresser, undresser, name = nil,  = nil)
  unless infotype.is_a?(Type)
    raise ArgumentError, "Type expected, got `#{infotype}`"
  end
  unless dresser.respond_to?(:call)
    raise ArgumentError, "r(:call) expected, got `#{dresser}`"
  end
  unless undresser.respond_to?(:call)
    raise ArgumentError, "r(:call) expected, got `#{undresser}`"
  end
  unless name.nil? or name.is_a?(Symbol)
    raise ArgumentError, "Symbol expected, got `#{name}`"
  end

  @name      = name
  @infotype  = infotype
  @dresser   = dresser
  @undresser = undresser
  @metadata  = 
end

Instance Attribute Details

#dresserObject (readonly)

Returns the value of attribute dresser.



25
26
27
# File 'lib/finitio/support/contract.rb', line 25

def dresser
  @dresser
end

#infotypeObject (readonly)

Returns the value of attribute infotype.



25
26
27
# File 'lib/finitio/support/contract.rb', line 25

def infotype
  @infotype
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/finitio/support/contract.rb', line 25

def name
  @name
end

#undresserObject (readonly)

Returns the value of attribute undresser.



25
26
27
# File 'lib/finitio/support/contract.rb', line 25

def undresser
  @undresser
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



36
37
38
39
40
41
42
43
44
# File 'lib/finitio/support/contract.rb', line 36

def ==(other)
  super || (
    other.is_a?(Contract) &&
    name == other.name &&
    infotype == other.infotype &&
    dresser == other.dresser &&
    undresser == other.undresser
  )
end

#bind_ruby_type(clazz) ⇒ Object



27
28
29
30
# File 'lib/finitio/support/contract.rb', line 27

def bind_ruby_type(clazz)
  @dresser   = clazz.method(name.to_sym)
  @undresser = clazz.instance_method(:"to_#{name}")
end

#hashObject



32
33
34
# File 'lib/finitio/support/contract.rb', line 32

def hash
  infotype.hash ^ dresser.hash ^ undresser.hash
end

#resolve_proxies(system) ⇒ Object



47
48
49
# File 'lib/finitio/support/contract.rb', line 47

def resolve_proxies(system)
  Contract.new(infotype.resolve_proxies(system), dresser, undresser, name, )
end

#unconstrainedObject



51
52
53
# File 'lib/finitio/support/contract.rb', line 51

def unconstrained
  Contract.new(infotype.unconstrained, dresser, undresser, name, )
end