Class: Peek::Views::View

Inherits:
Object
  • Object
show all
Defined in:
lib/peek/views/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ View

Returns a new instance of View.



4
5
6
7
8
9
# File 'lib/peek/views/view.rb', line 4

def initialize(options = {})
  @options = options

  parse_options
  setup_subscribers
end

Instance Method Details

#contextObject

Additional context for any view to render tooltips for.

Returns Hash.



75
76
77
# File 'lib/peek/views/view.rb', line 75

def context
  {}
end

#context?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/peek/views/view.rb', line 79

def context?
  context.any?
end

#context_idObject

The context id that is derived from the classname.

Examples:

Peek::Views::PerformanceBar => "peek-context-performance-bar"
Peek::Views::Resque => "peek-context-resque"

Returns String.



61
62
63
# File 'lib/peek/views/view.rb', line 61

def context_id
  "peek-context-#{key}"
end

#dom_idObject

The wrapper ID for the individual view in the Peek bar.

Returns String.



68
69
70
# File 'lib/peek/views/view.rb', line 68

def dom_id
  "peek-view-#{key}"
end

#enabled?Boolean

Conditionally enable views based on any gathered data. Helpful if you don’t want views to show up when they return 0 or are touched during the request.

Returns true.

Returns:

  • (Boolean)


24
25
26
# File 'lib/peek/views/view.rb', line 24

def enabled?
  true
end

#keyObject Also known as: defer_key

The defer key that is derived from the classname.

Examples:

Peek::Views::PerformanceBar => "performance-bar"
Peek::Views::Resque => "resque"

Returns String.



48
49
50
# File 'lib/peek/views/view.rb', line 48

def key
  self.class.to_s.split('::').last.underscore.gsub(/\_/, '-')
end

#parse_optionsObject

Where any subclasses should pick and pull from @options to set any and all instance variables they like.

Returns nothing.



15
16
17
# File 'lib/peek/views/view.rb', line 15

def parse_options
  # pass
end

#partial_pathObject

The path to the partial that will be rendered to the Peek bar.

Examples:

Peek::Views::PerformanceBar.partial_path => "peek/views/performance_bar"
CustomResque.partial_path => "performance_bar"

Returns String.



36
37
38
# File 'lib/peek/views/view.rb', line 36

def partial_path
  self.class.to_s.underscore
end

#resultsObject

The data results that are inserted at the end of the request for use in deferred placeholders in the Peek the bar.

Returns Hash.



87
88
89
# File 'lib/peek/views/view.rb', line 87

def results
  {}
end

#results?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/peek/views/view.rb', line 91

def results?
  results.any?
end

#subscribe(*args) ⇒ Object



95
96
97
98
99
# File 'lib/peek/views/view.rb', line 95

def subscribe(*args)
  ActiveSupport::Notifications.subscribe(*args) do |name, start, finish, id, payload|
    yield name, start, finish, id, payload
  end
end