Module: MapfishCoreExtensions::ActiveRecord::Base

Defined in:
lib/mapfish_core_extensions/active_record/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



47
48
49
# File 'lib/mapfish_core_extensions/active_record/base.rb', line 47

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#to_geojson(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mapfish_core_extensions/active_record/base.rb', line 24

def to_geojson(options = {})
  only = options.delete(:only)
  geoson = { :type => 'Feature' }
  geoson[:properties] = attributes.delete_if do |name, value|
    if value.is_a?(Geometry) then
      geoson[:geometry] = value if name == self.class.geometry_column.name
      true
    elsif name == self.class.primary_key then
      geoson[:id] = value
      true
    elsif only 
      !only.include?(name.to_sym)        
    end
  end
  geoson.to_json
end

#update_attributes_from_feature(feature) ⇒ Object



41
42
43
44
45
# File 'lib/mapfish_core_extensions/active_record/base.rb', line 41

def update_attributes_from_feature(feature)
  attr = feature.properties
  attr[self.class.geometry_column.name] = feature.geometry
  update_attributes(attr)
end