Skip to content

Instantly share code, notes, and snippets.

@justinleveck
Last active August 29, 2015 14:13
Show Gist options
  • Save justinleveck/0209b044b7de622727af to your computer and use it in GitHub Desktop.
Save justinleveck/0209b044b7de622727af to your computer and use it in GitHub Desktop.
class EventsMailerPreview
EVENT_TYPES.each do |event_type|
CM_CONTACT_STATES.keys.each do |cm_contact_state|
create_contact_state_method(event_type, cm_contact_state)
create_existing_contact_method(event_type, cm_contact_state)
end
end
private
def create_contact_state_method(event_type, cm_contact_state)
define_method("#{cm_contact_state}_contact_#{event_type}".to_sym) do
contact = send("update_#{event_type}_contact_state", cm_contact_state)
NewContactMailer.notifier(contact.id)
end
end
def create_existing_contact_method(event_type, cm_contact_state)
define_method("#{cm_contact_state}_#{event_type}_existing".to_sym) do
contact = send("update_#{event_type}_contact_state", cm_contact_state, true)
NewContactMailer.notifier(contact.id)
end
end
end
@justinleveck
Copy link
Author

  def self.create_contact_state_method(event_type, cm_contact_state)
    define_method("#{cm_contact_state}_contact_#{event_type}".to_sym) do
      contact = send("update_#{event_type}_contact_state", cm_contact_state)
      NewContactMailer.notifier(contact.id)
    end
  end

  def self.create_existing_contact_method(event_type, cm_contact_state)
    define_method("#{cm_contact_state}_#{event_type}_existing".to_sym) do
      contact = send("update_#{event_type}_contact_state", cm_contact_state, true)
      NewContactMailer.notifier(contact.id)
    end
  end

  EVENT_TYPES.each do |event_type|
    CM_CONTACT_STATES.keys.each do |cm_contact_state|
      self.create_contact_state_method(event_type, cm_contact_state)
      self.create_existing_contact_method(event_type, cm_contact_state)
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment