Module: MetaRequest::Utils

Defined in:
lib/meta_request/utils.rb

Class Method Summary collapse

Class Method Details

.dev_callsite(caller) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/meta_request/utils.rb', line 7

def dev_callsite(caller)
  app_line = caller.detect { |c| valid_application_path? c }
  return nil unless app_line

  _, filename, _, line, _, method = app_line.split(/^(.*?)(:(\d+))(:in `(.*)')?$/)

  {
    filename: sub_source_path(filename),
    line: line.to_i,
    method: method
  }
end

.ignored_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/meta_request/utils.rb', line 32

def ignored_path?(path)
  MetaRequest.config.ignored_paths.any? do |ignored_path|
    path.start_with?(ignored_path.to_s)
  end
end

.sub_source_path(path) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/meta_request/utils.rb', line 20

def sub_source_path(path)
  rails_root = MetaRequest.rails_root
  source_path = MetaRequest.config.source_path
  return path if rails_root == source_path

  path.sub(rails_root, source_path)
end

.valid_application_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/meta_request/utils.rb', line 28

def valid_application_path?(path)
  path.start_with?(MetaRequest.rails_root) && !ignored_path?(path)
end