activerecord-postgis-adapter 3.1.0 → 3.1.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
2
  SHA1:
3
- metadata.gz: 18cc2ab739bf03f97b736b5cd82d07ab340486cd
4
- data.tar.gz: 7f2dee610840113f94fd189baa59003e10f9afd2
3
+ metadata.gz: 1d5794e492a6374fc116f335ff8479b594c666f1
4
+ data.tar.gz: e5ad43bd812c617dee1f37d3332b16e2a54cf662
5
5
  SHA512:
6
- metadata.gz: 19606ec67a62af3ff989698c6ccc41a0511934fc326d30b38f4e21d7b9a09a52a5831850fe22ae23a5596b32997f2e93d253be02ed679f16da92b7b4d92f2fc6
7
- data.tar.gz: 93f5d82f78520b7be8bf3a6d7ed17200d93af0f3850b3a00bf965282f0cec358e9a979cd4902b978495f94ba9f0184cbde5add0233a59ab360a10cca331ecbdd
6
+ metadata.gz: a50bfec3c23b81fe7ed5df48d2099e78bef8ab48e5ed4a1a72dd36b2a586a65ac3def49088f0adf7336ed2365b415051e384b15fbf584713d054aa703956e504
7
+ data.tar.gz: 29e8c1573d012b33fb5580db8ba9e8ed4d5e33e213da169fb4422a8728d90bcb874d5085183787654aec8a50bd0a12506e39b6b8b6c6e180f02b2807953fbefc
@@ -11,9 +11,9 @@ module Arel # :nodoc:
11
11
  include RGeo::ActiveRecord::SpatialToSql
12
12
 
13
13
  FUNC_MAP = {
14
- 'st_wkttosql' => 'ST_GeomFromEWKT',
14
+ "st_wkttosql" => "ST_GeomFromEWKT",
15
15
  }
16
-
16
+
17
17
  def st_func(standard_name)
18
18
  FUNC_MAP[standard_name.downcase] || standard_name
19
19
  end
@@ -25,8 +25,6 @@ module Arel # :nodoc:
25
25
  def visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector)
26
26
  aggregate(st_func(node.name), node, collector)
27
27
  end
28
-
29
28
  end
30
-
31
29
  end
32
30
  end
@@ -1,13 +1,12 @@
1
- if RUBY_ENGINE == 'jruby'
2
- require 'active_record/connection_adapters/jdbcpostgresql_adapter'
1
+ if RUBY_ENGINE == "jruby"
2
+ require "active_record/connection_adapters/jdbcpostgresql_adapter"
3
3
  else
4
- require 'pg'
4
+ require "pg"
5
5
  end
6
6
 
7
7
  module ActiveRecord # :nodoc:
8
8
  module ConnectionHandling # :nodoc:
9
-
10
- if RUBY_ENGINE == 'jruby'
9
+ if RUBY_ENGINE == "jruby"
11
10
 
12
11
  def postgis_connection(config)
13
12
  config[:adapter_class] = ConnectionAdapters::PostGISAdapter
@@ -39,6 +38,5 @@ module ActiveRecord # :nodoc:
39
38
  end
40
39
 
41
40
  end
42
-
43
41
  end
44
42
  end
@@ -7,7 +7,7 @@ namespace :db do
7
7
  ActiveRecord::Base.configurations
8
8
  .values_at(*environments)
9
9
  .compact
10
- .reject{ |config| config["database"].blank? }
10
+ .reject { |config| config["database"].blank? }
11
11
  .each do |config|
12
12
  ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(config).setup_gis
13
13
  end
@@ -24,17 +24,17 @@ 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,geography]\((.*)\)$/i)
27
+ if sql_type =~ /[geography,geography]\((.*)\)$/i
28
28
  # geometry(Point,4326)
29
- params = $1.split(',')
29
+ params = Regexp.last_match(1).split(",")
30
30
  if params.size > 1
31
31
  if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
32
- has_z = $2.length > 0
33
- has_m = $3.length > 0
34
- geo_type = $1
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
35
  end
36
36
  if params.last =~ /(\d+)/
37
- srid = $1.to_i
37
+ srid = Regexp.last_match(1).to_i
38
38
  end
39
39
  else
40
40
  # geometry(Point)
@@ -2,7 +2,6 @@ module ActiveRecord # :nodoc:
2
2
  module ConnectionAdapters # :nodoc:
3
3
  module PostGIS # :nodoc:
4
4
  class PostGISDatabaseTasks < ::ActiveRecord::Tasks::PostgreSQLDatabaseTasks # :nodoc:
5
-
6
5
  def initialize(config)
7
6
  super
8
7
  ensure_installation_configs
@@ -19,9 +18,9 @@ module ActiveRecord # :nodoc:
19
18
  # Override to set the database owner and call setup_gis
20
19
  def create(master_established = false)
21
20
  establish_master_connection unless master_established
22
- extra_configs = { 'encoding' => encoding }
23
- extra_configs['owner'] = username if has_su?
24
- connection.create_database(configuration['database'], configuration.merge(extra_configs))
21
+ extra_configs = { "encoding" => encoding }
22
+ extra_configs["owner"] = username if has_su?
23
+ connection.create_database(configuration["database"], configuration.merge(extra_configs))
25
24
  setup_gis
26
25
  rescue ::ActiveRecord::StatementInvalid => error
27
26
  if /database .* already exists/ === error.message
@@ -36,23 +35,23 @@ module ActiveRecord # :nodoc:
36
35
  # Override to use su_username and su_password
37
36
  def establish_master_connection
38
37
  establish_connection(configuration.merge(
39
- 'database' => 'postgres',
40
- 'password' => su_password,
41
- 'schema_search_path' => 'public',
42
- 'username' => su_username,
38
+ "database" => "postgres",
39
+ "password" => su_password,
40
+ "schema_search_path" => "public",
41
+ "username" => su_username,
43
42
  ))
44
43
  end
45
44
 
46
45
  def establish_su_connection
47
46
  establish_connection(configuration.merge(
48
- 'password' => su_password,
49
- 'schema_search_path' => 'public',
50
- 'username' => su_username,
47
+ "password" => su_password,
48
+ "schema_search_path" => "public",
49
+ "username" => su_username,
51
50
  ))
52
51
  end
53
52
 
54
53
  def username
55
- @username ||= configuration['username']
54
+ @username ||= configuration["username"]
56
55
  end
57
56
 
58
57
  def quoted_username
@@ -60,64 +59,64 @@ module ActiveRecord # :nodoc:
60
59
  end
61
60
 
62
61
  def password
63
- @password ||= configuration['password']
62
+ @password ||= configuration["password"]
64
63
  end
65
64
 
66
65
  def su_username
67
- @su_username ||= configuration['su_username'] || username
66
+ @su_username ||= configuration["su_username"] || username
68
67
  end
69
68
 
70
69
  def su_password
71
- @su_password ||= configuration['su_password'] || password
70
+ @su_password ||= configuration["su_password"] || password
72
71
  end
73
72
 
74
73
  def has_su?
75
- @has_su = configuration.include?('su_username') unless defined?(@has_su)
74
+ @has_su = configuration.include?("su_username") unless defined?(@has_su)
76
75
  @has_su
77
76
  end
78
77
 
79
78
  def search_path
80
- @search_path ||= configuration['schema_search_path'].to_s.strip.split(',').map(&:strip)
79
+ @search_path ||= configuration["schema_search_path"].to_s.strip.split(",").map(&:strip)
81
80
  end
82
81
 
83
82
  def extension_names
84
83
  @extension_names ||= begin
85
- extensions = configuration['postgis_extension']
84
+ extensions = configuration["postgis_extension"]
86
85
  case extensions
87
86
  when ::String
88
- extensions.split(',')
87
+ extensions.split(",")
89
88
  when ::Array
90
89
  extensions
91
90
  else
92
- ['postgis']
91
+ ["postgis"]
93
92
  end
94
93
  end
95
94
  end
96
95
 
97
96
  def ensure_installation_configs
