activerecord-postgis-adapter 4.1.2 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: b7f31291d3a3bac2b1ebe80cd26338922c4a5f1ec7df74fee00a2584e6540800
4
- data.tar.gz: b2d85cda7e6d77806f8bce76cc9fa7bff74be5955e769bd263a307ad93736ee0
2
+ SHA1:
3
+ metadata.gz: 7b3f788f4ff2a7994a5b09fe55a85fb34e4c07af
4
+ data.tar.gz: 150c100ea1c01b61c118a3072780514c313cd44d
5
5
  SHA512:
6
- metadata.gz: 047ed7b22f3ed708e9a2bd4c61c89f5ee9a0b816cf95a92d3edfb0337408b59e3582c21fae299269bda70ca814f6e69e62139ca8928780b2ff738df2a52b528e
7
- data.tar.gz: 1425b7e58930b20a9c48d3c9f089a8fdbf85a5248bd96fc8b0e9f0d680a634ba3dee22b8b0b1499ce00db033df37634a67bab3e9bb07b0946e96433b080a1d03
6
+ metadata.gz: 4cb6baff936647c96561d781260d6cd3b61e56130ea87c337d4285050686f81b68c5130fdcd4696684583fccdcba6ec21a1b602ed542ad2bdc648eba71474899
7
+ data.tar.gz: 41c64f27461a9fa46d1046fb9e8376ad5fa80ad5737dbd4d0b26e25b13891363a83f059be730eec27fe742fa21e41c68720c4629a797b09a589a7ece3d3ea429
@@ -43,8 +43,8 @@ module ActiveRecord
43
43
  column(name, :st_polygon, options)
44
44
  end
45
45
  end
46
- end
47
46
 
48
- PostgreSQL::Table.include PostGIS::ColumnMethods
47
+ PostgreSQL::Table.send(:include, ColumnMethods)
48
+ end
49
49
  end
50
50
  end
@@ -30,7 +30,7 @@ module ActiveRecord # :nodoc:
30
30
  conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
31
31
 
32
32
  # Forward only valid config params to PGconn.connect.
33
- valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
33
+ valid_conn_param_keys = PGconn.conndefaults_hash.keys + [:requiressl]
34
34
  conn_params.slice!(*valid_conn_param_keys)
35
35
 
36
36
  # The postgres drivers don't allow the creation of an unconnected PGconn object,
@@ -24,16 +24,21 @@ module ActiveRecord
24
24
  def self.parse_sql_type(sql_type)
25
25
  geo_type, srid, has_z, has_m = nil, 0, false, false
26
26
 
27
- if sql_type =~ /(geography|geometry)\((.*)\)$/i
27
+ if sql_type =~ /[geography,geometry]\((.*)\)$/i
28
28
  # geometry(Point,4326)
29
- params = Regexp.last_match(2).split(",")
30
- if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
31
- has_z = Regexp.last_match(2).length > 0
32
- has_m = Regexp.last_match(3).length > 0
33
- geo_type = Regexp.last_match(1)
34
- end
35
- if params.last =~ /(\d+)/
36
- srid = Regexp.last_match(1).to_i
29
+ params = Regexp.last_match(1).split(",")
30
+ if params.size > 1
31
+ if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
32
+ has_z = Regexp.last_match(2).length > 0
33
+ has_m = Regexp.last_match(3).length > 0
34
+ geo_type = Regexp.last_match(1)
35
+ end
36
+ if params.last =~ /(\d+)/
37
+ srid = Regexp.last_match(1).to_i
38
+ end
39
+ else
40
+ # geometry(Point)
41
+ geo_type = params[0]
37
42
  end
38
43
  else
39
44
  # geometry
@@ -1,9 +1,12 @@
1
+ require "rails/railtie"
2
+ require "active_record/connection_adapters/postgis_adapter"
3
+
1
4
  module ActiveRecord # :nodoc:
2
5
  module ConnectionAdapters # :nodoc:
3
6
  module PostGIS # :nodoc:
4
7
  class Railtie < ::Rails::Railtie # :nodoc:
5
8
  rake_tasks do
6
- load "active_record/connection_adapters/postgis/databases.rake"
9
+ load ::File.expand_path("databases.rake", ::File.dirname(__FILE__))
7
10
  end
8
11
  end
9
12
  end
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
  # pass table_name to #new_column
7
7
  def columns(table_name)
8
8
  # Limit, precision, and scale are all handled by the superclass.
9
- column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod, collation, comment|
9
+ column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod, collation|
10
10
  oid = oid.to_i
