Skip to content

Commit

Permalink
Remove dead code. => → :. Break some lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
dschweisguth committed Jul 23, 2017
1 parent 1e6e69d commit 6ca28ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def columns(table_name_, name_=nil)
columns_ = []
result_.each(symbolize_keys: true, as: :hash) do |field_|
columns_ << SpatialColumn.new(@rgeo_factory_settings, table_name_.to_s,
field_[:Field], field_[:Default], lookup_cast_type(field_[:Type]), field_[:Type], field_[:Null] == "YES", field_[:Collation], field_[:Extra])
field_[:Field], field_[:Default], lookup_cast_type(field_[:Type]),
field_[:Type], field_[:Null] == "YES", field_[:Collation], field_[:Extra])
end
columns_
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ module ActiveRecord
module ConnectionAdapters
module Mysql2SpatialAdapter
class SpatialColumn < ConnectionAdapters::Mysql2Adapter::Column
FACTORY_SETTINGS_CACHE = {}

def initialize(factory_settings_, table_name_, name_, default_, cast_type_ = nil, sql_type_ = nil, null_ = true, collation_ = nil, extra_ = "")
def initialize(factory_settings_, table_name_, name_,
default_, cast_type_ = nil, sql_type_ = nil, null_ = true, collation_ = nil, extra_ = "")
super(name_, default_, cast_type_, sql_type_, null_, collation_, false, extra_)
if type == :spatial
cast_type.set_geo_params(factory_settings_, table_name_, ::RGeo::ActiveRecord.geometric_type_from_name(sql_type_))
cast_type.set_geo_params(factory_settings_, table_name_)
end
FACTORY_SETTINGS_CACHE[factory_settings_.object_id] = factory_settings_
end

end
end
end
Expand Down
13 changes: 6 additions & 7 deletions lib/active_record/type/spatial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,37 @@ def type
end

def spatial?
type == :spatial
true
end

def klass
type == :spatial ? ::RGeo::Feature::Geometry : super
::RGeo::Feature::Geometry
end

def set_geo_params(factory_settings, table_name, geometric_type)
def set_geo_params(factory_settings, table_name)
@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)
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)
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)
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)
Expand Down

0 comments on commit 6ca28ee

Please sign in to comment.