Sha256: ebd52ec84ec452cb2c80240026163a894eedd5e6abf0cc38823b0a01eb1472f5
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
require 'address' module OnTheMap module Addressable extend ActiveSupport::Concern included do embeds_one :address, as: :addressable Address.address_fields.each do |fname| delegate fname, to: :address meth_name = "#{fname}=" define_method meth_name do |value| # create new empty address if none defined self.address ||= Address.new unless value.to_s.strip.blank? # set address field self.address.send(meth_name, value) # update full address self.address.send :set_full perform_geocoding if perform_geocoding? fname address.save! end end end delegate :region, :geolocatable?, to: :address end def perform_geocoding? name return unless respond_to? :perform_geocoding geocode_field?(name) end def set_address hash adr = Hashie::Mash.new hash Address.address_fields.each do |name| self.send("#{name}=", adr.send(name)) if adr.send(name) end end def full_address self.address.full end def floor_adr= adr self.address.floor_adr = adr if address end protected def geocode_field? name [:city, :region].include? name.to_sym end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
on_the_map-0.1.1 | lib/on_the_map/addressable.rb |