Class: Nite::Owl::PredicateAction

Inherits:
Action
  • Object
show all
Defined in:
lib/nite/owl/niteowl.rb

Direct Known Subclasses

After, IfNot, OnlyIf

Instance Attribute Summary

Attributes inherited from Action

#parent

Instance Method Summary collapse

Methods inherited from Action

#add, #after, #also, call_all_deferred_actions, #cancel, #changes, #contains?, #created, #current_action, #defer, #delay, #deleted, #handle_delay, #if_not, #ignore, #modified, #only_if, #only_once, #remove, #renamed, #root, #run, #undefer

Constructor Details

#initializePredicateAction

Returns a new instance of PredicateAction.



324
325
326
327
328
# File 'lib/nite/owl/niteowl.rb', line 324

def initialize
  super()
  @time = nil
  @expires = nil
end

Instance Method Details

#call(name, flags) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/nite/owl/niteowl.rb', line 339

def call(name,flags)
  $current_action = self
  begin
    unless @time
      @time = Time.now.to_f
    end
    if expired?
      cancel
    elsif predicate?(name,flags)
      super(name,flags)
      cancel
    else
      defer(name,flags)
    end
  rescue Cancel => c
    undefer()
    @time = nil
  rescue Delay => d
    handle_delay(d)
    defer(name,flags)
  rescue Exception => e
    STDERR.puts e.message
    STDERR.puts e.backtrace
  end
end

#expired?Boolean

Returns:

  • (Boolean)


332
333
334
# File 'lib/nite/owl/niteowl.rb', line 332

def expired?
  @expires and @time and (@time+@expires) >= Time.now.to_f
end

#expires(delay) ⇒ Object



335
336
337
338
# File 'lib/nite/owl/niteowl.rb', line 335

def expires(delay)
  @expires = delay.to_f
  self
end

#predicate?(name, flags) ⇒ Boolean

Returns:

  • (Boolean)


329
330
331
# File 'lib/nite/owl/niteowl.rb', line 329

def predicate?(name,flags)
  true
end