class Dependencytree::ClassModel
Model for classes and modules
Attributes
constant_names[R]
full_name_array[R]
method_names[R]
name[R]
parent[R]
path[R]
references[R]
resolved_references[R]
unresolved_references[R]
uuid[R]
Public Class Methods
generator=(generator)
click to toggle source
# File lib/dependencytree/classmodel.rb, line 50 def self.generator=(generator) @@generator = generator end
new(type, path, name)
click to toggle source
type: :class or :module path: the filesystem path the parsed class was found in module_name: eventual module name or :anonymous class_name: the class name
# File lib/dependencytree/classmodel.rb, line 27 def initialize(type, path, name) # unique uuid for reference @uuid = @@generator.uuid # :module or :class @type = type # filesystem path of (first) definition @path = path # local name (without enclosing modules) @name = name # list of names of methods @method_names = [] # list of names of constants @constant_names = [] # list of (unresolved) references as arrays @references = [] # no parent by default (will be set later) @parent = nil @resolved_references = [] @unresolved_references = [] end
Public Instance Methods
add_constant(constant_name)
click to toggle source
Adds a constant by its name to the list of constants.
# File lib/dependencytree/classmodel.rb, line 106 def add_constant(constant_name) @constant_names << constant_name.to_sym end
add_method(method_name)
click to toggle source
Adds a method by its name to the list of methods.
# File lib/dependencytree/classmodel.rb, line 101 def add_method(method_name) @method_names << method_name.to_sym end
add_reference(ref)
click to toggle source
Adds a reference by its array-style full name.
# File lib/dependencytree/classmodel.rb, line 111 def add_reference(ref) @references << ref end
as_json(*a)
click to toggle source
# File lib/dependencytree/classmodel.rb, line 76 def as_json(*a) result = { "uuid" => @uuid, "type" => @type, "path" => @path, "name" => @name, "full_name" => full_name, "methods" => @method_names, "constants" => @constant_names, "refs" => @references.uniq.each_with_object([]) { |clazz, arr| arr<<clazz.join("::") }, "resolved_refs" => @resolved_references.uniq, "unresolved_refs" => @unresolved_references.uniq.each_with_object([]) { |clazz, arr| arr<<clazz.join("::") } } if @parent result["parent_uuid"] = @parent.uuid end result end
full_name()
click to toggle source
Gets the full name of the class/module. @return the full name, for example “ModuleA::ModuleB::ClassA”
# File lib/dependencytree/classmodel.rb, line 67 def full_name full_name_array.join("::") end
set_parent(parent)
click to toggle source
# File lib/dependencytree/classmodel.rb, line 71 def set_parent(parent) raise ArgumentError, "Self parent reference for name #{@name}" if parent == self @parent = parent end
to_json(*a)
click to toggle source
# File lib/dependencytree/classmodel.rb, line 96 def to_json(*a) as_json.to_json(*a) end