Class: Pinspec::Inputs::Hydrator

Inherits:
Object
  • Object
show all
Defined in:
lib/pinspec/inputs/hydrator.rb

Constant Summary collapse

MAX_DEPTH =
3
MAX_ROWS_PER_CLUSTER =
20
VOLATILE =
%w[created_at updated_at].freeze
DB_FUNCTION_DEFAULT =
/\A(?:->|gen_random_uuid|now|uuid_generate_v4|CURRENT_)/i.freeze

Instance Method Summary collapse

Constructor Details

#initialize(schema:, redactor:, factories:, max_depth: MAX_DEPTH, max_rows: MAX_ROWS_PER_CLUSTER) ⇒ Hydrator

Returns a new instance of Hydrator.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pinspec/inputs/hydrator.rb', line 14

def initialize(schema:, redactor:, factories:, max_depth: MAX_DEPTH,
               max_rows: MAX_ROWS_PER_CLUSTER)
  raise ArgumentError, "factories: is required - without it an imported row " \
                      "gets a camelized table name, which is the wrong constant " \
                      "on any app whose tables sit behind an engine prefix" if factories.nil?

  @schema    = schema
  @redactor  = redactor
  @resolver  = Setup::DependencyResolver.new(schema, factories)
  @max_depth = max_depth
  @max_rows  = max_rows
end

Instance Method Details

#hydrate(table, rows, all_rows, target_source: "") ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pinspec/inputs/hydrator.rb', line 27

def hydrate(table, rows, all_rows, target_source: "")
  @notes = []
  clusters = []
  ordinal  = 0

  @refs = {}
  @counters = Hash.new(0)
  @budget = @max_rows

  Array(rows).each do |row|
    ordinal += 1
    clusters.concat(build_cluster(table, row, all_rows, ordinal, target_source))
  end

  [clusters, @notes]
end