active_geo_db 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/.gitignore +17 -0
- data/.gitkeep +0 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +3 -0
- data/active_geo_db.gemspec +19 -0
- data/lib/active_geo_db/connection_configuration.rb +23 -0
- data/lib/active_geo_db/connection_provider.rb +7 -0
- data/lib/active_geo_db/railtie.rb +7 -0
- data/lib/active_geo_db/version.rb +3 -0
- data/lib/active_geo_db.rb +25 -0
- metadata +118 -0
data/.gitignore
ADDED
data/.gitkeep
ADDED
|
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Kostiantyn Kahanskyi
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# ActiveGeoDb
|
|
2
|
+
|
|
3
|
+
Rails (ActiveRecord) lib for accessing OpenGeoDb
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem("active_geo_db")
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If you want to manage OpenGeoDb databases from within the Rails project add to your Gemfile also:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem("open_geo_db", :require => false) # See https://github.com/kostia/open_geo_db for detailed informations
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
$ bundle
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
$ gem install active_geo_db
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
First create an OpenGeoDb database (see https://github.com/kostia/open_geo_db)
|
|
34
|
+
|
|
35
|
+
Now you should be able to retrieve coordinates via:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
ActiveGeoDb.coordinates("Berlin") # => [52.5167, 13.4]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
1. Fork it
|
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
45
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path("../lib/active_geo_db/version", __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.add_dependency("activerecord")
|
|
6
|
+
gem.add_dependency("rails")
|
|
7
|
+
gem.add_development_dependency("open_geo_db")
|
|
8
|
+
gem.authors = ["Kostiantyn Kahanskyi"]
|
|
9
|
+
gem.description = %q{Rails (ActiveRecord) lib for accessing OpenGeoDb}
|
|
10
|
+
gem.email = %w(kostiantyn.kahanskyi@googlemail.com)
|
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
|
13
|
+
gem.homepage = "https://github.com/kostia/active_geo_db"
|
|
14
|
+
gem.name = "active_geo_db"
|
|
15
|
+
gem.require_paths = %w(lib)
|
|
16
|
+
gem.summary = %q{Rails (ActiveRecord) lib for accessing OpenGeoDb}
|
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
+
gem.version = ActiveGeoDb::VERSION
|
|
19
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
module ActiveGeoDb
|
|
4
|
+
class ConnectionConfiguration
|
|
5
|
+
# Key in Rails database configuration under which the configuration for OpenGeoDb database
|
|
6
|
+
# can be found
|
|
7
|
+
CONFIGURATION_KEY = "open_geo_db"
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
# Read configuration file and load appropriate section
|
|
11
|
+
def load_file(path)
|
|
12
|
+
@configuration_data = YAML.load_file(path)[CONFIGURATION_KEY]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
alias_method(:new, :load_file) # For convenience reasons only...
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Return previously loaded configuration
|
|
19
|
+
def to_hash
|
|
20
|
+
@configuration_data
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "active_geo_db/version"
|
|
2
|
+
require "active_geo_db/connection_configuration"
|
|
3
|
+
require "active_geo_db/connection_provider"
|
|
4
|
+
require "active_geo_db/railtie" if defined?(Rails)
|
|
5
|
+
|
|
6
|
+
module ActiveGeoDb
|
|
7
|
+
# Initialize ActiveGeoDb:
|
|
8
|
+
# * Load configuration
|
|
9
|
+
# * Establish connection to OpenGeoDb database
|
|
10
|
+
def self.initialize(application)
|
|
11
|
+
connection_configuration_path = application.paths["config/database"].first
|
|
12
|
+
connection_configuration = ConnectionConfiguration.load_file(connection_configuration_path)
|
|
13
|
+
ConnectionProvider.establish_connection(connection_configuration.to_hash)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Find coordinates for a specific location
|
|
17
|
+
def self.coordinates(location)
|
|
18
|
+
results = ConnectionProvider.connection.execute(%{
|
|
19
|
+
SELECT lat, lon
|
|
20
|
+
FROM geodb_coordinates, geodb_textdata
|
|
21
|
+
WHERE geodb_textdata.text_val = "#{location}"
|
|
22
|
+
AND geodb_textdata.loc_id = geodb_coordinates.loc_id
|
|
23
|
+
}).first
|
|
24
|
+
end
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: active_geo_db
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Kostiantyn Kahanskyi
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2012-01-12 00:00:00 Z
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: activerecord
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
hash: 3
|
|
29
|
+
segments:
|
|
30
|
+
- 0
|
|
31
|
+
version: "0"
|
|
32
|
+
type: :runtime
|
|
33
|
+
version_requirements: *id001
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: rails
|
|
36
|
+
prerelease: false
|
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
38
|
+
none: false
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
hash: 3
|
|
43
|
+
segments:
|
|
44
|
+
- 0
|
|
45
|
+
version: "0"
|
|
46
|
+
type: :runtime
|
|
47
|
+
version_requirements: *id002
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: open_geo_db
|
|
50
|
+
prerelease: false
|
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
52
|
+
none: false
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
hash: 3
|
|
57
|
+
segments:
|
|
58
|
+
- 0
|
|
59
|
+
version: "0"
|
|
60
|
+
type: :development
|
|
61
|
+
version_requirements: *id003
|
|
62
|
+
description: Rails (ActiveRecord) lib for accessing OpenGeoDb
|
|
63
|
+
email:
|
|
64
|
+
- kostiantyn.kahanskyi@googlemail.com
|
|
65
|
+
executables: []
|
|
66
|
+
|
|
67
|
+
extensions: []
|
|
68
|
+
|
|
69
|
+
extra_rdoc_files: []
|
|
70
|
+
|
|
71
|
+
files:
|
|
72
|
+
- .gitignore
|
|
73
|
+
- .gitkeep
|
|
74
|
+
- Gemfile
|
|
75
|
+
- LICENSE
|
|
76
|
+
- README.md
|
|
77
|
+
- Rakefile
|
|
78
|
+
- active_geo_db.gemspec
|
|
79
|
+
- lib/active_geo_db.rb
|
|
80
|
+
- lib/active_geo_db/connection_configuration.rb
|
|
81
|
+
- lib/active_geo_db/connection_provider.rb
|
|
82
|
+
- lib/active_geo_db/railtie.rb
|
|
83
|
+
- lib/active_geo_db/version.rb
|
|
84
|
+
homepage: https://github.com/kostia/active_geo_db
|
|
85
|
+
licenses: []
|
|
86
|
+
|
|
87
|
+
post_install_message:
|
|
88
|
+
rdoc_options: []
|
|
89
|
+
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
none: false
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
hash: 3
|
|
98
|
+
segments:
|
|
99
|
+
- 0
|
|
100
|
+
version: "0"
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
none: false
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
hash: 3
|
|
107
|
+
segments:
|
|
108
|
+
- 0
|
|
109
|
+
version: "0"
|
|
110
|
+
requirements: []
|
|
111
|
+
|
|
112
|
+
rubyforge_project:
|
|
113
|
+
rubygems_version: 1.8.15
|
|
114
|
+
signing_key:
|
|
115
|
+
specification_version: 3
|
|
116
|
+
summary: Rails (ActiveRecord) lib for accessing OpenGeoDb
|
|
117
|
+
test_files: []
|
|
118
|
+
|