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

#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