rgeo-activerecord 0.6.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/LICENSE.txt +29 -0
- data/lib/rgeo-activerecord.rb +0 -1
- data/lib/rgeo/active_record.rb +5 -64
- data/lib/rgeo/active_record/adapter_test_helper.rb +0 -56
- data/lib/rgeo/active_record/ar_factory_settings.rb +1 -81
- data/lib/rgeo/active_record/arel_spatial_queries.rb +13 -111
- data/lib/rgeo/active_record/common_adapter_elements.rb +35 -77
- data/lib/rgeo/active_record/geometry_mixin.rb +0 -49
- data/lib/rgeo/active_record/spatial_expressions.rb +5 -49
- data/lib/rgeo/active_record/version.rb +1 -52
- data/test/tc_basic.rb +2 -56
- data/test/test_helper.rb +8 -13
- metadata +21 -20
- data/Version +0 -1
- data/lib/rgeo/active_record/task_hacker.rb +0 -105
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3891bad7ab5e1f7408095e87bcf8a731a7130ba7
         | 
| 4 | 
            +
              data.tar.gz: 4d466201e93d07234853ea049823968898761407
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f493f620c706f0adc498ec9f729c9d0a019fdd316f4e41e2e4fa4faef7df2a93a32143329ad01d34ad850dda6ec55a5830a6792c6f908fbe79025691540c6d32
         | 
| 7 | 
            +
              data.tar.gz: 38b04b4a6938fea2e95128409bc9e3346a213ce9289e267e023a7da19c9e6afe3ced84ef59020a4f501081dd9969ba28dff60e8913435b0927fdbe41155f4eef
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # -----------------------------------------------------------------------------
         | 
| 2 | 
            +
            # Copyright 2010-2012 Daniel Azuma
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # All rights reserved.
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            # Redistribution and use in source and binary forms, with or without
         | 
| 7 | 
            +
            # modification, are permitted provided that the following conditions are met:
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            # * Redistributions of source code must retain the above copyright notice,
         | 
| 10 | 
            +
            #   this list of conditions and the following disclaimer.
         | 
| 11 | 
            +
            # * Redistributions in binary form must reproduce the above copyright notice,
         | 
| 12 | 
            +
            #   this list of conditions and the following disclaimer in the documentation
         | 
| 13 | 
            +
            #   and/or other materials provided with the distribution.
         | 
| 14 | 
            +
            # * Neither the name of the copyright holder, nor the names of any other
         | 
| 15 | 
            +
            #   contributors to this software, may be used to endorse or promote products
         | 
| 16 | 
            +
            #   derived from this software without specific prior written permission.
         | 
| 17 | 
            +
            #
         | 
| 18 | 
            +
            # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
         | 
| 19 | 
            +
            # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
         | 
| 20 | 
            +
            # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
         | 
| 21 | 
            +
            # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
         | 
| 22 | 
            +
            # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
         | 
| 23 | 
            +
            # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
         | 
| 24 | 
            +
            # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
         | 
| 25 | 
            +
            # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
         | 
| 26 | 
            +
            # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
         | 
| 27 | 
            +
            # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
         | 
| 28 | 
            +
            # POSSIBILITY OF SUCH DAMAGE.
         | 
| 29 | 
            +
            # -----------------------------------------------------------------------------
         | 
    
        data/lib/rgeo-activerecord.rb
    CHANGED
    
    
    
        data/lib/rgeo/active_record.rb
    CHANGED
    
    | @@ -1,44 +1,3 @@ | |
| 1 | 
            -
            # -----------------------------------------------------------------------------
         | 
| 2 | 
            -
            #
         | 
| 3 | 
            -
            # ActiveRecord extensions for RGeo
         | 
| 4 | 
            -
            #
         | 
| 5 | 
            -
            # -----------------------------------------------------------------------------
         | 
| 6 | 
            -
            # Copyright 2010-2012 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 | 
            -
            # Dependencies
         | 
| 38 | 
            -
            require 'rgeo'
         | 
| 39 | 
            -
            require 'active_record'
         | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 1 | 
             
            # RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
         | 
| 43 2 | 
             
            #
         | 
| 44 3 | 
             
            # The optional RGeo::ActiveRecord module provides spatial extensions for
         | 
| @@ -46,8 +5,6 @@ require 'active_record' | |
| 46 5 | 
             
            # spatial connection adapters.
         | 
| 47 6 |  | 
| 48 7 | 
             
            module RGeo
         | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 8 | 
             
              # This module contains a set of ActiveRecord extensions for RGeo.
         | 
