Class: Gamma::Parser::DataParser

Inherits:
Gamma::Parser show all
Defined in:
lib/gamma/parser/data_parser.rb

Constant Summary collapse

DEFAULT_SYNC_MODE =
"replace"

Instance Method Summary collapse

Constructor Details

#initialize(data_yaml_path, hook_root_dir, in_client, out_client, apply: false) ⇒ DataParser

Returns a new instance of DataParser.



4
5
6
7
8
9
10
# File 'lib/gamma/parser/data_parser.rb', line 4

def initialize(data_yaml_path, hook_root_dir, in_client, out_client, apply: false)
  @data_settings = YAML.load_file(data_yaml_path).map(&:with_indifferent_access)
  @hook_root_dir = hook_root_dir
  @in_client = in_client
  @out_client = out_client
  @apply = apply
end

Instance Method Details

#gamma_tablesObject



12
13
14
15
16
17
# File 'lib/gamma/parser/data_parser.rb', line 12

def gamma_tables
  exist_tables = database_exist_tables
  @data_settings.map do |d|
    parse_data_settings(d[:data], exist_tables)
  end.flatten
end

#parse_data_settings(data, exist_tables) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gamma/parser/data_parser.rb', line 19

def parse_data_settings(data, exist_tables)
  tables = if Array(data[:table]).join == "*"
             without = Array(data[:table_without]) || []
             exist_tables.reject { |v| without.include?(v.table_name) }
           else
             Array(data[:table]).map do |table_name|
               exist_tables.find { |t| t.table_name == table_name }
             end.compact
           end
  tables = tables.map do |t|
    t.sync_mode = data[:mode].presence || DEFAULT_SYNC_MODE
    t.delta_column = data[:delta_column]
    t.hooks = data[:hooks].present? ? parse_hooks(data[:hooks], t) : []

    t
  end
  tables
end