Module: Geokit::ActsAsMappable::Glue::ClassMethods
- Defined in:
- lib/geokit-rails/acts_as_mappable.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#acts_as_mappable(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/geokit-rails/acts_as_mappable.rb', line 14 def acts_as_mappable( = {}) = (class << self; self; end) include Geokit::ActsAsMappable cattr_accessor :through self.through = [:through] if reflection = Geokit::ActsAsMappable.end_of_reflection_chain(self.through, self) .instance_eval do [ :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name ].each do |method_name| define_method method_name do reflection.klass.send(method_name) end end end else cattr_accessor :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name self.distance_column_name = [:distance_column_name] || 'distance' self.default_units = [:default_units] || Geokit::default_units self.default_formula = [:default_formula] || Geokit::default_formula self.lat_column_name = [:lat_column_name] || 'lat' self.lng_column_name = [:lng_column_name] || 'lng' self.qualified_lat_column_name = "#{table_name}.#{lat_column_name}" self.qualified_lng_column_name = "#{table_name}.#{lng_column_name}" if .include?(:auto_geocode) && [:auto_geocode] # if the form auto_geocode=>true is used, let the defaults take over by suppling an empty hash [:auto_geocode] = {} if [:auto_geocode] == true cattr_accessor :auto_geocode_field, :auto_geocode_error_message self.auto_geocode_field = [:auto_geocode][:field] || 'address' self. = [:auto_geocode][:error_message] || 'could not locate address' # set the actual callback here before_validation :auto_geocode_address, :on => :create end end end |