Skip to content

Commit

Permalink
fixes, clean, move to jeweler
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Apr 23, 2009
1 parent b2c9eb2 commit 25f97dd
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 146 deletions.
120 changes: 34 additions & 86 deletions Rakefile
@@ -1,100 +1,48 @@
#$:.unshift(File.join(File.dirname(__FILE__) ,'../../gems/georuby/lib/'))
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'rubygems'
require 'rake'
require 'spec/rake/spectask'
require 'rake/rdoctask'
require 'active_record'
require 'active_record/connection_adapters/postgresql_adapter'
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
require File.dirname(__FILE__) + '/lib/postgis_adapter'

# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)PostgisAdapter::VERSION
$hoe = Hoe.new('postgis_adapter', PostgisAdapter::VERSION) do |p|
p.developer('Marcos Piccinini', 'x@nofxx.com')
p.summary = "Postgis Adapter for Activer Record"
p.description = "Postgis Adapter for Activer Record"
p.url = "http://github.com/nofxx/postgis_adapter"
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
# p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
p.rubyforge_name = "postgis_adapter" # TODO this is default value
p.extra_deps = [
['activerecord','>= 2.0.2'],
]
p.extra_dev_deps = [
['newgem', ">= #{::Newgem::VERSION}"]
]

p.clean_globs |= %w[**/.DS_Store tmp *.log]
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
p.rsync_args = '-av --delete --ignore-errors'
end

require 'newgem/tasks' # load /tasks/*.rake
Dir['tasks/**/*.rake'].each { |t| load t }

# TODO - want other tests/tasks run by default? Add them to the list
# task :default => [:spec, :features]
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "postgis_adapter"
gem.summary = %Q{TODO}
gem.email = "x@nofxx.com"
gem.homepage = "http://github.com/nofxx/postgis_adapter"
gem.authors = ["Marcos Augusto"]

desc 'Default: run specs.'
task :default => :spec

desc "Run all specs"
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/*_spec.rb']
t.spec_opts = ['--options', 'spec/spec.opts']
unless ENV['NO_RCOV']
t.rcov = true
t.rcov_dir = 'coverage'
t.rcov_opts = ['--html', '--exclude', "\.autotest,schema.rb,init.rb,\.gitignore,spec\/spec_helper.rb,spec\/db/*,#{ENV['GEM_HOME']}"]
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

desc "Look for TODO and FIXME tags in the code"
task :todo do
egrep /(FIXME|TODO|TBD)/
end

namespace :db do
task :migrate do
load('spec/db/schema_postgis.rb')
end
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end

desc "Generate the documentation"
Rake::RDocTask::new do |rdoc|
rdoc.rdoc_dir = 'doc/'
rdoc.title = "PostGIS Adapter for Rails Documentation"
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

# From Rspec Rakefile
#
def egrep(pattern)
Dir['**/*.rb'].each do |fn|
count = 0
open(fn) do |f|
while line = f.gets
count += 1
if line =~ pattern
puts "#{fn}:#{count}:#{line}"
end
end
end
end
end

desc "verify_committed, verify_rcov, post_news, release"
task :complete_release => [:verify_committed, :post_news, :release]
task :default => :spec

desc "Verifies that there is no uncommitted code"
task :verify_committed do
IO.popen('git status') do |io|
io.each_line do |line|
raise "\n!!! Do a git commit first !!!\n\n" if line =~ /^#\s*modified:/
end
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION.yml')
config = YAML.load(File.read('VERSION.yml'))
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
else
version = ""
end

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "postgis_adapter #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

4 changes: 4 additions & 0 deletions VERSION.yml
@@ -0,0 +1,4 @@
---
:major: 0
:minor: 3
:patch: 7
8 changes: 2 additions & 6 deletions lib/postgis_adapter.rb
Expand Up @@ -19,7 +19,7 @@
include SpatialAdapter

module PostgisAdapter
VERSION = '0.3.4'
VERSION = '0.3.5'
end

