Module: ClassDependencies::BaseModuleMethods

Includes:
ClassName
Defined in:
lib/class_dependencies.rb

Overview

methods for the base module, on which the dependency map and descendants list live

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassName

#class_to_sym, #sym_to_class

Instance Attribute Details

#relationship_nameObject (readonly)

Returns the value of attribute relationship_name.



116
117
118
# File 'lib/class_dependencies.rb', line 116

def relationship_name
  @relationship_name
end

Instance Method Details

#add_dependency(from, to) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/class_dependencies.rb', line 122

def add_dependency(from, to)
  from_sym = class_to_sym(from)
  to_sym = class_to_sym(to)
  return if from_sym == to_sym
  deps = (class_dependencies[from_sym] ||= [])
  raise "circular dependency" if all_dependencies_of(to_sym).include?(from_sym)
  deps << to_sym
  nil
end

#all_dependencies_of(from) ⇒ Object



132
133
134
135
# File 'lib/class_dependencies.rb', line 132

def all_dependencies_of(from)
  from_sym = class_to_sym(from)
  find_dependencies_of(from_sym, Set.new()).delete(from_sym).to_a
end

#all_dependencies_of_classes(from) ⇒ Object



137
138
139
# File 'lib/class_dependencies.rb', line 137

def all_dependencies_of_classes(from)
  all_dependencies_of(from).map{|sym| sym_to_class(sym)}
end

#descendant_classesObject



149
150
151
# File 'lib/class_dependencies.rb', line 149

def descendant_classes
  descendants.map{|sym| sym_to_class(sym)}
end

#ordered_dependenciesObject



141
142
143
# File 'lib/class_dependencies.rb', line 141

def ordered_dependencies
  class_dependencies.tsort
end

#ordered_dependent_classesObject



145
146
147
# File 'lib/class_dependencies.rb', line 145

def ordered_dependent_classes
  ordered_dependencies.map{|sym| sym_to_class(sym)}
end

#set_relationship_name(name) ⇒ Object



118
119
120
# File 'lib/class_dependencies.rb', line 118

def set_relationship_name(name)
  @relationship_name = name
end