Skip to content

Commit c12e87e

Browse files
authored
Merge pull request #28 from dschweisguth/code-cleanup-this-time-for-sure
Code cleanup
2 parents cfe0bdb + 6813b68 commit c12e87e

File tree

13 files changed

+46
-163
lines changed

13 files changed

+46
-163
lines changed

Gemfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -----------------------------------------------------------------------------
21
#
32
# Gemfile used for CI testing.
43
#
5-
# -----------------------------------------------------------------------------
64
# Copyright 2012 Daniel Azuma
75
#
86
# All rights reserved.
@@ -30,8 +28,7 @@
3028
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3129
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3230
# POSSIBILITY OF SUCH DAMAGE.
33-
# -----------------------------------------------------------------------------
3431

35-
source "https://rubygems.org"
32+
source 'https://rubygems.org'
3633

3734
gemspec

History.rdoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
=== 0.5.2
2+
3+
* Code cleanup, whitespace, comments
4+
* Use Ruby 1.9+ syntax for hashes
5+
16
=== 0.5.1 / 2017-07-04
27

38
* Move dependency on rgeo-activerecord from unreleased 1.0 branch to 1.3.0 release.

README.rdoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ column may need to be NOT NULL.
2121

2222
Examples (require update):
2323

24-
create_table :my_spatial_table, :options => 'ENGINE=MyISAM' do |t|
25-
t.column :latlon, :point, :null => false
24+
create_table :my_spatial_table, options: 'ENGINE=MyISAM' do |t|
25+
t.column :latlon, :point, null: false
2626
t.line_string :path
2727
t.geometry :shape
2828
end
2929
change_table :my_spatial_table do |t|
30-
t.index :latlon, :spatial => true
30+
t.index :latlon, spatial: true
3131
end
3232

3333
=== Spatial Attributes
@@ -80,11 +80,11 @@ Now you can interact with the data using the RGeo types:
8080
You can create simple queries based on objective equality in the same way
8181
you would on a scalar column:
8282

83-
rec = MySpatialTable.where(:latlon => RGeo::Geos.factory.point(-122, 47)).first
83+
rec = MySpatialTable.where(latlon: RGeo::Geos.factory.point(-122, 47)).first
8484

8585
You can also use WKT:
8686

87-
rec = MySpatialTable.where(:latlon => 'POINT(-122 47)').first
87+
rec = MySpatialTable.where(latlon: 'POINT(-122 47)').first
8888

8989
The adapter also provides experimental support for more complex queries
9090
such as radius searches. However, these extensions require Arel 2.1

Rakefile

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -----------------------------------------------------------------------------
21
#
32
# Generic Gem Rakefile
43
#
5-
# -----------------------------------------------------------------------------
64
# Copyright 2010-2012 Daniel Azuma
75
#
86
# All rights reserved.
@@ -30,8 +28,6 @@
3028
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3129
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3230
# POSSIBILITY OF SUCH DAMAGE.
33-
# -----------------------------------------------------------------------------
34-
;
3531

3632

3733
# Load config if present
@@ -44,7 +40,6 @@ RAKEFILE_CONFIG = {} unless defined?(::RAKEFILE_CONFIG)
4440
# Gemspec
4541

