qp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 248e54482422d481aededf02d0583067c59b6f92
4
+ data.tar.gz: 984a2f8d55f3ce4ea74954fa8752a07242c4265a
5
+ SHA512:
6
+ metadata.gz: 0d1e9495160de283603c76ffdacc71a88aad80e51a4f6bbd3fad0b18f7dbb54790177cb33c21c24a13a73edde06c9e2a410c0684f839a10c85b799f5191e8b16
7
+ data.tar.gz: 85aa81deffccdaeee8420aa0865f4aa5c1697a7d604973c5245d2bf34d4f93fe0f028efad2b6a3cc743f678d3286b5ac4ba6c4249f56fc7b2929a2543be6f22f
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qp.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Geoff Hayes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # Qp
2
+
3
+ Qp is a simple ruby gem for inline code debugging
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'qp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install qp
20
+
21
+ ## Usage
22
+
23
+ Q.p is a call-inclusive log message
24
+
25
+ ```ruby
26
+ name = "Doug"
27
+ Q.p [name, 'band', 3]
28
+
29
+ # prints `Q.p Q.p [name, 'band', 3] -> ["Doug","band",3]`
30
+ ```
31
+
32
+ T.p is a benchmark trace point, showing difference since last call (keeps state via IVar)
33
+
34
+ ```ruby
35
+ T.p
36
+ sleep 1
37
+ T.p
38
+ ```
39
+
40
+ ```
41
+ 15:54:21,263 Track Place 1 /Code/qp/spec/t_spec.rb:6:in `block (2 levels) in <top (required)>' {} +0.00ms (d+)
42
+ 15:54:21,375 Track Place 2 /Code/qp/spec/t_spec.rb:8:in `block (2 levels) in <top (required)>' {} +100.99ms (d+100.99ms)
43
+ ```
44
+
45
+ T.p can also accept maps which will show in output `T.p {extra: "information"}` and a "threshold" parameter
46
+
47
+ ```ruby
48
+ T.p {extra: "information"}
49
+ sleep 2
50
+ T.p {threshold: 100} # Since longer than 100 ms from last tp, will raise an exception
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/[my-github-username]/qp/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ require "qp/version"
2
+ require "qp/q"
3
+ require "qp/t"
@@ -0,0 +1,20 @@
1
+
2
+ module Q
3
+ def self.p(*args, &block)
4
+ callable = block || args[0]
5
+
6
+ if callable.respond_to?(:yield)
7
+ source = callable.source.strip if RUBY_VERSION[0].to_i >= 2
8
+
9
+ puts "#{source} -> #{callable.yield}"
10
+ else
11
+ if RUBY_VERSION[0].to_i >= 2
12
+ cl = caller_locations[0]
13
+
14
+ source = File.readlines(cl.path)[cl.lineno-1].strip
15
+ end
16
+
17
+ puts "#{source} -> #{args.join(',')}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+
2
+ module T
3
+ def self.p(map={})
4
+ threshold = map.delete(:threshold)
5
+ scope = caller[0..(map.delete(:scope) || 0)]
6
+
7
+ @tp = ( @tp || 0 ) + 1
8
+
9
+ now = Time.now.to_f
10
+ @first_tp ||= now
11
+ @last_tp ||= 0
12
+
13
+ total_diff = sprintf("%.2fms", ( now - @first_tp ) * 1000)
14
+
15
+ if @last_tp.zero?
16
+ delta_ms = nil
17
+ delta_formatted = nil
18
+ else
19
+ delta_ms = ( now - @last_tp ) * 1000
20
+ delta_formatted = sprintf("%.2fms", delta_ms)
21
+ end
22
+
23
+ puts [ Time.now.strftime("%T,%L"), 'Track Place', @tp, scope, map, "+#{total_diff} (d+#{delta_formatted})" ].join(" ")
24
+
25
+ if threshold && delta_ms && delta_ms > threshold
26
+ raise "Delta took longer than threshold (#{delta_formatted} > #{threshold}ms) in #{scope}", map: map
27
+ end
28
+
29
+ @last_tp = now
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Qp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qp"
8
+ spec.version = Qp::VERSION
9
+ spec.authors = ["Geoff Hayes"]
10
+ spec.email = ["hayesgm@gmail.com"]
11
+ spec.description = %q{Qp is a simple tool for inline debugging}
12
+ spec.summary = %q{Run `qp my_object` to get `/User/you/code/my_file.rb: "qp my_object" -> "object value"`. More features including simple benchmarking.}
13
+ spec.homepage = "https://github.com/hayesgm/qp"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Q do
4
+
5
+ it "should print command" do
6
+ Q.p "hi mom"
7
+ end
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'qp'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe T do
4
+
5
+ it "should handle 100ms sleep" do
6
+ T.p
7
+ sleep 0.1
8
+ T.p
9
+ end
10
+
11
+ it "should print benchmark differences" do
12
+ T.p msg: "hi mom"
13
+
14
+ T.p msg: "hi dad"
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Hayes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Qp is a simple tool for inline debugging
56
+ email:
57
+ - hayesgm@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - lib/qp.rb
68
+ - lib/qp/q.rb
69
+ - lib/qp/t.rb
70
+ - lib/qp/version.rb
71
+ - qp.gemspec
72
+ - spec/q_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/t_spec.rb
75
+ homepage: https://github.com/hayesgm/qp
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: 'Run `qp my_object` to get `/User/you/code/my_file.rb: "qp my_object" ->
99
+ "object value"`. More features including simple benchmarking.'
100
+ test_files:
101
+ - spec/q_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/t_spec.rb
104
+ has_rdoc: