Sha256: 2cecaf440370a55c5eb3f19d813ea8c218cccef48a01dd1bc360b31b76edb94f

Contents?: true

Size: 819 Bytes

Versions: 8

Compression:

Stored size: 819 Bytes

Contents

#
# PostGIS Adapter
#
# http://github.com/nofxx/postgis_adapter
#
module PostgisFunctions
  def self.included(base)
    base.send :extend, ClassMethods
  end

  module ClassMethods

    # acts_as_geom :geom
    def acts_as_geom(*columns)
      cattr_accessor :postgis_geoms
      self.postgis_geoms = {:columns => columns}
      columns.map do |g|
        case get_geom_type(g)
        when :point then send :include, PointFunctions
        when :polygon then send :include, PolygonFunctions
        when :line_string then send :include, LineStringFunctions
        end
      end
    end

    def get_geom_type(column)
      self.columns.select { |c| c.name == column.to_s }[0].geometry_type
    rescue ActiveRecord::StatementInvalid => e
      nil
    end
  end
end

ActiveRecord::Base.send :include, PostgisFunctions

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
nofxx-postgis_adapter-0.3.9 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.5.0 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.5.1 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.5.5 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.5.6 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.5.7 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.5.0 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.5.1 lib/postgis_adapter/acts_as_geom.rb