lib/archruby/architecture/module_definition.rb in archruby-0.2.0 vs lib/archruby/architecture/module_definition.rb in archruby-0.3.0
- old
+ new
@@ -1,19 +1,20 @@
module Archruby
module Architecture
class ModuleDefinition
- ALLOWED_CONSTRAINTS = ['required', 'allowed', 'forbidden']
+ ALLOWED_CONSTRAINTS = %w(required allowed forbidden)
attr_reader :name, :allowed_modules, :required_modules, :forbidden_modules,
- :dependencies, :classes_and_dependencies, :class_methods_and_deps,
- :class_methods_calls
+ :dependencies, :classes_and_dependencies, :class_methods_and_deps,
+ :class_methods_calls, :type_inference_dependencies,
+ :type_inference_methods_calls
attr_accessor :classes
- def initialize config_definition, base_directory
+ def initialize(config_definition, base_directory)
@config_definition = config_definition
@name = @config_definition.module_name
@allowed_modules = @config_definition.allowed_modules
@required_modules = @config_definition.required_modules
@forbidden_modules = @config_definition.forbidden_modules
@@ -22,55 +23,66 @@
@classes = []
@dependencies = []
@classes_and_dependencies = []
@class_methods_and_deps = []
@class_methods_calls = []
+ @type_inference_dependencies = []
+ @type_inference_methods_calls =[]
extract_content_of_files
extract_dependencies
+ #break type = TypeInferenceChecker.new
end
- def extract_content_of_files file_extractor = Archruby::Architecture::FileContent
+ def extract_content_of_files(file_extractor = Archruby::Architecture::FileContent)
return if !@classes.empty?
file_extractor = file_extractor.new(@base_directory)
@config_definition.files.each do |file|
- file_content = file_extractor.all_content_from_directory file
+ file_content = file_extractor.all_content_from_directory(file)
@files_and_contents << file_content
end
end
- def extract_dependencies ruby_parser = Archruby::Ruby::Parser
+ def extract_dependencies(ruby_parser = Archruby::Ruby::Parser)
return if !@classes.empty?
@files_and_contents.each do |file_and_content|
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
+ @type_inference_dependencies << parser.type_propagation_parser.dependencies
+ @type_inference_methods_calls << parser.type_propagation_parser.method_definitions
end
end
@classes << @config_definition.gems
@classes.flatten!
@dependencies.flatten!
@class_methods_and_deps.flatten!
@class_methods_calls.flatten!
+ @type_inference_dependencies.flatten!
+ @type_inference_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
+ def add_new_dep(class_name, type_inference_dep)
+ if !type_inference_dep.nil? && !already_has_dependency?(class_name, type_inference_dep)
+ new_dep = Archruby::Architecture::Dependency.new(type_inference_dep, nil)
+ @dependencies << type_inference_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
+ # aqui precisamos tomar cuidado quando a classe ainda não está na estrutura
+ # classes and dependencies (tem exemplo disso no findmeontwitter)
+ # precisamos verificar se a dependencia foi adicionada, e caso não tenha sido
+ # devemos adicionar ao final do loop
end
- def already_has_dependency? class_name, class_dep
+ 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)
@@ -81,11 +93,12 @@
end
end
has_dep
end
- def is_mine? class_name
+ def is_mine?(class_name)
+ #binding.pry
splited_class_name = class_name.split('::')
first_class_name = splited_class_name.first
is_mine = false
if first_class_name.empty?
#pocurando por um match exato de dependencia
@@ -148,22 +161,22 @@
def is_empty?
@classes.empty?
end
- def verify_constraints architecture
- required_breaks = verify_required architecture
- forbidden_breaks = verify_forbidden architecture
- allowed_breaks = verify_allowed architecture
+ def verify_constraints(architecture)
+ required_breaks = verify_required(architecture)
+ forbidden_breaks = verify_forbidden(architecture)
+ allowed_breaks = verify_allowed(architecture)
all_constraints_breaks = [required_breaks, forbidden_breaks, allowed_breaks].flatten
all_constraints_breaks.delete(nil)
all_constraints_breaks
end
# Verifica todas as classes do modulo
# Cada uma deve, de alguma forma, depender dos modulos que estao listados como required
- def verify_required architecture
+ def verify_required(architecture)
return if @config_definition.required_modules.empty?
breaks = []
@classes_and_dependencies.each_with_index do |class_and_depencies, index|
if class_and_depencies.empty?
breaks << Archruby::Architecture::ConstraintBreak.new(
@@ -195,11 +208,11 @@
end
end
breaks
end
- def verify_forbidden architecture
+ def verify_forbidden(architecture)
return if @config_definition.forbidden_modules.empty?
breaks = []
@classes_and_dependencies.each do |class_and_depencies|
class_and_depencies.each do |class_name, dependencies|
dependencies.each do |dependency|
@@ -220,10 +233,10 @@
end
end
breaks
end
- def verify_allowed architecture
+ def verify_allowed(architecture)
return if @config_definition.allowed_modules.empty?
breaks = []
@classes_and_dependencies.each do |class_and_depencies|
class_and_depencies.each do |class_name, dependencies|
dependencies.each do |dependency|