Class: SystemNavigation::MethodQuery
- Inherits:
-
Object
- Object
- SystemNavigation::MethodQuery
- Defined in:
- lib/system_navigation/method_query.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
- #all_in_the_same_file? ⇒ Boolean
- #convert_to_methods ⇒ Object
- #find_accessing_methods(var:, only_set:, only_get:) ⇒ Object
- #find_literal(literal:) ⇒ Object
-
#initialize(collection, behavior) ⇒ MethodQuery
constructor
A new instance of MethodQuery.
- #select_sent_messages ⇒ Object
- #tupleize ⇒ Object
Constructor Details
#initialize(collection, behavior) ⇒ MethodQuery
Returns a new instance of MethodQuery.
9 10 11 12 |
# File 'lib/system_navigation/method_query.rb', line 9 def initialize(collection, behavior) @collection = collection @behavior = behavior end |
Class Method Details
.execute(collection:, query:, behavior: nil, **rest) ⇒ Object
3 4 5 6 7 |
# 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 |
Instance Method Details
#all_in_the_same_file? ⇒ Boolean
41 42 43 44 45 |
# 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 ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# 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:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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:) ⇒ Object
32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/system_navigation/method_query.rb', line 65 def self.instance_and_singleton_do( for_all: proc { |_scope, _selectors, method| compiled_method = CompiledMethod.compile(method) compiled_method..uniq.map(&:to_sym) } ) end |
#tupleize ⇒ Object
26 27 28 29 30 |
# 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 |