Class: PgDice::Validation

Inherits:
Object
  • Object
show all
Includes:
TableFinder
Defined in:
lib/pgdice/validation.rb

Overview

Collection of utilities that provide ways for users to ensure things are working properly

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TableFinder

#batched_tables, #find_droppable_partitions, #table_tester, #tables_newer_than, #tables_older_than, #tables_to_grab

Methods included from DateHelper

#pad_date, #safe_date_builder, #truncate_date

Constructor Details

#initialize(logger:, partition_lister:, period_fetcher:, approved_tables:, current_date_provider:) ⇒ Validation

Returns a new instance of Validation.



10
11
12
13
14
15
16
# File 'lib/pgdice/validation.rb', line 10

def initialize(logger:, partition_lister:, period_fetcher:, approved_tables:, current_date_provider:)
  @logger = logger
  @approved_tables = approved_tables
  @partition_lister = partition_lister
  @period_fetcher = period_fetcher
  @current_date_provider = current_date_provider
end

Instance Attribute Details

#approved_tablesObject (readonly)

Returns the value of attribute approved_tables.



8
9
10
# File 'lib/pgdice/validation.rb', line 8

def approved_tables
  @approved_tables
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/pgdice/validation.rb', line 8

def logger
  @logger
end

Instance Method Details

#assert_tables(table_name, opts = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pgdice/validation.rb', line 18

def assert_tables(table_name, opts = nil)
  table, period, all_params, params = filter_parameters(approved_tables.fetch(table_name), opts)
  validate_parameters(all_params)
  logger.debug { "Running asserts on table: #{table} with params: #{all_params}" }

  partitions = @partition_lister.call(all_params)

  assert_future_tables(table_name, partitions, period, params[:future]) if params && params[:future]
  assert_past_tables(table_name, partitions, period, params[:past]) if params && params[:past]
  true
end

#validate_parameters(params) ⇒ Object



30
31
32
33
34
35
# File 'lib/pgdice/validation.rb', line 30

def validate_parameters(params)
  validate_table_name(params)
  validate_period(params)

  true
end