def subscribe(options = {})
      subscribed_at = options[:subscribed_at] || Time.current
      with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : true
      with_optional_targets   = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : true
      new_attributes = { subscribing: true, subscribed_at: subscribed_at, optional_targets: optional_targets }
      new_attributes = new_attributes.merge(subscribing_to_email: true, subscribed_to_email_at: subscribed_at) if with_email_subscription
      if with_optional_targets
        optional_target_names.each do |optional_target_name|
          new_attributes[:optional_targets] = new_attributes[:optional_targets].merge(
            Subscription.to_optional_target_key(optional_target_name) => true,
            Subscription.to_optional_target_subscribed_at_key(optional_target_name) => subscribed_at)
        end
      end
      update(new_attributes)
    end
def subscribe(options = {})
      subscribed_at = options[:subscribed_at] || Time.current
      with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : true
      with_optional_targets   = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : true
      new_attributes = { subscribing: true, subscribed_at: subscribed_at, optional_targets: optional_targets }
      new_attributes = new_attributes.merge(subscribing_to_email: true, subscribed_to_email_at: subscribed_at) if with_email_subscription
      if with_optional_targets
        optional_target_names.each do |optional_target_name|
          new_attributes[:optional_targets] = new_attributes[:optional_targets].merge(
            Subscription.to_optional_target_key(optional_target_name) => true,
            Subscription.to_optional_target_subscribed_at_key(optional_target_name) => subscribed_at)
        end
      end
      update(new_attributes)
    end
Subscribes to the notification and notification email.

 @param [Hash] options Options for subscribing to the notification
 @option options [DateTime] :subscribed_at           (Time.current) Time to set to subscribed_at and subscribed_to_email_at of the subscription record
 @option options [Boolean]  :with_email_subscription (true)         If the subscriber also subscribes notification email
 @option options [Boolean]  :with_optional_targets   (true)         If the subscriber also subscribes optional_targets
 @return [Boolean] If successfully updated subscription instance