Module: Peek

Defined in:
lib/peek.rb,
lib/peek/railtie.rb,
lib/peek/version.rb,
lib/peek/views/view.rb,
lib/peek/adapters/base.rb,
lib/peek/adapters/redis.rb,
lib/peek/adapters/memory.rb,
lib/peek/adapters/memcache.rb,
lib/peek/controller_helpers.rb,
lib/peek/adapters/elasticsearch.rb,
app/controllers/peek/results_controller.rb

Defined Under Namespace

Modules: Adapters, ControllerHelpers, Views Classes: Railtie, ResultsController

Constant Summary collapse

ALLOWED_ENVS =
['development', 'staging'].freeze
VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.adapterObject


10
11
12
# File 'lib/peek.rb', line 10

def self.adapter
  @adapter
end

.adapter=(*adapter_options) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/peek.rb', line 14

def self.adapter=(*adapter_options)
  adapter, *parameters = *Array.wrap(adapter_options).flatten

  @adapter = case adapter
  when Symbol
    adapter_class_name = adapter.to_s.camelize
    adapter_class =
      begin
        require "peek/adapters/#{adapter}"
      rescue LoadError => e
        raise "Could not find adapter for #{adapter} (#{e})"
      else
        Peek::Adapters.const_get(adapter_class_name)
      end
    adapter_class.new(*parameters)
  when nil
    Peek::Adapters::Memory.new
  else
    adapter
  end

  @adapter
end

.enabled?Boolean


38
39
40
# File 'lib/peek.rb', line 38

def self.enabled?
  ALLOWED_ENVS.include?(env)
end

.envObject


42
43
44
# File 'lib/peek.rb', line 42

def self.env
  Rails.env
end

.into(klass, options = {}) ⇒ Object


73
74
75
76
# File 'lib/peek.rb', line 73

def self.into(klass, options = {})
  @views ||= []
  @views << [klass, options]
end

.resetObject

Clears out any and all views.

Returns nothing.


81
82
83
84
# File 'lib/peek.rb', line 81

def self.reset
  @views = nil
  @cached_views = nil
end

.resultsObject


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/peek.rb', line 54

def self.results
  results = {
    context: {},
    data: Hash.new { |h, k| h[k] = {} }
  }

  views.each do |view|
    if view.context?
      results[:context][view.key] = view.context
    end

    view.results.each do |key, value|
      results[:data][view.key][key] = value
    end
  end

  results
end

.setupObject


86
87
88
# File 'lib/peek.rb', line 86

def self.setup
  ActiveSupport::Deprecation.warn "'Peek.setup' is deprecated and does nothing.", caller
end

.viewsObject


46
47
48
49
50
51
52
# File 'lib/peek.rb', line 46

def self.views
  @cached_views ||= if @views && @views.any?
    @views.collect { |klass, options| klass.new(options.dup) }.select(&:enabled?)
  else
    []
  end
end