Class: Cure::Launcher

Inherits:
Object
  • Object
show all
Includes:
Configuration, Database, Helpers::FileHelpers
Defined in:
lib/cure/launcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FileHelpers

#clean_dir, #open_file, #read_file, #with_file, #with_temp_dir

Methods included from Configuration

#config, #create_config, #register_config

Methods included from Database

#database_service, #init_database

Constructor Details

#initialize(coordinator: Coordinator.new, planner: Planner.new) ⇒ Launcher

Returns a new instance of Launcher.



21
22
23
24
25
26
# File 'lib/cure/launcher.rb', line 21

def initialize(coordinator: Coordinator.new, planner: Planner.new)
  @coordinator = coordinator
  @planner = planner
  @validated = false
  @csv_files = []
end

Instance Attribute Details

#coordinatorCure::Coordinator

Returns:



19
20
21
# File 'lib/cure/launcher.rb', line 19

def coordinator
  @coordinator
end

Instance Method Details

#process(type, obj, print_query_plan: true) ⇒ void

Deprecated.

This method returns an undefined value.

This will only support single file CSV processing, and is deprecated now

Parameters:

  • type (Symbol)
  • obj (Object)
  • print_query_plan (TrueClass, FalseClass) (defaults to: true)


35
36
37
38
# File 'lib/cure/launcher.rb', line 35

def process(type, obj, print_query_plan: true)
  @csv_files << Cure::Configuration::CsvFileProxy.load_file(type, obj, "_default")
  run_export(print_query_plan: print_query_plan)
end

#query_planvoid

This method returns an undefined value.



105
106
107
108
109
# File 'lib/cure/launcher.rb', line 105

def query_plan
  raise "Not initialized" unless @validated

  @planner.process
end

#run_export(print_query_plan: true) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/cure/launcher.rb', line 40

def run_export(print_query_plan: true)
  setup

  raise "Not initialized" unless @validated

  query_plan if print_query_plan
  @coordinator.process
end

#setupCure::Main

Returns:

  • (Cure::Main)


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cure/launcher.rb', line 90

def setup
  raise "CSV File(s) are required" if @csv_files.empty?
  raise "Template is required" unless @template

  config = create_config(@csv_files, @template)
  register_config(config)

  init_database
  init_history

  @validated = true
  self
end

#with_config(&block) ⇒ Cure::Main

Returns:

  • (Cure::Main)


64
65
66
67
68
69
70
71
72
73
# File 'lib/cure/launcher.rb', line 64

def with_config(&block)
  raise "No block given to config" unless block

  dsl = Dsl::DslHandler.init(&block)
  @template = dsl.generate

  load_csv_from_config

  self
end

#with_config_file(file_location) ⇒ Cure::Main

Returns:

  • (Cure::Main)


76
77
78
79
80
81
82
83
84
85
# File 'lib/cure/launcher.rb', line 76

def with_config_file(file_location)
  contents = read_file(file_location.to_s)

  dsl = Dsl::DslHandler.init_from_content(contents, "cure")
  @template = dsl.generate

  load_csv_from_config

  self
end

#with_csv_file(type, obj, ref_name: nil) ⇒ Cure::Main

Parameters:

  • type (Symbol)
  • obj (Object)

Returns:

  • (Cure::Main)


54
55
56
57
58
59
60
61
# File 'lib/cure/launcher.rb', line 54

def with_csv_file(type, obj, ref_name: nil)
  if ref_name.nil?
    ref_name = @csv_files.length.zero? ? "_default" : "_default_#{@csv_files.length}"
  end

  @csv_files << Cure::Configuration::CsvFileProxy.load_file(type, obj, ref_name)
  self
end