Class: Segmentor::Target
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Segmentor::Target
- Defined in:
- lib/segmentor/target.rb
Overview
Target is single piece of data, returned by a
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_notified? ⇒ Boolean
- #get_binding ⇒ Object
- #issue_receipt!(rendered_value = nil) ⇒ Object
- #most_recent_receipt ⇒ Object
- #preview(&block) ⇒ Object
Class Method Details
Instance Method Details
#can_be_notified? ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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.repeat_frequency != ::Segmentor::Segment::NO_REPEAT && most_recent_receipt.sent_at < segment.repeat_frequency.days.ago end |
#get_binding ⇒ Object
35 36 37 |
# File 'lib/segmentor/target.rb', line 35 def get_binding binding end |
#issue_receipt!(rendered_value = nil) ⇒ Object
27 28 29 |
# File 'lib/segmentor/target.rb', line 27 def issue_receipt!(rendered_value = nil) ::Segmentor::Receipt.record_receipt(self, rendered_value) end |
#most_recent_receipt ⇒ Object
31 32 33 |
# 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) ⇒ Object
39 40 41 42 43 |
# File 'lib/segmentor/target.rb', line 39 def preview(&block) raise ArgumentError, 'block required' unless block_given? block.call(self, segment.notifier_context) end |