Module: Messaging::Message::Copy

Extended by:
Copy
Included in:
Copy
Defined in:
lib/messaging/message/copy.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(source, receiver = nil, copy: nil, include: nil, exclude: nil, metadata: nil, strict: nil) ⇒ Object



8
9
10
# File 'lib/messaging/message/copy.rb', line 8

def self.call(source, receiver=nil, copy: nil, include: nil, exclude: nil, metadata: nil, strict: nil)
  copy(source, receiver, copy: copy, include: include, exclude: exclude, metadata: , strict: strict)
end

Instance Method Details

#copy(source, receiver = nil, copy: nil, include: nil, exclude: nil, metadata: nil, strict: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/messaging/message/copy.rb', line 12

def copy(source, receiver=nil, copy: nil, include: nil, exclude: nil, metadata: nil, strict: nil)
   ||= false
  strict ||= false

  if receiver.nil?
    receiver = self
  end

  if receiver.class == Class
    receiver = receiver.build
  end

  if copy.nil? && include.nil?
    include = source.class.attribute_names
  end

  begin
    SetAttributes.(receiver, source, copy: copy, include: include, exclude: exclude, strict: strict)
  rescue SetAttributes::Assign::Error => e
    raise Error, e.message, e.backtrace
  end

  if 
     = source..class.attribute_names - [:properties, :local_properties]

    SetAttributes.(receiver., source., include: )

    receiver..properties = source..properties.dup
    receiver..local_properties = source..local_properties.dup
  end

  receiver
end