module MailControl::LoggedEmail

Public Instance Methods

refresh_data() click to toggle source
# File lib/mail-control/logged_email.rb, line 86
def refresh_data
  save(:validate => false)
end
send_email(data = {}) click to toggle source

Publishes the mailing to the receivers

@param [ Hash ] options The options to send_email with.

# File lib/mail-control/logged_email.rb, line 79
def send_email(data = {})
  assign_properties(data)

  self
end

Protected Instance Methods

assign_properties(data = {}) click to toggle source
# File lib/mail-control/logged_email.rb, line 92
def assign_properties(data = {})

  self.verb      = data.delete(:verb)


  write_attribute(:send_after, data[:send_after])
  data.delete(:send_after)

  write_attribute(:send_before, data[:send_before])
  data.delete(:send_before)

  self.state = 'initial'

  [:actor, :act_object, :act_target].each do |type|

    cur_object = data[type]

    unless cur_object
      if definition.send(type.to_sym)
        raise verb.to_json
        #raise MailControl::InvalidData.new(type)
      else
        next

      end
    end

    class_sym = cur_object.class.name.to_sym

    raise MailControl::InvalidData.new(class_sym) unless definition.send(type) == class_sym

    case type
      when :actor
        self.actor = cur_object
      when :act_object
        self.act_object = cur_object
      when :act_target
        self.act_target = cur_object
      else
        raise "unknown type"
    end

    data.delete(type)

  end

  [:grouped_actor].each do |group|


    grp_object = data[group]

    if grp_object == nil
      if definition.send(group.to_sym)
        raise verb.to_json
        #raise MailControl::InvalidData.new(group)
      else
        next

      end
    end

    grp_object.each do |cur_obj|
      raise MailControl::InvalidData.new(class_sym) unless definition.send(group) == cur_obj.class.name.to_sym

      self.grouped_actors << cur_obj

    end

    data.delete(group)

  end

  cur_bond_type = definition.send(:bond_type)

  if cur_bond_type
    write_attribute( :bond_type, cur_bond_type.to_s )
  end

  if definition.send(:unsubscribe_by)
    write_attribute(:unsubscribe_by, definition.send(:unsubscribe_by))
  else
    raise "definition must define unsubscribe_by option"
  end

  if self.act_target.is_unsubscribed_to?(self)
    self.state = 'unsubscribed'
  end

  def_options = definition.send(:options)
  def_options.each do |cur_option|
    cur_object = data[cur_option]

    if cur_object

      if cur_option == :description
        self.description = cur_object
      else
        options[cur_option] = cur_object
      end
      data.delete(cur_option)

    else
      #all options defined must be used
      raise Streama::InvalidData.new(cur_object[0])
    end
  end

  if data.size > 0
    raise "unexpected arguments: " + data.to_json
  end



  self.save


end
definition() click to toggle source
# File lib/mail-control/logged_email.rb, line 210
def definition
  @definition ||= MailControl::Definition.find(verb)
end