class Segmentor::Target

Target is single piece of data, returned by a

Public Class Methods

new_with_user(user) click to toggle source
# File lib/segmentor/target.rb, line 19
def self.new_with_user(user)
  ::Segmentor::Target.new(user_id: user.id, payload: {})
end
new_with_user_and_payload(user, payload) click to toggle source
# File lib/segmentor/target.rb, line 23
def self.new_with_user_and_payload(user, payload)
  ::Segmentor::Target.new(user_id: user.id, payload: payload)
end

Public Instance Methods

can_be_notified?() click to toggle source
# File lib/segmentor/target.rb, line 45
def can_be_notified?
  most_recent_receipt = segment.receipts.where(user_id: user_id).order(:sent_at).last

  # notification can be sent if there is a receipt for this target that
  # is older than the repeat frequency of its segment
  return true if most_recent_receipt.nil?

  # we have a receipt. notify only if:
  # segment repeat frequency is not NO_REPEAT
  # receipt is older than segment repeat frequency
  segment.notify_frequency != ::Segmentor::Segment::NO_REPEAT &&
    most_recent_receipt.sent_at < segment.notify_frequency.days.ago
end
get_binding() click to toggle source
# File lib/segmentor/target.rb, line 35
def get_binding
  binding
end
issue_receipt!(rendered_value = nil) click to toggle source
# File lib/segmentor/target.rb, line 27
def issue_receipt!(rendered_value = nil)
  ::Segmentor::Receipt.record_receipt(self, rendered_value)
end
most_recent_receipt() click to toggle source
# File lib/segmentor/target.rb, line 31
def most_recent_receipt
  segment.receipts.where(user_id: user_id).order(:sent_at).last
end
preview(&block) click to toggle source
# File lib/segmentor/target.rb, line 39
def preview(&block)
  raise ArgumentError, 'block required' unless block_given?

  block.call(self, segment.notifier_context)
end

Private Instance Methods

set_segment_if_nil() click to toggle source
# File lib/segmentor/target.rb, line 61
def set_segment_if_nil
  self.segment_id ||= session.segment_id
end