| 52 9 | 
             
              # Generally, you will not need to interact with the contents of this
         | 
| 53 10 | 
             
              # module directly, unless you are writing a spatial ActiveRecord
         | 
| @@ -55,29 +12,13 @@ module RGeo | |
| 55 12 |  | 
| 56 13 | 
             
              module ActiveRecord
         | 
| 57 14 | 
             
              end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 15 | 
             
            end
         | 
| 61 16 |  | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
            module Arel
         | 
| 67 | 
            -
            end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
            # The rgeo-activerecord gem installs several patches to ActiveRecord
         | 
| 71 | 
            -
            # to support services needed by spatial adapters.
         | 
| 72 | 
            -
             | 
| 73 | 
            -
            module ActiveRecord
         | 
| 74 | 
            -
            end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
            # Implementation files
         | 
| 78 | 
            -
            require 'rgeo/active_record/version.rb'
         | 
| 79 | 
            -
            require 'rgeo/active_record/spatial_expressions.rb'
         | 
| 17 | 
            +
            require 'rgeo'
         | 
| 18 | 
            +
            require 'active_record'
         | 
| 19 | 
            +
            require 'rgeo/active_record/version'
         | 
| 20 | 
            +
            require 'rgeo/active_record/spatial_expressions'
         | 
| 80 21 | 
             
            require 'rgeo/active_record/arel_spatial_queries'
         | 
| 81 | 
            -
            require 'rgeo/active_record/common_adapter_elements | 
| 22 | 
            +
            require 'rgeo/active_record/common_adapter_elements'
         | 
| 82 23 | 
             
            require 'rgeo/active_record/ar_factory_settings'
         | 
| 83 24 | 
             
            require 'rgeo/active_record/geometry_mixin'
         | 
| @@ -1,55 +1,13 @@ | |
| 1 | 
            -
            # -----------------------------------------------------------------------------
         | 
| 2 | 
            -
            #
         | 
| 3 | 
            -
            # Helper methods for ActiveRecord adapter tests
         | 
| 4 | 
            -
            #
         | 
| 5 | 
            -
            # -----------------------------------------------------------------------------
         | 
| 6 | 
            -
            # Copyright 2010-2012 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 1 | 
             
            require 'rgeo/active_record'
         | 
| 38 2 | 
             
            require 'yaml'
         | 
| 39 3 | 
             
            require 'logger'
         | 
| 40 4 |  | 
| 41 | 
            -
             | 
| 42 5 | 
             
            module RGeo
         | 
| 43 6 | 
             
              module ActiveRecord
         | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 7 | 
             
                # A helper module for creating unit tests for adapters.
         | 
| 47 | 
            -
             | 
| 48 8 | 
             
                module AdapterTestHelper
         | 
| 49 | 
            -
             | 
| 50 9 | 
             
                  @class_num = 0
         | 
| 51 10 |  | 
| 52 | 
            -
             | 
| 53 11 | 
             
                  # When this module is included in a test case class, it
         | 
| 54 12 | 
             
                  # automatically attempts to load the database config file from the
         | 
| 55 13 | 
             
                  # path specified by constants defined in the class. It first tries
         | 
| @@ -89,7 +47,6 @@ module RGeo | |
| 89 47 | 
             
                    end
         | 
| 90 48 | 
             
                  end
         | 
| 91 49 |  | 
| 92 | 
            -
             | 
| 93 50 | 
             
                  def self.new_class(param_)  # :nodoc:
         | 
| 94 51 | 
             
                    base_ = param_.kind_of?(::Class) ? param_ : ::ActiveRecord::Base
         | 
| 95 52 | 
             
                    config_ = param_.kind_of?(::Hash) ? param_ : nil
         | 
| @@ -103,7 +60,6 @@ module RGeo | |
| 103 60 | 
             
                    klass_
         | 
| 104 61 | 
             
                  end
         | 
| 105 62 |  | 
| 106 | 
            -
             | 
| 107 63 | 
             
                  # Default setup method that calls cleanup_tables.
         | 
| 108 64 | 
             
                  # It also defines a couple of useful factories: @factory (a
         | 
| 109 65 | 
             
                  # cartesian factory) and @geographic_factory (a spherical factory)
         | 
| @@ -115,7 +71,6 @@ module RGeo | |
| 115 71 | 
             
                    cleanup_caches
         | 
| 116 72 | 
             
                  end
         | 