98
- if configuration['setup'] == 'default' && !configuration['postgis_extension']
99
- share_dir = `pg_config --sharedir`.strip rescue '/usr/share'
100
- control_file = ::File.expand_path('extension/postgis.control', share_dir)
97
+ if configuration["setup"] == "default" && !configuration["postgis_extension"]
98
+ share_dir = `pg_config --sharedir`.strip rescue "/usr/share"
99
+ control_file = ::File.expand_path("extension/postgis.control", share_dir)
101
100
  if ::File.readable?(control_file)
102
- configuration['postgis_extension'] = 'postgis'
101
+ configuration["postgis_extension"] = "postgis"
103
102
  end
104
103
  end
105
104
  end
106
105
 
107
106
  def setup_gis_from_extension
108
107
  extension_names.each do |extname|
109
- if extname == 'postgis_topology'
110
- raise ::ArgumentError, "'topology' must be in schema_search_path for postgis_topology" unless search_path.include?('topology')
108
+ if extname == "postgis_topology"
109
+ raise ::ArgumentError, "'topology' must be in schema_search_path for postgis_topology" unless search_path.include?("topology")
111
110
  connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} SCHEMA topology")
112
111
  else
113
- if (postgis_schema = configuration['postgis_schema'])
112
+ if (postgis_schema = configuration["postgis_schema"])
114
113
  schema_clause = "WITH SCHEMA #{postgis_schema}"
115
114
  unless schema_exists?(postgis_schema)
116
115
  connection.execute("CREATE SCHEMA #{postgis_schema}")
117
116
  connection.execute("GRANT ALL ON SCHEMA #{postgis_schema} TO PUBLIC")
118
117
  end
119
118
  else
120
- schema_clause = ''
119
+ schema_clause = ""
121
120
  end
122
121
 
123
122
  connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} #{schema_clause}")
@@ -131,7 +130,6 @@ module ActiveRecord # :nodoc:
131
130
  end
132
131
 
133
132
  ::ActiveRecord::Tasks::DatabaseTasks.register_task(/postgis/, PostGISDatabaseTasks)
134
-
135
133
  end
136
134
  end
137
135
  end
@@ -1,5 +1,5 @@
1
- require 'rails/railtie'
2
- require 'active_record/connection_adapters/postgis_adapter'
1
+ require "rails/railtie"
2
+ require "active_record/connection_adapters/postgis_adapter"
3
3
 
4
4
  module ActiveRecord # :nodoc:
5
5
  module ConnectionAdapters # :nodoc:
@@ -10,7 +10,7 @@ module ActiveRecord
10
10
  oid = get_oid_type(oid.to_i, fmod.to_i, column_name, type)
11
11
  default_value = extract_value_from_default(oid, default)
12
12
  default_function = extract_default_function(default_value, default)
13
- new_column(table_name, column_name, default_value, oid, type, notnull == 'f', default_function)
13
+ new_column(table_name, column_name, default_value, oid, type, notnull == "f", default_function)
14
14
  end
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ module ActiveRecord
18
18
  def new_column(table_name, column_name, default, cast_type, sql_type = nil, null = true, default_function = nil)
19
19
  # JDBC gets true/false in Rails 4, where other platforms get 't'/'f' strings.
20
20
  if null.is_a?(String)
21
- null = (null == 't')
21
+ null = (null == "t")
22
22
  end
23
23
 
24
24
  column_info = spatial_column_info(table_name).get(column_name, sql_type)
@@ -49,7 +49,7 @@ module ActiveRecord
49
49
  def type_to_sql(type, limit = nil, precision = nil, scale = nil)
50
50
  case type
51
51
  when :geometry, :geography
52
- "#{ type.to_s }(#{ limit })"
52
+ "#{type}(#{limit})"
53
53
  else
54
54
  super
55
55
  end
@@ -96,14 +96,12 @@ module ActiveRecord
96
96
  multi_polygon
97
97
  st_point
98
98
  st_polygon
99
- )
100
- .each do |geo_type|
101
- map.register_type(geo_type) do |oid, _, sql_type|
102
- OID::Spatial.new(oid, sql_type)
103
- end
99
+ ).each do |geo_type|
100
+ map.register_type(geo_type) do |oid, _, sql_type|
101
+ OID::Spatial.new(oid, sql_type)
104
102
  end