11
11
  fmod = fmod.to_i
12
12
  type_metadata = fetch_type_metadata(column_name, type, oid, fmod)
@@ -14,12 +14,12 @@ module ActiveRecord
14
14
  default_value = extract_value_from_default(default)
15
15
 
16
16
  default_function = extract_default_function(default_value, default)
17
- new_column(table_name, column_name, default_value, cast_type, type_metadata, !notnull, default_function, collation, comment)
17
+ new_column(table_name, column_name, default_value, cast_type, type_metadata, !notnull, default_function, collation)
18
18
  end
19
19
  end
20
20
 
21
21
  # override
22
- def new_column(table_name, column_name, default, cast_type, sql_type_metadata = nil, null = true, default_function = nil, collation = nil, comment = nil)
22
+ def new_column(table_name, column_name, default, cast_type, sql_type_metadata = nil, null = true, default_function = nil, collation = nil)
23
23
  # JDBC gets true/false in Rails 4, where other platforms get 't'/'f' strings.
24
24
  if null.is_a?(String)
25
25
  null = (null == "t")
@@ -34,7 +34,6 @@ module ActiveRecord
34
34
  table_name,
35
35
  default_function,
36
36
  collation,
37
- comment,
38
37
  cast_type,
39
38
  column_info)
40
39
  end
@@ -52,10 +51,10 @@ module ActiveRecord
52
51
  #
53
52
  # type_to_sql(:geography, "Point,4326")
54
53
  # => "geography(Point,4326)"
55
- def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil)
54
+ def type_to_sql(type, options = {})
56
55
  case type
57
56
  when :geometry, :geography
58
- "#{type}(#{limit})"
57
+ "#{type}(#{options[:limit]})"
59
58
  else
60
59
  super
61
60
  end
@@ -8,7 +8,7 @@ module ActiveRecord # :nodoc:
8
8
  # cast_type example classes:
9
9
  # OID::Spatial
10
10
  # OID::Integer
11
- def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment = nil, cast_type = nil, opts = nil)
11
+ def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, cast_type = nil, opts = nil)
12
12
  @cast_type = cast_type
13
13
  @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
14
14
  if opts
@@ -29,7 +29,7 @@ module ActiveRecord # :nodoc:
29
29
  # @geometric_type = geo_type_from_sql_type(sql_type)
30
30
  build_from_sql_type(sql_type_metadata.sql_type)
31
31
  end
32
- super(name, default, sql_type_metadata, null, table_name, default_function, collation, comment: comment)
32
+ super(name, default, sql_type_metadata, null, table_name, default_function, collation)
33
33
  if spatial?
34
34
  if @srid
35
35
  @limit = { srid: @srid, type: to_type_name(geometric_type) }
@@ -11,109 +11,42 @@ module ActiveRecord # :nodoc:
11
11
  options.merge!(limit) if limit.is_a?(::Hash)
12
12
  end
13
13
 
14
- geo_type = ColumnDefinition.geo_type(options[:type] || type || info[:type])
14
+ geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
15
15
  base_type = info[:type] || (options[:geographic] ? :geography : :geometry)
16
16
 
17
17
  # puts name.dup << " - " << type.to_s << " - " << options.to_s << " :: " << geo_type.to_s << " - " << base_type.to_s
18
18
 
19
- if options[:geographic]
20
- options[:limit] = ColumnDefinition.options_to_limit(geo_type, options)
21
- end
19
+ options[:limit] = ColumnDefinitionUtils.limit_from_options(geo_type, options)
20
+ options[:spatial_type] = geo_type
22
21
  column = super(name, base_type, options)
23
- column.spatial_type = geo_type
24
- column.geographic = options[:geographic]
25
- column.srid = options[:srid]
26
- column.has_z = options[:has_z]
27
- column.has_m = options[:has_m]
28
22
  else
29
23
  column = super(name, type, options)
30
24
  end
31
25
 
32
26
  column
33
27
  end
34
-
35
- private
36
-
37
- def create_column_definition(name, type)
38
- if PostGISAdapter.spatial_column_options(type.to_sym)
39
- PostGIS::ColumnDefinition.new(name, type)
40
- else
41
- super
42
- end
43
- end
44
28
  end
45
29
 