| 117 73 |  | 
| 118 | 
            -
             | 
| 119 74 | 
             
                  # Default teardown method that calls cleanup_tables.
         | 
| 120 75 |  | 
| 121 76 | 
             
                  def teardown
         | 
| @@ -123,7 +78,6 @@ module RGeo | |
| 123 78 | 
             
                    cleanup_caches
         | 
| 124 79 | 
             
                  end
         | 
| 125 80 |  | 
| 126 | 
            -
             | 
| 127 81 | 
             
                  # Utility method that attempts to clean up any table that was
         | 
| 128 82 | 
             
                  # created by a test method. Normally called automatically at setup
         | 
| 129 83 | 
             
                  # and teardown. If you override those methods, you'll need to call
         | 
| @@ -150,12 +104,10 @@ module RGeo | |
| 150 104 |  | 
| 151 105 | 
             
                    # Clear out any ActiveRecord caches that are present.
         | 
| 152 106 | 
             
                    # Different Rails versions use different types of caches.
         | 
| 153 | 
            -
                    has_schema_cache_ = false
         | 
| 154 107 | 
             
                    klass_.connection_pool.with_connection do |c_|
         | 
| 155 108 | 
             
                      if c_.respond_to?(:schema_cache)
         | 
| 156 109 | 
             
                        # 3.2.x and 4.0.x
         | 
| 157 110 | 
             
                        c_.schema_cache.clear!
         | 
| 158 | 
            -
                        has_schema_cache_ = true
         | 
| 159 111 | 
             
                      end
         | 
| 160 112 | 
             
                      if c_.respond_to?(:clear_cache!)
         | 
| 161 113 | 
             
                        # 3.1 and above
         | 
| @@ -164,13 +116,8 @@ module RGeo | |
| 164 116 | 
             
                      # All 3.x and 4.0
         | 
| 165 117 | 
             
                      c_.clear_query_cache
         | 
| 166 118 | 
             
                    end
         | 
| 167 | 
            -
                    if !has_schema_cache_ && klass_.connection_pool.respond_to?(:clear_cache!)
         | 
| 168 | 
            -
                      # 3.1.x only
         | 
| 169 | 
            -
                      klass_.connection_pool.clear_cache!
         | 
| 170 | 
            -
                    end
         | 
| 171 119 | 
             
                  end
         | 
| 172 120 |  | 
| 173 | 
            -
             | 
| 174 121 | 
             
                  # Utility method that creates and returns a new ActiveRecord class
         | 
| 175 122 | 
             
                  # subclassing the DEFAULT_AR_CLASS.
         | 
| 176 123 |  | 
| @@ -178,9 +125,6 @@ module RGeo | |
| 178 125 | 
             
                    @ar_class = AdapterTestHelper.new_class(self.class.const_get(:DEFAULT_AR_CLASS))
         | 
| 179 126 | 
             
                  end
         | 
| 180 127 |  | 
| 181 | 
            -
             | 
| 182 128 | 
             
                end
         | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 185 129 | 
             
              end
         | 
| 186 130 | 
             
            end
         | 
| @@ -1,47 +1,5 @@ | |
| 1 | 
            -
            # -----------------------------------------------------------------------------
         | 
| 2 | 
            -
            #
         | 
| 3 | 
            -
            # Additions to ActiveRecord::Base for factory settings
         | 
| 4 | 
            -
            #
         | 
| 5 | 
            -
            # -----------------------------------------------------------------------------
         | 
| 6 | 
            -
            # Copyright 2010-2012 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 'active_record'
         | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 1 | 
             
            module RGeo
         | 
| 41 | 
            -
             | 
| 42 2 | 
             
              module ActiveRecord
         | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 3 | 
             
                # The default factory generator for ActiveRecord::Base.
         | 
| 46 4 |  | 
| 47 5 | 
             
                DEFAULT_FACTORY_GENERATOR = ::Proc.new do |config_|
         | 
| @@ -52,9 +10,7 @@ module RGeo | |
| 52 10 | 
             
                  end
         | 
| 53 11 | 
             
                end
         | 
| 54 12 |  | 
| 55 | 
            -
             | 
| 56 13 | 
             
                # An object that manages the RGeo factories for a ConnectionPool.
         | 
| 57 | 
            -
             | 
| 58 14 | 
             
                class RGeoFactorySettings
         | 
| 59 15 |  | 
| 60 16 | 
             
                  def initialize  # :nodoc:
         | 