103
+ end
105
104
  end
106
-
107
105
  end
108
106
  end
109
107
  end
@@ -1,11 +1,9 @@
1
1
  module ActiveRecord # :nodoc:
2
2
  module ConnectionAdapters # :nodoc:
3
3
  module PostGIS # :nodoc:
4
-
5
4
  def self.initial_setup
6
- ::ActiveRecord::SchemaDumper.ignore_tables |= %w[geometry_columns spatial_ref_sys layer topology]
5
+ ::ActiveRecord::SchemaDumper.ignore_tables |= %w(geometry_columns spatial_ref_sys layer topology)
7
6
  end
8
-
9
7
  end
10
8
  end
11
9
  end
@@ -2,7 +2,6 @@ module ActiveRecord # :nodoc:
2
2
  module ConnectionAdapters # :nodoc:
3
3
  module PostGIS # :nodoc:
4
4
  class SpatialColumn < ConnectionAdapters::PostgreSQLColumn # :nodoc:
5
-
6
5
  # sql_type examples:
7
6
  # "Geometry(Point,4326)"
8
7
  # "Geography(Point,4326)"
@@ -16,7 +16,7 @@ module ActiveRecord # :nodoc:
16
16
  type = row[3]
17
17
  dimension = row[1].to_i
18
18
  has_m = !!(type =~ /m$/i)
19
- type.sub!(/m$/, '')
19
+ type.sub!(/m$/, "")
20
20
  has_z = dimension > 3 || dimension == 3 && !has_m
