Module: Garner::Strategies::Keys::Caller

Defined in:
lib/garner/strategies/keys/caller_strategy.rb

Overview

Injects the caller’s location into the key.

Class Method Summary collapse

Class Method Details

.apply(key, context = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/garner/strategies/keys/caller_strategy.rb', line 12

def apply(key, context = {})
  rc = key ? key.dup : {}
  caller.each do |line|
    split = line.split(":")
    next unless split.length >= 2
    path = Pathname.new(split[0]).realpath.to_s
    next if path.include?("lib/garner")
    next unless path.include?("/app/") || path.include?("/spec/")
    rc[field] = "#{path}:#{split[1]}"
    break
  end
  rc
end

.fieldObject



8
9
10
# File 'lib/garner/strategies/keys/caller_strategy.rb', line 8

def field
  :caller
end