Class: Yoda::Store::Objects::Patch::ParentModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/objects/patch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patch) ⇒ ParentModifier

Returns a new instance of ParentModifier.

Parameters:



58
59
60
# File 'lib/yoda/store/objects/patch.rb', line 58

def initialize(patch)
  @patch = patch
end

Instance Attribute Details

#patchObject (readonly)

Returns the value of attribute patch.



55
56
57
# File 'lib/yoda/store/objects/patch.rb', line 55

def patch
  @patch
end

Instance Method Details

#add_address_to_parent(code_object) ⇒ void

This method returns an undefined value.

Parameters:

  • code_object (Base)


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/yoda/store/objects/patch.rb', line 64

def add_address_to_parent(code_object)
  parent_module = patch.find(code_object.parent_address) || create_parent_module(code_object)
  return unless parent_module.namespace?
  patch.register(parent_module) if !patch.has_key?(parent_module.address) && parent_module.address != code_object.address

  case code_object.kind
  when :method
    parent_module.instance_method_addresses.push(code_object.address) unless parent_module.instance_method_addresses.include?(code_object.address)
  when :class, :module, :value
    parent_module.constant_addresses.push(code_object.address) unless parent_module.constant_addresses.include?(code_object.address)
  end
end

#create_parent_module(code_object) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/yoda/store/objects/patch.rb', line 77

def create_parent_module(code_object)
  if code_object.address == code_object.parent_address
    code_object
  elsif MetaClassObject.meta_class_address?(code_object.parent_address)
    MetaClassObject.new(path: MetaClassObject.path_of(code_object.parent_address))
  else
    ModuleObject.new(path: code_object.parent_address)
  end
end