Class: Jiminy::Recording::NPlusOne

Inherits:
Object
  • Object
show all
Defined in:
lib/jiminy/recording/n_plus_one.rb

Constant Summary collapse

LOCATION_REGEXP =
%r{^
(?<file>[\w_\-/.]+\.(?:erb|rb|jbuilder)):
(?<line>\d+):in\s`(?:block\sin\s)?
(?<method>[^']+)'?}x.freeze
EXAMPLES_COUNT =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, queries: []) ⇒ NPlusOne

Returns a new instance of NPlusOne.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jiminy/recording/n_plus_one.rb', line 15

def initialize(location:, queries: [])
  @location = location.to_s.strip
  @queries = queries
  match_result = location.match(LOCATION_REGEXP)

  @file = match_result[:file]
  @line = match_result[:line]
  @method_name = match_result[:method]

  freeze
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/jiminy/recording/n_plus_one.rb', line 6

def file
  @file
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/jiminy/recording/n_plus_one.rb', line 6

def location
  @location
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
# File 'lib/jiminy/recording/n_plus_one.rb', line 27

def ==(other)
  location == other.location
end

#to_hObject



31
32
33
34
35
# File 'lib/jiminy/recording/n_plus_one.rb', line 31

def to_h
  {
    location => attributes
  }
end