Class: ClassSource::Index
- Inherits:
-
Object
- Object
- ClassSource::Index
- Defined in:
- lib/class_source/index.rb
Overview
An index of all source code available for a class
Instance Method Summary collapse
-
#==(value) ⇒ Object
Convenience method for comparing sources as string values.
-
#all(options = {}) ⇒ Hash
Returns a hash of source code fragments indexed by location.
-
#class_methods ⇒ Object
Returns an index of all methods found for the class.
-
#files ⇒ Object
Returns an array of file containing relevant source code.
-
#initialize(target_class, options = {}) ⇒ Index
constructor
A new instance of Index.
-
#locations(options = {}) ⇒ Array
Returns an array of source code locations.
-
#locator ⇒ Object
Returns an instance of the source locator object that searches out source locations.
-
#methods ⇒ Object
Returns an index of all methods found for the class.
-
#to_s(options = {}) ⇒ String
This returns a string containing all the class’ source code.
Constructor Details
#initialize(target_class, options = {}) ⇒ Index
Returns a new instance of Index.
6 7 8 9 |
# File 'lib/class_source/index.rb', line 6 def initialize(target_class, = {}) @target_class = target_class @options = end |
Instance Method Details
#==(value) ⇒ Object
Convenience method for comparing sources as string values
35 36 37 |
# File 'lib/class_source/index.rb', line 35 def ==(value) to_s == value end |
#all(options = {}) ⇒ Hash
Returns a hash of source code fragments indexed by location
23 24 25 |
# File 'lib/class_source/index.rb', line 23 def all(={}) @collator ||= Collator.new(@target_class, self).to_hash() end |
#class_methods ⇒ Object
Returns an index of all methods found for the class
47 48 49 |
# File 'lib/class_source/index.rb', line 47 def class_methods methods.klass end |
#files ⇒ Object
Returns an array of file containing relevant source code
59 60 61 |
# File 'lib/class_source/index.rb', line 59 def files locator.files end |
#locations(options = {}) ⇒ Array
Returns an array of source code locations
29 30 31 |
# File 'lib/class_source/index.rb', line 29 def locations(={}) locator.to_a end |
#locator ⇒ Object
Returns an instance of the source locator object that searches out source locations
53 54 55 |
# File 'lib/class_source/index.rb', line 53 def locator @locator ||= Locator.new(@target_class, @options) end |
#methods ⇒ Object
Returns an index of all methods found for the class
41 42 43 |
# File 'lib/class_source/index.rb', line 41 def methods @method_details ||= MethodIndex.new(@target_class) end |
#to_s(options = {}) ⇒ String
This returns a string containing all the class’ source code. Order is not guaranteed to match evaluation order.
16 17 18 |
# File 'lib/class_source/index.rb', line 16 def to_s(={}) all().values.join("") end |