display 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README +0 -0
  2. data/Rakefile +11 -0
  3. data/VERSION +1 -0
  4. data/lib/display.rb +34 -0
  5. data/spec/spec.display.rb +40 -0
  6. metadata +88 -0
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'jeweler'
2
+ Jeweler::Tasks.new do |s|
3
+ s.name = "display"
4
+ s.summary = "ruby tool for quick debug statements display a, b => 'spec.display,9: a=3, b=3' without any extra work from you"
5
+ s.email = "rogerdpack@gmail.com"
6
+ s.homepage = "http://github.com/rdp/display"
7
+ s.authors = ["Roger Pack"]
8
+ s.add_development_dependency 'rspec'
9
+ s.add_development_dependency 'sane'
10
+ s.add_dependency 'redparse'
11
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/display.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'redparse' # takes forever on doze [ltodo]
2
+
3
+ class Object
4
+ def display *args
5
+ a = caller
6
+ last_caller = a[0] # "spec.analyze:9" # TODO work with full paths
7
+ file, line, *rest = last_caller.split(":") # TODO cache shtuff
8
+ exact_line = File.readlines(file)[line.to_i - 1].strip
9
+ parser=RedParse.new(exact_line)
10
+ tree = parser.parse
11
+ out = nil
12
+ # the trick is to break out with the first method call...
13
+ right_call_node = give_me_first_call_node tree
14
+ # eureka
15
+ out = "#{File.basename(file)},#{line}: "
16
+ out += right_call_node.params.map{ |p|
17
+ "#{p.unparse}=#{args.shift}"
18
+ }.join(', ')
19
+
20
+ puts out
21
+ out
22
+ end
23
+
24
+ def give_me_first_call_node tree
25
+ tree.walk{|parent,i,subi,node|
26
+ if node.class == RedParse::CallNode
27
+ return tree
28
+ else
29
+ return give_me_first_call_node(node.right)
30
+ end
31
+ }
32
+ end
33
+
34
+ end
@@ -0,0 +1,40 @@
1
+ require 'sane'
2
+ require_rel '../lib/display'
3
+ require 'spec/autorun'
4
+
5
+ describe "display" do
6
+
7
+ before do
8
+ a = 3
9
+ b=4
10
+ @output = display a, b
11
+ end
12
+
13
+ it "should be callable" do
14
+ assert @output.contain?( "a=")
15
+ assert @output.contain?( "b=")
16
+ end
17
+
18
+ it "should add spacing appropriately with commas" do
19
+ assert @output.contain?(", ")
20
+ end
21
+
22
+ it "should show linenumber too" do
23
+ assert @output.contain?(",10")
24
+ end
25
+
26
+ it "should retrieve call nodes for ya" do
27
+ for string in ["c = display a, b", "display a, b"] do
28
+ parser=RedParse.new(string)
29
+ tree = parser.parse
30
+ node = give_me_first_call_node tree
31
+ assert node.class == RedParse::CallNode
32
+ assert node.params.length == 2
33
+ end
34
+ end
35
+
36
+ it "shouldn't barf with more complex things" do
37
+ output = display 3, 4+5
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: display
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roger Pack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sane
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: redparse
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description:
46
+ email: rogerdpack@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README
53
+ files:
54
+ - README
55
+ - Rakefile
56
+ - VERSION
57
+ - lib/display.rb
58
+ - spec/spec.display.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/rdp/display
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: "ruby tool for quick debug statements display a, b => 'spec.display,9: a=3, b=3' without any extra work from you"
87
+ test_files:
88
+ - spec/spec.display.rb