Sha256: a9b19f570ef10cc7c6060faa741687df1f338efa6b4199db8583ed1903b40b89

Contents?: true

Size: 600 Bytes

Versions: 2

Compression:

Stored size: 600 Bytes

Contents

# frozen_string_literal: true

require_relative 'mysql/linestring'
require_relative 'mysql/multilinestring'
require_relative 'mysql/point'

module ActiveRecordMysqlSpatial
  module ActiveRecord
    module Quoting
      def quote(value)
        case value
        when MySQL::Linestring, MySQL::Multilinestring, MySQL::Point
          quote_geom(value)
        else
          super
        end
      end

      private

      def quote_geom(value)
        spatial_raw = value.to_sql

        return 'NULL' if spatial_raw.blank?

        "ST_GeomFromText('#{spatial_raw}')"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record_mysql_spatial-0.2.0 lib/active_record_mysql_spatial/active_record/quoting.rb
active_record_mysql_spatial-0.1.0 lib/active_record_mysql_spatial/active_record/quoting.rb