Class: Pocolog::Upgrade::Ops::Base

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

Overview

Base class for all the operations

One MUST reimplement either #call or #convert. Otherwise, they will do an infinite recursion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to_type) ⇒ Base

Returns a new instance of Base



11
12
13
# File 'lib/pocolog/upgrade/ops/base.rb', line 11

def initialize(to_type)
    @to_type = to_type
end

Instance Attribute Details

#to_typeObject (readonly)

Returns the value of attribute to_type



9
10
11
# File 'lib/pocolog/upgrade/ops/base.rb', line 9

def to_type
  @to_type
end

Instance Method Details

#call(target, value) ⇒ Object



15
16
17
# File 'lib/pocolog/upgrade/ops/base.rb', line 15

def call(target, value)
    Typelib.copy(target, convert(value))
end

#convert(value) ⇒ Object



19
20
21
22
23
# File 'lib/pocolog/upgrade/ops/base.rb', line 19

def convert(value)
    target = to_type.new
    call(target, value)
    target
end

#identity?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/pocolog/upgrade/ops/base.rb', line 25

def identity?
    false
end