Class: Flyer::Notification
- Inherits:
-
Object
- Object
- Flyer::Notification
- Defined in:
- lib/flyer/notification.rb
Constant Summary collapse
- @@notifications =
[]
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#params ⇒ Object
Returns the value of attribute params.
-
#valid ⇒ Object
Returns the value of attribute valid.
Class Method Summary collapse
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Boolean Has the notification expired?.
-
#initialize(controller) ⇒ Notification
constructor
A new instance of Notification.
- #message(&block) ⇒ Object
- #on(&block) ⇒ Object
- #path(&block) ⇒ Object
-
#used! ⇒ Object
Mark current notification has used.
-
#validate! ⇒ Object
Raise an error if @id or @message is missing.
-
#view ⇒ Object
Flyer::ViewObject Object to be passed to view.
-
#visible? ⇒ Boolean
Boolean Should the notification be visible?.
Constructor Details
#initialize(controller) ⇒ Notification
Returns a new instance of Notification.
26 27 28 29 30 |
# File 'lib/flyer/notification.rb', line 26 def initialize(controller) @on = [] @limit = 1 @controller = controller end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/flyer/notification.rb', line 4 def id @id end |
#limit ⇒ Object
Returns the value of attribute limit.
4 5 6 |
# File 'lib/flyer/notification.rb', line 4 def limit @limit end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/flyer/notification.rb', line 4 def params @params end |
#valid ⇒ Object
Returns the value of attribute valid.
4 5 6 |
# File 'lib/flyer/notification.rb', line 4 def valid @valid end |
Class Method Details
.init(&block) ⇒ Object
8 9 10 |
# File 'lib/flyer/notification.rb', line 8 def self.init(&block) @@notifications << block end |
.notifications ⇒ Object
19 20 21 |
# File 'lib/flyer/notification.rb', line 19 def self.notifications @@notifications end |
.reset! ⇒ Object
12 13 14 |
# File 'lib/flyer/notification.rb', line 12 def self.reset! @@notifications = [] end |
Instance Method Details
#expired? ⇒ Boolean
Returns Boolean Has the notification expired?.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/flyer/notification.rb', line 50 def expired? return false unless @valid if @valid[:to] if Date.parse(@valid.fetch(:to)) < Date.today return true end end if @valid[:from] if Date.parse(@valid.fetch(:from)) > Date.today return true end end end |
#message(&block) ⇒ Object
93 94 95 |
# File 'lib/flyer/notification.rb', line 93 def (&block) @message = block end |
#on(&block) ⇒ Object
100 101 102 |
# File 'lib/flyer/notification.rb', line 100 def on(&block) @on << block end |
#path(&block) ⇒ Object
86 87 88 |
# File 'lib/flyer/notification.rb', line 86 def path(&block) @path = block end |
#used! ⇒ Object
Mark current notification has used
43 44 45 |
# File 'lib/flyer/notification.rb', line 43 def used! .permanent[token] = current_count + 1 end |
#validate! ⇒ Object
Raise an error if @id or @message is missing
35 36 37 38 |
# File 'lib/flyer/notification.rb', line 35 def validate! raise Flyer::IdMissingError.new unless @id raise Flyer::MessageMissingError.new unless @message end |
#view ⇒ Object
Returns Flyer::ViewObject Object to be passed to view.
79 80 81 |
# File 'lib/flyer/notification.rb', line 79 def view Flyer::ViewObject.new(@controller, @path, @message, @params, @id) end |
#visible? ⇒ Boolean
Returns Boolean Should the notification be visible?.
69 70 71 72 73 74 |
# File 'lib/flyer/notification.rb', line 69 def visible? return false if hit_limit? return false if expired? return true if @on.empty? @on.any?{ |blk| @controller.instance_eval(&blk) } end |