def route(activity)
      raise "Activity must be stored before routing: #{activity.inspect}" if !activity.stored?

      result = 0

      activity.run_callbacks(:route) do
        # iterate on all timelines
        Activr.registry.timelines.values.each do |timeline_class|
          # check if timeline refuses that activity
          next unless timeline_class.should_route_activity?(activity)

          # store activity in timelines
          self.recipients_for_timeline(timeline_class, activity).each do |recipient, route|
            result += 1

            timeline = timeline_class.new(recipient)
            if timeline.should_handle_activity?(activity, route)
              Activr::Async.hook(:timeline_handle, timeline, activity, route)
            end
          end
        end
      end

      result
    end
def route(activity)
      raise "Activity must be stored before routing: #{activity.inspect}" if !activity.stored?

      result = 0

      activity.run_callbacks(:route) do
        # iterate on all timelines
        Activr.registry.timelines.values.each do |timeline_class|
          # check if timeline refuses that activity
          next unless timeline_class.should_route_activity?(activity)

          # store activity in timelines
          self.recipients_for_timeline(timeline_class, activity).each do |recipient, route|
            result += 1

            timeline = timeline_class.new(recipient)
            if timeline.should_handle_activity?(activity, route)
              Activr::Async.hook(:timeline_handle, timeline, activity, route)
            end
          end
        end
      end

      result
    end
Route an activity

 @param activity [Activity] Activity to route
 @return [Integer] The number of resolved recipients that will handle activity