Skip to content

Commit

Permalink
Upgrate Active Record dependency to 4.2. Drop rgeo 0.4 appraisal.
Browse files Browse the repository at this point in the history
  • Loading branch information
dschweisguth committed Jun 30, 2017
1 parent bdc9394 commit e40987d
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 216 deletions.
8 changes: 3 additions & 5 deletions Appraisals
@@ -1,7 +1,5 @@
appraise 'rgeo-0.4.0' do
gem 'rgeo', '0.4.0'
end

appraise 'rgeo-0.6.0' do
appraise 'current' do
gem 'activerecord', '4.2.9'
gem 'mysql2', '0.3.21'
gem 'rgeo', '0.6.0'
end
4 changes: 0 additions & 4 deletions Gemfile
Expand Up @@ -35,7 +35,3 @@
source "https://rubygems.org"

gemspec

# This dependency is here because gemspecs can't use git sources.
# It overrides the less specific dependency in gemspec.
gem 'rgeo-activerecord', git: 'https://github.com/rgeo/rgeo-activerecord.git', branch: '1.0'
4 changes: 2 additions & 2 deletions activerecord-mysql2spatial-adapter.gemspec
Expand Up @@ -47,8 +47,8 @@
['Version']
s_.extra_rdoc_files = ::Dir.glob("*.rdoc")
s_.platform = ::Gem::Platform::RUBY
s_.add_dependency('activerecord', '>= 4.0', '< 4.2')
s_.add_dependency('rgeo-activerecord', '~> 1.0')
s_.add_dependency('activerecord', '~> 4.2.9')
s_.add_dependency('rgeo-activerecord', '~> 2.1.1')
s_.add_dependency('mysql2', '>= 0.2.13', '< 0.4.0')
s_.add_development_dependency('appraisal')
s_.add_development_dependency('pry')
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rgeo_0.6.0.gemfile → gemfiles/current.gemfile
Expand Up @@ -2,7 +2,8 @@

source "https://rubygems.org"

gem "rgeo-activerecord", git: "https://github.com/rgeo/rgeo-activerecord.git", branch: "1.0"
gem "activerecord", "4.2.9"
gem "mysql2", "0.3.21"
gem "rgeo", "0.6.0"

gemspec path: "../"
41 changes: 17 additions & 24 deletions gemfiles/rgeo_0.6.0.gemfile.lock → gemfiles/current.gemfile.lock
@@ -1,45 +1,34 @@
GIT
remote: https://github.com/rgeo/rgeo-activerecord.git
revision: 0d3f7975b476135b7baf8b1831b4fa2528500616
branch: 1.0
specs:
rgeo-activerecord (1.2.0)
activerecord (~> 4.0)
rgeo (~> 0.3)

PATH
remote: ..
specs:
activerecord-mysql2spatial-adapter (0.5.0)
activerecord (>= 4.0, < 4.2)
activerecord (~> 4.2.9)
mysql2 (>= 0.2.13, < 0.4.0)
rgeo-activerecord (~> 1.0)
rgeo-activerecord (~> 2.1.1)

GEM
remote: https://rubygems.org/
specs:
activemodel (4.1.16)
activesupport (= 4.1.16)
activemodel (4.2.9)
activesupport (= 4.2.9)
builder (~> 3.1)
activerecord (4.1.16)
activemodel (= 4.1.16)
activesupport (= 4.1.16)
arel (~> 5.0.0)
activesupport (4.1.16)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
activerecord (4.2.9)
activemodel (= 4.2.9)
activesupport (= 4.2.9)
arel (~> 6.0)
activesupport (4.2.9)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
appraisal (2.2.0)
bundler
rake
thor (>= 0.14.0)
arel (5.0.1.20140414130214)
arel (6.0.4)
builder (3.2.3)
coderay (1.1.1)
i18n (0.8.4)
json (1.8.6)
method_source (0.8.2)
minitest (5.10.2)
mysql2 (0.3.21)
Expand All @@ -50,6 +39,9 @@ GEM
rake (12.0.0)
rdoc (5.1.0)
rgeo (0.6.0)
rgeo-activerecord (2.1.1)
activerecord (~> 4.2)
rgeo (~> 0.3)
slop (3.6.0)
thor (0.19.4)
thread_safe (0.3.6)
Expand All @@ -60,13 +52,14 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord (= 4.2.9)
activerecord-mysql2spatial-adapter!
appraisal
mysql2 (= 0.3.21)
pry
rake (>= 0.9.2)
rdoc (>= 3.12)
rgeo (= 0.6.0)
rgeo-activerecord!

BUNDLED WITH
1.15.1
8 changes: 0 additions & 8 deletions gemfiles/rgeo_0.4.0.gemfile

This file was deleted.