| @@ -62,24 +18,18 @@ module RGeo | |
| 62 18 | 
             
                    @column_factories = {}
         | 
| 63 19 | 
             
                  end
         | 
| 64 20 |  | 
| 65 | 
            -
             | 
| 66 21 | 
             
                  # Get the default factory generator for the given table
         | 
| 67 | 
            -
             | 
| 68 22 | 
             
                  def get_factory_generator(table_name_)
         | 
| 69 23 | 
             
                    @factory_generators[table_name_.to_s] || ::RGeo::ActiveRecord::DEFAULT_FACTORY_GENERATOR
         | 
| 70 24 | 
             
                  end
         | 
| 71 25 |  | 
| 72 | 
            -
             | 
| 73 26 | 
             
                  # Set the default factory generator for the given table
         | 
| 74 | 
            -
             | 
| 75 27 | 
             
                  def set_factory_generator(table_name_, gen_)
         | 
| 76 28 | 
             
                    @factory_generators[table_name_.to_s] = gen_
         | 
| 77 29 | 
             
                  end
         | 
| 78 30 |  | 
| 79 | 
            -
             | 
| 80 31 | 
             
                  # Get the factory or factory generator for the given table name
         | 
| 81 32 | 
             
                  # and column name.
         | 
| 82 | 
            -
             | 
| 83 33 | 
             
                  def get_column_factory(table_name_, column_name_, params_=nil)
         | 
| 84 34 | 
             
                    table_name_ = table_name_.to_s
         | 
| 85 35 | 
             
                    column_name_ = column_name_.to_s
         | 
| @@ -91,17 +41,13 @@ module RGeo | |
| 91 41 | 
             
                    result_
         | 
| 92 42 | 
             
                  end
         | 
| 93 43 |  | 
| 94 | 
            -
             | 
| 95 44 | 
             
                  # Set the factory or factory generator for the given table name
         | 
| 96 45 | 
             
                  # and column name.
         | 
| 97 | 
            -
             | 
| 98 46 | 
             
                  def set_column_factory(table_name_, column_name_, factory_)
         | 
| 99 47 | 
             
                    (@column_factories[table_name_.to_s] ||= {})[column_name_.to_s] = factory_
         | 
| 100 48 | 
             
                  end
         | 
| 101 49 |  | 
| 102 | 
            -
             | 
| 103 50 | 
             
                  # Clear settings for the given table name, or for all tables
         | 
| 104 | 
            -
             | 
| 105 51 | 
             
                  def clear!(table_name_=nil)
         | 
| 106 52 | 
             
                    if table_name_
         | 
| 107 53 | 
             
                      table_name_ = table_name_.to_s
         | 
| @@ -113,22 +59,14 @@ module RGeo | |
| 113 59 | 
             
                    end
         | 
| 114 60 | 
             
                  end
         | 
| 115 61 |  | 
| 116 | 
            -
             | 
| 117 62 | 
             
                  DEFAULT = self.new
         | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 63 | 
             
                end
         | 
| 121 64 |  | 
| 122 | 
            -
             | 
| 123 65 | 
             
                # Additional class methods on ::ActiveRecord::Base that provide
         | 
| 124 66 | 
             
                # a way to control the RGeo factory used for ActiveRecord objects.
         | 
| 125 | 
            -
             | 
| 126 67 | 
             
                module ActiveRecordBaseFactorySettings
         | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 68 | 
             
                  # Return the RGeoFactorySettings object associated with this
         | 
| 130 69 | 
             
                  # class's connection.
         | 
| 131 | 
            -
             | 
| 132 70 | 
             
                  def rgeo_factory_settings
         | 
| 133 71 | 
             
                    pool_ = begin
         | 
| 134 72 | 
             
                      connection_pool
         | 
| @@ -138,7 +76,6 @@ module RGeo | |
| 138 76 | 
             
                    pool_ ? pool_.rgeo_factory_settings : RGeoFactorySettings::DEFAULT
         | 
| 139 77 | 
             
                  end
         | 
| 140 78 |  | 
| 141 | 
            -
             | 
| 142 79 | 
             
                  # The value of this attribute is a RGeo::Feature::FactoryGenerator
         | 
| 143 80 | 
             
                  # that is used to generate the proper factory when loading geometry
         | 
| 144 81 | 
             
                  # objects from the database. For example, if the data being loaded
         | 
| @@ -154,31 +91,24 @@ module RGeo | |
| 154 91 | 
             
                    rgeo_factory_settings.get_factory_generator(table_name)
         | 
