Class: XDry::Generators::Dealloc

Inherits:
Generator show all
Defined in:
lib/xdry/generators/dealloc.rb

Instance Attribute Summary

Attributes inherited from Generator

#patcher

Instance Method Summary collapse

Methods inherited from Generator

id, inherited, #initialize, #process_attribute, #verbose?

Constructor Details

This class inherits a constructor from XDry::Generators::Generator

Instance Method Details

#process_class(oclass) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xdry/generators/dealloc.rb', line 16

def process_class oclass
  # avoid generation of empty deallocs
  lines = generate_release_calls_if(oclass) { true }
  return if lines.empty?

  MethodPatcher.new(patcher, oclass, 'dealloc', ImplementationStartIP.new(oclass), DEALLOC_CODE) do |dealloc_method|
    impl = dealloc_method.impl
    ip = BeforeSuperCallIP.new(impl)

    existing_releases = impl.children.select { |child| child.is_a? NReleaseCall }
    lines = generate_release_calls_if(oclass) do |oattr|
      !existing_releases.any? { |n| n.expr == oattr.field_name || n.expr == "self.#{oattr.name}" }
    end

    ip.insert @patcher, lines unless lines.empty?
  end
end