Skip to content

Commit

Permalink
update rubocop and clean unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
TyGuy committed May 17, 2017
1 parent e1e38e1 commit 726eb05
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 108 deletions.
5 changes: 3 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Style/SpaceInsideHashLiteralBraces:
Style/FileName:
Enabled: false

Metrics/AbcSize:
Max: 20

#---------------------------
# Don't intend to fix these:
#---------------------------
Expand Down Expand Up @@ -68,5 +71,3 @@ Style/Lambda:
# Reason: I'm proud to be part of the double negative Ruby tradition
Style/DoubleNegation:
Enabled: false


12 changes: 2 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ install:
- "bundle exec rake neo4j_spatial:install"
- "bundle exec rake neo4j:start --trace"
- "sleep 20"
- "bundle exec rake neo4j:generate_schema_migration[constraint,Restaurant,uuid]"
sudo: false
cache: bundler
script:
- "travis_retry bundle exec rake default --trace"
language: ruby
jdk: oraclejdk8
rvm:
- 2.0.0
- 2.2.4
- 2.3.1
- jruby-9.0.5.0
env:
global:
- JRUBY_OPTS="-J-Xmx1280m -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -Xcompile.mode=OFF"
- NEO4J_VERSION=3.0.1
- NEO4J_VERSION=3.1.0
matrix:
- NEO4J_URL="http://localhost:7474"
matrix:
Expand All @@ -32,11 +32,3 @@ matrix:
install:
script: "bundle exec rubocop"
env: "RUBOCOP=true"

# Older versions of Neo4j with latest version of Ruby
- rvm: 2.3.1
env: NEO4J_VERSION=2.3.3
- rvm: 2.3.1
env: NEO4J_VERSION=2.2.2
- rvm: 2.3.1
env: NEO4J_VERSION=2.1.8
27 changes: 0 additions & 27 deletions lib/neo4j/active_node/spatial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,11 @@ def remove_layer

Neo4j::ActiveBase.current_session.remove_layer(spatial_layer_name)
end

# private
end
end

# TODO: here!!!!
# Fix the thing to parse the params_string (on the right) and make it
# work for one of the procedures (withinDistance, bbox, etc.)
module Query
class QueryProxy
# def spatial_match_retro(var, params_string, spatial_layer = nil)
# Neo4j::Session.current.query
# .start("#{var} = node:#{layer}({spatial_params})")
# .proxy_as(model, var)
# .params(spatial_params: params_string)
#
# end

# NOTE: should these be scopes?
def spatial_match(var, params, spatial_layer = nil)
layer = model.spatial_layer_name || spatial_layer
fail 'Cannot query without layer. Set layer in model or as third argument.' unless layer

if params.is_a?(String)
# TODO: deprecation warning
params = parse_retro_params(params)
end
end

def parse_retro_params(params)
end

def within_distance(coordinate, distance, layer_name = nil)
layer = model.spatial_layer_name || layer_name

Expand Down
46 changes: 14 additions & 32 deletions lib/neo4j/spatial.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Neo4j
module Core
# rubocop:disable Metrics/ModuleLength
module Spatial
# rubocop:enable Metrics/ModuleLength
def spatial?
spatial_procedures
true
Expand All @@ -27,12 +29,12 @@ def add_layer(name, type = nil, lat = nil, lon = nil)
end

def remove_layer(name)
options = { name: name }
options = {name: name}
wrap_spatial_procedure('removeLayer', options, node: false)
end

def add_point_layer(layer)
options = { layer: layer }
options = {layer: layer}

wrap_spatial_procedure('addPointLayer', options)
end
Expand Down Expand Up @@ -78,21 +80,21 @@ def add_node_to_layer(layer, node, execute: true)

query_ = Query.new(session: self)
procedure = query_.match(:n)
.where('id(n) = {node_id}')
.with(:n).call('spatial.addNode({layer}, n) YIELD node')
.return('node')
.params(options)
.where('id(n) = {node_id}')
.with(:n).call('spatial.addNode({layer}, n) YIELD node')
.return('node')
.params(options)

procedure = execute_and_format_response(procedure) if execute
procedure
end