| 155 92 | 
             
                  end
         | 
| 156 93 |  | 
| 157 | 
            -
             | 
| 158 94 | 
             
                  # Set the rgeo_factory_generator attribute
         | 
| 159 | 
            -
             | 
| 160 95 | 
             
                  def rgeo_factory_generator=(gen_)
         | 
| 161 96 | 
             
                    rgeo_factory_settings.set_factory_generator(table_name, gen_)
         | 
| 162 97 | 
             
                  end
         | 
| 163 98 |  | 
| 164 | 
            -
             | 
| 165 99 | 
             
                  # This is a convenient way to set the rgeo_factory_generator by
         | 
| 166 100 | 
             
                  # passing a block.
         | 
| 167 | 
            -
             | 
| 168 101 | 
             
                  def to_generate_rgeo_factory(&block_)
         | 
| 169 102 | 
             
                    rgeo_factory_settings.set_factory_generator(table_name, block_)
         | 
| 170 103 | 
             
                  end
         | 
| 171 104 |  | 
| 172 | 
            -
             | 
| 173 105 | 
             
                  # Set a specific factory for this ActiveRecord class and the given
         | 
| 174 106 | 
             
                  # column name. This setting, if present, overrides the result of the
         | 
| 175 107 | 
             
                  # rgeo_factory_generator.
         | 
| 176 | 
            -
             | 
| 177 108 | 
             
                  def set_rgeo_factory_for_column(column_name_, factory_)
         | 
| 178 109 | 
             
                    rgeo_factory_settings.set_column_factory(table_name, column_name_, factory_)
         | 
| 179 110 | 
             
                  end
         | 
| 180 111 |  | 
| 181 | 
            -
             | 
| 182 112 | 
             
                  # Returns the factory generator or specific factory to use for this
         | 
| 183 113 | 
             
                  # ActiveRecord class and the given column name.
         | 
| 184 114 | 
             
                  # If an explicit factory was set for the given column, returns it.
         | 
| @@ -186,29 +116,23 @@ module RGeo | |
| 186 116 | 
             
                  # rgeo_factory_generator for this class, and returns the resulting
         | 
| 187 117 | 
             
                  # factory. Otherwise, if no params hash is given, just returns the
         | 
| 188 118 | 
             
                  # rgeo_factory_generator for this class.
         | 
| 189 | 
            -
             | 
| 190 119 | 
             
                  def rgeo_factory_for_column(column_name_, params_=nil)
         | 
| 191 120 | 
             
                    rgeo_factory_settings.get_column_factory(table_name, column_name_, params_)
         | 
| 192 121 | 
             
                  end
         | 
| 193 | 
            -
             | 
| 194 | 
            -
             | 
| 195 122 | 
             
                end
         | 
| 196 123 |  | 
| 197 124 | 
             
                ::ActiveRecord::Base.extend(ActiveRecordBaseFactorySettings)
         | 
| 198 125 |  | 
| 199 | 
            -
             | 
| 200 126 | 
             
                # :stopdoc:
         | 
| 201 127 |  | 
| 202 | 
            -
             | 
| 203 128 | 
             
                # Patch for connection pool to track geo factories per table name
         | 
| 204 | 
            -
             | 
| 205 129 | 
             
                ::ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
         | 
| 206 | 
            -
             | 
| 207 130 | 
             
                  def rgeo_factory_settings
         | 
| 208 131 | 
             
                    @_rgeo_factory_settings ||= RGeoFactorySettings.new
         | 
| 209 132 | 
             
                  end
         | 
| 210 133 |  | 
| 211 134 | 
             
                  private
         | 
| 135 | 
            +
             | 
| 212 136 | 
             
                  alias_method :new_connection_without_rgeo_modification, :new_connection
         | 
| 213 137 | 
             
                  def new_connection
         | 
| 214 138 | 
             
                    result_ = new_connection_without_rgeo_modification
         | 
| @@ -217,13 +141,9 @@ module RGeo | |
| 217 141 | 
             
                    end
         | 
| 218 142 | 
             
                    result_
         | 
| 219 143 | 
             
                  end
         | 
| 220 | 
            -
             | 
| 221 144 | 
             
                end
         | 
| 222 145 |  | 
| 223 | 
            -
             | 
| 224 146 | 
             
                # :startdoc:
         | 
| 225 147 |  | 
| 226 | 
            -
             | 
| 227 148 | 
             
              end
         | 
| 228 | 
            -
             | 
| 229 149 | 
             
            end
         |