callsite 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,21 @@ Gives back
18
18
 
19
19
  This is also suitable for parsing a backtrace, to get detailed information about it.
20
20
 
21
+ begin
22
+ raise
23
+ rescue
24
+ pp Callsite.parse($!)
25
+ end
26
+
27
+ Produces
28
+
29
+ => [#<struct Callsite::Line filename="(irb)", line=27, method="irb_binding">,
30
+ #<struct Callsite::Line
31
+ filename="/opt/local/lib/ruby/1.8/irb/workspace.rb",
32
+ line=52,
33
+ method="irb_binding">,
34
+ #<struct Callsite::Line filename="", line=0, method=nil>]
35
+
21
36
  There are also six methods which patch existing objects to give you powerful usage of the caller.
22
37
 
23
38
  === Callsite.activate_string_methods
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec'
2
2
  require 'spec/rake/spectask'
3
- task :spec => ['spec:dirge', 'spec:load_path_find']
3
+ task :spec => ['spec:dirge', 'spec:load_path_find', 'spec:callsite']
4
4
  namespace(:spec) do
5
5
  Spec::Rake::SpecTask.new(:dirge) do |t|
6
6
  t.spec_opts ||= []
@@ -18,5 +18,15 @@ namespace(:spec) do
18
18
  t.spec_files = FileList['spec/**/load_path_find_spec.rb']
19
19
  end
20
20
 
21
+ Spec::Rake::SpecTask.new(:callsite) do |t|
22
+ t.spec_opts ||= []
23
+ t.spec_opts << "-rubygems"
24
+ t.spec_opts << '-rlib/load_path_find'
25
+ t.spec_opts << "--options" << "spec/spec.opts"
26
+ t.spec_files = FileList['spec/**/callsite_spec.rb']
27
+ end
28
+
21
29
  end
22
30
 
31
+ require 'ext/gem_rake'
32
+ Bundler::GemHelper.install_tasks
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
10
  s.authors = ["Joshua Hull"]
11
- s.date = %q{2010-07-15}
11
+ s.date = %q{2010-07-22}
12
12
  s.description = %q{Caller/backtrace parser with some useful utilities for manipulating the load path, and doing other relative things.}
13
13
  s.email = %q{joshbuddy@gmail.com}
14
14
  s.extra_rdoc_files = [
@@ -0,0 +1,126 @@
1
+ module Bundler
2
+ class GemHelper
3
+
4
+ def self.install_tasks
5
+ dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
6
+ GemHelper.new(dir).install
7
+ end
8
+
9
+ attr_reader :spec_path, :base, :name
10
+
11
+ def initialize(base, name = nil)
12
+ @base = base
13
+ @name = name || interpolate_name
14
+ @spec_path = File.join(@base, "#{@name}.gemspec")
15
+ end
16
+
17
+ def install
18
+ desc 'Build your gem into the pkg directory'
19
+ task 'build' do
20
+ build_gem
21
+ end
22
+
23
+ desc 'Install your gem into the pkg directory'
24
+ task 'install' do
25
+ install_gem
26
+ end
27
+
28
+ desc 'Push your gem to rubygems'
29
+ task 'push' do
30
+ push_gem
31
+ end
32
+ end
33
+
34
+ def build_gem
35
+ file_name = nil
36
+ sh("gem build #{spec_path}") {
37
+ file_name = File.basename(built_gem_path)
38
+ FileUtils.mkdir_p(File.join(base, 'pkg'))
39
+ FileUtils.mv(built_gem_path, 'pkg')
40
+ }
41
+ File.join(base, 'pkg', file_name)
42
+ end
43
+
44
+ def install_gem
45
+ built_gem_path = build_gem
46
+ sh("gem install #{built_gem_path}")
47
+ end
48
+
49
+ def push_gem
50
+ guard_clean
51
+ guard_already_tagged
52
+ tag_version {
53
+ git_push
54
+ rubygem_push(build_gem)
55
+ }
56
+ end
57
+
58
+ protected
59
+ def rubygem_push(path)
60
+ sh("gem push #{path}")
61
+ end
62
+
63
+ def built_gem_path
64
+ Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
65
+ end
66
+
67
+ def interpolate_name
68
+ gemspecs = Dir[File.join(base, "*.gemspec")]
69
+ raise "Unable to determine name from existing gemspec." unless gemspecs.size == 1
70
+
71
+ File.basename(gemspecs.first)[/^(.*)\.gemspec$/, 1]
72
+ end
73
+
74
+ def git_push
75
+ sh "git push --all"
76
+ sh "git push --tags"
77
+ end
78
+
79
+ def guard_already_tagged
80
+ sh('git tag').split(/\n/).include?(current_version_tag) and raise("This tag has already been committed to the repo.")
81
+ end
82
+
83
+ def guard_clean
84
+ clean? or raise("There are files that need to be committed first.")
85
+ end
86
+
87
+ def clean?
88
+ sh("git ls-files -dm").split("\n").size.zero?
89
+ end
90
+
91
+ def tag_version
92
+ sh "git tag #{current_version_tag}"
93
+ yield if block_given?
94
+ rescue
95
+ sh "git tag -d #{current_version_tag}"
96
+ raise
97
+ end
98
+
99
+ def current_version
100
+ raise("Version file could not be found at #{version_file_path}") unless File.exist?(version_file_path)
101
+ File.read(version_file_path)[/V(ERSION|ersion)\s*=\s*(["'])(.*?)\2/, 3]
102
+ end
103
+
104
+ def version_file_path
105
+ File.join(base, 'lib', name, 'version.rb')
106
+ end
107
+
108
+ def current_version_tag
109
+ "v#{current_version}"
110
+ end
111
+
112
+ def sh(cmd, &block)
113
+ output, code = sh_with_code(cmd, &block)
114
+ code == 0 ? output : raise(output)
115
+ end
116
+
117
+ def sh_with_code(cmd, &block)
118
+ output = ''
119
+ Dir.chdir(base) {
120
+ output = `#{cmd}`
121
+ block.call if block and $? == 0
122
+ }
123
+ [output, $?]
124
+ end
125
+ end
126
+ end
@@ -14,7 +14,9 @@ module Callsite
14
14
  end
15
15
 
16
16
  def self.parse(input)
17
- if input.is_a?(Array)
17
+ if input.respond_to?(:backtrace)
18
+ parse(input.backtrace)
19
+ elsif input.is_a?(Array)
18
20
  block_given? ?
19
21
  input.each{|line| yield parse(line)} :
20
22
  input.map{|line| parse(line)}
@@ -1,3 +1,3 @@
1
1
  module Callsite
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
@@ -4,7 +4,7 @@ module Kernel
4
4
  end
5
5
 
6
6
  def require_next(req)
7
- found, current = false, File.expand_path(caller.first[/^[^:]+/])
7
+ found, current = false, File.expand_path(caller.first[/(.*)(:\d+)/,1])
8
8
  $LOAD_PATH.find_all_files(req, ".rb") do |file|
9
9
  if found
10
10
  $LOADED_FEATURES << req
@@ -0,0 +1,16 @@
1
+ describe 'Callsite' do
2
+
3
+ it "should parse dir:name/file:name:12" do
4
+ @parsed = Callsite.parse('dir:name/file:name:12')
5
+ @parsed.filename.should == 'dir:name/file:name'
6
+ @parsed.line.should == 12
7
+ @parsed.method.should == nil
8
+ end
9
+
10
+ it "should parse dir:name/file:name:12:in `something'" do
11
+ @parsed = Callsite.parse("dir:name/file:name:12:in `something'")
12
+ @parsed.filename.should == 'dir:name/file:name'
13
+ @parsed.line.should == 12
14
+ @parsed.method.should == 'something'
15
+ end
16
+ end
@@ -1,22 +1,26 @@
1
1
  describe 'Dirge' do
2
+ before do
3
+ @dir = 'test2test'
4
+ end
2
5
  it "should resolve a path through String#~" do
3
- (~'test:2test/test').should == File.expand_path(File.join(File.dirname(__FILE__), 'test:2test', 'test'))
6
+ (~"#{@dir}/test").should == File.expand_path(File.join(File.dirname(__FILE__), @dir, 'test'))
4
7
  end
5
8
 
6
9
  it "should resolve a path through File#relative" do
7
- File.relative('test:2test/test').should == File.expand_path(File.join(File.dirname(__FILE__), 'test:2test', 'test'))
10
+ File.relative("#{@dir}/test").should == File.expand_path(File.join(File.dirname(__FILE__), @dir, 'test'))
8
11
  end
9
12
 
10
13
  it 'should require a relative path' do
11
14
  proc {
12
- require_relative 'test:2test/test'
15
+ require_relative "#{@dir}/test"
13
16
  }.should raise_error(RuntimeError, 'okay okay, you included me')
14
17
  end
15
18
 
16
19
  it 'should autoload a relative path' do
20
+ dir = @dir
17
21
  proc {
18
22
  mod = Module.new do
19
- autoload_relative :TestingTime, 'test:2test/test'
23
+ autoload_relative :TestingTime, "#{dir}/test"
20
24
  end
21
25
  mod::TestingTime
22
26
  }.should raise_error(RuntimeError, 'okay okay, you included me')
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callsite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-15 00:00:00 -04:00
18
+ date: 2010-07-22 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -32,6 +32,7 @@ files:
32
32
  - Rakefile
33
33
  - VERSION
34
34
  - callsite.gemspec
35
+ - ext/gem_rake.rb
35
36
  - lib/callsite.rb
36
37
  - lib/callsite/version.rb
37
38
  - lib/dirge.rb
@@ -39,6 +40,7 @@ files:
39
40
  - lib/loaders/kernel_dir.rb
40
41
  - lib/loaders/kernel_require.rb
41
42
  - lib/loaders/load_path.rb
43
+ - spec/callsite_spec.rb
42
44
  - spec/data/dir1/file1
43
45
  - spec/data/dir1/test.rb
44
46
  - spec/data/dir1/test2.rb
@@ -48,7 +50,7 @@ files:
48
50
  - spec/dirge_spec.rb
49
51
  - spec/load_path_find_spec.rb
50
52
  - spec/spec.opts
51
- - spec/test:2test/test.rb
53
+ - spec/test2test/test.rb
52
54
  has_rdoc: true
53
55
  homepage: http://github.com/joshbuddy/callsite
54
56
  licenses: []
@@ -84,6 +86,7 @@ signing_key:
84
86
  specification_version: 3
85
87
  summary: Caller/backtrace parser with some useful utilities for manipulating the load path, and doing other relative things.
86
88
  test_files:
89
+ - spec/callsite_spec.rb
87
90
  - spec/data/dir1/file1
88
91
  - spec/data/dir1/test.rb
89
92
  - spec/data/dir1/test2.rb
@@ -93,4 +96,4 @@ test_files:
93
96
  - spec/dirge_spec.rb
94
97
  - spec/load_path_find_spec.rb
95
98
  - spec/spec.opts
96
- - spec/test:2test/test.rb
99
+ - spec/test2test/test.rb