From b22d8c02d289de129cea5393ce8ec980805af663 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 9 Nov 2018 16:10:15 -0500 Subject: [PATCH 1/2] Upgraded RuboCop to 0.60.0. --- .rubocop_todo.yml | 54 ++++++++++++++++---- CHANGELOG.md | 2 +- Gemfile | 18 +++---- Rakefile | 2 +- bench/bench | 2 +- lib/mongoid/geospatial.rb | 2 +- lib/mongoid/geospatial/fields/point.rb | 7 +++ lib/mongoid/geospatial/wrappers/georuby.rb | 1 + mongoid-geospatial.gemspec | 3 +- spec/mongoid/geospatial/geospatial_spec.rb | 2 +- spec/mongoid/geospatial/helpers/core_spec.rb | 3 ++ spec/support/authentication.rb | 1 - 12 files changed, 69 insertions(+), 28 deletions(-) mode change 100644 => 100755 Rakefile diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2b614b5..5d35699 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,40 +1,65 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-09-25 10:29:59 -0400 using RuboCop version 0.45.0. +# on 2018-11-09 16:09:41 -0500 using RuboCop version 0.60.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 4 +# Configuration parameters: Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/DuplicatedGem: + Exclude: + - 'Gemfile' + +# Offense count: 2 +Lint/DuplicateMethods: + Exclude: + - 'lib/mongoid/geospatial/fields/circle.rb' + # Offense count: 3 Metrics/AbcSize: Max: 22 +# Offense count: 21 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 216 + # Offense count: 1 Metrics/CyclomaticComplexity: Max: 7 -# Offense count: 15 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives. -# URISchemes: http, https -Metrics/LineLength: - Max: 113 - # Offense count: 1 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 11 # Offense count: 1 -Style/AccessorMethodName: +Naming/AccessorMethodName: Exclude: - 'spec/models/address.rb' +# Offense count: 9 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db +Naming/UncommunicativeMethodParamName: + Exclude: + - 'lib/mongoid/geospatial/fields/point.rb' + - 'lib/mongoid/geospatial/geometry_field.rb' + # Offense count: 3 Style/ClassVars: Exclude: - 'lib/mongoid/geospatial.rb' +# Offense count: 4 +Style/CommentedKeyword: + Exclude: + - 'lib/mongoid/geospatial/fields/point.rb' + # Offense count: 6 Style/Documentation: Exclude: @@ -45,7 +70,8 @@ Style/Documentation: - 'lib/mongoid/geospatial/config/point.rb' # Offense count: 2 -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. # SupportedStyles: module_function, extend_self Style/ModuleFunction: Exclude: @@ -54,8 +80,14 @@ Style/ModuleFunction: # Offense count: 4 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Exclude: - 'Guardfile' + +# Offense count: 15 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 113 diff --git a/CHANGELOG.md b/CHANGELOG.md index 692518a..979c9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ * [#61](https://github.com/mongoid/mongoid-geospatial/pull/64): Add global configuration for switching between LngLat and LatLng - [@dblock](https://github.com/dblock). * [#59](https://github.com/mongoid/mongoid-geospatial/pull/59), [#65](https://github.com/mongoid/mongoid-geospatial/pull/65): Test against Mongoid 5, 6 and 7 - [@dblock](https://github.com/dblock). -* [#52](https://github.com/mongoid/mongoid-geospatial/pull/52): Added Danger and Rubocop, PR and code linters - [@dblock](https://github.com/dblock). +* [#52](https://github.com/mongoid/mongoid-geospatial/pull/52), [#70](https://github.com/mongoid/mongoid-geospatial/pull/70): Added Danger and Rubocop, PR and code linters - [@dblock](https://github.com/dblock). * Your contribution here. ## 5.0.0 (2015/07/23) diff --git a/Gemfile b/Gemfile index a79b88f..7115699 100644 --- a/Gemfile +++ b/Gemfile @@ -16,22 +16,22 @@ end gemspec group :development, :test do - gem 'rake' - gem 'pry' - gem 'yard' gem 'fuubar' gem 'guard' - gem 'guard-rubocop' gem 'guard-rspec' + gem 'guard-rubocop' + gem 'pry' + gem 'rake' + gem 'yard' end group :test do - gem 'nokogiri' + gem 'coveralls', require: false if ENV['CI'] gem 'dbf' - gem 'rgeo' gem 'georuby' - gem 'rspec' - gem 'coveralls', require: false if ENV['CI'] gem 'mongoid-danger', '~> 0.1.0', require: false - gem 'rubocop', '0.45.0' + gem 'nokogiri' + gem 'rgeo' + gem 'rspec' + gem 'rubocop', '0.60.0' end diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 1f788dc..29fb683 --- a/Rakefile +++ b/Rakefile @@ -15,6 +15,6 @@ end require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) -task default: [:rubocop, :spec] +task default: %i[rubocop spec] require 'yard' diff --git a/bench/bench b/bench/bench index 534ba33..dcf7f39 100755 --- a/bench/bench +++ b/bench/bench @@ -2,7 +2,7 @@ # # Just for fun # -$LOAD_PATH << File.expand_path('../../lib', __FILE__) +$LOAD_PATH << File.expand_path('../lib', __dir__) require 'mongoid/geospatial' diff --git a/lib/mongoid/geospatial.rb b/lib/mongoid/geospatial.rb index 57e4eba..ac488c1 100644 --- a/lib/mongoid/geospatial.rb +++ b/lib/mongoid/geospatial.rb @@ -38,7 +38,7 @@ module Geospatial # Earth radius in multiple units EARTH_RADIUS = { - m: EARTH_RADIUS_KM * 1000, + m: EARTH_RADIUS_KM * 1000, km: EARTH_RADIUS_KM, mi: EARTH_RADIUS_KM * 0.621371192, ft: EARTH_RADIUS_KM * 5280 * 0.621371192, diff --git a/lib/mongoid/geospatial/fields/point.rb b/lib/mongoid/geospatial/fields/point.rb index 5d3c2ec..19aecaa 100644 --- a/lib/mongoid/geospatial/fields/point.rb +++ b/lib/mongoid/geospatial/fields/point.rb @@ -18,6 +18,7 @@ def initialize(x, y, z = nil) # @return (Array) def mongoize return nil unless x && y + [x, y] end alias to_a mongoize @@ -144,6 +145,7 @@ def mongoize(obj) when NilClass then nil else return obj.to_xy if obj.respond_to?(:to_xy) + raise 'Invalid Point' end end @@ -171,6 +173,7 @@ def evolve(obj) # def from_string(str) return nil if str.empty? + str.split(/,|\s/).reject(&:empty?).map(&:to_f) end @@ -185,6 +188,7 @@ def from_string(str) # def from_array(array) return nil if array.empty? + array.flatten[0..1].map(&:to_f) end @@ -204,18 +208,21 @@ def from_array(array) # def from_hash(hsh) raise 'Hash must have at least 2 items' if hsh.size < 2 + [from_hash_x(hsh), from_hash_y(hsh)] end def from_hash_y(hsh) v = (Mongoid::Geospatial::Config::Point.y & hsh.keys).first return hsh[v].to_f if !v.nil? && hsh[v] + raise "Hash must contain #{Mongoid::Geospatial::Config::Point.y.inspect}" end def from_hash_x(hsh) v = (Mongoid::Geospatial::Config::Point.x & hsh.keys).first return hsh[v].to_f if !v.nil? && hsh[v] + raise "Hash must contain #{Mongoid::Geospatial::Config::Point.x.inspect}" end end # << self diff --git a/lib/mongoid/geospatial/wrappers/georuby.rb b/lib/mongoid/geospatial/wrappers/georuby.rb index 84e227b..fa28884 100644 --- a/lib/mongoid/geospatial/wrappers/georuby.rb +++ b/lib/mongoid/geospatial/wrappers/georuby.rb @@ -16,6 +16,7 @@ module Geospatial # @return (GeoRuby::SimpleFeatures::Point) def to_geo return unless valid? + GeoRuby::SimpleFeatures::Point.xy(x, y) end diff --git a/mongoid-geospatial.gemspec b/mongoid-geospatial.gemspec index fa13d18..81867da 100644 --- a/mongoid-geospatial.gemspec +++ b/mongoid-geospatial.gemspec @@ -1,5 +1,4 @@ -# -*- encoding: utf-8 -*- -require File.expand_path('../lib/mongoid/geospatial/version', __FILE__) +require File.expand_path('lib/mongoid/geospatial/version', __dir__) Gem::Specification.new do |gem| gem.authors = ['Ryan Ong', 'Marcos Piccinini'] diff --git a/spec/mongoid/geospatial/geospatial_spec.rb b/spec/mongoid/geospatial/geospatial_spec.rb index 91aec79..0aec5b5 100644 --- a/spec/mongoid/geospatial/geospatial_spec.rb +++ b/spec/mongoid/geospatial/geospatial_spec.rb @@ -72,7 +72,7 @@ before do Alarm.create_indexes 50.times do - Alarm.create(spot: [rand(10) + 1, rand(10) + 1]) + Alarm.create(spot: [rand(1..10), rand(1..10)]) end end diff --git a/spec/mongoid/geospatial/helpers/core_spec.rb b/spec/mongoid/geospatial/helpers/core_spec.rb index 5d174f9..7ff1030 100644 --- a/spec/mongoid/geospatial/helpers/core_spec.rb +++ b/spec/mongoid/geospatial/helpers/core_spec.rb @@ -6,12 +6,14 @@ def self.from_array(ary) def self.from_hash(hsh) raise 'Hash must have at least 2 items' if hsh.size < 2 + [from_hash_x(hsh), from_hash_y(hsh)] end def self.from_hash_y(hsh) v = (Mongoid::Geospatial.lat_symbols & hsh.keys).first return hsh[v].to_f if !v.nil? && hsh[v] + if Mongoid::Geospatial.lng_symbols.index(hsh.keys[1]) raise "Hash cannot contain #{Mongoid::Geospatial.lng_symbols.inspect} "\ "as second arg without #{Mongoid::Geospatial.lat_symbols.inspect}" @@ -22,6 +24,7 @@ def self.from_hash_y(hsh) def self.from_hash_x(hsh) v = (Mongoid::Geospatial.lng_symbols & hsh.keys).first return hsh[v].to_f if !v.nil? && hsh[v] + if Mongoid::Geospatial.lat_symbols.index(keys[0]) raise "Hash cannot contain #{Mongoid::Geospatial.lat_symbols.inspect} "\ "as first arg without #{Mongoid::Geospatial.lng_symbols.inspect}" diff --git a/spec/support/authentication.rb b/spec/support/authentication.rb index 317f17b..b9fb7bc 100644 --- a/spec/support/authentication.rb +++ b/spec/support/authentication.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 module Support #:nodoc: # module Authentication # extend self From b57a2f5e0e9ca68c39845e8250da5a1c12dad629 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 9 Nov 2018 16:12:28 -0500 Subject: [PATCH 2/2] Use Ruby 2.5.3 in CI. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be1b9f1..00826f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ cache: bundler services: mongodb rvm: - - 2.3.1 + - 2.5.3 before_install: - gem update bundler