Class: Pocolog::Upgrade::Ops::Custom

Inherits:
Base
  • Object
show all
Defined in:
lib/pocolog/upgrade/ops/custom.rb

Overview

Definition of a custom conversion of a given type to another

Instance Attribute Summary collapse

Attributes inherited from Base

#to_type

Instance Method Summary collapse

Methods inherited from Base

#convert, #identity?

Constructor Details

#initialize(time_to, from_type, to_type, converter, name: nil) ⇒ Custom

Create a type converter for a given type, with an optional time limit

Parameters:

  • name (String)

    the descriptive name of the converter

  • time_to (Time)

    the validity limit for this converter Samples created after this time won't be valid. Leave nil if this converter is purely based on type signatures.

  • from_type (Typelib::Type)

    the expected type signature of the value that will be converted

  • to_type (Typelib::Type)

    the type signature of the the value that has been converted



34
35
36
37
38
39
40
# File 'lib/pocolog/upgrade/ops/custom.rb', line 34

def initialize(time_to, from_type, to_type, converter, name: nil)
    @name = name
    @time_to = time_to
    @from_type = from_type
    super(to_type)
    @converter = converter
end

Instance Attribute Details

#converter#call (readonly)

Returns the object that will perform the conversion

Returns:

  • (#call)

    the object that will perform the conversion



21
22
23
# File 'lib/pocolog/upgrade/ops/custom.rb', line 21

def converter
  @converter
end

#from_typeTypelib::Type

Returns the expected type signature of the value that will be converted

Returns:

  • (Typelib::Type)

    the expected type signature of the value that will be converted



16
17
18
# File 'lib/pocolog/upgrade/ops/custom.rb', line 16

def from_type
  @from_type
end

#nameString (readonly)

Returns the descriptive name of the converter

Returns:

  • (String)

    the descriptive name of the converter



7
8
9
# File 'lib/pocolog/upgrade/ops/custom.rb', line 7

def name
  @name
end

#time_toTime (readonly)

Returns the validity limit for this converter Samples created after this time won't be valid. Leave nil if this converter is purely based on type signatures.

Returns:

  • (Time)

    the validity limit for this converter Samples created after this time won't be valid. Leave nil if this converter is purely based on type signatures.



12
13
14
# File 'lib/pocolog/upgrade/ops/custom.rb', line 12

def time_to
  @time_to
end

#to_type=(value) ⇒ Object (writeonly)

Sets the attribute to_type

Parameters:

  • value

    the value to set the attribute to_type to.



18
19
20
# File 'lib/pocolog/upgrade/ops/custom.rb', line 18

def to_type=(value)
  @to_type = value
end

Instance Method Details

#call(target, sample) ⇒ Object



42
43
44
# File 'lib/pocolog/upgrade/ops/custom.rb', line 42

def call(target, sample)
    converter.call(target, sample)
end