4642
require 'rubygems'
47-
require 'pry'
4843
gemspec_ = eval(::File.read(::Dir.glob('*.gemspec').first))
4944
release_gemspec_ = eval(::File.read(::Dir.glob('*.gemspec').first))
5045
release_gemspec_.version = gemspec_.version.to_s.sub(/\.nonrelease$/, '')
@@ -93,14 +88,14 @@ internal_ext_info_ = gemspec_.extensions.map do |extconf_path_|
9388
source_dir_ = ::File.dirname(extconf_path_)
9489
name_ = ::File.basename(source_dir_)
9590
{
96-
:name => name_,
97-
:source_dir => source_dir_,
98-
:extconf_path => extconf_path_,
99-
:source_glob => "#{source_dir_}/*.{c,h}",
100-
:obj_glob => "#{source_dir_}/*.{o,dSYM}",
101-
:suffix_makefile_path => "#{source_dir_}/Makefile_#{platform_suffix_}",
102-
:built_lib_path => "#{source_dir_}/#{name_}.#{dlext_}",
103-
:staged_lib_path => "#{source_dir_}/#{name_}_#{platform_suffix_}.#{dlext_}",
91+
name: name_,
92+
source_dir: source_dir_,
93+
extconf_path: extconf_path_,
94+
source_glob: "#{source_dir_}/*.{c,h}",
95+
obj_glob: "#{source_dir_}/*.{o,dSYM}",
96+
suffix_makefile_path: "#{source_dir_}/Makefile_#{platform_suffix_}",
97+
built_lib_path: "#{source_dir_}/#{name_}.#{dlext_}",
98+
staged_lib_path: "#{source_dir_}/#{name_}_#{platform_suffix_}.#{dlext_}",
10499
}
105100
end
106101
internal_ext_info_ = [] if platform_ == :jruby
@@ -123,7 +118,7 @@ internal_ext_info_.each do |info_|
123118
end
124119
end
125120

126-
task :build_ext => internal_ext_info_.map{ |info_| info_[:staged_lib_path] } do
121+
task build_ext: internal_ext_info_.map{ |info_| info_[:staged_lib_path] } do
127122
internal_ext_info_.each do |info_|
128123
target_prefix_ = target_name_ = nil
129124
::Dir.chdir(info_[:source_dir]) do
@@ -161,7 +156,7 @@ end
161156

162157
# RDoc tasks
163158

164-
task :build_rdoc => "#{doc_directory_}/index.html"
159+
task build_rdoc: "#{doc_directory_}/index.html"
165160
all_rdoc_files_ = ::Dir.glob("lib/**/*.rb") + gemspec_.extra_rdoc_files
166161
main_rdoc_file_ = ::RAKEFILE_CONFIG[:main_rdoc_file]
167162
main_rdoc_file_ = 'README.rdoc' if !main_rdoc_file_ && ::File.readable?('README.rdoc')
@@ -184,19 +179,19 @@ end
184179

185180
task :build_other
186181

187-
task :build_gem => :build_other do
182+
task build_gem: :build_other do
188183
::Gem::Builder.new(gemspec_).build
189184
mkdir_p(pkg_directory_)
190185
mv "#{gemspec_.name}-#{gemspec_.version}.gem", "#{pkg_directory_}/"
191186
end
192187

193-
task :build_release => :build_other do
188+
task build_release: :build_other do
194189
::Gem::Builder.new(release_gemspec_).build
195190
mkdir_p(pkg_directory_)
196191
mv "#{release_gemspec_.name}-#{release_gemspec_.version}.gem", "#{pkg_directory_}/"
197192
end
198193

199-
task :release_gem => :build_release do
194+
task release_gem: :build_release do
200195
::Dir.chdir(pkg_directory_) do
201196
sh "#{::RbConfig::TOPDIR}/bin/gem push #{release_gemspec_.name}-#{release_gemspec_.version}.gem"
202197
end
@@ -205,7 +200,7 @@ end
205200

206201
# Unit test task
207202

208-
task :test => [:build_ext, :build_other] do
203+
task test: [:build_ext, :build_other] do
209204
$:.unshift(::File.expand_path('lib', ::File.dirname(__FILE__)))
210205
if ::ENV['TESTCASE']
211206
test_files_ = ::Dir.glob("test/#{::ENV['TESTCASE']}.rb")
@@ -221,4 +216,4 @@ end
221216

222217
# Default task
223218

224-
task :default => [:clean, :test]
219+
task default: [:clean, :test]

activerecord-mysql2spatial-adapter.gemspec

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -----------------------------------------------------------------------------
21
#
32
# MySQL2 Spatial ActiveRecord Adapter Gemspec
43
#
5-
# -----------------------------------------------------------------------------
64
# Copyright 2011-2012 Daniel Azuma
75
#
86
# All rights reserved.
@@ -30,7 +28,6 @@
3028
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3129
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3230
# POSSIBILITY OF SUCH DAMAGE.
33-
# -----------------------------------------------------------------------------
3431

