Class: SystemNavigation
- Inherits:
-
Object
- Object
- SystemNavigation
- Extended by:
- Forwardable
- Defined in:
- lib/system_navigation.rb,
lib/system_navigation/method_hash.rb,
lib/system_navigation/method_query.rb,
lib/system_navigation/compiled_method.rb,
lib/system_navigation/expression_tree.rb,
lib/system_navigation/array_refinement.rb,
lib/system_navigation/ruby_environment.rb,
lib/system_navigation/module_refinement.rb,
lib/system_navigation/instruction_stream.rb,
lib/system_navigation/ancestor_method_finder.rb,
lib/system_navigation/instruction_stream/decoder.rb,
lib/system_navigation/instruction_stream/instruction.rb,
lib/system_navigation/instruction_stream/instruction/attr_instruction.rb
Defined Under Namespace
Modules: ArrayRefinement, ModuleRefinement Classes: AncestorMethodFinder, CompiledMethod, ExpressionTree, InstructionStream, MethodHash, MethodQuery, RubyEnvironment
Constant Summary collapse
- VERSION_FILE =
The VERSION file must be in the root directory of the library.
File.('../../VERSION', __FILE__)
- VERSION =
File.exist?(VERSION_FILE) ? File.read(VERSION_FILE).chomp : '(could not find VERSION file)'
Class Method Summary collapse
Instance Method Summary collapse
-
#all_accesses(to:, from: nil, only_get: nil, only_set: nil) ⇒ Array<UnboundMethod>
Query methods for instance variables in descending (subclasses) and ascending (superclasses) fashion.
-
#all_c_methods ⇒ Array<UnboundMethod>
Get all methods implemented in C.
-
#all_calls(on:, from: nil, gem: nil) ⇒ Array<UnboundMethod>
Query methods for literals they call.
-
#all_classes_and_modules_in_gem_named(gem) ⇒ Array<Class, Module>
Query gems for classes and modules they implement.
-
#all_classes_implementing(selector) ⇒ Array<Class>
Query classes for the methods they implement.
-
#all_classes_in_gem_named(gem) ⇒ Array<Class>
Query gems for classes they implement.
-
#all_implementors_of(selector) ⇒ Array<Class, Module>
Query classes and modules for the methods they implement.
-
#all_methods ⇒ Array<UnboundMethod>
Get all methods defined in current Ruby process.
-
#all_methods_with_source(string:, match_case: true) ⇒ Array<UnboundMethod>
Search for a string in all classes and modules including their comments and names.
-
#all_modules_implementing(selector) ⇒ Array<Class>
Query modules for the methods they implement.
-
#all_modules_in_gem_named(gem) ⇒ Array<Class>
Query gems for modules they implement.
-
#all_rb_methods ⇒ Array<UnboundMethod>
Get all methods implemented in Ruby.
-
#all_senders_of(message) ⇒ Array<UnboundMethod>
Get all methods that implement
message. -
#all_sent_messages ⇒ Array<Symbol>
Get all messages that all methods send.
-
#initialize ⇒ SystemNavigation
constructor
A new instance of SystemNavigation.
Constructor Details
#initialize ⇒ SystemNavigation
Returns a new instance of SystemNavigation.
38 39 40 |
# File 'lib/system_navigation.rb', line 38 def initialize @environment = ::RubyEnvironment.new end |
Class Method Details
.default ⇒ Object
34 35 36 |
# File 'lib/system_navigation.rb', line 34 def self.default self.new end |
Instance Method Details
#all_accesses(to:, from: nil, only_get: nil, only_set: nil) ⇒ Array<UnboundMethod>
This is a very costly operation, if you don’t provide the from argument
Query methods for instance variables in descending (subclasses) and ascending (superclasses) fashion.
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/system_navigation.rb', line 100 def all_accesses(to:, from: nil, only_get: nil, only_set: nil) if only_set && only_get fail ArgumentError, 'both only_get and only_set were provided' end if from && !from.instance_of?(Class) fail TypeError, "from must be a Class (#{from.class} given)" end (from || BasicObject).with_all_sub_and_superclasses.flat_map do |klass| klass.select_methods_that_access(to, only_get, only_set) end end |
#all_c_methods ⇒ Array<UnboundMethod>
Get all methods implemented in C.
325 326 327 328 329 |
# File 'lib/system_navigation.rb', line 325 def all_c_methods self.all_classes_and_modules.flat_map do |klassmod| klassmod.select_c_methods end end |
#all_calls(on:, from: nil, gem: nil) ⇒ Array<UnboundMethod>
This is a very costly operation, if you don’t provide the from argument
The list of supported literals can be found here: ruby-doc.org/core-2.2.2/doc/syntax/literals_rdoc.html
Query methods for literals they call.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/system_navigation.rb', line 165 def all_calls(on:, from: nil, gem: nil) if from && gem fail ArgumentError, 'both from and gem were provided' end subject = if from from.with_all_subclasses elsif gem self.all_classes_and_modules_in_gem_named(gem) else self.all_classes_and_modules end subject.flat_map { |behavior| behavior.select_methods_that_refer_to(on) } end |
#all_classes_and_modules_in_gem_named(gem) ⇒ Array<Class, Module>
Query gems for classes and modules they implement.
260 261 262 |
# File 'lib/system_navigation.rb', line 260 def all_classes_and_modules_in_gem_named(gem) self.all_classes_and_modules.select { |klassmod| klassmod.belongs_to?(gem) } end |
#all_classes_implementing(selector) ⇒ Array<Class>
Query classes for the methods they implement.
191 192 193 |
# File 'lib/system_navigation.rb', line 191 def all_classes_implementing(selector) self.all_classes.select { |klass| klass.includes_selector?(selector) } end |
#all_classes_in_gem_named(gem) ⇒ Array<Class>
Query gems for classes they implement.
233 234 235 |
# File 'lib/system_navigation.rb', line 233 def all_classes_in_gem_named(gem) self.all_classes.select { |klass| klass.belongs_to?(gem) } end |
#all_implementors_of(selector) ⇒ Array<Class, Module>
Query classes and modules for the methods they implement.
217 218 219 220 221 |
# File 'lib/system_navigation.rb', line 217 def all_implementors_of(selector) self.all_classes_and_modules.select do |klass| klass.includes_selector?(selector) end end |
#all_methods ⇒ Array<UnboundMethod>
Get all methods defined in current Ruby process.
272 273 274 275 276 |
# File 'lib/system_navigation.rb', line 272 def all_methods self.all_classes_and_modules.map do |klassmod| klassmod.own_methods.as_array end.flatten end |
#all_methods_with_source(string:, match_case: true) ⇒ Array<UnboundMethod>
This is a very costly operation
Search for a string in all classes and modules including their comments and names.
sn.all_methods_with_source(string: ‘hello_hi’) #=> [#<UnboundMethod: B#bar>, #<UnboundMethod: A#foo>, #<UnboundMethod: M#foo>]
309 310 311 312 313 314 315 |
# File 'lib/system_navigation.rb', line 309 def all_methods_with_source(string:, match_case: true) return [] if string.empty? self.all_classes_and_modules.flat_map do |klassmod| klassmod.select_matching_methods(string, match_case) end end |
#all_modules_implementing(selector) ⇒ Array<Class>
Query modules for the methods they implement.
204 205 206 |
# File 'lib/system_navigation.rb', line 204 def all_modules_implementing(selector) self.all_modules.select { |mod| mod.includes_selector?(selector) } end |
#all_modules_in_gem_named(gem) ⇒ Array<Class>
Query gems for modules they implement.
246 247 248 |
# File 'lib/system_navigation.rb', line 246 def all_modules_in_gem_named(gem) self.all_modules.select { |mod| mod.belongs_to?(gem) } end |
#all_rb_methods ⇒ Array<UnboundMethod>
Get all methods implemented in Ruby.
339 340 341 342 343 |
# File 'lib/system_navigation.rb', line 339 def all_rb_methods self.all_classes_and_modules.flat_map do |klassmod| klassmod.select_rb_methods end end |
#all_senders_of(message) ⇒ Array<UnboundMethod>
Get all methods that implement message.
354 355 356 357 358 |
# File 'lib/system_navigation.rb', line 354 def all_senders_of() self.all_classes_and_modules.flat_map do |klassmod| klassmod.select_senders_of() end end |
#all_sent_messages ⇒ Array<Symbol>
This is a very costly operation
Get all messages that all methods send.
369 370 371 372 373 |
# File 'lib/system_navigation.rb', line 369 def self.all_classes_and_modules.flat_map do |klassmod| klassmod..as_array end.uniq end |