peek-1.1.0/ 0000755 0000041 0000041 00000000000 13546140043 012465 5 ustar www-data www-data peek-1.1.0/.travis.yml 0000644 0000041 0000041 00000000174 13546140043 014600 0 ustar www-data www-data language: ruby
rvm:
- 2.3.1
- 2.2.5
gemfile:
- Gemfile # Rails 5
- Gemfile-rails42
notifications:
email: false
peek-1.1.0/test/ 0000755 0000041 0000041 00000000000 13546140043 013444 5 ustar www-data www-data peek-1.1.0/test/peek_test.rb 0000644 0000041 0000041 00000002515 13546140043 015757 0 ustar www-data www-data require 'test_helper'
class Staff < Peek::Views::View
def initialize(options = {})
@username = options.delete(:username)
end
def username
@username
end
def enabled?
!!@username
end
end
describe Peek do
describe "enabled?" do
it "should not be enabled in test" do
refute Peek.enabled?
end
end
describe "env" do
it "should return the current environment" do
assert_equal 'test', Peek.env
end
end
describe "views" do
before do
Peek.reset
end
it "should have none by default" do
assert_equal [], Peek.views
end
it "should be able to append views" do
Peek.into Staff, username: 'dewski'
assert_kind_of Staff, Peek.views.first
end
it "should be able to append views with options" do
Peek.into Staff, username: 'dewski'
@staff = Peek.views.first
assert_kind_of Staff, @staff
assert_equal 'dewski', @staff.username
end
it "should only return enabled views" do
Peek.into Staff, username: false
assert_equal [], Peek.views
end
end
describe "reset" do
before do
Peek.reset
end
it "should clear any current views" do
Peek.into Staff, username: 'dewski'
assert_kind_of Staff, Peek.views.first
Peek.reset
assert_equal [], Peek.views
end
end
end
peek-1.1.0/test/controllers/ 0000755 0000041 0000041 00000000000 13546140043 016012 5 ustar www-data www-data peek-1.1.0/test/controllers/requests_test.rb 0000644 0000041 0000041 00000001460 13546140043 021252 0 ustar www-data www-data require 'test_helper'
require_relative '../dummy/lib/test_view'
class RequestsTest < ActionDispatch::IntegrationTest
setup do
Peek.adapter.reset
Peek.reset
end
test "the request id is set" do
assert_empty Peek.adapter.requests
get '/'
assert_not_empty Peek.adapter.requests
end
test "the request ID and data are set correctly for concurrent requests" do
Peek.into TestView
concurrent_requests = 10
assert_empty Peek.adapter.requests
concurrent_requests.times.map do
Thread.new { get '/' }
end.map(&:join)
result_sequence = Peek.adapter.requests.values.map { |value| value[:data]['test-view'][:number] }
assert_equal Peek.adapter.requests.length, concurrent_requests
assert_equal result_sequence, 1.upto(concurrent_requests).to_a
end
end
peek-1.1.0/test/dummy/ 0000755 0000041 0000041 00000000000 13546140043 014577 5 ustar www-data www-data peek-1.1.0/test/dummy/config.ru 0000644 0000041 0000041 00000000232 13546140043 016411 0 ustar www-data www-data # This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
peek-1.1.0/test/dummy/bin/ 0000755 0000041 0000041 00000000000 13546140043 015347 5 ustar www-data www-data peek-1.1.0/test/dummy/bin/bundle 0000755 0000041 0000041 00000000201 13546140043 016537 0 ustar www-data www-data #!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
peek-1.1.0/test/dummy/bin/rails 0000755 0000041 0000041 00000000222 13546140043 016403 0 ustar www-data www-data #!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
peek-1.1.0/test/dummy/bin/rake 0000755 0000041 0000041 00000000132 13546140043 016213 0 ustar www-data www-data #!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
peek-1.1.0/test/dummy/app/ 0000755 0000041 0000041 00000000000 13546140043 015357 5 ustar www-data www-data peek-1.1.0/test/dummy/app/helpers/ 0000755 0000041 0000041 00000000000 13546140043 017021 5 ustar www-data www-data peek-1.1.0/test/dummy/app/helpers/application_helper.rb 0000644 0000041 0000041 00000000035 13546140043 023206 0 ustar www-data www-data module ApplicationHelper
end
peek-1.1.0/test/dummy/app/controllers/ 0000755 0000041 0000041 00000000000 13546140043 017725 5 ustar www-data www-data peek-1.1.0/test/dummy/app/controllers/application_controller.rb 0000644 0000041 0000041 00000000470 13546140043 025021 0 ustar www-data www-data class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def peek_enabled?
if defined?(@peek_enabled)
!!@peek_enabled
else
true
end
end
end
peek-1.1.0/test/dummy/app/controllers/home_controller.rb 0000644 0000041 0000041 00000000260 13546140043 023443 0 ustar www-data www-data class HomeController < ApplicationController
def enabled
@peek_enabled = true
render :show
end
def disabled
@peek_enabled = false
render :show
end
end
peek-1.1.0/test/dummy/app/assets/ 0000755 0000041 0000041 00000000000 13546140043 016661 5 ustar www-data www-data peek-1.1.0/test/dummy/app/assets/javascripts/ 0000755 0000041 0000041 00000000000 13546140043 021212 5 ustar www-data www-data peek-1.1.0/test/dummy/app/assets/javascripts/application.js 0000644 0000041 0000041 00000001216 13546140043 024053 0 ustar www-data www-data // This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require peek
//= require_tree .
peek-1.1.0/test/dummy/app/assets/stylesheets/ 0000755 0000041 0000041 00000000000 13546140043 021235 5 ustar www-data www-data peek-1.1.0/test/dummy/app/assets/stylesheets/application.css 0000644 0000041 0000041 00000001063 13546140043 024252 0 ustar www-data www-data /*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require peek
*= require_self
*= require_tree .
*/
peek-1.1.0/test/dummy/app/views/ 0000755 0000041 0000041 00000000000 13546140043 016514 5 ustar www-data www-data peek-1.1.0/test/dummy/app/views/layouts/ 0000755 0000041 0000041 00000000000 13546140043 020214 5 ustar www-data www-data peek-1.1.0/test/dummy/app/views/layouts/application.html.erb 0000644 0000041 0000041 00000000477 13546140043 024164 0 ustar www-data www-data
Dummy
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'peek/bar' %>
<%= yield %>
peek-1.1.0/test/dummy/app/views/home/ 0000755 0000041 0000041 00000000000 13546140043 017444 5 ustar www-data www-data peek-1.1.0/test/dummy/app/views/home/show.html.erb 0000644 0000041 0000041 00000000206 13546140043 022057 0 ustar www-data www-data Home#show
Find me in app/views/home/show.html.erb
<%= debug({ peek_enabled: @peek_enabled }) %>
<%= debug cookies %>
peek-1.1.0/test/dummy/app/views/peek/ 0000755 0000041 0000041 00000000000 13546140043 017440 5 ustar www-data www-data peek-1.1.0/test/dummy/app/views/peek/_test_view.html.erb 0000644 0000041 0000041 00000000126 13546140043 023244 0 ustar www-data www-data ... number
peek-1.1.0/test/dummy/log/ 0000755 0000041 0000041 00000000000 13546140043 015360 5 ustar www-data www-data peek-1.1.0/test/dummy/log/.keep 0000644 0000041 0000041 00000000000 13546140043 016273 0 ustar www-data www-data peek-1.1.0/test/dummy/Rakefile 0000644 0000041 0000041 00000000372 13546140043 016246 0 ustar www-data www-data # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Dummy::Application.load_tasks
peek-1.1.0/test/dummy/lib/ 0000755 0000041 0000041 00000000000 13546140043 015345 5 ustar www-data www-data peek-1.1.0/test/dummy/lib/test_view.rb 0000644 0000041 0000041 00000000437 13546140043 017707 0 ustar www-data www-data require 'concurrent/atomics'
class TestView < Peek::Views::View
class << self
attr_accessor :counter
end
self.counter = Concurrent::AtomicFixnum.new
def results
{
number: self.class.counter.increment
}
end
def partial_path
"peek/test_view"
end
end
peek-1.1.0/test/dummy/README.rdoc 0000644 0000041 0000041 00000000736 13546140043 016413 0 ustar www-data www-data == README
This README would normally document whatever steps are necessary to get the
application up and running.
Things you may want to cover:
* Ruby version
* System dependencies
* Configuration
* Database creation
* Database initialization
* How to run the test suite
* Services (job queues, cache servers, search engines, etc.)
* Deployment instructions
* ...
Please feel free to use a different markup language if you do not plan to run
rake doc:app.
peek-1.1.0/test/dummy/config/ 0000755 0000041 0000041 00000000000 13546140043 016044 5 ustar www-data www-data peek-1.1.0/test/dummy/config/boot.rb 0000644 0000041 0000041 00000000362 13546140043 017335 0 ustar www-data www-data # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
peek-1.1.0/test/dummy/config/routes.rb 0000644 0000041 0000041 00000000252 13546140043 017711 0 ustar www-data www-data Dummy::Application.routes.draw do
mount Peek::Railtie => 'peek'
get '/enabled' => 'home#enabled'
get '/disabled' => 'home#disabled'
root to: 'home#enabled'
end
peek-1.1.0/test/dummy/config/initializers/ 0000755 0000041 0000041 00000000000 13546140043 020552 5 ustar www-data www-data peek-1.1.0/test/dummy/config/initializers/backtrace_silencers.rb 0000644 0000041 0000041 00000000624 13546140043 025067 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
peek-1.1.0/test/dummy/config/initializers/inflections.rb 0000644 0000041 0000041 00000001207 13546140043 023414 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end
peek-1.1.0/test/dummy/config/initializers/session_store.rb 0000644 0000041 0000041 00000000212 13546140043 023771 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
peek-1.1.0/test/dummy/config/initializers/filter_parameter_logging.rb 0000644 0000041 0000041 00000000302 13546140043 026125 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
peek-1.1.0/test/dummy/config/initializers/peek.rb 0000644 0000041 0000041 00000000104 13546140043 022016 0 ustar www-data www-data require_relative '../../../dummy/lib/test_view'
Peek.into TestView
peek-1.1.0/test/dummy/config/initializers/mime_types.rb 0000644 0000041 0000041 00000000315 13546140043 023251 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
peek-1.1.0/test/dummy/config/initializers/secret_token.rb 0000644 0000041 0000041 00000001222 13546140043 023561 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
Rails.application.config.secret_key_base = '94c84623660ec36e05fa8584f7dad694c280aae1894eedb73fc017564933a4eea53962e7d8aba5dc33be928373045982ec9af92cef8150bb9576eaa55ad36d5b'
peek-1.1.0/test/dummy/config/initializers/wrap_parameters.rb 0000644 0000041 0000041 00000001005 13546140043 024267 0 ustar www-data www-data # Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end
peek-1.1.0/test/dummy/config/application.rb 0000644 0000041 0000041 00000001733 13546140043 020700 0 ustar www-data www-data require File.expand_path('../boot', __FILE__)
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'sprockets/railtie'
require 'rails/test_unit/railtie'
Bundler.require(*Rails.groups)
require 'peek'
module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
peek-1.1.0/test/dummy/config/locales/ 0000755 0000041 0000041 00000000000 13546140043 017466 5 ustar www-data www-data peek-1.1.0/test/dummy/config/locales/en.yml 0000644 0000041 0000041 00000001172 13546140043 020614 0 ustar www-data www-data # Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"
peek-1.1.0/test/dummy/config/environment.rb 0000644 0000041 0000041 00000000227 13546140043 020736 0 ustar www-data www-data # Load the rails application.
require File.expand_path('../application', __FILE__)
# Initialize the rails application.
Dummy::Application.initialize!
peek-1.1.0/test/dummy/config/environments/ 0000755 0000041 0000041 00000000000 13546140043 020573 5 ustar www-data www-data peek-1.1.0/test/dummy/config/environments/test.rb 0000644 0000041 0000041 00000003027 13546140043 022101 0 ustar www-data www-data Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
end
peek-1.1.0/test/dummy/config/environments/development.rb 0000644 0000041 0000041 00000001605 13546140043 023444 0 ustar www-data www-data Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
end
peek-1.1.0/test/dummy/public/ 0000755 0000041 0000041 00000000000 13546140043 016055 5 ustar www-data www-data peek-1.1.0/test/dummy/public/422.html 0000644 0000041 0000041 00000002466 13546140043 017262 0 ustar www-data www-data
The change you wanted was rejected (422)
The change you wanted was rejected.
Maybe you tried to change something you didn't have access to.
If you are the application owner check the logs for more information.
peek-1.1.0/test/dummy/public/500.html 0000644 0000041 0000041 00000002362 13546140043 017252 0 ustar www-data www-data
We're sorry, but something went wrong (500)
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
peek-1.1.0/test/dummy/public/404.html 0000644 0000041 0000041 00000002507 13546140043 017256 0 ustar www-data www-data
The page you were looking for doesn't exist (404)
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
peek-1.1.0/test/dummy/public/favicon.ico 0000644 0000041 0000041 00000000000 13546140043 020164 0 ustar www-data www-data peek-1.1.0/test/peek/ 0000755 0000041 0000041 00000000000 13546140043 014370 5 ustar www-data www-data peek-1.1.0/test/peek/views/ 0000755 0000041 0000041 00000000000 13546140043 015525 5 ustar www-data www-data peek-1.1.0/test/peek/views/view_test.rb 0000644 0000041 0000041 00000001366 13546140043 020071 0 ustar www-data www-data require 'test_helper'
describe Peek::Views::View do
before do
@view = Peek::Views::View.new
end
describe "partial path" do
it "should return correct partial class" do
assert_equal 'peek/views/view', @view.partial_path
end
end
describe "dom_id" do
it "should return correct dom_id" do
assert_equal 'peek-view-view', @view.dom_id
end
end
describe "key" do
it "should return correct key" do
assert_equal 'view', @view.key
end
end
describe "context" do
it "should return correct context_id" do
assert_equal 'peek-context-view', @view.context_id
end
end
describe "toggling off and on" do
it "should be enabled by default" do
assert @view.enabled?
end
end
end
peek-1.1.0/test/test_helper.rb 0000644 0000041 0000041 00000001023 13546140043 016303 0 ustar www-data www-data ENV['RAILS_ENV'] = 'test'
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'rails/test_help'
Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end
require 'minitest/autorun'
begin
require 'turn'
rescue LoadError
# Not installed.
end
peek-1.1.0/README.md 0000644 0000041 0000041 00000020304 13546140043 013743 0 ustar www-data www-data # Peek
[](https://travis-ci.org/peek/peek) [](http://badge.fury.io/rb/peek) [](http://inch-ci.org/github/peek/peek)
Take a peek into your Rails application.

This is a profiling tool originally built at GitHub to help us get an insight into our application. Now, we have extracted this into Peek, so that other Rails applications can experience the same benefit.
Peek puts a little bar on top of your application to show you all sorts of helpful information about your application. From the screenshot above, you can see that Peek provides information about database queries, cache, Resque workers and more. However, this is only part of Peek's beauty.
The true beauty of Peek lies in the fact that it is an extensible platform. If there are some performance metrics that you need but are not available on Peek, you can find them in the list of available [Peek Views](#available-peek-views) and integrate them into Peek. Even if you do not find what you want on Peek Views, you can always [create your own](#creating-your-own-peek-item).
## Installation
Add this line to your application's Gemfile:
gem 'peek'
And then execute:
$ bundle
Or install it yourself as:
$ gem install peek
## Usage
Now that Peek is installed, you'll need to mount the engine within your `config/routes.rb`
file:
```ruby
Some::Application.routes.draw do
mount Peek::Railtie => '/peek'
root to: 'home#show'
end
```
To pick which views you want to see in your Peek bar, just create a file at
`config/initializers/peek.rb` that has a list of the views you'd like to include:
```ruby
Peek.into Peek::Views::Git, nwo: 'github/janky'
Peek.into Peek::Views::Mysql2
Peek.into Peek::Views::Redis
Peek.into Peek::Views::Dalli
```
Feel free to pick and install from the [list](https://github.com/peek/peek#available-peek-views) or create your own. The order they
are added to Peek is the order they will appear in your bar.
Next, to render the Peek bar in your application, add the following snippet
just after the opening `` tag in your application layout.
```erb
<%= render 'peek/bar' %>
```
It will look like:
```erb
Application
<%= render 'peek/bar' %>
<%= yield %>
```
Peek fetches the data collected throughout your requests by using the unique request id
that was assigned to the request by Rails. It will call out to its own controller at
[Peek::ResultsController](https://github.com/peek/peek/blob/master/app/controllers/peek/results_controller.rb) which will render the data and be inserted into the bar.
Now that you have the partials in your application, you will need to include the
CSS and JS that help make Peek :sparkles:
In `app/assets/stylesheets/application.scss`:
```scss
//= require peek
```
In `app/assets/javascripts/application.coffee`:
```coffeescript
#= require jquery
#= require jquery_ujs
#= require peek
```
Note: Each additional view may have their own CSS and JS that you may need to require
which should be stated in their usage documentation.
### Configuring the default adapter
For Peek to work, it keeps track of all requests made in your application
so it can report back and display that information in the Peek bar. By default
it stores this information in memory, which is not recommended for production environments.
In production environments you may have application servers on multiple hosts.
Peek will not be able to access the request data if it was saved in memory on
another host. Peek provides additional adapters for multi server environments.
You can configure which adapter Peek uses by updating your application
config or an individual environment config file. We'll use production as an example.
Note: Peek does not provide the dependencies for each of these adapters. If you use these
adapters be sure to include their dependencies in your application.
- Redis - The [redis](https://github.com/redis/redis-rb) gem
- Dalli - The [dalli](https://github.com/mperham/dalli) gem
- Elasticsearch - The [elasticsearch](https://github.com/elasticsearch/elasticsearch-ruby) gem
```ruby
Peeked::Application.configure do
# ...
# Redis with no options
config.peek.adapter = :redis
# Redis with options
config.peek.adapter = :redis, {
client: Redis.new,
expires_in: 60 * 30 # => 30 minutes in seconds
}
# Memcache with no options
config.peek.adapter = :memcache
# Memcache with options
config.peek.adapter = :memcache, {
client: Dalli::Client.new,
expires_in: 60 * 30 # => 30 minutes in seconds
}
# Elasticsearch with no options
config.peek.adapter = :elasticsearch
# Elasticsearch with options
config.peek.adapter = :elasticsearch, {
client: Elasticsearch::Client.new,
expires_in: 60 * 30, # => 30 minutes in seconds
index: 'peek_requests_index',
type: 'peek_request'
}
# ...
end
```
Peek doesn't persist the request data forever. It uses a safe 30 minute cache
length so that data will be available if you'd like to aggregate it or
use it for other Peek views. You can update this to be 30 seconds if you don't
want the data to be available for these or other uses.
### Customizing the bar
You can customize the appearance of the bar by customizing it in your own application's CSS.
One common example is fixing the peek bar to the bottom, rather than top, of a page, for use with [Bootstrap](http://getbootstrap.com/):
```css
#peek {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 999;
}
```
## Using Peek with PJAX
It just works.
## Using Peek with Turbolinks
It just works.
## Access Control
Peek will only render in development and staging environments. If you'd
like to whitelist a select number of users to view Peek in production you
can override the `peek_enabled?` guard in `ApplicationController`:
```ruby
class ApplicationController < ActionController::Base
def peek_enabled?
current_user.staff?
end
end
```
## Available Peek views
- [peek-active_resource](https://github.com/gotmayonase/peek-active_resource)
- [peek-alt-routes](https://github.com/mkcode/peek-alt-routes)
- [peek-dalli](https://github.com/peek/peek-dalli)
- [peek-delayed_job](https://github.com/18F/peek-delayed_job)
- [peek-devise](https://github.com/gencer/peek-devise)
- [peek-faraday](https://github.com/grk/peek-faraday)
- [peek-flexirest](https://github.com/andyjeffries/peek-flexirest)
- [peek-gc](https://github.com/peek/peek-gc)
- [peek-git](https://github.com/peek/peek-git)
- [peek-host](https://github.com/jacobbednarz/peek-host)
- [peek-mongo](https://github.com/peek/peek-mongo)
- [peek-moped](https://github.com/nodkz/peek-moped)
- [peek-mysql2](https://github.com/peek/peek-mysql2)
- [peek-performance_bar](https://github.com/peek/peek-performance_bar)
- [peek-pg](https://github.com/peek/peek-pg)
- [peek-rblineprof](https://github.com/peek/peek-rblineprof)
- [peek-redis](https://github.com/peek/peek-redis)
- [peek-resque](https://github.com/peek/peek-resque)
- [peek-sidekiq](https://github.com/suranyami/peek-sidekiq)
- [peek-svn](https://github.com/neilco/peek-svn)
- Unicorn :soon:
Feel free to submit a Pull Request adding your own Peek item to this list.
## Creating your own Peek item
Each Peek item is a self contained Rails engine which gives you the power to
use all features of Ruby on Rails to dig in deep within your application and
report it back to the Peek bar. A Peek item is just a custom class that
is responsible for fetching and building the data that should be reported back
to the user.
There are still some docs to be written, but if you'd like to check out a simple
example of how to create your own, just checkout [peek-git](https://github.com/peek/peek-git).
To just look at an example view, there is [Peek::Views::Git](https://github.com/peek/peek-git/blob/master/lib/peek/views/git.rb).
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
peek-1.1.0/CHANGELOG.md 0000644 0000041 0000041 00000010165 13546140043 014301 0 ustar www-data www-data # 0.0.1
- Initial release.
# 0.0.2
- Add own tipsy plugin to allow for tooltips.
# 0.0.3
- Change the scope of the .tipsy selector as it's inserted outside of the Glimpse div.
# 0.0.4
- Don't capture ` being pressed when in combination with `cmd`
- Support for [Turbolinks](https://github.com/rails/turbolinks) (#14)
# 0.0.5
- Namespace the tooltips to the `.glimpse-tooltip` class name to not conflict with any application styles for `.tooltip`. (#18)
# 0.0.6
- Added Peek::Views::View#parse_options that gets called within initialize for subclasses to use to parse their options.
# 0.1.0
- Introduced a new JS event `peek:render` that includes the request id and request payload data that is used to update the information in the bar.
- Request information has moved from the `peek/results` partial to an AJAX request that happens on page load, and when PJAX/Turbolinks change pages.
- Removed the need for `peek/results` partial.
- Introduced a Redis and Memcache adapter for multi-server environments to store request payloads.
- Tooltips automatically repositions depending on where the Peek bar is.
# 0.1.1
- Fix bug with how `peek:render` was passing arguments around.
# 0.1.2
- Fix path to memcache adapter - [#34](https://github.com/peek/peek/pull/34) [@grk](https://github.com/grk)
- Prevent namespace collision when using [peek-dalli](https://github.com/peek/peek-dalli) - [#34](https://github.com/peek/peek/pull/34) [@grk](https://github.com/grk)
# 0.1.3
- Remove Redis dependency from Gemfile
# 0.1.4
- Don't access xhr object when not present in pjax:end
# 0.1.5
- Don't trigger `peek:update` event when the peek bar isn't present - [#37](https://github.com/peek/peek/issues/37) [@dewski](https://github.com/dewski)
- Add `after_request` helper method for Peek::Views::View to help reset state
# 0.1.6
- Use `event.which` for normalization between `event.keyCode` and `event.charCode` - [#38](https://github.com/peek/peek/pull/38) [@leongersing](https://github.com/leongersing)
# 0.1.7
- Support all Rails 3.x.x versions by not using `request.uuid` instead `env` - [#39](https://github.com/peek/peek/pull/39) [@bryanmikaelian](https://github.com/bryanmikaelian)
# 0.1.8
- Include the ControllerHelpers directly into `ActionController::Base` - [#41](https://github.com/peek/peek/pull/41) [@lucasmazza](https://github.com/lucasmazza)
# 0.1.9
- Rescue & log Dalli exceptions instead of crashing - [#50](https://github.com/peek/peek/pull/50) [@barunio](https://github.com/barunio)
# 0.1.10
- Take off Responders - [#65](https://github.com/peek/peek/pull/65) [@nwjsmith](https://github.com/nwjsmith)
# 0.2.0
- Add image dependencies for asset compilation - [#67](https://github.com/peek/peek/pull/67) [@fedesoria](https://github.com/fedesoria)
- Update JSON to 1.8.2 for compatibility with Ruby 2.2.2 - [#73](https://github.com/peek/peek/pull/73) [@eitoball](https://github.com/eitoball)
- Use concurrent-ruby gem in favor of deprecated atomic gem. - [#73](https://github.com/peek/peek/pull/73) [@eitoball](https://github.com/eitoball)
- Prevent errors if compatibility mode is enabled for jQuery - [#74](https://github.com/peek/peek/pull/74) [@warseph](https://github.com/warseph)
- Add dependency for coffee-rails for Rails. - [#80](https://github.com/peek/peek/pull/80) [@cllns](https://github.com/cllns)
- Fix deprecation warnings for `helper_method` for future versions of Rails past Rails v5. - [#85](https://github.com/peek/peek/pull/85) [@mgrachev](https://github.com/mgrachev)
- Listen to Turbolinks v5 `turbolinks:load` JS event to trigger peek updates. - [#88](https://github.com/peek/peek/pull/88) [@lucasmazza](https://github.com/lucasmazza)
# 1.0
- Rails 4+ compatibility
- Update `before_filter` to `before_action` @mkcode
- Replace GIFs with colors @tarebyte
- Remove CoffeeScript @dewski
- Use Ruby JSON syntax for hashes
# 1.1.0
- Ensure that Peek can handle concurrent requests with a multithreaded application server - [#113](https://github.com/peek/peek/pull/113) [@smcgivern](https://github.com/smcgivern)
- Don't store metrics if no request ID is present - [#112](https://github.com/peek/peek/pull/112) [@rymai](https://github.com/rymai)
peek-1.1.0/.gitignore 0000644 0000041 0000041 00000000274 13546140043 014460 0 ustar www-data www-data *.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/dummy/log
test/tmp
test/version_tmp
tmp
/bin
.ruby-version
peek-1.1.0/app/ 0000755 0000041 0000041 00000000000 13546140043 013245 5 ustar www-data www-data peek-1.1.0/app/controllers/ 0000755 0000041 0000041 00000000000 13546140043 015613 5 ustar www-data www-data peek-1.1.0/app/controllers/peek/ 0000755 0000041 0000041 00000000000 13546140043 016537 5 ustar www-data www-data peek-1.1.0/app/controllers/peek/results_controller.rb 0000644 0000041 0000041 00000001017 13546140043 023027 0 ustar www-data www-data module Peek
class ResultsController < ApplicationController
before_action :restrict_non_access
def show
respond_to do |format|
format.json do
if request.xhr?
render json: Peek.adapter.get(params[:request_id])
else
render nothing: true, status: :not_found
end
end
end
end
private
def restrict_non_access
unless peek_enabled?
raise ActionController::RoutingError.new('Not Found')
end
end
end
end
peek-1.1.0/app/assets/ 0000755 0000041 0000041 00000000000 13546140043 014547 5 ustar www-data www-data peek-1.1.0/app/assets/javascripts/ 0000755 0000041 0000041 00000000000 13546140043 017100 5 ustar www-data www-data peek-1.1.0/app/assets/javascripts/peek.js 0000644 0000041 0000041 00000004601 13546140043 020363 0 ustar www-data www-data //= require peek/vendor/jquery.tipsy
var requestId;
requestId = null;
(function($) {
var fetchRequestResults, getRequestId, initializeTipsy, peekEnabled, toggleBar, updatePerformanceBar;
getRequestId = function() {
if (requestId != null) {
return requestId;
} else {
return $('#peek').data('request-id');
}
};
peekEnabled = function() {
return $('#peek').length;
};
updatePerformanceBar = function(results) {
var key, label;
for (key in results.data) {
for (label in results.data[key]) {
$("[data-defer-to=" + key + "-" + label + "]").text(results.data[key][label]);
}
}
return $(document).trigger('peek:render', [getRequestId(), results]);
};
initializeTipsy = function() {
return $('#peek .peek-tooltip, #peek .tooltip').each(function() {
var el, gravity;
el = $(this);
gravity = el.hasClass('rightwards') || el.hasClass('leftwards') ? $.fn.tipsy.autoWE : $.fn.tipsy.autoNS;
return el.tipsy({
gravity: gravity
});
});
};
toggleBar = function(event) {
var wrapper;
if ($(event.target).is(':input')) {
return;
}
if (event.which === 96 && !event.metaKey) {
wrapper = $('#peek');
if (wrapper.hasClass('disabled')) {
wrapper.removeClass('disabled');
return document.cookie = "peek=true; path=/";
} else {
wrapper.addClass('disabled');
return document.cookie = "peek=false; path=/";
}
}
};
fetchRequestResults = function() {
return $.ajax('/peek/results', {
data: {
request_id: getRequestId()
},
success: function(data, textStatus, xhr) {
return updatePerformanceBar(data);
},
error: function(xhr, textStatus, error) {}
});
};
$(document).on('keypress', toggleBar);
$(document).on('peek:update', initializeTipsy);
$(document).on('peek:update', fetchRequestResults);
$(document).on('pjax:end', function(event, xhr, options) {
if (xhr != null) {
requestId = xhr.getResponseHeader('X-Request-Id');
}
if (peekEnabled()) {
return $(this).trigger('peek:update');
}
});
$(document).on('page:change turbolinks:load', function() {
if (peekEnabled()) {
return $(this).trigger('peek:update');
}
});
return $(function() {
if (peekEnabled()) {
return $(this).trigger('peek:update');
}
});
})(jQuery);
peek-1.1.0/app/assets/javascripts/peek/ 0000755 0000041 0000041 00000000000 13546140043 020024 5 ustar www-data www-data peek-1.1.0/app/assets/javascripts/peek/vendor/ 0000755 0000041 0000041 00000000000 13546140043 021321 5 ustar www-data www-data peek-1.1.0/app/assets/javascripts/peek/vendor/jquery.tipsy.js 0000644 0000041 0000041 00000023133 13546140043 024347 0 ustar www-data www-data // tipsy, facebook style tooltips for jquery
// version 1.0.0a
// (c) 2008-2010 jason frame [jason@onehackoranother.com]
// released under the MIT license
(function($) {
function maybeCall(thing, ctx) {
return (typeof thing == 'function') ? (thing.call(ctx)) : thing;
};
function isElementInDOM(ele) {
while (ele = ele.parentNode) {
if (ele == document) return true;
}
return false;
};
function Tipsy(element, options) {
this.$element = $(element);
this.options = options;
this.enabled = true;
this.fixTitle();
};
Tipsy.prototype = {
show: function() {
var title = this.getTitle();
if (title && this.enabled) {
var $tip = this.tip();
$tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
$tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
$tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body);
var pos = $.extend({}, this.$element.offset(), {
width: this.$element[0].offsetWidth,
height: this.$element[0].offsetHeight
});
var actualWidth = $tip[0].offsetWidth,
actualHeight = $tip[0].offsetHeight,
gravity = maybeCall(this.options.gravity, this.$element[0]);
var tp;
switch (gravity.charAt(0)) {
case 'n':
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
break;
case 's':
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
break;
case 'e':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
break;
case 'w':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
break;
}
if (gravity.length == 2) {
if (gravity.charAt(1) == 'w') {
tp.left = pos.left + pos.width / 2 - 15;
} else {
tp.left = pos.left + pos.width / 2 - actualWidth + 15;
}
}
$tip.css(tp).addClass('tipsy-' + gravity);
$tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0);
if (this.options.className) {
$tip.addClass(maybeCall(this.options.className, this.$element[0]));
}
if (this.options.fade) {
$tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
} else {
$tip.css({visibility: 'visible', opacity: this.options.opacity});
}
}
},
hide: function() {
if (this.options.fade) {
this.tip().stop().fadeOut(function() { $(this).remove(); });
} else {
this.tip().remove();
}
},
fixTitle: function() {
var $e = this.$element;
if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
$e.attr('original-title', $e.attr('title') || '').removeAttr('title');
}
},
getTitle: function() {
var title, $e = this.$element, o = this.options;
this.fixTitle();
var title, o = this.options;
if (typeof o.title == 'string') {
title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
} else if (typeof o.title == 'function') {
title = o.title.call($e[0]);
}
title = ('' + title).replace(/(^\s*|\s*$)/, "");
return title || o.fallback;
},
tip: function() {
if (!this.$tip) {
this.$tip = $('').html('');
this.$tip.data('tipsy-pointee', this.$element[0]);
}
return this.$tip;
},
validate: function() {
if (!this.$element[0].parentNode) {
this.hide();
this.$element = null;
this.options = null;
}
},
enable: function() { this.enabled = true; },
disable: function() { this.enabled = false; },
toggleEnabled: function() { this.enabled = !this.enabled; }
};
$.fn.tipsy = function(options) {
if (options === true) {
return this.data('tipsy');
} else if (typeof options == 'string') {
var tipsy = this.data('tipsy');
if (tipsy) tipsy[options]();
return this;
}
options = $.extend({}, $.fn.tipsy.defaults, options);
function get(ele) {
var tipsy = $.data(ele, 'tipsy');
if (!tipsy) {
tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
$.data(ele, 'tipsy', tipsy);
}
return tipsy;
}
function enter() {
var tipsy = get(this);
tipsy.hoverState = 'in';
if (options.delayIn == 0) {
tipsy.show();
} else {
tipsy.fixTitle();
setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
}
};
function leave() {
var tipsy = get(this);
tipsy.hoverState = 'out';
if (options.delayOut == 0) {
tipsy.hide();
} else {
setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
}
};
if (!options.live) this.each(function() { get(this); });
if (options.trigger != 'manual') {
var binder = options.live ? 'live' : 'bind',
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
this[binder](eventIn, enter)[binder](eventOut, leave);
}
return this;
};
$.fn.tipsy.defaults = {
className: null,
delayIn: 0,
delayOut: 0,
fade: false,
fallback: '',
gravity: 'n',
html: false,
live: false,
offset: 0,
opacity: 0.8,
title: 'title',
trigger: 'hover'
};
$.fn.tipsy.revalidate = function() {
$('.tipsy').each(function() {
var pointee = $.data(this, 'tipsy-pointee');
if (!pointee || !isElementInDOM(pointee)) {
$(this).remove();
}
});
};
// Overwrite this method to provide options on a per-element basis.
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
// (remember - do not modify 'options' in place!)
$.fn.tipsy.elementOptions = function(ele, options) {
return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
};
$.fn.tipsy.autoNS = function() {
return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
};
$.fn.tipsy.autoWE = function() {
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
};
/**
* yields a closure of the supplied parameters, producing a function that takes
* no arguments and is suitable for use as an autogravity function like so:
*
* @param margin (int) - distance from the viewable region edge that an
* element should be before setting its tooltip's gravity to be away
* from that edge.
* @param prefer (string, e.g. 'n', 'sw', 'w') - the direction to prefer
* if there are no viewable region edges effecting the tooltip's
* gravity. It will try to vary from this minimally, for example,
* if 'sw' is preferred and an element is near the right viewable
* region edge, but not the top edge, it will set the gravity for
* that element's tooltip to be 'se', preserving the southern
* component.
*/
$.fn.tipsy.autoBounds = function(margin, prefer) {
return function() {
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
boundTop = $(document).scrollTop() + margin,
boundLeft = $(document).scrollLeft() + margin,
$this = $(this);
if ($this.offset().top < boundTop) dir.ns = 'n';
if ($this.offset().left < boundLeft) dir.ew = 'w';
if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';
return dir.ns + (dir.ew ? dir.ew : '');
}
};
})(jQuery);
peek-1.1.0/app/assets/stylesheets/ 0000755 0000041 0000041 00000000000 13546140043 017123 5 ustar www-data www-data peek-1.1.0/app/assets/stylesheets/peek.scss 0000644 0000041 0000041 00000002557 13546140043 020755 0 ustar www-data www-data //= require peek/vendor/tipsy
#peek {
background: #000;
height: 35px;
line-height: 35px;
color: #999;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
.hidden {
display: none;
visibility: visible;
}
&.disabled {
display: none;
}
&.production {
background-color: #222;
}
&.staging {
background-color: #291430;
}
&.development {
background-color: #4c1210;
}
.wrapper {
width: 800px;
margin: 0 auto;
}
// UI Elements
.bucket {
background: #111;
display: inline-block;
padding: 4px 6px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
line-height: 1;
color: #ccc;
border-radius: 3px;
box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 1px 2px rgba(0,0,0,.25);
.hidden {
display: none;
}
&:hover .hidden {
display: inline;
}
}
strong {
color: #fff;
}
.view {
margin-right: 15px;
float: left;
&:last-child {
margin-right: 0;
}
}
.css-truncate {
&.css-truncate-target,
.css-truncate-target {
display: inline-block;
max-width: 125px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
vertical-align: top;
}
&.expandable:hover .css-truncate-target,
&.expandable:hover.css-truncate-target {
max-width: 10000px !important;
}
}
}
peek-1.1.0/app/assets/stylesheets/peek/ 0000755 0000041 0000041 00000000000 13546140043 020047 5 ustar www-data www-data peek-1.1.0/app/assets/stylesheets/peek/vendor/ 0000755 0000041 0000041 00000000000 13546140043 021344 5 ustar www-data www-data peek-1.1.0/app/assets/stylesheets/peek/vendor/tipsy.scss 0000644 0000041 0000041 00000003734 13546140043 023420 0 ustar www-data www-data .tipsy { font-size: 10px; position: absolute; padding: 5px; z-index: 100000; }
.tipsy-inner { background-color: #000; color: #FFF; max-width: 200px; padding: 5px 8px 4px 8px; text-align: center; }
/* Rounded corners */
.tipsy-inner { border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
.tipsy-arrow { position: absolute; width: 0; height: 0; line-height: 0; border: 5px dashed #000; }
/* Rules to colour arrows */
.tipsy-arrow-n { border-bottom-color: #000; }
.tipsy-arrow-s { border-top-color: #000; }
.tipsy-arrow-e { border-left-color: #000; }
.tipsy-arrow-w { border-right-color: #000; }
.tipsy-n .tipsy-arrow { top: 0px; left: 50%; margin-left: -5px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent; }
.tipsy-nw .tipsy-arrow { top: 0; left: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
.tipsy-ne .tipsy-arrow { top: 0; right: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
.tipsy-s .tipsy-arrow { bottom: 0; left: 50%; margin-left: -5px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
.tipsy-sw .tipsy-arrow { bottom: 0; left: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
.tipsy-se .tipsy-arrow { bottom: 0; right: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
.tipsy-e .tipsy-arrow { right: 0; top: 50%; margin-top: -5px; border-left-style: solid; border-right: none; border-top-color: transparent; border-bottom-color: transparent; }
.tipsy-w .tipsy-arrow { left: 0; top: 50%; margin-top: -5px; border-right-style: solid; border-left: none; border-top-color: transparent; border-bottom-color: transparent; }
peek-1.1.0/app/views/ 0000755 0000041 0000041 00000000000 13546140043 014402 5 ustar www-data www-data peek-1.1.0/app/views/peek/ 0000755 0000041 0000041 00000000000 13546140043 015326 5 ustar www-data www-data peek-1.1.0/app/views/peek/_bar.html.erb 0000644 0000041 0000041 00000000555 13546140043 017673 0 ustar www-data www-data <% if peek_enabled? %>
<% Peek.views.each do |view| %>
<%= render view.partial_path, view: view %>
<% end %>
<% end %>
peek-1.1.0/Gemfile-rails42 0000644 0000041 0000041 00000001250 13546140043 015234 0 ustar www-data www-data source 'https://rubygems.org'
# Specify your gem's dependencies in peek.gemspec
gemspec
gem 'rake'
gem 'json', '~> 1.8.3'
gem 'rails', '~> 4.2.7.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
peek-1.1.0/Rakefile 0000644 0000041 0000041 00000000400 13546140043 014124 0 ustar www-data www-data require 'bundler/gem_tasks'
require 'rake/testtask'
desc 'Default: run tests'
task default: :test
desc 'Run Peek tests.'
Rake::TestTask.new do |t|
t.libs << 'lib'
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
peek-1.1.0/lib/ 0000755 0000041 0000041 00000000000 13546140043 013233 5 ustar www-data www-data peek-1.1.0/lib/peek.rb 0000644 0000041 0000041 00000003410 13546140043 014502 0 ustar www-data www-data require 'peek/version'
require 'rails'
require 'peek/adapters/memory'
require 'peek/views/view'
module Peek
ALLOWED_ENVS = ['development', 'staging'].freeze
def self.adapter
@adapter
end
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
def self.enabled?
ALLOWED_ENVS.include?(env)
end
def self.env
Rails.env
end
def self.views
@cached_views ||= if @views && @views.any?
@views.collect { |klass, options| klass.new(options.dup) }.select(&:enabled?)
else
[]
end
end
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
def self.into(klass, options = {})
@views ||= []
@views << [klass, options]
end
# Clears out any and all views.
#
# Returns nothing.
def self.reset
@views = nil
@cached_views = nil
end
def self.setup
ActiveSupport::Deprecation.warn "'Peek.setup' is deprecated and does nothing.", caller
end
end
require 'peek/railtie'
ActiveSupport.run_load_hooks(:peek, Peek)
peek-1.1.0/lib/peek/ 0000755 0000041 0000041 00000000000 13546140043 014157 5 ustar www-data www-data peek-1.1.0/lib/peek/version.rb 0000644 0000041 0000041 00000000044 13546140043 016167 0 ustar www-data www-data module Peek
VERSION = '1.1.0'
end
peek-1.1.0/lib/peek/adapters/ 0000755 0000041 0000041 00000000000 13546140043 015762 5 ustar www-data www-data peek-1.1.0/lib/peek/adapters/memory.rb 0000644 0000041 0000041 00000000675 13546140043 017627 0 ustar www-data www-data require 'peek/adapters/base'
module Peek
module Adapters
class Memory < Base
attr_accessor :requests
def initialize(options = {})
@requests = {}
end
def get(request_id)
@requests[request_id]
end
def save(request_id)
return false if request_id.blank?
@requests[request_id] = Peek.results
end
def reset
@requests.clear
end
end
end
end
peek-1.1.0/lib/peek/adapters/memcache.rb 0000644 0000041 0000041 00000001336 13546140043 020054 0 ustar www-data www-data require 'peek/adapters/base'
require 'dalli'
module Peek
module Adapters
class Memcache < Base
def initialize(options = {})
@client = options.fetch(:client, ::Dalli::Client.new)
@expires_in = options.fetch(:expires_in, 60 * 30)
end
def get(request_id)
@client.get("peek:requests:#{request_id}")
rescue ::Dalli::DalliError => e
Rails.logger.error "#{e.class.name}: #{e.message}"
end
def save(request_id)
return false if request_id.blank?
@client.add("peek:requests:#{request_id}", Peek.results.to_json, @expires_in)
rescue ::Dalli::DalliError => e
Rails.logger.error "#{e.class.name}: #{e.message}"
end
end
end
end
peek-1.1.0/lib/peek/adapters/base.rb 0000644 0000041 0000041 00000000453 13546140043 017223 0 ustar www-data www-data module Peek
module Adapters
class Base
def initialize(options = {})
end
def get(request_id)
raise "#{self.class}#get(request_id) is not yet implemented"
end
def save
raise "#{self.class}#save is not yet implemented"
end
end
end
end
peek-1.1.0/lib/peek/adapters/redis.rb 0000644 0000041 0000041 00000001034 13546140043 017413 0 ustar www-data www-data require 'peek/adapters/base'
require 'redis'
module Peek
module Adapters
class Redis < Base
def initialize(options = {})
@client = options.fetch(:client, ::Redis.new)
@expires_in = Integer(options.fetch(:expires_in, 60 * 30))
end
def get(request_id)
@client.get("peek:requests:#{request_id}")
end
def save(request_id)
return false if request_id.blank?
@client.setex("peek:requests:#{request_id}", @expires_in, Peek.results.to_json)
end
end
end
end
peek-1.1.0/lib/peek/adapters/elasticsearch.rb 0000644 0000041 0000041 00000002014 13546140043 021116 0 ustar www-data www-data require 'peek/adapters/base'
require 'elasticsearch'
module Peek
module Adapters
class Elasticsearch < Base
def initialize(options = {})
@client = options.fetch(:client, ::Elasticsearch::Client.new)
@expires_in = Integer(options.fetch(:expires_in, 60 * 30) * 1000)
@index = options.fetch(:index, 'peek_requests_index')
@type = options.fetch(:type, 'peek_request')
end
def get(request_id)
result = @client.get_source index: @index, type: @type, id: "#{request_id}"
result.to_json
rescue ::Elasticsearch::Transport::Transport::Errors::NotFound
# pass
end
def save(request_id)
return false if request_id.blank?
@client.index index: @index,
type: @type,
id: "#{request_id}",
body: Peek.results.to_json,
ttl: @expires_in
rescue ::Elasticsearch::Transport::Transport::Errors::BadRequest
false
end
end
end
end
peek-1.1.0/lib/peek/railtie.rb 0000644 0000041 0000041 00000001704 13546140043 016137 0 ustar www-data www-data require 'peek/controller_helpers'
module Peek
class Railtie < ::Rails::Engine
isolate_namespace Peek
engine_name :peek
config.peek = ActiveSupport::OrderedOptions.new
# Default adapter
config.peek.adapter = :memory
initializer 'peek.set_configs' do |app|
ActiveSupport.on_load(:peek) do
app.config.peek.each do |k,v|
send "#{k}=", v
end
end
end
initializer 'peek.persist_request_data' do
ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_name, _start, _finish, _id, payload|
if request_id = payload[:headers].env['action_dispatch.request_id']
Peek.adapter.save(request_id)
end
end
end
initializer 'peek.include_controller_helpers' do
ActiveSupport.on_load(:action_controller) do
include Peek::ControllerHelpers
end
config.to_prepare do
Peek.views
end
end
end
end
peek-1.1.0/lib/peek/controller_helpers.rb 0000644 0000041 0000041 00000000571 13546140043 020414 0 ustar www-data www-data module Peek
module ControllerHelpers
extend ActiveSupport::Concern
included do
if respond_to? :helper_method
helper_method :peek_enabled?
helper_method :peek_request_id
end
end
protected
def peek_enabled?
Peek.enabled?
end
def peek_request_id
request.env['action_dispatch.request_id']
end
end
end
peek-1.1.0/lib/peek/views/ 0000755 0000041 0000041 00000000000 13546140043 015314 5 ustar www-data www-data peek-1.1.0/lib/peek/views/view.rb 0000644 0000041 0000041 00000005771 13546140043 016625 0 ustar www-data www-data module Peek
module Views
class View
def initialize(options = {})
@options = options
parse_options
setup_subscribers
end
# Where any subclasses should pick and pull from @options to set any and
# all instance variables they like.
#
# Returns nothing.
def parse_options
# pass
end
# 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.
def enabled?
true
end
# 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.
def partial_path
self.class.to_s.underscore
end
# The defer key that is derived from the classname.
#
# Examples:
#
# Peek::Views::PerformanceBar => "performance-bar"
# Peek::Views::Resque => "resque"
#
# Returns String.
def key
self.class.to_s.split('::').last.underscore.gsub(/\_/, '-')
end
alias defer_key key
# 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.
def context_id
"peek-context-#{key}"
end
# The wrapper ID for the individual view in the Peek bar.
#
# Returns String.
def dom_id
"peek-view-#{key}"
end
# Additional context for any view to render tooltips for.
#
# Returns Hash.
def context
{}
end
def context?
context.any?
end
# The data results that are inserted at the end of the request for use in
# deferred placeholders in the Peek the bar.
#
# Returns Hash.
def results
{}
end
def results?
results.any?
end
def subscribe(*args)
ActiveSupport::Notifications.subscribe(*args) do |name, start, finish, id, payload|
yield name, start, finish, id, payload
end
end
private
def setup_subscribers
# pass
end
# Helper method for subscribing to the event that is fired when new
# requests are made.
def before_request
subscribe 'start_processing.action_controller' do |name, start, finish, id, payload|
yield name, start, finish, id, payload
end
end
# Helper method for subscribing to the event that is fired when requests
# are finished.
def after_request
subscribe 'process_action.action_controller' do |name, start, finish, id, payload|
yield name, start, finish, id, payload
end
end
end
end
end
peek-1.1.0/config/ 0000755 0000041 0000041 00000000000 13546140043 013732 5 ustar www-data www-data peek-1.1.0/config/routes.rb 0000644 0000041 0000041 00000000122 13546140043 015573 0 ustar www-data www-data Peek::Railtie.routes.draw do
get '/results' => 'results#show', as: :results
end
peek-1.1.0/Gemfile 0000644 0000041 0000041 00000001433 13546140043 013761 0 ustar www-data www-data source 'https://rubygems.org'
# Specify your gem's dependencies in peek.gemspec
gemspec
gem 'rake'
gem 'json', '~> 2.0', '>= 2.0.2'
# For the test application
gem 'rails', '~> 5.0', '>= 5.0.0.1'
gem 'concurrent-ruby', '>= 0.9.0'
gem 'concurrent-ruby-ext', '>= 0.9.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
peek-1.1.0/LICENSE.txt 0000644 0000041 0000041 00000002061 13546140043 014307 0 ustar www-data www-data Copyright (c) 2013 Garrett Bjerkhoel
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. peek-1.1.0/peek.gemspec 0000644 0000041 0000041 00000001467 13546140043 014766 0 ustar www-data www-data # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'peek/version'
Gem::Specification.new do |gem|
gem.name = 'peek'
gem.version = Peek::VERSION
gem.authors = ['Garrett Bjerkhoel']
gem.email = ['me@garrettbjerkhoel.com']
gem.description = %q{Take a peek into your Rails application.}
gem.summary = %q{Take a peek into your Rails application.}
gem.homepage = 'https://github.com/peek/peek'
gem.license = 'MIT'
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
gem.add_dependency 'railties', '>= 4.0.0'
end