Class: MetricFu::Location
- Inherits:
-
Object
- Object
- MetricFu::Location
- Includes:
- Comparable
- Defined in:
- lib/base/location.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#simple_method_name ⇒ Object
Returns the value of attribute simple_method_name.
Class Method Summary collapse
-
.for(class_or_method_name) ⇒ Object
END we need these methods as a temporary hack where we’re using Location as a hash key.
- .get(file_path, class_name, method_name) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#eql?(other) ⇒ Boolean
TODO - we need this method (and hash accessor above) as a temporary hack where we’re using Location as a hash key.
-
#initialize(file_path, class_name, method_name) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(file_path, class_name, method_name) ⇒ Location
Returns a new instance of Location.
24 25 26 27 28 29 30 |
# File 'lib/base/location.rb', line 24 def initialize(file_path, class_name, method_name) @file_path = file_path @class_name = class_name @method_name = method_name @simple_method_name = @method_name.sub(@class_name,'') unless @method_name == nil @hash = [@file_path, @class_name, @method_name].hash end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
5 6 7 |
# File 'lib/base/location.rb', line 5 def class_name @class_name end |
#file_path ⇒ Object
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/base/location.rb', line 5 def file_path @file_path end |
#hash ⇒ Object
Returns the value of attribute hash.
5 6 7 |
# File 'lib/base/location.rb', line 5 def hash @hash end |
#method_name ⇒ Object
Returns the value of attribute method_name.
5 6 7 |
# File 'lib/base/location.rb', line 5 def method_name @method_name end |
#simple_method_name ⇒ Object
Returns the value of attribute simple_method_name.
5 6 7 |
# File 'lib/base/location.rb', line 5 def simple_method_name @simple_method_name end |
Class Method Details
.for(class_or_method_name) ⇒ Object
END we need these methods as a temporary hack where we’re using Location as a hash key
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/base/location.rb', line 38 def self.for(class_or_method_name) class_or_method_name = strip_modules(class_or_method_name) if(class_or_method_name) begin match = class_or_method_name.match(/(.*)((\.|\#|\:\:[a-z])(.+))/) rescue => error #new error during port to metric_fu occasionally a unintialized #MatchData object shows up here. Not expected. match = nil end # reek reports the method with :: not # on modules like # module ApplicationHelper \n def signed_in?, convert it so it records correctly # but classes have to start with a capital letter... HACK for REEK bug, reported underlying issue to REEK if(match) class_name = strip_modules(match[1]) method_name = class_or_method_name.gsub(/\:\:/,"#") else class_name = strip_modules(class_or_method_name) method_name = nil end else class_name = nil method_name = nil end self.get(nil, class_name, method_name) end |
.get(file_path, class_name, method_name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/base/location.rb', line 7 def self.get(file_path, class_name, method_name) # This could be more 'confident' using Maybe, but we want it to be as fast as possible file_path_copy = file_path == nil ? nil : file_path.clone class_name_copy = class_name == nil ? nil : class_name.clone method_name_copy = method_name == nil ? nil : method_name.clone key = [file_path_copy, class_name_copy, method_name_copy] @@locations ||= {} if @@locations.has_key?(key) @@locations[key] else location = self.new(file_path_copy, class_name_copy, method_name_copy) @@locations[key] = location location.freeze # we cache a lot of method call results, so we want location to be immutable location end end |
Instance Method Details
#<=>(other) ⇒ Object
66 67 68 |
# File 'lib/base/location.rb', line 66 def <=>(other) [self.file_path.to_s, self.class_name.to_s, self.method_name.to_s] <=> [other.file_path.to_s, other.class_name.to_s, other.method_name.to_s] end |
#eql?(other) ⇒ Boolean
TODO - we need this method (and hash accessor above) as a temporary hack where we’re using Location as a hash key
33 34 35 |
# File 'lib/base/location.rb', line 33 def eql?(other) [self.file_path.to_s, self.class_name.to_s, self.method_name.to_s] == [other.file_path.to_s, other.class_name.to_s, other.method_name.to_s] end |