lib/archruby/architecture/module_definition.rb in archruby-0.1.1 vs lib/archruby/architecture/module_definition.rb in archruby-0.2.0

- old
+ new

@@ -4,11 +4,12 @@ class ModuleDefinition ALLOWED_CONSTRAINTS = ['required', 'allowed', 'forbidden'] attr_reader :name, :allowed_modules, :required_modules, :forbidden_modules, - :dependencies, :classes_and_dependencies + :dependencies, :classes_and_dependencies, :class_methods_and_deps, + :class_methods_calls attr_accessor :classes def initialize config_definition, base_directory @config_definition = config_definition @@ -19,10 +20,12 @@ @base_directory = base_directory @files_and_contents = [] @classes = [] @dependencies = [] @classes_and_dependencies = [] + @class_methods_and_deps = [] + @class_methods_calls = [] extract_content_of_files extract_dependencies end def extract_content_of_files file_extractor = Archruby::Architecture::FileContent @@ -40,17 +43,48 @@ file_and_content.each do |file_name, content| parser = ruby_parser.new content @classes << parser.classes @dependencies << parser.dependencies @classes_and_dependencies << parser.classes_and_dependencies + @class_methods_and_deps << parser.type_inference + @class_methods_calls << parser.method_calls end end @classes << @config_definition.gems @classes.flatten! @dependencies.flatten! + @class_methods_and_deps.flatten! + @class_methods_calls.flatten! end + def add_new_dep class_name, type_inference_dep + if !type_inference_dep.class_dep.nil? && !already_has_dependency?(class_name, type_inference_dep.class_dep) + new_dep = Archruby::Architecture::Dependency.new(type_inference_dep.class_dep, nil) + @dependencies << type_inference_dep.class_dep + @classes_and_dependencies.each do |class_and_dep| + if class_and_dep.keys.first.eql?(class_name) + class_and_dep[class_and_dep.keys.first].push(new_dep) + end + end + end + end + + def already_has_dependency? class_name, class_dep + has_dep = false + @classes_and_dependencies.each do |class_and_dep| + if class_and_dep.keys.first.eql?(class_name) + class_and_dep[class_and_dep.keys.first].each do |dependency| + if dependency.class_name.eql?(class_dep) + has_dep = true + break + end + end + end + end + has_dep + end + def is_mine? class_name splited_class_name = class_name.split('::') first_class_name = splited_class_name.first is_mine = false if first_class_name.empty? @@ -195,10 +229,10 @@ class_and_depencies.each do |class_name, dependencies| dependencies.each do |dependency| module_name = architecture.module_name(dependency.class_name) next if architecture.is_ruby_internals? module_name if module_name != self.name && !@config_definition.allowed_modules.include?(module_name) - next if /[A-Z]_+[A-Z]/.match(dependency.class_name) + next if /[A-Z]_+[A-Z]/.match(dependency.class_name) || @config_definition.required_modules.include?(module_name) breaks << Archruby::Architecture::ConstraintBreak.new( :type => 'divergence', :class_origin => class_name, :line_origin => dependency.line_number, :class_target => dependency.class_name,