cutter 0.0.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +30 -13
- data/lib/cutter/inspection.rb +14 -8
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,30 +1,47 @@
|
|
1
1
|
= cutter
|
2
2
|
|
3
|
-
For now it is two-methods-gem
|
4
|
-
|
3
|
+
For now it is two-methods-gem I use a lot for simple debugging & performance measuring purposes.
|
5
4
|
Include it into Gemfile:
|
6
|
-
gem 'cutter'
|
5
|
+
gem 'cutter'
|
7
6
|
|
8
7
|
Methods are:
|
9
8
|
|
10
|
-
I)
|
11
|
-
|
12
|
-
|
9
|
+
==I) #inspect!
|
10
|
+
|
11
|
+
Insert #inspect! method into any of your methods:
|
12
|
+
def your_method *your_args
|
13
|
+
inspect! {} # this string exactly!
|
13
14
|
...
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
your_method(1,"foo",:bar) =>
|
17
18
|
method `your_method'
|
18
19
|
variables:
|
19
20
|
args: [1, "foo", :bar]
|
20
21
|
|
22
|
+
or in more rigorous way:
|
23
|
+
|
24
|
+
def your_another_method(first, second, third, &block)
|
25
|
+
inspect!(binding)
|
26
|
+
end
|
27
|
+
|
28
|
+
your_another_method(1,"foo",:bar) =>
|
29
|
+
method `your_another_method'
|
30
|
+
variables:
|
31
|
+
first: 1
|
32
|
+
second: "foo"
|
33
|
+
third: :bar
|
34
|
+
block:
|
35
|
+
|
21
36
|
|
22
|
-
Gives simple but nice trace for inspection: method's name
|
37
|
+
Gives simple but nice trace for inspection: method's name and args that were passed to method
|
23
38
|
|
24
39
|
If you want all #inspect! methods fall silent at once, use
|
25
|
-
|
40
|
+
Cutter::Inspection.quiet!
|
41
|
+
To make them sound again do
|
42
|
+
Cutter::Inspection.loud!
|
26
43
|
|
27
|
-
II)
|
44
|
+
==II) #stamper
|
28
45
|
def your_method
|
29
46
|
stamper("testing pieces of code") do
|
30
47
|
piece_of_code #1
|
@@ -50,8 +67,8 @@ II)
|
|
50
67
|
}
|
51
68
|
end
|
52
69
|
|
53
|
-
Acts as self.benchmark{} or Benchmark.measure{} but with stamps in any position in block executed
|
54
|
-
to write it quickly than all these Measure-dos.
|
70
|
+
Acts as self.benchmark{} (in Rails) or Benchmark.measure{} (common Ruby) but with stamps in any position in block executed.
|
71
|
+
It is much simpler to write it quickly than all these Measure-dos.
|
55
72
|
|
56
73
|
== Contributing to cutter
|
57
74
|
|
@@ -65,6 +82,6 @@ to write it quickly than all these Measure-dos.
|
|
65
82
|
|
66
83
|
== Copyright
|
67
84
|
|
68
|
-
Copyright (c) 2011
|
85
|
+
Copyright (c) 2011 Stanislaw Pankevich. See LICENSE.txt for
|
69
86
|
further details.
|
70
87
|
|
data/lib/cutter/inspection.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module Cutter
|
2
2
|
class Inspection
|
3
|
-
attr_accessor :quiet
|
4
|
-
|
5
3
|
class << self
|
6
4
|
def quiet!
|
7
5
|
@quiet = true
|
8
6
|
end
|
9
7
|
|
8
|
+
def loud!
|
9
|
+
@quiet = nil
|
10
|
+
end
|
11
|
+
|
10
12
|
def quiet?
|
11
13
|
@quiet
|
12
14
|
end
|
@@ -18,16 +20,20 @@ class Object
|
|
18
20
|
# For now inspect! method only may be used with two arguments (local_variables, binding)
|
19
21
|
# Binding is a Ruby class: http://www.ruby-doc.org/core/classes/Binding.html
|
20
22
|
|
21
|
-
def inspect!
|
23
|
+
def inspect! _binding = nil, &block
|
22
24
|
return true if Cutter::Inspection.quiet?
|
23
|
-
|
25
|
+
raise "Try binding as argument or wrap method content into block!" if (!block_given?&&!_binding)
|
26
|
+
_binding ||= block.binding
|
27
|
+
puts "method: `#{caller_method_name}'"
|
24
28
|
puts %{ variables:}
|
25
|
-
|
26
|
-
puts %{ #{lv}: #{
|
29
|
+
eval('local_variables',_binding).map do |lv|
|
30
|
+
puts %{ #{lv}: #{eval(lv.to_s, _binding)} }
|
27
31
|
end
|
32
|
+
yield if block_given?
|
28
33
|
end
|
29
34
|
|
30
|
-
def
|
31
|
-
|
35
|
+
def caller_method_name(level = 1)
|
36
|
+
caller[level][/`([^']*)'/,1].to_sym
|
32
37
|
end
|
38
|
+
|
33
39
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.5.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- stanislaw
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-15 00:00:00 +03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
112
|
+
hash: 951765971
|
113
113
|
segments:
|
114
114
|
- 0
|
115
115
|
version: "0"
|