Module: HasDistance::Distance::Glue::ClassMethods
- Defined in:
- lib/has_distance/distance.rb
Instance Method Summary collapse
Instance Method Details
#has_distance(field_name = :distance, options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/has_distance/distance.rb', line 10 def has_distance(field_name=:distance, ={}, &block) cattr_accessor :distance_config self.distance_config = Struct.new(:column_name, :lat_name, :lng_name, :units, :distance, :limit ).new( field_name, [:latitude] || 'latitude', [:longitude] || 'longitude', [:units] || :miles, [:distance] || 20, [:limit] || 12 ) if block_given? block.call(self.distance_config) end end |
#nearby(opts = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/has_distance/distance.rb', line 32 def nearby(opts={}) _config = self.distance_config _this = new _this.send("#{_config.lat_name}=".to_sym, opts.delete(:lat)) _this.send("#{_config.lng_name}=".to_sym, opts.delete(:lng)) _this.nearby(opts) end |