Class: Trans::Api::TorrentDummy
- Inherits:
-
Object
- Object
- Trans::Api::TorrentDummy
- Defined in:
- lib/trans-api/torrent.rb
Overview
Dummy class to handle chained calling Inspired by delayed_job (message_sending.rb) github.com/collectiveidea/delayed_job/blob/master/lib/delayed/message_sending.rb
Instance Method Summary collapse
-
#initialize(task, target_object, place) ⇒ TorrentDummy
constructor
A new instance of TorrentDummy.
-
#method_missing(method, *args) ⇒ Object
handling Torrent method calls.
- #wait ⇒ Object
Constructor Details
#initialize(task, target_object, place) ⇒ TorrentDummy
Returns a new instance of TorrentDummy.
303 304 305 306 307 308 309 |
# File 'lib/trans-api/torrent.rb', line 303 def initialize(task, target_object, place) @task = task # lambda @target_object = target_object @place = place self.wait if @place == :before end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
handling Torrent method calls
312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/trans-api/torrent.rb', line 312 def method_missing(method, *args) unless args.empty? @target_object.send method, *args else @target_object.send method end self.wait if @place == :after end |
Instance Method Details
#wait ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/trans-api/torrent.rb', line 324 def wait begin # keep trying task (and refreshing the torrent file) while true do @target_object.reset! t = @task.call @target_object break if t # task achieved! end rescue Exception => e # some error has occured () @@last_error = {error: "wait_exception", message: e.} end end |