Module: Mailee::Sync::ClassMethods

Defined in:
lib/mailee/active_record.rb

Instance Method Summary collapse

Instance Method Details

#sync_with_mailee(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mailee/active_record.rb', line 30

def sync_with_mailee(options = {})
  unless syncd? # don't let AR call this twice
    cattr_accessor :sync_options
    after_create :create_in_mailee
    after_update :update_in_mailee
    after_destroy :destroy_in_mailee
    self.sync_options = {:email => :email, :name => :name, :news => :news}.merge(options)
    unless self.column_names.include?(self.sync_options[:email].to_s)
      raise "Campo #{sync_options[:email]} não existe em #{new.class}."
    end
    unless self.column_names.include?(self.sync_options[:name].to_s)
      self.sync_options[:name] = nil
    end
    unless self.column_names.include?(self.sync_options[:news].to_s)
      self.sync_options[:news] = nil
    end
  end
  include InstanceMethods
end

#syncd?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/mailee/active_record.rb', line 50

def syncd?
  self.included_modules.include?(InstanceMethods)
end