Sha256: a0e238722c7e6e4c9c24592e31d1e9fba77beb8c7710dc48faf604f5db566cbb
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 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, 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.0 | lib/on_the_map/addressable.rb |