Sha256: 04398608c8a6e3edd1e3a184df483f9afb24a7e8cec387d464e07172bc57db7b

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

class ActiveRecord::Base 

  def self.acts_as_campaign(params = {})
  	EpomRails.config.campaign[:model] = self
    acts_as(Epom::Campaign, params)

    override_belongs_to_advertiser
  end

  def self.override_belongs_to_advertiser
  	advertiser_association = EpomRails.config.campaign[:belongs_to].find{|a| a[:epom_element]=="Advertiser"}
  	
    if advertiser_association
      # overriding belongs_to: advertiser
    	define_method advertiser_association[:name] do
    		fields = EpomRails.config.campaign[:fields]
    		object = super()

    		if object.respond_to?(fields.key('id')) and object.send(fields.key('id'))
          # here, retrieve this advertiser from Epom
        end
        object
    	end
    end  
  end

end  

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
epom_rails-1.3.2 lib/epom_rails/acts_as_campaign.rb