class SystemNavigation::MethodQuery
Public Class Methods
execute(collection:, query:, behavior: nil, **rest)
click to toggle source
# File lib/system_navigation/method_query.rb, line 3 def self.execute(collection:, query:, behavior: nil, **rest) args = [query] args << rest unless rest.empty? self.new(collection, behavior).__send__(*args) end
new(collection, behavior)
click to toggle source
# File lib/system_navigation/method_query.rb, line 9 def initialize(collection, behavior) @collection = collection @behavior = behavior end
Public Instance Methods
all_in_the_same_file?()
click to toggle source
# File lib/system_navigation/method_query.rb, line 41 def all_in_the_same_file? self.instance_and_singleton_do( for_all: proc { |_scope, _selectors, method| method.source_location[0] } ).as_array.uniq.count == 1 end
convert_to_methods()
click to toggle source
# File lib/system_navigation/method_query.rb, line 14 def convert_to_methods self.instance_and_singleton_do( for_instance: proc { |_scope, _selectors, selector| @behavior.instance_method(selector) }, for_singleton: proc { |_scope, _selectors, selector| @behavior.singleton_class.instance_method(selector) } ) end
find_accessing_methods(var:, only_set:, only_get:)
click to toggle source
# File lib/system_navigation/method_query.rb, line 47 def find_accessing_methods(var:, only_set:, only_get:) self.instance_and_singleton_do( for_all: proc { |_scope, _selectors, method| compiled_method = CompiledMethod.compile(method) if only_set compiled_method.unwrap if compiled_method.writes_field?(var) elsif only_get compiled_method.unwrap if compiled_method.reads_field?(var) else if compiled_method.reads_field?(var) || compiled_method.writes_field?(var) compiled_method.unwrap end end } ) end
find_literal(literal:)
click to toggle source
# File lib/system_navigation/method_query.rb, line 32 def find_literal(literal:) self.instance_and_singleton_do( for_all: proc { |_scope, _selectors, method| compiled_method = CompiledMethod.compile(method) compiled_method.unwrap if compiled_method.has_literal?(literal) } ) end
select_sent_messages()
click to toggle source
# File lib/system_navigation/method_query.rb, line 65 def select_sent_messages self.instance_and_singleton_do( for_all: proc { |_scope, _selectors, method| compiled_method = CompiledMethod.compile(method) compiled_method.sent_messages.uniq.map(&:to_sym) } ) end
tupleize()
click to toggle source
# File lib/system_navigation/method_query.rb, line 26 def tupleize self.instance_and_singleton_do( for_all: proc { |_scope, _selectors, method| [method.name, method] } ) end
Protected Instance Methods
evaluate(callable:, group:, hash:, scope:, selectors:)
click to toggle source
# File lib/system_navigation/method_query.rb, line 88 def evaluate(callable:, group:, hash:, scope:, selectors:) return if callable.nil? result = selectors[group].map do |selector| callable.call(scope, selectors, selector) end hash[scope][group].concat(result) end
instance_and_singleton_do(for_instance: nil, for_singleton: nil, for_all: nil)
click to toggle source
# File lib/system_navigation/method_query.rb, line 76 def instance_and_singleton_do(for_instance: nil, for_singleton: nil, for_all: nil) for_instance = for_all && for_singleton = for_all if for_all @collection.inject(MethodHash.new) do |h, (scope, selectors)| self.evaluate(callable: for_instance, group: :instance, hash: h, scope: scope, selectors: selectors) self.evaluate(callable: for_singleton, group: :singleton, hash: h, scope: scope, selectors: selectors) h end end