Module: Domain::Reuse

Defined in:
lib/domain/factory/reuse.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.class_module(reuse_domain, predicate) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/domain/factory/reuse.rb', line 10

def self.class_module(reuse_domain, predicate)
  Module.new{
    define_method(:predicate) do
      predicate
    end
    define_method(:domain_check!) do |i|
      domain_error!(i) unless reuse_domain===i && predicate.call(i)
    end
  }
end

.instance_module(reuse_domain) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/domain/factory/reuse.rb', line 21

def self.instance_module(reuse_domain)
  Module.new{
    define_method(:initialize) do |arg|
      @reused_instance = arg
    end
    define_method(:reused_instance) do
      @reused_instance
    end
    protected :reused_instance
    include Equalizer.new(:reused_instance)
  }
end

.new(reuse_domain, predicate = nil, &bl) ⇒ Object



4
5
6
7
8
# File 'lib/domain/factory/reuse.rb', line 4

def self.new(reuse_domain, predicate = nil, &bl)
  predicate = predicate || bl || Domain::TRUE_PREDICATE
  DomainFactory.factor [ Helpers, class_module(reuse_domain, predicate) ],
                       [ instance_module(reuse_domain) ]
end