3532
::Gem::Specification.new do |s_|
3633
s_.name = 'activerecord-mysql2spatial-adapter'
@@ -50,7 +47,6 @@
5047
s_.add_dependency('activerecord', '>= 4.0', '< 4.2')
5148
s_.add_dependency('rgeo-activerecord', '~> 1.3')
5249
s_.add_dependency('mysql2', '>= 0.2.13', '< 0.4.0')
53-
s_.add_development_dependency('pry')
5450
s_.add_development_dependency('rake', '>= 0.9.2')
5551
s_.add_development_dependency('rdoc', '>= 3.12')
5652
end

lib/active_record/connection_adapters/mysql2spatial_adapter.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -----------------------------------------------------------------------------
21
#
32
# Mysql2Spatial adapter for ActiveRecord
43
#
5-
# -----------------------------------------------------------------------------
64
# Copyright 2010 Daniel Azuma
75
#
86
# All rights reserved.
@@ -30,26 +28,21 @@
3028
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3129
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3230
# POSSIBILITY OF SUCH DAMAGE.
33-
# -----------------------------------------------------------------------------
34-
;
3531

3632

3733
require 'rgeo/active_record'
3834
require 'active_record/connection_adapters/mysql2_adapter'
3935

40-
4136
# The activerecord-mysql2spatial-adapter gem installs the *mysql2spatial*
4237
# connection adapter into ActiveRecord.
4338

4439
module ActiveRecord
4540

46-
4741
# ActiveRecord looks for the mysql2spatial_connection factory method in
4842
# this class.
4943

5044
class Base
5145

52-
5346
# Create a mysql2spatial connection adapter.
5447

5548
def self.mysql2spatial_connection(config_)
@@ -62,10 +55,8 @@ def self.mysql2spatial_connection(config_)
6255
::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::MainAdapter.new(client_, logger, options_, config_)
6356
end
6457

65-
6658
end
6759

68-
6960
# All ActiveRecord adapters go in this namespace.
7061
module ConnectionAdapters
7162

@@ -76,13 +67,9 @@ module Mysql2SpatialAdapter
7667
ADAPTER_NAME = 'Mysql2Spatial'.freeze
7768

7869
end
79-
8070
end
81-
82-
8371
end
8472

85-
8673
require 'active_record/connection_adapters/mysql2spatial_adapter/version.rb'
8774
require 'active_record/connection_adapters/mysql2spatial_adapter/column_methods.rb' # check if this works with Rails < 4.x
8875
require 'active_record/connection_adapters/mysql2spatial_adapter/main_adapter.rb'

lib/active_record/connection_adapters/mysql2spatial_adapter/arel_tosql.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -----------------------------------------------------------------------------
21
#
32
# Mysql2Spatial adapter for ActiveRecord
43
#
5-
# -----------------------------------------------------------------------------
64
# Copyright 2010 Daniel Azuma
75
#
86
# All rights reserved.
@@ -30,15 +28,12 @@
3028
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3129
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3230
# POSSIBILITY OF SUCH DAMAGE.
33-
# -----------------------------------------------------------------------------
34-
;
3531

3632

3733
# :stopdoc:
3834

3935
module Arel
4036
module Visitors
41-
4237
class MySQL2Spatial < MySQL
4338

4439
if ::Arel::Visitors.const_defined?(:BindVisitor)

lib/active_record/connection_adapters/mysql2spatial_adapter/main_adapter.rb

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# -----------------------------------------------------------------------------
21
#
32
# Mysql2Spatial adapter for ActiveRecord
43
#
5-
# -----------------------------------------------------------------------------
64
# Copyright 2010 Daniel Azuma
75
#
86
# All rights reserved.
@@ -30,25 +28,17 @@
3028
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3129
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3230
# POSSIBILITY OF SUCH DAMAGE.
33-
# -----------------------------------------------------------------------------
34-
;
3531

3632

