activerecord-spatialite-adapter 0.2.2 → 0.2.3

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/History.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.2.3 / 2011-01-06
2
+
3
+ * Many of ActiveRecord's rake tasks weren't working because they need to know about every adapter explicitly. I hesitate to call this "fixed" since I see it as a problem in ActiveRecord, but we now at least have a workaround so the rake tasks will run properly. (Reported by Tad Thorley.)
4
+
1
5
  === 0.2.2 / 2010-12-27
2
6
 
3
7
  * Support for basic spatial equality queries. e.g. constructs such as:
data/README.rdoc CHANGED
@@ -7,17 +7,7 @@ the {RGeo}[http://github.com/dazuma/rgeo] library to represent spatial
7
7
  data in Ruby. Like the standard sqlite3 adapter, this adapter requires
8
8
  the sqlite3-ruby gem.
9
9
 
10
- === Usage
11
-
12
- To use this adapter, add this gem, "activerecord-spatialite-adapter",
13
- to your Gemfile, and then request the adapter name "spatialite" in
14
- your database connection configuration (which, for a Rails application,
15
- is in the config/database.yml file). The other database connection
16
- configuration parameters are the same as for the stock sqlite3 adapter,
17
- with the exception of one additional parameter, <tt>libspatialite</tt>,
18
- which should be set to the full path to the libspatialite shared library,
19
- if it is not installed in a standard place (such as /usr/local or
20
- /opt/local).
10
+ === What This Adapter Provides
21
11
 
22
12
  First, this adapter extends the migration syntax to support creating
23
13
  spatial columns and indexes. To create a spatial column, use the
@@ -89,15 +79,15 @@ Other types of queries currently must be written in SQL. However, we are
89
79
  investigating writing a set of Arel extensions for constructing arbitrary
90
80
  spatial queries.
91
81
 
92
- === Installation
82
+ === Installing The Adapter Gem
93
83
 
94
84
  This adapter has the following requirements:
95
85
 
96
86
  * Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
97
87
  * SpatiaLite 2.3 or later (2.4 recommended).
98
88
  * \ActiveRecord 3.0.3 or later. Earlier versions will not work.
99
- * rgeo gem 0.2.3 or later.
100
- * rgeo-activerecord gem 0.2.1 or later.
89
+ * rgeo gem 0.2.4 or later.
90
+ * rgeo-activerecord gem 0.2.2 or later.
101
91
  * sqlite3 gem 1.3 or later.
102
92
 
103
93
  Install this adapter as a gem:
@@ -107,6 +97,28 @@ Install this adapter as a gem:
107
97
  See the README for the "rgeo" gem, a required dependency, for further
108
98
  installation information.
109
99
 
100
+ === Setting Up The Adapter
101
+
102
+ To use this adapter, add this gem, "activerecord-spatialite-adapter",
103
+ to your Gemfile, and then request the adapter name "spatialite" in
104
+ your database connection configuration (which, for a Rails application,
105
+ is in the config/database.yml file). The other database connection
106
+ configuration parameters are the same as for the stock sqlite3 adapter,
107
+ with the exception of one additional parameter, <tt>libspatialite</tt>,
108
+ which should be set to the full path to the libspatialite shared library,
109
+ if it is not installed in a standard place (such as /usr/local or
110
+ /opt/local).
111
+
112
+ Furthermore, the SpatiaLite adapter includes a special railtie that
113
+ provides support for SpatiaLite databases in ActiveRecord's rake tasks.
114
+ This railtie is required in order to run, e.g., rake test. To install
115
+ this railtie, you should add this line to your config/application.rb:
116
+
117
+ require 'rgeo/active_record/spatialite_adapter/railtie'
118
+
119
+ Note that this railtie must load after the ActiveRecord railtie. That is,
120
+ the above require command should appear after <tt>require 'rails/all'</tt>.
121
+
110
122
  === Known bugs and limitations
111
123
 
112
124
  The spatialite adapter works in principle, but there are a few known holes
data/Version CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -0,0 +1,100 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Rakefile changes for SpatiaLite adapter
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'rgeo/active_record/task_hacker'
38
+
39
+
40
+ class Object
41
+ alias_method :create_database_without_spatialite, :create_database
42
+ alias_method :drop_database_without_spatialite, :drop_database
43
+ end
44
+
45
+
46
+ def create_database(config_)
47
+ if config_['adapter'] == 'spatialite'
48
+ if ::File.exist?(config_['database'])
49
+ $stderr.puts "#{config_['database']} already exists"
50
+ else
51
+ begin
52
+ # Create the SQLite database
53
+ ::ActiveRecord::Base.establish_connection(config_)
54
+ conn_ = ::ActiveRecord::Base.connection
55
+ conn_.execute('SELECT InitSpatialMetaData()')
56
+ rescue ::Exception => e_
57
+ $stderr.puts e_, *(e_.backtrace)
58
+ $stderr.puts "Couldn't create database for #{config_.inspect}"
59
+ end
60
+ end
61
+ else
62
+ create_database_without_spatialite(config_)
63
+ end
64
+ end
65
+
66
+
67
+ def drop_database(config_)
68
+ if config_['adapter'] == 'spatialite'
69
+ require 'pathname'
70
+ path_ = ::Pathname.new(config_['database'])
71
+ file_ = path_.absolute? ? path_.to_s : ::File.join(::Rails.root, path_)
72
+ ::FileUtils.rm(file_)
73
+ else
74
+ drop_database_without_spatialite(config_)
75
+ end
76
+ end
77
+
78
+
79
+ ::RGeo::ActiveRecord::TaskHacker.modify('db:charset', nil, 'spatialite') do |config_|
80
+ ::ActiveRecord::Base.establish_connection(config_)
81
+ puts(::ActiveRecord::Base.connection.encoding)
82
+ end
83
+
84
+
85
+ ::RGeo::ActiveRecord::TaskHacker.modify('db:structure:dump', nil, 'spatialite') do |config_|
86
+ dbfile_ = config_["database"] || config_["dbfile"]
87
+ `sqlite3 #{dbfile_} .schema > db/#{::Rails.env}_structure.sql`
88
+ end
89
+
90
+
91
+ ::RGeo::ActiveRecord::TaskHacker.modify('db:test:clone_structure', 'test', 'spatialite') do |config_|
92
+ dbfile_ = config_["database"] || config_["dbfile"]
93
+ `sqlite3 #{dbfile_} < #{::Rails.root}/db/#{::Rails.env}_structure.sql`
94
+ end
95
+
96
+
97
+ ::RGeo::ActiveRecord::TaskHacker.modify('db:test:purge', 'test', 'spatialite') do |config_|
98
+ dbfile_ = config_["database"] || config_["dbfile"]
99
+ ::File.delete(dbfile_) if ::File.exist?(dbfile_)
100
+ end
@@ -0,0 +1,58 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Railtie for SpatiaLite adapter
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'rails/railtie'
38
+
39
+
40
+ module RGeo
41
+
42
+ module ActiveRecord
43
+
44
+ module SpatialiteAdapter
45
+
46
+ class Railtie < ::Rails::Railtie
47
+
48
+ rake_tasks do
49
+ load "rgeo/active_record/spatialite_adapter/databases.rake"
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Azuma
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-27 00:00:00 -08:00
17
+ date: 2011-01-06 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -28,8 +28,8 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  - 2
31
- - 1
32
- version: 0.2.1
31
+ - 2
32
+ version: 0.2.2
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -58,6 +58,8 @@ extra_rdoc_files:
58
58
  - README.rdoc
59
59
  files:
60
60
  - lib/active_record/connection_adapters/spatialite_adapter.rb
61
+ - lib/rgeo/active_record/spatialite_adapter/railtie.rb
62
+ - lib/rgeo/active_record/spatialite_adapter/databases.rake
61
63
  - History.rdoc
62
64
  - README.rdoc
63
65
  - test/tc_basic.rb