72 changes: 0 additions & 72 deletions gemfiles/rgeo_0.4.0.gemfile.lock

This file was deleted.

Expand Up @@ -31,8 +31,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
;


require 'rgeo/active_record'
require 'active_record/connection_adapters/mysql2_adapter'
Expand Down Expand Up @@ -88,3 +86,4 @@ module Mysql2SpatialAdapter
require 'active_record/connection_adapters/mysql2spatial_adapter/main_adapter.rb'
require 'active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb'
require 'active_record/connection_adapters/mysql2spatial_adapter/arel_tosql.rb'
require 'active_record/type/spatial.rb'
Expand Up @@ -31,8 +31,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
;


# :stopdoc:

Expand Down Expand Up @@ -111,11 +109,11 @@ def add_index(table_name_, column_name_, options_={})


def columns(table_name_, name_=nil)
result_ = execute("SHOW FIELDS FROM #{quote_table_name(table_name_)}", :skip_logging)
result_ = @connection.query "SHOW FULL FIELDS FROM #{quote_table_name(table_name_)}"
columns_ = []
result_.each(:symbolize_keys => true, :as => :hash) do |field_|
columns_ << SpatialColumn.new(@rgeo_factory_settings, table_name_.to_s,
field_[:Field], field_[:Default], field_[:Type], field_[:Null] == "YES")
field_[:Field], field_[:Default], lookup_cast_type(field_[:Type]), field_[:Type], field_[:Null] == "YES", field_[:Collation], field_[:Extra])
end
columns_
end
Expand Down Expand Up @@ -147,6 +145,15 @@ def indexes(table_name_, name_=nil)
indexes_
end

protected

def initialize_type_map(m)
super
register_class_with_limit m, %r(geometry)i, Type::Spatial
m.alias_type %r(point)i, 'geometry'
m.alias_type %r(linestring)i, 'geometry'
m.alias_type %r(polygon)i, 'geometry'
end

end

Expand Down
Expand Up @@ -31,116 +31,26 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
;


# :stopdoc:

module ActiveRecord

module ConnectionAdapters

module Mysql2SpatialAdapter


# ActiveRecord 3.2 uses ConnectionAdapters::Mysql2Adapter::Column
# whereas 3.0 and 3.1 use ConnectionAdapters::Mysql2Column
column_base_class_ = defined?(ConnectionAdapters::Mysql2Adapter::Column) ?
ConnectionAdapters::Mysql2Adapter::Column : ConnectionAdapters::Mysql2Column

class SpatialColumn < column_base_class_


class SpatialColumn < ConnectionAdapters::Mysql2Adapter::Column
FACTORY_SETTINGS_CACHE = {}


def initialize(factory_settings_, table_name_, name_, default_, sql_type_=nil, null_=true)
@factory_settings = factory_settings_
@table_name = table_name_
super(name_, default_,sql_type_, null_)
@geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(sql_type_)
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
@limit = { type: @geometric_type.type_name.underscore }
cast_type.set_geo_params(factory_settings_, table_name_, ::RGeo::ActiveRecord.geometric_type_from_name(sql_type_))
end
FACTORY_SETTINGS_CACHE[factory_settings_.object_id] = factory_settings_
end


attr_reader :geometric_type


def spatial?
type == :spatial
end


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


def type_cast(value_)
if type == :spatial
SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name)
else
super
end
end


def type_cast_code(var_name_)
if type == :spatial
"::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn.convert_to_geometry("+
"#{var_name_}, ::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn::"+
"FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, #{name.inspect})"
else
super
end
end


private

def simplified_type(sql_type_)
sql_type_ =~ /geometry|point|linestring|polygon/i ? :spatial : super
end


def self.convert_to_geometry(input_, factory_settings_, table_name_, column_)
case input_
when ::RGeo::Feature::Geometry
factory_ = factory_settings_.get_column_factory(table_name_, column_, :srid => input_.srid)
::RGeo::Feature.cast(input_, factory_) rescue nil
when ::String
marker_ = input_[4,1]
if marker_ == "\x00" || marker_ == "\x01"
factory_ = factory_settings_.get_column_factory(table_name_, column_,
:srid => input_[0,4].unpack(marker_ == "\x01" ? 'V' : 'N').first)
::RGeo::WKRep::WKBParser.new(factory_).parse(input_[4..-1]) rescue nil
elsif input_[0,10] =~ /[0-9a-fA-F]{8}0[01]/
srid_ = input_[0,8].to_i(16)
if input[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(input_[8..-1]) rescue nil
else
factory_ = factory_settings_.get_column_factory(table_name_, column_)
::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true).parse(input_) rescue nil
end
else
nil
end
end


end


end

end

end

# :startdoc:

0 comments on commit e40987d

Please sign in to comment.