21
21
  result[name] = {
22
22
  dimension: dimension,
@@ -50,7 +50,7 @@ module ActiveRecord # :nodoc:
50
50
  spatial_type = geo_type(type)
51
51
  spatial_type << "Z" if options[:has_z]
52
52
  spatial_type << "M" if options[:has_m]
53
- spatial_type << ",#{ options[:srid] || 4326 }"
53
+ spatial_type << ",#{options[:srid] || 4326}"
54
54
  spatial_type
55
55
  end
56
56
 
@@ -61,12 +61,12 @@ module ActiveRecord # :nodoc:
61
61
  value << self.class.geo_type(spatial_type)
62
62
  value << "Z" if has_z?
63
63
  value << "M" if has_m?
64
- value << ",#{ srid }"
64
+ value << ",#{srid}"
65
65
  end
66
66
  end
67
67
 
68
68
  def self.geo_type(type = "GEOMETRY")
69
- g_type = type.to_s.gsub("_", "").upcase
69
+ g_type = type.to_s.delete("_").upcase
70
70
  return "POINT" if g_type == "STPOINT"
71
71
  return "POLYGON" if g_type == "STPOLYGON"
72
72
  g_type
@@ -116,7 +116,6 @@ module ActiveRecord # :nodoc:
116
116
  @has_m = !!value
117
117
  end
118
118
  end
119
-
120
119
  end
121
120
  end
122
121
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostGIS
4
- VERSION = '3.1.0'.freeze
4
+ VERSION = "3.1.1".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -3,24 +3,24 @@
3
3
 
4
4
  # :stopdoc:
5
5
 
6
- require 'active_record/connection_adapters/postgresql_adapter'
7
- require 'rgeo/active_record'
8
- require 'active_record/connection_adapters/postgis/version'
9
- require 'active_record/connection_adapters/postgis/column_methods'
10
- require 'active_record/connection_adapters/postgis/schema_statements'
11
- require 'active_record/connection_adapters/postgis/spatial_column_info'
12
- require 'active_record/connection_adapters/postgis/spatial_table_definition'
13
- require 'active_record/connection_adapters/postgis/spatial_column'
14
- require 'active_record/connection_adapters/postgis/arel_tosql'
15
- require 'active_record/connection_adapters/postgis/setup'
16
- require 'active_record/connection_adapters/postgis/oid/spatial'
17
- require 'active_record/connection_adapters/postgis/create_connection'
18
- require 'active_record/connection_adapters/postgis/postgis_database_tasks'
6
+ require "active_record/connection_adapters/postgresql_adapter"
7
+ require "rgeo-activerecord"
8
+ require "active_record/connection_adapters/postgis/version"
9
+ require "active_record/connection_adapters/postgis/column_methods"
10
+ require "active_record/connection_adapters/postgis/schema_statements"
11
+ require "active_record/connection_adapters/postgis/spatial_column_info"
12
+ require "active_record/connection_adapters/postgis/spatial_table_definition"
13
+ require "active_record/connection_adapters/postgis/spatial_column"
14
+ require "active_record/connection_adapters/postgis/arel_tosql"
15
+ require "active_record/connection_adapters/postgis/setup"
16
+ require "active_record/connection_adapters/postgis/oid/spatial"
17
+ require "active_record/connection_adapters/postgis/create_connection"
18
+ require "active_record/connection_adapters/postgis/postgis_database_tasks"
19
19
 
20
20
  ::ActiveRecord::ConnectionAdapters::PostGIS.initial_setup
21
21
 
22
22
  if defined?(::Rails::Railtie)
23
- load ::File.expand_path('postgis/railtie.rb', ::File.dirname(__FILE__))
23
+ load ::File.expand_path("postgis/railtie.rb", ::File.dirname(__FILE__))
24
24
  end
25
25
 
26
26
  # :startdoc:
@@ -70,18 +70,18 @@ module ActiveRecord
70
70
 
71
71
  def srs_database_columns
72
72
  {
73
- auth_name_column: 'auth_name',
74
- auth_srid_column: 'auth_srid',
75
- proj4text_column: 'proj4text',
76
- srtext_column: 'srtext',
73
+ auth_name_column: "auth_name",
74
+ auth_srid_column: "auth_srid",
75
+ proj4text_column: "proj4text",
76
+ srtext_column: "srtext",
77
77
  }
78
78
  end
79
79
 
80
80
  def quote(value, column = nil)
81
81
  if RGeo::Feature::Geometry.check_type(value)
82
- "'#{ RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value) }'"
82
+ "'#{RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)}'"
83
83
  elsif value.is_a?(RGeo::Cartesian::BoundingBox)
84
- "'#{ value.min_x },#{ value.min_y },#{ value.max_x },#{ value.max_y }'::box"
84
+ "'#{value.min_x},#{value.min_y},#{value.max_x},#{value.max_y}'::box"
85
85
  else
86
86
  super
87
87
  end
@@ -1 +1 @@
1
- require 'active_record/connection_adapters/postgis_adapter.rb'
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: 3.1.0
4
+ version: 3.1.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: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -118,15 +118,6 @@ files:
118
118
  - lib/active_record/connection_adapters/postgis/version.rb
119
119
  - lib/active_record/connection_adapters/postgis_adapter.rb
120
120
  - lib/activerecord-postgis-adapter.rb
121
- - test/basic_test.rb
122
- - test/database.yml
123
- - test/ddl_test.rb
124
- - test/nested_class_test.rb
125
- - test/setup_test.rb
126
- - test/spatial_queries_test.rb
127
- - test/tasks_test.rb
128
- - test/test_helper.rb
129
- - test/type_test.rb
130
121
  homepage: http://github.com/rgeo/activerecord-postgis-adapter
131
122
  licenses:
132
123
  - BSD
@@ -147,17 +138,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
138
  version: '0'
148
139
  requirements: []
149
140
  rubyforge_project:
150
- rubygems_version: 2.5.0
141
+ rubygems_version: 2.5.1
151
142
  signing_key:
152
143
  specification_version: 4
153
144
  summary: ActiveRecord adapter for PostGIS, based on RGeo.
154
- test_files:
155
- - test/basic_test.rb
156
- - test/database.yml
157
- - test/ddl_test.rb
158
- - test/nested_class_test.rb
159
- - test/setup_test.rb
160
- - test/spatial_queries_test.rb
161
- - test/tasks_test.rb
162
- - test/test_helper.rb
163
- - test/type_test.rb
145
+ test_files: []
146
+ has_rdoc: