Module: WhyQuery

Defined in:
lib/why_query.rb,
lib/why_query/config.rb,
lib/why_query/version.rb,
lib/why_query/railtile.rb

Defined Under Namespace

Classes: Config, Railtie

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



12
13
14
# File 'lib/why_query.rb', line 12

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



14
15
16
# File 'lib/why_query.rb', line 14

def configure
  yield(config)
end

.enabled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/why_query.rb', line 22

def enabled?
  config.enabled
end

.log_originObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/why_query.rb', line 26

def log_origin
  stack = caller_locations(3, 10)

  location = stack.find do |loc|
    path = loc.path
    path.start_with?(Rails.root.to_s) && !path.include?("/gems/")
  end if config.app_only

  location ||= stack[0] # fallback to any top stack

  if location
    config.logger.call("↳ Called from: #{location.path.sub(Rails.root.to_s + "/", "")}:#{location.lineno}")
  end
end