Module: Alf::Algebra::TypeCheck

Included in:
Operator
Defined in:
lib/alf/algebra/support/type_check.rb

Instance Method Summary collapse

Instance Method Details

#joinable_headings!(left, right, options) ⇒ Object


39
40
41
42
43
44
45
46
47
# File 'lib/alf/algebra/support/type_check.rb', line 39

def joinable_headings!(left, right, options)
  if options[:strict]
    commons = left.to_attr_list & right.to_attr_list
    left_h, right_h = left.project(commons), right.project(commons)
    same_heading!(left_h, right_h)
  else
    left & right
  end
end

#no_name_clash!(left, right) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/alf/algebra/support/type_check.rb', line 20

def no_name_clash!(left, right)
  commons = (left & right).to_a
  unless commons.empty?
    msg = "#{to_s}: cannot override "
    msg << commons.map{|a| "`#{a}`" }.join(',')
    type_check_error!(msg)
  end
end

#same_heading!(left, right) ⇒ Object


33
34
35
36
37
# File 'lib/alf/algebra/support/type_check.rb', line 33

def same_heading!(left, right)
  unless left == right
    type_check_error!("heading mismatch `#{left}` vs. `#{right}`")
  end
end

#type_check_error!(msg) ⇒ Object

Raises:


5
6
7
# File 'lib/alf/algebra/support/type_check.rb', line 5

def type_check_error!(msg)
  raise TypeCheckError, msg
end

#valid_ordering!(ordering, attr_list) ⇒ Object


29
30
31
# File 'lib/alf/algebra/support/type_check.rb', line 29

def valid_ordering!(ordering, attr_list)
  no_unknown!(ordering.to_attr_list - attr_list)
end