Class: Kward::NativeShell::MailNotifications
- Inherits:
-
Object
- Object
- Kward::NativeShell::MailNotifications
- Defined in:
- lib/kward/shell/native_interactive.rb
Instance Method Summary collapse
- #check(variables, directory, now:) ⇒ Object
-
#initialize ⇒ MailNotifications
constructor
A new instance of MailNotifications.
Constructor Details
#initialize ⇒ MailNotifications
Returns a new instance of MailNotifications.
116 117 118 |
# File 'lib/kward/shell/native_interactive.rb', line 116 def initialize @seen = {} end |
Instance Method Details
#check(variables, directory, now:) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/kward/shell/native_interactive.rb', line 120 def check(variables, directory, now:) interval = variables.fetch("MAILCHECK", "600") interval = interval.match?(/\A[0-9]+\z/) ? interval.to_i : 600 return if @checked && now - @checked < interval @checked = now paths = variables.key?("MAILPATH") ? variables["MAILPATH"].split(":") : [variables["MAIL"]].compact current = {} paths.each do |entry| path, = parse(entry) next if path.empty? key = nil begin key = directory.resolve(path) modified = File.stat(key).mtime rescue SystemCallError, IOError, ArgumentError key ||= path modified = nil end yield( || "you have mail") if @seen.key?(key) && modified && modified != @seen[key] current[key] = modified end @seen = current end |