Module: DeferrableGratification

Extended by:
Combinators::ClassMethods, Primitives
Defined in:
lib/deferrable_gratification.rb,
lib/deferrable_gratification/fluent.rb,
lib/deferrable_gratification/bothback.rb,
lib/deferrable_gratification/primitives.rb,
lib/deferrable_gratification/combinators.rb,
lib/deferrable_gratification/combinators/bind.rb,
lib/deferrable_gratification/combinators/join.rb,
lib/deferrable_gratification/default_deferrable.rb

Overview

Deferrable Gratification (DG) makes evented code less error-prone and easier to compose, and thus easier to create higher-level abstractions around. It also enhances the API offered by Ruby Deferrables to make them more pleasant to work with.

Defined Under Namespace

Modules: Bothback, Combinators, Fluent, Primitives Classes: DefaultDeferrable, GuardFailed

Class Method Summary collapse

Methods included from Combinators::ClassMethods

chain, join_first_success, join_successes, loop_until_success

Methods included from Primitives

blank, const, failure, success

Class Method Details

.enhance!(module_or_class) ⇒ Object

Bestow DG goodness upon an existing module or class.

N.B. calling this on a module won’t enhance any classes that have already included that module.



39
40
41
42
43
# File 'lib/deferrable_gratification.rb', line 39

def self.enhance!(module_or_class)
  module_or_class.send :include, Combinators
  module_or_class.send :include, Fluent
  module_or_class.send :include, Bothback
end

.enhance_all_deferrables!Object

Enhance EventMachine::Deferrable itself so that any class including it gets DG goodness. This should mean that all Deferrables in the current process will get enhanced.

N.B. this will not enhance any classes that have already included Deferrable before this method was called, so you should call this before loading any other Deferrable libraries, and before defining any of your own Deferrable classes. (If that isn’t possible, you can always call enhance! on them after definition.)



54
55
56
57
58
59
60
61
62
63
# File 'lib/deferrable_gratification.rb', line 54

def self.enhance_all_deferrables!
  require 'eventmachine'
  require 'em/deferrable'

  enhance! EventMachine::Deferrable

  # Also have to do that to EM::DefaultDeferrable because it included
  # Deferrable before we enhanced it.
  enhance! EventMachine::DefaultDeferrable
end