module SystemNavigation::ModuleRefinement
Public Instance Methods
all_messages()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 204 def all_messages MethodQuery.execute( collection: self.own_methods, query: :select_sent_messages) end
all_neighbour_methods?()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 152 def all_neighbour_methods? MethodQuery.execute( collection: self.own_methods, query: :all_in_the_same_file?) end
all_subclasses()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 17 def all_subclasses all_subclasses = [] ObjectSpace.each_object(self.singleton_class) do |klass| all_subclasses.unshift(klass) if klass != self end all_subclasses end
ancestor_methods()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 217 def ancestor_methods AncestorMethodFinder.find_all_ancestors(of: self) end
belongs_to?(gem_name)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 111 def belongs_to?(gem_name) gemspec = Gem::Specification.find_all_by_name(gem_name).last return false if gemspec.nil? || self.own_selectors.empty? pattern = %r{(?:/gems/#{gem_name}-#{gemspec.version}/)|(?:/lib/ruby/[[0-9]\.]+/#{gem_name}/)} match_location = proc { |locations| !!locations.max_by { |_k, value| value }[0].match(pattern) } if self.contains_only_rb_methods? if self.all_neighbour_methods? self.own_methods.as_array.all? do |method| method.source_location.first.match(pattern) end else grouped_locations = self.group_locations_by_path return false if grouped_locations.empty? if grouped_locations.all? { |l| l[0].match(pattern) } true else match_location.call(grouped_locations) end end else grouped_locations = self.group_locations_by_path grouped_locations.delete_if { |k, v| k.nil? } if grouped_locations.empty? false else match_location.call(grouped_locations) end end end
contains_only_rb_methods?()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 148 def contains_only_rb_methods? self.own_methods.as_array.all? { |method| method.source_location } end
group_locations_by_path()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 158 def group_locations_by_path Hash[ self.own_methods.as_array.map do |method| method.source_location && method.source_location.first || nil end.group_by(&:itself).map do |key, value| [key, value.count] end.reject { |k, _v| k.nil? } ] end
includes_selector?(selector)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 221 def includes_selector?(selector) self.own_selectors.as_array.include?(selector) end
own_method_hash()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 93 def own_method_hash MethodQuery.execute( collection: self.own_methods, query: :tupleize) end
own_methods()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 80 def own_methods MethodQuery.execute( collection: self.own_selectors, query: :convert_to_methods, behavior: self) end
own_selectors()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 69 def own_selectors MethodHash.create(based_on: self, include_super: false) end
reachable_method_hash()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 87 def reachable_method_hash MethodQuery.execute( collection: self.reachable_methods, query: :tupleize) end
reachable_methods()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 73 def reachable_methods MethodQuery.execute( collection: self.reachable_selectors, query: :convert_to_methods, behavior: self) end
reachable_selectors()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 65 def reachable_selectors MethodHash.create(based_on: self, include_super: true) end
select_c_methods()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 177 def select_c_methods self.own_methods.as_array.select do |method| compiled_method = CompiledMethod.compile(method) if compiled_method.c_method? compiled_method.unwrap end end end
select_matching_methods(string, match_case)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 168 def select_matching_methods(string, match_case) self.own_methods.as_array.select do |method| compiled_method = CompiledMethod.compile(method) if compiled_method.source_contains?(string, match_case) compiled_method.unwrap end end end
select_methods_that_access(var, only_get, only_set)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 38 def select_methods_that_access(var, only_get, only_set) own_methods = self.own_methods if ancestor_methods.any? ancestor_methods.each do |methods| own_methods.merge!(methods) do |_group, old_h, new_h| old_h.merge!(new_h) { |_key, oldval, newval| oldval | newval } end end end MethodQuery.execute( collection: own_methods, query: :find_accessing_methods, var: var, only_get: only_get, only_set: only_set, behavior: self).as_array end
select_methods_that_refer_to(literal)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 57 def select_methods_that_refer_to(literal) MethodQuery.execute( collection: self.own_methods, query: :find_literal, literal: literal, behavior: self).as_array end
select_rb_methods()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 186 def select_rb_methods self.own_methods.as_array.select do |method| compiled_method = CompiledMethod.compile(method) if compiled_method.rb_method? compiled_method.unwrap end end end
select_senders_of(message)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 195 def select_senders_of(message) self.own_methods.as_array.select do |method| compiled_method = CompiledMethod.compile(method) if compiled_method.sends_message?(message) compiled_method.unwrap end end end
which_global_selectors_refer_to(literal)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 99 def which_global_selectors_refer_to(literal) who = [] self.own_selectors_and_methods do |selector, method| if method.has_literal?(literal) who << selector end end who end
which_selectors_store_into(var)
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 210 def which_selectors_store_into(var) self.selectors.select do |sel| meth = self.instance_method(sel) meth.writes_field?(var) end end
with_all_sub_and_superclasses()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 4 def with_all_sub_and_superclasses Enumerator.new do |y| self.with_all_subclasses.each { |klass| y << klass } self.with_all_superclasses.each { |klass| y << klass } end end
with_all_subclasses()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 11 def with_all_subclasses Enumerator.new do |y| self.all_subclasses.push(self).each { |subclass| y << subclass } end end
with_all_superclasses()
click to toggle source
# File lib/system_navigation/module_refinement.rb, line 27 def with_all_superclasses if self.superclass Enumerator.new do |y| y.yield self.superclass self.superclass.with_all_superclasses.each { |klass| y << klass } end else [] end end