46
- class ColumnDefinition < PostgreSQL::ColumnDefinition
47
- # needs to accept the spatial type? or figure out from limit ?
48
-
49
- def self.options_to_limit(type, options = {})
50
- spatial_type = geo_type(type)
51
- spatial_type << "Z" if options[:has_z]
52
- spatial_type << "M" if options[:has_m]
53
- spatial_type << ",#{options[:srid] || 4326}"
54
- spatial_type
55
- end
56
-
57
- # limit is how column options are passed to #type_to_sql
58
- # returns: "Point,4326"
59
- def limit
60
- "".tap do |value|
61
- value << self.class.geo_type(spatial_type)
62
- value << "Z" if has_z?
63
- value << "M" if has_m?
64
- value << ",#{srid}"
30
+ module ColumnDefinitionUtils
31
+ class << self
32
+ def geo_type(type = "GEOMETRY")
33
+ g_type = type.to_s.delete("_").upcase
34
+ return "POINT" if g_type == "STPOINT"
35
+ return "POLYGON" if g_type == "STPOLYGON"
36
+ g_type
65
37
  end
66
- end
67
-
68
- def self.geo_type(type = "GEOMETRY")
69
- g_type = type.to_s.delete("_").upcase
70
- return "POINT" if g_type == "STPOINT"
71
- return "POLYGON" if g_type == "STPOLYGON"
72
- g_type
73
- end
74
-
75
- def spatial_type
76
- @spatial_type
77
- end
78
-
79
- def spatial_type=(value)
80
- @spatial_type = value.to_s
81
- end
82
38
 
83
- def geographic?
84
- @geographic
85
- end
86
-
87
- def geographic=(value)
88
- @geographic = !!value
89
- end
90
-
91
- def srid
92
- if @srid
93
- @srid.to_i
94
- else
95
- geographic? ? 4326 : PostGISAdapter::DEFAULT_SRID
39
+ def limit_from_options(type, options = {})
40
+ spatial_type = geo_type(type)
41
+ spatial_type << "Z" if options[:has_z]
42
+ spatial_type << "M" if options[:has_m]
43
+ spatial_type << ",#{options[:srid] || default_srid(options)}"
44
+ spatial_type
96
45
  end
97
- end
98
-
99
- def srid=(value)
100
- @srid = value
101
- end
102
46
 
103
- def has_z?
104
- @has_z
105
- end
106
-
107
- def has_z=(value)
108
- @has_z = !!value
109
- end
110
-
111
- def has_m?
112
- @has_m
113
- end
114
-
115
- def has_m=(value)
116
- @has_m = !!value
47
+ def default_srid(options)
48
+ options[:geographic] ? 4326 : PostGISAdapter::DEFAULT_SRID
49
+ end
117
50
  end
118
51
  end
119
52
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostGIS
4
- VERSION = "4.1.2"
4
+ VERSION = "5.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -3,16 +3,8 @@
3
3
 
4
4
  # :stopdoc:
5
5
 
6
- require "rgeo/active_record"
7
-
8
- # autoload AbstractAdapter to avoid circular require and void context warnings
9
- module ActiveRecord
10
- module ConnectionAdapters
11
- AbstractAdapter
12
- end
13
- end
14
-
15
6
  require "active_record/connection_adapters/postgresql_adapter"
7
+ require "rgeo/active_record"
16
8
  require "active_record/connection_adapters/postgis/version"
17
9
  require "active_record/connection_adapters/postgis/column_methods"
18
10
  require "active_record/connection_adapters/postgis/schema_statements"
@@ -28,7 +20,7 @@ require "active_record/connection_adapters/postgis/postgis_database_tasks"
28
20
  ::ActiveRecord::ConnectionAdapters::PostGIS.initial_setup
29
21
 
30
22
  if defined?(::Rails::Railtie)
31
- require "active_record/connection_adapters/postgis/railtie"
23
+ load ::File.expand_path("postgis/railtie.rb", ::File.dirname(__FILE__))
32
24
  end
33
25
 
34
26
  # :startdoc:
@@ -94,7 +86,7 @@ module ActiveRecord
94
86
  }
95
87
  end
96
88
 
97
- def quote(value, column = nil)
89
+ def quote(value)
98
90
  if RGeo::Feature::Geometry.check_type(value)
99
91
  "'#{RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)}'"
100
92
  elsif value.is_a?(RGeo::Cartesian::BoundingBox)
@@ -1 +1 @@
1
- require "active_record/connection_adapters/postgis_adapter"
1
+ require "active_record/connection_adapters/postgis_adapter.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma, Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: '5.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rgeo-activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '5.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '6.0'
40
+ version: '5.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.7.6
141
+ rubygems_version: 2.6.11
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: ActiveRecord adapter for PostGIS, based on RGeo.