#tables to ignore in migration : relative to PostGIS management of geometric columns
Expand Down Expand Up @@ -51,11 +51,7 @@ def self.get_conditions(attrs)
"#{table_name}.#{column_name} && ? "
end
else
begin
"#{table_name}.#{attribute_condition(column_name, value)}"
rescue ArgumentError
"#{table_name}.#{column_name} #{attribute_condition(value)}"
end
"#{table_name}.#{attribute_condition(column_name, value)}"
end
end.join(' AND ')
end
Expand Down
7 changes: 0 additions & 7 deletions lib/postgis_functions/common.rb
Expand Up @@ -684,13 +684,6 @@ def line_substring(s,e)
#
module PointFunctions

#
# Some nice getters
#
def x; @x ||= self[get_column_name].x; end
def y; @y ||= self[get_column_name].y; end
def z; @z ||= self[get_column_name].z; end

#
# Returns a float between 0 and 1 representing the location of the closest point
# on LineString to the given Point, as a fraction of total 2d line length.
Expand Down
72 changes: 51 additions & 21 deletions postgis_adapter.gemspec
Expand Up @@ -2,39 +2,69 @@

Gem::Specification.new do |s|
s.name = %q{postgis_adapter}
s.version = "0.3.4"
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
s.date = %q{2009-04-13}
s.description = %q{Postgis Adapter for Activer Record}
s.email = ["x@nofxx.com"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "init.rb", "install.rb", "lib/postgis_adapter.rb", "lib/postgis_adapter/acts_as_geom.rb", "lib/postgis_adapter/common_spatial_adapter.rb", "lib/postgis_functions.rb", "lib/postgis_functions/bbox.rb", "lib/postgis_functions/class.rb", "lib/postgis_functions/common.rb", "postgis_adapter.gemspec", "rails/init.rb", "script/console", "script/destroy", "script/generate", "spec/db/database_postgis.yml", "spec/db/models_postgis.rb", "spec/db/schema_postgis.rb", "spec/postgis_adapter/acts_as_geom_spec.rb", "spec/postgis_adapter/common_spatial_adapter_spec.rb", "spec/postgis_adapter_spec.rb", "spec/postgis_functions/bbox_spec.rb", "spec/postgis_functions/class_spec.rb", "spec/postgis_functions/common_spec.rb", "spec/postgis_functions_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "uninstall.rb"]
s.authors = ["Marcos Augusto"]
s.date = %q{2009-04-23}
s.email = %q{x@nofxx.com}
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
"History.txt",
"Manifest.txt",
"README.rdoc",
"Rakefile",
"lib/postgis_adapter.rb",
"lib/postgis_adapter/acts_as_geom.rb",
"lib/postgis_adapter/common_spatial_adapter.rb",
"lib/postgis_functions.rb",
"lib/postgis_functions/bbox.rb",
"lib/postgis_functions/class.rb",
"lib/postgis_functions/common.rb",
"lib/sfsfsf",
"rails/init.rb",
"spec/db/database_postgis.yml",
"spec/db/models_postgis.rb",
"spec/db/schema_postgis.rb",
"spec/debug.log",
"spec/postgis_adapter/acts_as_geom_spec.rb",
"spec/postgis_adapter/common_spatial_adapter_spec.rb",
"spec/postgis_adapter_spec.rb",
"spec/postgis_functions/bbox_spec.rb",
"spec/postgis_functions/class_spec.rb",
"spec/postgis_functions/common_spec.rb",
"spec/postgis_functions_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb"
]
s.has_rdoc = true
s.homepage = %q{http://github.com/nofxx/postgis_adapter}
s.rdoc_options = ["--main", "README.rdoc"]
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{postgis_adapter}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Postgis Adapter for Activer Record}
s.rubygems_version = %q{1.3.2}
s.summary = %q{TODO}
s.test_files = [
"spec/db/models_postgis.rb",
"spec/db/schema_postgis.rb",
"spec/postgis_adapter/acts_as_geom_spec.rb",
"spec/postgis_adapter/common_spatial_adapter_spec.rb",
"spec/postgis_functions_spec.rb",
"spec/spec_helper.rb",
"spec/postgis_adapter_spec.rb",
"spec/postgis_functions/class_spec.rb",
"spec/postgis_functions/common_spec.rb",
"spec/postgis_functions/bbox_spec.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.2"])
s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
else
s.add_dependency(%q<activerecord>, [">= 2.0.2"])
s.add_dependency(%q<newgem>, [">= 1.3.0"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
else
s.add_dependency(%q<activerecord>, [">= 2.0.2"])
s.add_dependency(%q<newgem>, [">= 1.3.0"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
end
5 changes: 5 additions & 0 deletions spec/postgis_adapter_spec.rb
Expand Up @@ -169,6 +169,11 @@ class Park < ActiveRecord::Base
pts[1].data.should match /Point/
end

it "should not mess with rails finder" do
pts = Park.find_all_by_data "Point1"
pts.should have(1).park
end

end

end
17 changes: 14 additions & 3 deletions spec/postgis_functions/class_spec.rb
Expand Up @@ -2,9 +2,11 @@

describe "Class Functions" do
before(:all) do
@c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
@s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[88,88]],4326))
@p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,4326))
@c1 ||= City.create!(:data => "CityClass", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
@s1 ||= Street.create!(:data => "StreetClass", :geom => LineString.from_coordinates([[1,1],[99,88]],4326))
@s2 ||= Street.create!(:data => "StreetClassTiny", :geom => LineString.from_coordinates([[1,1],[1.1,1.1]],4326))
@p1 ||= Position.create!(:data => "PointClass", :geom => Point.from_x_y(99,99,4326))
@p2 ||= Position.create!(:data => "PointClassClose", :geom => Point.from_x_y(99.9,99.9,4326))
end

it "should find the closest other point" do
Expand All @@ -19,6 +21,15 @@
Position.closest_to(@p1.geom).data.should == @p1.data
end

it "should sort by size" do
Street.by_length.first.data.should == "StreetClassTiny"
Street.by_length.last.data.should == "StreetClass"
end

it "largest" do
Street.longest.data.should == "StreetClass"
end

it "should sort by linestring length" do
Street.by_length.should be_instance_of(Array)
end
Expand Down
15 changes: 3 additions & 12 deletions spec/postgis_functions/common_spec.rb
Expand Up @@ -84,9 +84,9 @@
lambda { @p2.to_utm! }.should change(@p2, :srid)
end

it { @p3.x.should be_close(8.0, 0.1) }
it { @p3.y.should be_close(8.0, 0.1) }
it { @p3.z.should be_close(0.0, 0.1) }
# it { @p3.x.should be_close(8.0, 0.1) }
# it { @p3.y.should be_close(8.0, 0.1) }
# it { @p3.z.should be_close(0.0, 0.1) }

end

Expand Down Expand Up @@ -185,15 +185,6 @@

describe "LineString" do

it "should sort by size" do
Street.by_length.first.data.should == "Street1"
Street.by_length.last.data.should == "Street3"
end

it "largest" do
Street.longest.data.should == "Street3"
end

describe "Length" do
it { @s1.length.should be_close(1.4142135623731, 0.000001) }
it { @s2.length.should be_close(4.2, 0.1) }
Expand Down
17 changes: 6 additions & 11 deletions spec/spec_helper.rb
@@ -1,15 +1,10 @@
begin
require 'spec'
require 'postgres'
require 'rubygems'
require 'spec'
require 'postgres'
require 'activerecord'
rescue LoadError
require 'rubygems'
gem 'rspec'
require 'spec'
require 'postgres'
require 'activerecord'
end
require 'rspec_spinner'
require 'rspec_spinner'

gem 'activerecord', "=2.3.2"

$:.unshift(File.dirname(__FILE__) + '/../lib')
config = YAML.load_file(File.dirname(__FILE__) + '/db/database_postgis.yml')
Expand Down

0 comments on commit 25f97dd

Please sign in to comment.