Class: Kitcat::Framework

Inherits:
Object
  • Object
show all
Defined in:
lib/kitcat/framework.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(migration_strategy, migration_name: nil, number_of_items_to_process: nil, progress_bar: true, progress_bar_output: STDOUT) ⇒ Framework

migration_name String Optional.

  The name of the migration. Used as tag in log file name. If not given, a random/unique one is used.

number_of_items_to_process {Integer} Optional.
  If given, the processing will stop after processing that many number of items.

progress_bar {Boolean} Optional.
  When +True+. it will instantiate a use a progress bar, incrementing that by 1 every time
  the +migration_strategy+ finishes processing an item. The total load will be calculated based on the
  result of +migration_strategy#criteria#count+.
  When +False+, progress bar will not be used

progress_bar_output Optional. Defaults to STDOUT. Anything that responds to
  #print, #flush, #tty? and #puts.
  It is taken into account only if progress bar is enabled.


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kitcat/framework.rb', line 38

def initialize(migration_strategy,
               migration_name: nil,
               number_of_items_to_process: nil,
               progress_bar: true,
               progress_bar_output: STDOUT)
  @migration_strategy         = migration_strategy
  @number_of_items_to_process = number_of_items_to_process
  @last_item_processed        = nil
  @progress_bar               = initialize_progress_bar(progress_bar, progress_bar_output)
  @logging                    = Kitcat::Logging.new(migration_strategy, migration_name)
end

Instance Attribute Details

#last_item_processedObject (readonly)

Returns the value of attribute last_item_processed.



8
9
10
# File 'lib/kitcat/framework.rb', line 8

def last_item_processed
  @last_item_processed
end

#loggingObject (readonly)

Returns the value of attribute logging.



8
9
10
# File 'lib/kitcat/framework.rb', line 8

def logging
  @logging
end

#migration_strategyObject (readonly)

Returns the value of attribute migration_strategy.



8
9
10
# File 'lib/kitcat/framework.rb', line 8

def migration_strategy
  @migration_strategy
end

#number_of_items_processedObject (readonly)

Returns the value of attribute number_of_items_processed.



8
9
10
# File 'lib/kitcat/framework.rb', line 8

def number_of_items_processed
  @number_of_items_processed
end

Instance Method Details

#executeObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kitcat/framework.rb', line 50

def execute
  trap_signals

  start_logging

  @number_of_items_processed = 0

  items.each do |item|
    break unless execute_for(item)
  end

ensure
  end_logging
end

#number_of_items_to_processObject



65
66
67
# File 'lib/kitcat/framework.rb', line 65

def number_of_items_to_process
  @number_of_items_to_process ||= migration_strategy.criteria.count
end

#progressObject



73
74
75
76
# File 'lib/kitcat/framework.rb', line 73

def progress
  return -1 unless progress_bar?
  @progress_bar.progress
end

#progress_bar?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/kitcat/framework.rb', line 69

def progress_bar?
  !@progress_bar.nil?
end