def bbox(layer, min, max, execute: true)
options = { layer: layer, min: min, max: max }
options = {layer: layer, min: min, max: max}

wrap_spatial_procedure('bbox', options, execute: execute)
end
alias find_geometries_in_bbox bbox
alias_method :find_geometries_in_bbox, :bbox

def within_distance(layer, coordinate, distance, execute: true)
options = {
Expand All @@ -103,10 +105,10 @@ def within_distance(layer, coordinate, distance, execute: true)

wrap_spatial_procedure('withinDistance', options, execute: execute)
end
alias find_geometries_within_distance within_distance
alias_method :find_geometries_within_distance, :within_distance

def intersects(layer, geometry, execute: true)
options = { layer: layer, geometry: geometry }
options = {layer: layer, geometry: geometry}

wrap_spatial_procedure('intersects', options, execute: execute)
end
Expand Down Expand Up @@ -166,29 +168,9 @@ def execute_and_format_response(procedure)
end
end

# def warn_deprecated(name:, preferred:)
# puts "WARNING: method '#{name}' is deprecated. Please use #{preferred}, which does the same thing."
# end

def request_error!(code, message, stack_trace)
fail Neo4jrbSpatial::RequestError, <<-ERROR
#{ANSI::CYAN}#{code}#{ANSI::CLEAR}: #{message}
#{stack_trace}
ERROR
end

def get_id(id)
return id.neo_id if id.respond_to?(:neo_id)
case id
when Array
get_id(id.first)
when Hash
id[:id]
when String
id.split('/').last
else
id
end
return get_id(id.first) if id.is_a?(Array)
id.neo_id
end
end

Expand Down
58 changes: 29 additions & 29 deletions lib/neo4jrb_spatial/rake_tasks/neo4j_spatial.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@ def system_or_fail(command)
system(command) || exit(1)
end

namespace :neo4j_spatial do
def match_version?(version, max_version)
min_version = max_version.split('.')[0..-2].join('.')
Gem::Version.new(version) <= Gem::Version.new(max_version) &&
Gem::Version.new(version) >= Gem::Version.new(min_version)
end
def match_version?(version, max_version)
min_version = max_version.split('.')[0..-2].join('.')
Gem::Version.new(version) <= Gem::Version.new(max_version) &&
Gem::Version.new(version) >= Gem::Version.new(min_version)
end

def fail_with_help(version, latest_versions)
message = <<-MSG
def fail_with_help(version, latest_versions)
message = <<-MSG
No compatible version of neo4j_spatial was found for neo4j version #{version}.
The latest version is (neo4j_spatial=#{latest_versions[0]}, neo4j=#{latest_versions[1]}).
No compatible version of neo4j_spatial was found for neo4j version #{version}.
The latest version is (neo4j_spatial=#{latest_versions[0]}, neo4j=#{latest_versions[1]}).
To install neo4j_spatial for a different version, run:
NEO4J_VERSION='#{latest_versions[1]}' bundle exec rake neo4j_spatial:install
To install neo4j_spatial for a different version, run:
NEO4J_VERSION='#{latest_versions[1]}' bundle exec rake neo4j_spatial:install
MSG
MSG

fail ArgumentError, message
end
fail ArgumentError, message
end

def matching_version(version)
uri = 'https://raw.githubusercontent.com/neo4j-contrib/m2/master/releases/org/neo4j/neo4j-spatial/maven-metadata.xml'
versions = Net::HTTP.get_response(URI.parse(uri)).body
versions = versions.scan(/<version>([a-z\-0-9\.]+)<\/version>/)
versions.map! { |e| e.first.split('-neo4j-') }
versions.select { |e| match_version?(version, e.last) }.last
def matching_version(version)
uri = 'https://raw.githubusercontent.com/neo4j-contrib/m2/master/releases/org/neo4j/neo4j-spatial/maven-metadata.xml'
versions = Net::HTTP.get_response(URI.parse(uri)).body
versions = versions.scan(/<version>([a-z\-0-9\.]+)<\/version>/)
versions.map! { |e| e.first.split('-neo4j-') }
versions.select { |e| match_version?(version, e.last) }.last

compatible_versions = versions.select { |e| match_version?(version, e.last) }.last
fail_with_help(version, versions.last) if compatible_versions.nil?
compatible_versions = versions.select { |e| match_version?(version, e.last) }.last
fail_with_help(version, versions.last) if compatible_versions.nil?

compatible_versions
end
compatible_versions
end

def neo4j_version_from_install(env)
server_file = Dir.glob("db/neo4j/#{env}/lib/neo4j-server-*.jar").first
server_file.match(/.*-server-(.*).jar$/)[1] if server_file
end
def neo4j_version_from_install(env)
server_file = Dir.glob("db/neo4j/#{env}/lib/neo4j-server-*.jar").first
server_file.match(/.*-server-(.*).jar$/)[1] if server_file
end

namespace :neo4j_spatial do
desc 'Install neo4j_spatial into /db/neo4j/[env]/plugins'
task :install, :environment do |_, args|
args.with_defaults(environment: 'development')
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4jrb_spatial/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Neo4jrbSpatial
VERSION = '1.2.0'
VERSION = '1.2.0'.freeze
end
2 changes: 1 addition & 1 deletion neo4jrb_spatial.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'pry'

spec.add_dependency 'neo4j', '>= 8.0.6'
spec.add_dependency 'neo4j', '>= 8.0.6', '<= 8.0.15'

This comment has been minimized.

Copy link
@pmackay

pmackay Jul 24, 2017

@TyGuy what is the reason for this dependency to be restricted to '<= 8.0.15' ? It makes it impossible to use on Rails 5.1.

This comment has been minimized.

Copy link
@cheerfulstoic

cheerfulstoic Aug 3, 2017

Contributor

I'm not sure of the reason, but I've never found maximum dependency specifications to be useful in a gem unless you're deprecating it. If you make a fork and test it then I'd be happy to merge a PR and release a patch

spec.add_dependency 'neo4j-core', '>= 7', '< 7.1.0'
spec.add_dependency 'neo4j-rake_tasks', '~> 0.3'
end
12 changes: 6 additions & 6 deletions spec/neo4jrb_spatial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
end

describe 'spatial matching queries' do
let(:properties) { { name: "Max's Restaurant", lat: 41.8819, lon: 87.6278 } }
let(:properties) { {name: "Max's Restaurant", lat: 41.8819, lon: 87.6278} }
let(:node_query) { Neo4j::Core::Query.new(session: neo).create(n: {Restaurant: properties}).return(:n) }

before do
Expand All @@ -157,8 +157,8 @@

describe '#bbox (#find_geometries_in_bbox)' do
it 'can find a geometry in a bounding box' do
min = { lon: 87.5, lat: 41.7 }
max = { lon: 87.7, lat: 41.9 }
min = {lon: 87.5, lat: 41.7}
max = {lon: 87.7, lat: 41.9}

nodes = neo.find_geometries_in_bbox('restaurants', min, max)
expect(nodes).not_to be_empty
Expand All @@ -171,7 +171,7 @@

describe '#within_distance (#find_geometries_within_distance)' do
it 'can find a geometry within distance' do
nodes = neo.find_geometries_within_distance('restaurants', { lon: 87.627, lat: 41.881 }, 10)
nodes = neo.find_geometries_within_distance('restaurants', {lon: 87.627, lat: 41.881}, 10)
expect(nodes).not_to be_empty

result = nodes.find { |n| n.props[:name] == "Max's Restaurant" }
Expand All @@ -193,11 +193,11 @@
describe '#closest' do
# TODO: poor test
it 'returns the closest node to the given coordinate' do
other_properties = { name: "Min's Restaurant", lat: 41.87, lon: 87.6 }
other_properties = {name: "Min's Restaurant", lat: 41.87, lon: 87.6}
other_node_query = Neo4j::Core::Query.new(session: neo).create(n: {Restaurant: other_properties}).return(:n)
neo.query(other_node_query).first.n

coordinate = { lat: 41.89, lon: 87.63 }
coordinate = {lat: 41.89, lon: 87.63}

closest = neo.closest('restaurants', coordinate).first
expect(closest.props[:name]).to eq(properties[:name])
Expand Down

0 comments on commit 726eb05

Please sign in to comment.