Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrate Active Record dependency to 4.2.
This commit reapplies fjl82 and agoln's commits from fjl82/activerecord-mysql2spatial-adapter to current master. Not all tests pass yet.
- Loading branch information
1 parent
b0ab983
commit f14b07f
Showing
5 changed files
with
73 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module ActiveRecord | ||
module Type | ||
class Spatial < Value # :nodoc: | ||
def type | ||
:spatial | ||
end | ||
|
||
def spatial? | ||
type == :spatial | ||
end | ||
|
||
def klass | ||
type == :spatial ? ::RGeo::Feature::Geometry : super | ||
end | ||
|
||
def set_geo_params(factory_settings, table_name, geometric_type) | ||
@factory_settings = factory_settings | ||
@table_name = table_name | ||
@geometric_type = geometric_type | ||
end | ||
|
||
private | ||
|
||
def cast_value(value) | ||
case value | ||
when ::RGeo::Feature::Geometry | ||
factory = @factory_settings.get_column_factory(@table_name, @column, :srid => value.srid) | ||
::RGeo::Feature.cast(value, factory) rescue nil | ||
when ::String | ||
marker = value[4,1] | ||
if marker == "\x00" || marker == "\x01" | ||
factory = @factory_settings.get_column_factory(@table_name, @column, | ||
:srid => value[0,4].unpack(marker == "\x01" ? 'V' : 'N').first) | ||
::RGeo::WKRep::WKBParser.new(factory).parse(value[4..-1]) rescue nil | ||
elsif value[0,10] =~ /[0-9a-fA-F]{8}0[01]/ | ||
srid = value[0,8].to_i(16) | ||
if value[9,1] == '1' | ||
srid = [srid].pack('V').unpack('N').first | ||
end | ||
factory = @factory_settings.get_column_factory(@table_name, @column, :srid => srid) | ||
::RGeo::WKRep::WKBParser.new(factory).parse(value[8..-1]) rescue nil | ||
else | ||
factory = @factory_settings.get_column_factory(@table_name, @column) | ||
::RGeo::WKRep::WKTParser.new(factory, support_ewkt: true).parse(value) rescue nil | ||
end | ||
else | ||
nil | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |