Sha256: a11116702916bf734c51fac75286e4f402b203795a546133509b4127114475f5

Contents?: true

Size: 1010 Bytes

Versions: 5

Compression:

Stored size: 1010 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 :db_field => :geom_type
    # Examples:
    #
    # acts_as_geom :data => :point
    # acts_as_geom :geom => :line_string
    # acts_as_geom :geom => :polygon
    #
    def acts_as_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 then  LineStringFunctions
      end unless geom[0].kind_of? Symbol
    end

    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

ActiveRecord::Base.send :include, PostgisFunctions

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
nofxx-postgis_adapter-0.7.0 lib/postgis_adapter/acts_as_geom.rb
ppe-postgis-adapter-0.7.3 lib/postgis_adapter/acts_as_geom.rb
ppe-postgis-adapter-0.7.2 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.7.2 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.7.1 lib/postgis_adapter/acts_as_geom.rb