Class: PgSync::TaskResolver

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/pgsync/task_resolver.rb

Constant Summary

Constants included from Utils

Utils::COLOR_CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#colorize, #confirm_tables_exist, #db_config_file, #deprecated, #escape, #friendly_name, #log, #monotonic_time, #output, #quote_ident, #quote_ident_full, #quote_string, #task_name, #warning

Constructor Details

#initialize(args:, opts:, source:, destination:, config:, first_schema:) ⇒ TaskResolver

Returns a new instance of TaskResolver.



7
8
9
10
11
12
13
14
15
16
# File 'lib/pgsync/task_resolver.rb', line 7

def initialize(args:, opts:, source:, destination:, config:, first_schema:)
  @args = args
  @opts = opts
  @source = source
  @destination = destination
  @config = config
  @groups = config["groups"] || {}
  @first_schema = first_schema
  @notes = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def args
  @args
end

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def config
  @config
end

#destinationObject (readonly)

Returns the value of attribute destination.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def destination
  @destination
end

#first_schemaObject (readonly)

Returns the value of attribute first_schema.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def first_schema
  @first_schema
end

#notesObject (readonly)

Returns the value of attribute notes.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def notes
  @notes
end

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def opts
  @opts
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/pgsync/task_resolver.rb', line 5

def source
  @source
end

Instance Method Details

#group?(group) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/pgsync/task_resolver.rb', line 47

def group?(group)
  @groups.key?(group)
end

#tasksObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pgsync/task_resolver.rb', line 18

def tasks
  tasks = []

  # get lists from args
  groups, tables = process_args

  # expand groups into tasks
  groups.each do |group|
    tasks.concat(group_to_tasks(group))
  end

  # expand tables into tasks
  tables.each do |table|
    tasks.concat(table_to_tasks(table))
  end

  # get default if none given
  if !opts[:groups] && !opts[:tables] && args.size == 0
    tasks.concat(default_tasks)
  end

  # resolve any tables that need it
  tasks.each do |task|
    task[:table] = fully_resolve(task[:table])
  end

  tasks
end