17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/activerecord-spatial/spatial_function.rb', line 17
def build_function_call(function, *args)
options = default_options(args.)
geom = options.fetch(:geom_arg, args.first)
args = Array.wrap(options.fetch(:args, args.from(1))).collect do |arg|
arel_quoted_value(arg)
end
column_name = column_name(options[:column])
first_geom_arg = wrap_column_or_geometry(
@klass.arel_table[column_name],
options[:column]
)
geom_args = [first_geom_arg]
if geom.present?
column_type = @klass.spatial_column_by_name(column_name).spatial_type
column_srid = @klass.srid_for(column_name)
if !geom.is_a?(Hash)
geom_arg = read_geos(geom, column_srid)
geom_srid = read_geom_srid(geom_arg, column_type)
geom_args << set_srid_or_transform(column_srid, geom_srid, geom_arg, column_type)
else
klass = if geom[:class]
geom[:class]
elsif geom[:class_name]
geom[:class_name].classify.constantize
else
raise ArgumentError, 'Need either a :class or :class_name option to determine the class.'
end
if geom[:value]
geom_arg = read_geos(geom[:value], column_srid)
geom_srid = read_geom_srid(geom_arg, column_type)
else
geom_arg = geom
geom_srid = klass.srid_for(column_name(geom[:column]))
end
transformed_geom = set_srid_or_transform(column_srid, geom_srid, geom_arg, column_type)
geom_args << wrap_column_or_geometry(transformed_geom, geom)
end
end
geom_args.reverse! if options[:invert] && geom_args.length > 1
ret = Arel::Nodes::NamedFunction.new(
function_name(function, options[:use_index]),
geom_args + args
)
ret = ret.or(first_geom_arg.eq(nil)) if options[:allow_null]
ret
end
|