Class: Glimpse::Views::View

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ View

Returns a new instance of View.



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

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

  setup_subscribers
end

Instance Method Details

#contextObject

Additional context for any view to render tooltips for.

Returns Hash.



65
66
67
# File 'lib/glimpse/views/view.rb', line 65

def context
  {}
end

#context?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/glimpse/views/view.rb', line 69

def context?
  context.any?
end

#context_dom_idObject

The context dom id that is derived from the classname.

Examples:

Glimpse::Views::PerformanceBar => "glimpse-context-performance-bar"
Glimpse::Views::Resque => "glimpse-context-resque"

Returns String.



51
52
53
# File 'lib/glimpse/views/view.rb', line 51

def context_dom_id
  "glimpse-context-#{defer_key}"
end

#defer_keyObject

The defer key that is derived from the classname.

Examples:

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

Returns String.



39
40
41
# File 'lib/glimpse/views/view.rb', line 39

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

#dom_idObject

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

Returns String.



58
59
60
# File 'lib/glimpse/views/view.rb', line 58

def dom_id
  "glimpse-view-#{defer_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)


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

def enabled?
  true
end

#partial_pathObject

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

Examples:

Glimpse::Views::PerformanceBar.partial_path => "glimpse/views/performance_bar"
CustomResque.partial_path => "performance_bar"

Returns String.



27
28
29
# File 'lib/glimpse/views/view.rb', line 27

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 Glimpse the bar.

Returns Hash.



77
78
79
# File 'lib/glimpse/views/view.rb', line 77

def results
  {}
end

#results?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/glimpse/views/view.rb', line 81

def results?
  results.any?
end

#subscribe(*args) ⇒ Object



85
86
87
88
89
# File 'lib/glimpse/views/view.rb', line 85

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