Class: PartialKs::ParentInferrer

Inherits:
Object
  • Object
show all
Defined in:
lib/partial_ks/parent_inferrer.rb

Constant Summary collapse

CannotInfer =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ ParentInferrer



6
7
8
# File 'lib/partial_ks/parent_inferrer.rb', line 6

def initialize(table)
  @table = table
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/partial_ks/parent_inferrer.rb', line 4

def table
  @table
end

Instance Method Details

#inferred_parent_tableObject



10
11
12
13
14
15
16
17
18
# File 'lib/partial_ks/parent_inferrer.rb', line 10

def inferred_parent_table
  if table.top_level_table?
    nil
  elsif table.non_nullable_parent_tables.size == 1
    table.non_nullable_parent_tables.first
  else
    raise CannotInfer, "table has multiple candidates for parents"
  end
end