Backtrace_Array 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ coverage
7
+ rdoc
8
+ .yardoc
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "Backtrace_Array/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "Backtrace_Array"
8
+ s.version = Backtrace_Array_Version
9
+ s.authors = ["da99"]
10
+ s.email = ["i-hate-spam-45671204@mailinator.com"]
11
+ s.homepage = "https://github.com/da99/Backtrace_Array"
12
+ s.summary = %q{
13
+ Turn backtrace String or Array into a specially made Array for your views.
14
+ }
15
+ s.description = %q{
16
+ Check the homepage because I can't describe it probably here.
17
+ }
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency 'bacon'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'Bacon_Colored'
27
+ s.add_development_dependency 'pry'
28
+
29
+ # Specify any dependencies here; for example:
30
+ s.add_runtime_dependency 'Split_Lines'
31
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Bob.gemspec
6
+ gemspec
@@ -0,0 +1,73 @@
1
+
2
+ Backtrace\_Array
3
+ ================
4
+
5
+ A Ruby gem to alter structure of a backtrace:
6
+
7
+ Original Backtrace:
8
+
9
+ [ String, String, String ]
10
+
11
+ New Array:
12
+
13
+ [
14
+ [ unique file 1, [ [line, code], [line, code], ... ] ]
15
+ [ unique file 2, [ [line, code], [line, code], ... ] ]
16
+ [ unique file 3, [ [line, code], [line, code], ... ] ]
17
+
18
+ ]
19
+
20
+ This lets you present it in your views as:
21
+
22
+ <p>
23
+ <pre>
24
+ <b style="color: purple;">unique file 1</b>
25
+ <b>line</b>: code
26
+ <b>line</b>: code
27
+ <b>line</b>: code
28
+
29
+ <b style="color: purple;">unique file 2</b>
30
+ <b>line</b>: code
31
+ <b>line</b>: code
32
+ <b>line</b>: code
33
+ </pre>
34
+ </p>
35
+
36
+ Installation
37
+ ------------
38
+
39
+ gem install Backtrace_Array
40
+
41
+ Usage
42
+ ------
43
+
44
+ require "Backtrace_Array"
45
+
46
+ begin
47
+ raise
48
+ rescue Object => e
49
+ Backtrace_Array $?.backtrace
50
+ end
51
+
52
+ # or ...
53
+ Backtrace_Array %~
54
+ file1:1: in `new'
55
+ file2:2: in `<main>'
56
+ file3:3: in `eval'
57
+ ~
58
+
59
+
60
+ Run Tests
61
+ ---------
62
+
63
+ git clone git@github.com:da99/Backtrace_Array.git
64
+ cd Backtrace_Array
65
+ bundle update
66
+ bundle exec bacon spec/lib/main.rb
67
+
68
+ "I hate writing."
69
+ -----------------------------
70
+
71
+ If you know of existing software that makes the above redundant,
72
+ please tell me. The last thing I want to do is maintain code.
73
+
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ require 'Backtrace_Array/version'
2
+ require 'Split_Lines'
3
+ def Backtrace_Array str_or_array
4
+ arr = if str_or_array.is_a?(Enumerable)
5
+ str_or_array
6
+ else
7
+ Split_Lines str_or_array
8
+ end
9
+
10
+ last_file = nil
11
+ final = []
12
+ arr.each { |l|
13
+ pieces = l.split( %r!:(\d+):! )
14
+ file = pieces.shift
15
+ num = pieces.shift
16
+ (num = Integer num) if num
17
+ code = pieces.join(':') unless pieces.empty?
18
+
19
+ if last_file != file
20
+ final << [ file, [] ]
21
+ last_file = file
22
+ end
23
+
24
+ content_arr = [num, code].compact
25
+ (final.last.last << content_arr) unless content_arr.empty?
26
+ }
27
+
28
+ final
29
+ end # === def Backtrace_Array
@@ -0,0 +1 @@
1
+ Backtrace_Array_Version = "0.1.0"
@@ -0,0 +1,86 @@
1
+
2
+ describe "Backtrace_Array string" do
3
+
4
+ before {
5
+ @arr = Backtrace_Array(%~
6
+ file1:1:in >main
7
+ file1:2:in >main
8
+ file2:3:in >main
9
+ file2:4:in >main
10
+ ~)
11
+ }
12
+
13
+ it "returns an Array of 2 element Arrays" do
14
+ @arr.map(&:size)
15
+ .should == [2, 2]
16
+ end
17
+
18
+ it "sets the first element equal to filename" do
19
+ @arr.map(&:first)
20
+ .should == %w{ file1 file2 }
21
+ end
22
+
23
+ it "sets the second element to a 2 element line/code pair" do
24
+ @arr.map(&:last)
25
+ .should == [
26
+ [[1, 'in >main'], [2, 'in >main']],
27
+ [[3, 'in >main'], [4, 'in >main']]
28
+ ]
29
+ end
30
+
31
+ end # === Backtrace_Array string
32
+
33
+ describe "Backtrace_Array array" do
34
+
35
+ before {
36
+ @arr = Backtrace_Array(Split_Lines %~
37
+ file1:1:in >main
38
+ file1:2:in >main
39
+ file2:3:in >main
40
+ file2:4:in >main
41
+ ~)
42
+ }
43
+
44
+ it "returns an Array of 2 element Arrays" do
45
+ @arr.map(&:size)
46
+ .should == [2, 2]
47
+ end
48
+
49
+ it "sets the first element equal to filename" do
50
+ @arr.map(&:first)
51
+ .should == %w{ file1 file2 }
52
+ end
53
+
54
+ it "sets the second element to a 2 element line/code pair" do
55
+ @arr.map(&:last)
56
+ .should == [
57
+ [[1, 'in >main'], [2, 'in >main']],
58
+ [[3, 'in >main'], [4, 'in >main']]
59
+ ]
60
+ end
61
+
62
+ end # === Backtrace_Array array
63
+
64
+
65
+ describe "Backtrace_Array non-backtrace lines" do
66
+
67
+ it "treats line as a file with no other content" do
68
+ Backtrace_Array(File.read('spec/file/thin_A.log'))
69
+ .last
70
+ .should == [ ">> Using rack adapter", [] ]
71
+ end
72
+
73
+ it "uses the first :\d+: as the line number, ignoring all others" do
74
+ Backtrace_Array(%~
75
+ file1:1:in:1:a
76
+ file2:2:in:2:a
77
+ ~)
78
+ .should == [
79
+ ['file1', [ [1, "in:1:a"] ] ],
80
+ ['file2', [ [2, "in:2:a"] ] ]
81
+ ]
82
+ end
83
+
84
+ end # === Backtrace_Array non-standard lines
85
+
86
+
@@ -0,0 +1,13 @@
1
+
2
+ bins = Dir.glob("bin/*")
3
+
4
+ unless bins.empty?
5
+ describe "permissions of bin/" do
6
+ bins.each { |file|
7
+ it "should chmod 755 for: #{file}" do
8
+ `stat -c %a #{file}`.strip
9
+ .should.be == "755"
10
+ end
11
+ }
12
+ end # === permissions of bin/
13
+ end # === unless bins.empty?
@@ -0,0 +1,16 @@
1
+ /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `block in <main>': uninitialized constant A (NameError)
2
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
3
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
4
+ from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `new'
5
+ from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `<main>'
6
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `eval'
7
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `load'
8
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:45:in `for'
9
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:169:in `load_adapter'
10
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:73:in `start'
11
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:185:in `run_command'
12
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:151:in `run!'
13
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/bin/thin:6:in `<top (required)>'
14
+ from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `load'
15
+ from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `<main>'
16
+ >> Using rack adapter
@@ -0,0 +1,16 @@
1
+ /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `block in <main>': uninitialized constant B (NameError)
2
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
3
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
4
+ from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `new'
5
+ from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `<main>'
6
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `eval'
7
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `load'
8
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:45:in `for'
9
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:169:in `load_adapter'
10
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:73:in `start'
11
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:185:in `run_command'
12
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:151:in `run!'
13
+ from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/bin/thin:6:in `<top (required)>'
14
+ from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `load'
15
+ from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `<main>'
16
+ >> Using rack adapter
@@ -0,0 +1,45 @@
1
+
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.print e.message, "\n"
8
+ $stderr.print "Run `bundle install` to install missing gems\n"
9
+ exit e.status_code
10
+ end
11
+ require 'bacon'
12
+
13
+ Gem_Dir = File.expand_path( File.join(File.dirname(__FILE__) + '/../..') )
14
+ $LOAD_PATH.unshift Gem_Dir
15
+ $LOAD_PATH.unshift( Gem_Dir + "/lib" )
16
+
17
+ Bacon.summary_on_exit
18
+
19
+ require 'Backtrace_Array'
20
+ require 'Bacon_Colored'
21
+ require 'pry'
22
+
23
+
24
+
25
+ # ======== Custom code.
26
+
27
+ # Nothing yet.
28
+
29
+
30
+
31
+
32
+ # ======== Include the tests.
33
+ target_files = ARGV[1, ARGV.size - 1].select { |a| File.file?(a) }
34
+
35
+ if target_files.empty?
36
+
37
+ # include all files
38
+ Dir.glob('./spec/*.rb').each { |file|
39
+ require file.sub('.rb', '') if File.file?(file)
40
+ }
41
+
42
+ else
43
+ # Do nothing. Bacon grabs the file.
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Backtrace_Array
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: Bacon_Colored
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: Split_Lines
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: ! "\n Check the homepage because I can't describe it probably here.\n
95
+ \ "
96
+ email:
97
+ - i-hate-spam-45671204@mailinator.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Backtrace_Array.gemspec
104
+ - Gemfile
105
+ - README.md
106
+ - Rakefile
107
+ - lib/Backtrace_Array.rb
108
+ - lib/Backtrace_Array/version.rb
109
+ - spec/Backtrace_Array.rb
110
+ - spec/bin.rb
111
+ - spec/file/thin_A.log
112
+ - spec/file/thin_B.log
113
+ - spec/lib/main.rb
114
+ homepage: https://github.com/da99/Backtrace_Array
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.23
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Turn backtrace String or Array into a specially made Array for your views.
138
+ test_files: []