sequel_mappable 0.0.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +19 -0
- data/README.rdoc +76 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/lib/sequel_mappable.rb +66 -0
- data/sequel_mappable.gemspec +58 -0
- data/spec/sequel_mappable_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +105 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010-2010 Corin Langosch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
=About
|
2
|
+
|
3
|
+
Mappable provides geo distance-based filters and distance calculation functionality for
|
4
|
+
model. It requires the geokit gem and was heavily inspired by the
|
5
|
+
{geokit-rails gem}[http://github.com/andre/geokit-rails].
|
6
|
+
|
7
|
+
==Install
|
8
|
+
|
9
|
+
Simply install it as any other gem:
|
10
|
+
|
11
|
+
gem install sequel_mappable
|
12
|
+
|
13
|
+
Or when using bundler, add it got your Gemfile:
|
14
|
+
|
15
|
+
gem sequel_mappable
|
16
|
+
|
17
|
+
This should also install the geokit gem.
|
18
|
+
|
19
|
+
==Quick Start
|
20
|
+
|
21
|
+
In your model:
|
22
|
+
|
23
|
+
class User < Sequel::Model
|
24
|
+
plugin :mappable
|
25
|
+
end
|
26
|
+
|
27
|
+
In your migrations:
|
28
|
+
|
29
|
+
class AddGeoDataToUser < Sequel::Migration
|
30
|
+
def up
|
31
|
+
alter_table :users do
|
32
|
+
add_column :lng, Float
|
33
|
+
add_column :lat, Float
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def down
|
38
|
+
alter_table :users do
|
39
|
+
drop_column :lng
|
40
|
+
drop_column :lat
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Now add some records with valid geo data.
|
46
|
+
|
47
|
+
In your controller you can then do:
|
48
|
+
|
49
|
+
def index
|
50
|
+
users_near_to_me = User.f_origin(User[1], 10)
|
51
|
+
end
|
52
|
+
|
53
|
+
==Filters
|
54
|
+
|
55
|
+
Please have a look at the source to get a full list of all available functionality.
|
56
|
+
|
57
|
+
==Todo
|
58
|
+
|
59
|
+
* Source documentation (rdoc)
|
60
|
+
* Source cleanup (no hardcoding of column names)
|
61
|
+
* Better support for :km, :miles, :sphere, :flat, etc.
|
62
|
+
* Tests
|
63
|
+
|
64
|
+
==Contributing
|
65
|
+
|
66
|
+
If you'd like to contribute a feature or bugfix: Thanks! To make sure your
|
67
|
+
fix/feature has a high chance of being included, please read the following
|
68
|
+
guidelines:
|
69
|
+
|
70
|
+
1. Fork the project.
|
71
|
+
2. Make your feature addition or bug fix.
|
72
|
+
3. Add tests for it. This is important so we don’t break anything in a future version unintentionally.
|
73
|
+
4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
74
|
+
5. Send me a pull request. Bonus points for topic branches.
|
75
|
+
|
76
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = 'sequel_mappable'
|
8
|
+
gem.authors = ['Corin Langosch']
|
9
|
+
gem.date = Date.today.to_s
|
10
|
+
gem.email = 'info@netskin.com'
|
11
|
+
gem.homepage = 'http://github.com/gucki/sequel_mappable'
|
12
|
+
gem.summary = 'Usefull geo data filters for Sequel'
|
13
|
+
gem.description = 'Sequel plugin which provides geo distance-based filters and distance calculation functionality for model.'
|
14
|
+
gem.add_dependency "geokit", ">= 1.5.0"
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "sequel_mappable #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Sequel
|
2
|
+
module Plugins
|
3
|
+
module Mappable
|
4
|
+
|
5
|
+
def self.apply(model, opts={}, &block)
|
6
|
+
model.send(:include, Geokit::Geocoders)
|
7
|
+
model.send(:include, Geokit::Mappable)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure(model, opts={}, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def acts_as_mappable
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def distance_column_name
|
19
|
+
:distance
|
20
|
+
end
|
21
|
+
|
22
|
+
def lat_column_name
|
23
|
+
:lat
|
24
|
+
end
|
25
|
+
|
26
|
+
def lng_column_name
|
27
|
+
:lng
|
28
|
+
end
|
29
|
+
|
30
|
+
def distance_sql(origin)
|
31
|
+
lat = deg2rad(origin.lat)
|
32
|
+
lng = deg2rad(origin.lng)
|
33
|
+
multiplier = units_sphere_multiplier(:kms)
|
34
|
+
%|
|
35
|
+
(ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(lat))*COS(RADIANS(lng))+
|
36
|
+
COS(#{lat})*SIN(#{lng})*COS(RADIANS(lat))*SIN(RADIANS(lng))+
|
37
|
+
SIN(#{lat})*SIN(RADIANS(lat))))*#{multiplier})
|
38
|
+
|
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module InstanceMethods
|
43
|
+
end
|
44
|
+
|
45
|
+
module DatasetMethods
|
46
|
+
def f_origin_bbox(origin, within)
|
47
|
+
bounds = Geokit::Bounds.from_point_and_radius(origin, within, :units => :kms)
|
48
|
+
sw, ne = bounds.sw, bounds.ne
|
49
|
+
filter = self
|
50
|
+
if bounds.crosses_meridian?
|
51
|
+
filter = filter.filter{(lng < ne.lng) | (lng > sw.lng)}
|
52
|
+
else
|
53
|
+
filter = filter.filter{(lng < ne.lng) & (lng > sw.lng)}
|
54
|
+
end
|
55
|
+
filter.filter{(lat < ne.lat) & (lat > sw.lat)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def f_origin(origin, within)
|
59
|
+
sql = model.distance_sql(origin)
|
60
|
+
f_origin_bbox(origin, within).filter{sql.lit <= within}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sequel_mappable}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Corin Langosch"]
|
12
|
+
s.date = %q{2010-08-31}
|
13
|
+
s.description = %q{Sequel plugin which provides geo distance-based filters and distance calculation functionality for model.}
|
14
|
+
s.email = %q{info@netskin.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/sequel_mappable.rb",
|
27
|
+
"sequel_mappable.gemspec",
|
28
|
+
"spec/sequel_mappable_spec.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/gucki/sequel_mappable}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{Usefull geo data filters for Sequel}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"spec/sequel_mappable_spec.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<geokit>, [">= 1.5.0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<geokit>, [">= 1.5.0"])
|
51
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<geokit>, [">= 1.5.0"])
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sequel_mappable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Corin Langosch
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-31 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: geokit
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 5
|
31
|
+
- 0
|
32
|
+
version: 1.5.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 2
|
46
|
+
- 9
|
47
|
+
version: 1.2.9
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Sequel plugin which provides geo distance-based filters and distance calculation functionality for model.
|
51
|
+
email: info@netskin.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- .document
|
61
|
+
- .gitignore
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- VERSION
|
66
|
+
- lib/sequel_mappable.rb
|
67
|
+
- sequel_mappable.gemspec
|
68
|
+
- spec/sequel_mappable_spec.rb
|
69
|
+
- spec/spec.opts
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/gucki/sequel_mappable
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --charset=UTF-8
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Usefull geo data filters for Sequel
|
103
|
+
test_files:
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/sequel_mappable_spec.rb
|