Sha256: 25ea6f18da1bd6663bb883e510aab4f9ea74c53f27edd772398d86a1394e7adf

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

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

  module ClassMethods

    # has_geom :db_field => :geom_type
    # Examples:
    #
    # has_geom :data => :point
    # has_geom :geom => :line_string
    # has_geom :geom => :polygon
    #
    def has_geom(*geom)
      cattr_accessor :postgis_geoms
      self.postgis_geoms = geom[0] # {:columns => column
      send :include, case geom[0].values[0]
        when :point       then  PointFunctions
        when :polygon     then PolygonFunctions
        when :line_string, :multi_line_string then  LineStringFunctions
        when :multi_polygon then MultiPolygonFunctions
      end unless geom[0].kind_of? Symbol
    end
    alias :acts_as_geom :has_geom

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

ActiveRecord::Base.send :include, PostgisAdapter::Functions

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
gotime-postgis_adapter-0.8.5 lib/postgis_adapter/acts_as_geom.rb
gotime-postgis_adapter-0.8.4 lib/postgis_adapter/acts_as_geom.rb
gotime-postgis_adapter-0.8.3 lib/postgis_adapter/acts_as_geom.rb
gotime-postgis_adapter-0.8.2 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.8.1 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.8.0 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.7.9 lib/postgis_adapter/acts_as_geom.rb