Class: RubyDetective::SourceRepresentation::Entities::Klass
- Defined in:
- lib/ruby_detective/source_representation/entities/klass.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#inheritance_class_name ⇒ Object
readonly
Returns the value of attribute inheritance_class_name.
-
#lines_of_code ⇒ Object
readonly
Returns the value of attribute lines_of_code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #constants ⇒ Object
- #dependencies ⇒ Object
- #dependents ⇒ Object
-
#initialize(name, namespace, inheritance_class_name: nil, file_path:, first_line:, last_line:) ⇒ Klass
constructor
A new instance of Klass.
- #merge(duplicate) ⇒ Object
Methods inherited from Base
#absolute_path?, #namespace_as_text, #namespace_without_root_sign, #path, #path_as_text, #path_without_root_sign
Constructor Details
#initialize(name, namespace, inheritance_class_name: nil, file_path:, first_line:, last_line:) ⇒ Klass
Returns a new instance of Klass.
7 8 9 10 11 12 13 14 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 7 def initialize(name, namespace, inheritance_class_name: nil, file_path:, first_line:, last_line:) @name = name @namespace = namespace @file_path = file_path @inheritance_class_name = inheritance_class_name @lines_of_code = last_line - first_line + 1 @data_store = SourceRepresentation::DataStore.instance end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 5 def file_path @file_path end |
#inheritance_class_name ⇒ Object (readonly)
Returns the value of attribute inheritance_class_name.
5 6 7 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 5 def inheritance_class_name @inheritance_class_name end |
#lines_of_code ⇒ Object (readonly)
Returns the value of attribute lines_of_code.
5 6 7 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 5 def lines_of_code @lines_of_code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 5 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 5 def namespace @namespace end |
Instance Method Details
#constants ⇒ Object
16 17 18 19 20 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 16 def constants data_store .query .constants(where: { caller: self }) end |
#dependencies ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 22 def dependencies constants .map(&:refers_to) .compact .reject{ |c| c.name == name } # Removes circular dependencies end |
#dependents ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 29 def dependents data_store.query .constants(where: { refers_to: self }) .map(&:caller) .compact .reject{ |c| c.name == name } # Removes circular dependencies end |
#merge(duplicate) ⇒ Object
37 38 39 40 |
# File 'lib/ruby_detective/source_representation/entities/klass.rb', line 37 def merge(duplicate) @inheritance_class_name ||= duplicate.inheritance_class_name @lines_of_code += duplicate.lines_of_code end |