Sha256: 6790a43010833c3bb1d2779fba1c87666b5422f731b1765a542e4bb287102c4d

Contents?: true

Size: 906 Bytes

Versions: 13

Compression:

Stored size: 906 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
      geoms = columns.map do |g|
        geom_type = get_geom_type(g)
        case geom_type
        when :point
          send :include, PointFunctions
        when :polygon
          send :include, PolygonFunctions
        when :line_string
          send :include, LineStringFunctions
        end
        g
      end
      self.postgis_geoms = {:columns => geoms}#, :opts => options}
    end

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

ActiveRecord::Base.send :include, PostgisFunctions

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
nofxx-postgis_adapter-0.2.1 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.2.2 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.3.0 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.3.1 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.3.3 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.3.4 lib/postgis_adapter/acts_as_geom.rb
nofxx-postgis_adapter-0.3.8 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.2.3 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.3.8 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.3.5 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.3.4 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.3.0 lib/postgis_adapter/acts_as_geom.rb
postgis_adapter-0.2.1 lib/postgis_adapter/acts_as_geom.rb