Class: Domain::Equalizer

Inherits:
Module
  • Object
show all
Defined in:
lib/domain/support/equalizer.rb

Defined Under Namespace

Modules: Methods

Instance Method Summary collapse

Constructor Details

#initialize(components = nil, &bl) ⇒ Equalizer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates an Equalizer instance.

Parameters:

  • bl (Proc)

    the proc to use to extract components that participate to equality



13
14
15
16
17
18
19
20
21
# File 'lib/domain/support/equalizer.rb', line 13

def initialize(components = nil, &bl)
  extractor = case components
              when NilClass then bl
              when Symbol   then proc{ [ send(components) ] }
              when Array    then proc{ components.map{|n| send(n)} }
              end
  define_method(:equality_components, &extractor)
  module_eval{ include(Methods) }
end