3733
# :stopdoc:
3834

3935
module ActiveRecord
40-
4136
module ConnectionAdapters
42-
4337
module Mysql2SpatialAdapter
44-
45-
4638
class MainAdapter < ConnectionAdapters::Mysql2Adapter
4739

48-
4940
NATIVE_DATABASE_TYPES = Mysql2Adapter::NATIVE_DATABASE_TYPES.merge(spatial: { name: 'geometry' })
5041

51-
5242
def initialize(*args_)
5343
super
5444
# Rails 3.2 way of defining the visitor: do so in the constructor
@@ -57,36 +47,30 @@ def initialize(*args_)
5747
end
5848
end
5949

60-
6150
def set_rgeo_factory_settings(factory_settings_)
6251
@rgeo_factory_settings = factory_settings_
6352
end
6453

65-
6654
def adapter_name
6755
Mysql2SpatialAdapter::ADAPTER_NAME
6856
end
6957

70-
7158
def spatial_column_constructor(name_)
7259
::RGeo::ActiveRecord::DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS[name_]
7360
end
7461

75-
7662
def native_database_types
7763
NATIVE_DATABASE_TYPES
7864
end
7965

80-
8166
def quote(value_, column_=nil)
8267
if ::RGeo::Feature::Geometry.check_type(value_)
83-
"GeomFromWKB(0x#{::RGeo::WKRep::WKBGenerator.new(:hex_format => true).generate(value_)},#{value_.srid})"
68+
"GeomFromWKB(0x#{::RGeo::WKRep::WKBGenerator.new(hex_format: true).generate(value_)},#{value_.srid})"
8469
else
8570
super
8671
end
8772
end
8873

89-
9074
def type_to_sql(type_, limit_=nil, precision_=nil, scale_=nil)
9175
if (info_ = spatial_column_constructor(type_.to_sym))
9276
type_ = limit_[:type] || type_ if limit_.is_a?(::Hash)
@@ -96,10 +80,9 @@ def type_to_sql(type_, limit_=nil, precision_=nil, scale_=nil)
9680
super(type_, limit_, precision_, scale_)
9781
end
9882

99-
10083
def add_index(table_name_, column_name_, options_={})
10184
if options_[:spatial]
102-
index_name_ = index_name(table_name_, :column => Array(column_name_))
85+
index_name_ = index_name(table_name_, column: Array(column_name_))
10386
if ::Hash === options_
10487
index_name_ = options_[:name] || index_name_
10588
end
@@ -109,11 +92,10 @@ def add_index(table_name_, column_name_, options_={})
10992
end
11093
end
11194

112-
11395
def columns(table_name_, name_=nil)
11496
result_ = execute("SHOW FIELDS FROM #{quote_table_name(table_name_)}", :skip_logging)
11597
columns_ = []
116-
result_.each(:symbolize_keys => true, :as => :hash) do |field_|
98+
result_.each(symbolize_keys: true, as: :hash) do |field_|
11799
columns_ << SpatialColumn.new(@rgeo_factory_settings, table_name_.to_s,
118100
field_[:Field], field_[:Default], field_[:Type], field_[:Null] == "YES")
119101
end
@@ -125,7 +107,7 @@ def indexes(table_name_, name_=nil)
125107
indexes_ = []
126108
current_index_ = nil
127109
result_ = execute("SHOW KEYS FROM #{quote_table_name(table_name_)}", name_)
128-
result_.each(:symbolize_keys => true, :as => :hash) do |row_|
110+
result_.each(symbolize_keys: true, as: :hash) do |row_|
129111
if current_index_ != row_[:Key_name]
130112
next if row_[:Key_name] == 'PRIMARY' # skip the primary key
131113
current_index_ = row_[:Key_name]
@@ -146,15 +128,9 @@ def indexes(table_name_, name_=nil)
146128
end
147129
indexes_
148130
end
149-
150-
151131
end
152-
153-
154132
end
155-
156133
end
157-
158134
end
159135

160136
# :startdoc:

0 commit comments

Comments
 (0)