module RubyToUML::UMLInfoGenerator::ProcessorHelpers

Private Instance Methods

add_inheritence_relationship(class_name, superclass_name) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 62
def add_inheritence_relationship(class_name, superclass_name)
  relationships << RelationshipInfo.new(class_name, superclass_name, :inherits)
end
add_module_relationship(class_name, arguments, type) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 78
def add_module_relationship(class_name, arguments, type)
  module_name = get_constant_name(arguments)
  relationships << RelationshipInfo.new(class_name, module_name, type)
end
add_module_relationships_if_exist_closure(class_name) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 66
def add_module_relationships_if_exist_closure(class_name)
  lambda do |node|
    if node.type == :send
      _, method, module_name = *node
      if %i[include extend prepend].include? method
        verb = "#{method}s".to_sym
        add_module_relationship(class_name, module_name, verb)
      end
    end
  end
end
get_arguments(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 117
def get_arguments(node)
  return [] if node.children.nil?

  node.children.each_with_object([]) { |node, args| args << node.children[0] }
end
get_class_body(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 11
def get_class_body(node)
  body_node_index = 2
  node.children[body_node_index]
end
get_class_name(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 6
def get_class_name(node)
  constant, inherit, children = *node
  get_constant_name(constant)
end
get_constant_name(const_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 83
def get_constant_name(const_node)
  constant_name_index = 1
  const_node.children[constant_name_index]
end
get_instance_method_args(def_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 93
def get_instance_method_args(def_node)
  args_index = 1
  get_arguments(def_node.children[args_index])
end
get_instance_methods_closure() click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 21
def get_instance_methods_closure
  type = :public
  lambda do |node, instance_methods_info|
    case node.type
    when :def
      method_name = get_method_name(node)
      args        = get_instance_method_args(node)
      instance_methods_info << InstanceMethodInfo.new(method_name, type, args)
    when :send
      method_name = get_send_method(node)
      new_type    = get_method_type_change(method_name)
      type = new_type if new_type
    end
  end
end
get_instance_variable_name(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 128
def get_instance_variable_name(node)
  name_index = 0
  node.children[name_index]
end
get_instance_variables_closure() click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 47
def get_instance_variables_closure
  lambda do |node, instance_variables_info|
    if node.type == :def && get_method_name(node) == :initialize
      method_body_node = BodyNodeWrapper.new(get_method_body_node(node))
      closure = lambda do |node|
        if node.type == :ivar || node.type == :ivasgn
          variable_name = get_instance_variable_name(node)
          instance_variables_info << variable_name
        end
      end
      method_body_node.simple_operation(&closure)
    end
  end
end
get_method_body_node(def_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 123
def get_method_body_node(def_node)
  body_index = 2
  def_node.children[body_index]
end
get_method_name(def_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 88
def get_method_name(def_node)
  name_index = 0
  def_node.children[name_index]
end
get_method_type_change(method_name) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 103
def get_method_type_change(method_name)
  %i[public private protected].include?(method_name) ? method_name : nil
end
get_module_body(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 138
def get_module_body(node)
  _, body = *node
  body
end
get_module_name(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 133
def get_module_name(node)
  constant, = *node
  get_constant_name(constant)
end
get_send_method(send_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 98
def get_send_method(send_node)
  caller, method, arguments = *send_node
  method
end
get_singleton_method_args(defs_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 112
def get_singleton_method_args(defs_node)
  args_index = 2
  get_arguments(defs_node.children[args_index])
end
get_singleton_method_name(defs_node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 107
def get_singleton_method_name(defs_node)
  name_index = 1
  defs_node.children[name_index]
end
get_singleton_methods_closure() click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 37
def get_singleton_methods_closure
  lambda do |node, singleton_methods_info|
    if node.type == :defs
      method_name = get_singleton_method_name(node)
      args        = get_singleton_method_args(node)
      singleton_methods_info << SingletonMethodInfo.new(method_name, args)
    end
  end
end
get_superclass_name(node) click to toggle source
# File lib/ruby_to_uml/uml_info_generator/processor_helpers.rb, line 16
def get_superclass_name(node)
  constant, inherit, children = *node
  inherit ? get_constant_name(inherit) : nil
end