dirge 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,3 +12,18 @@ begin
12
12
  rescue LoadError
13
13
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
14
14
  end
15
+
16
+ require 'spec'
17
+ require 'spec/rake/spectask'
18
+ task :spec => 'spec:all'
19
+ namespace(:spec) do
20
+ Spec::Rake::SpecTask.new(:all) do |t|
21
+ t.spec_opts ||= []
22
+ t.spec_opts << "-rubygems"
23
+ t.spec_opts << '-rlib/dirge'
24
+ t.spec_opts << "--options" << "spec/spec.opts"
25
+ t.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ end
29
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,25 +1,34 @@
1
1
  module Kernel
2
- def __DIR__(called_from = nil)
2
+ def __DIR_REL__(called_from = nil)
3
3
  called_from ||= caller.first
4
- caller_path = called_from[/(.*?(?=:\d))/, 1]
4
+ caller_path = called_from[/(.*?(?=:\d+(:|$)))/, 1]
5
5
  caller_path = '.' if caller_path == ''
6
6
  File.expand_path(File.dirname(caller_path))
7
7
  end
8
8
 
9
- def require_relative(path)
10
- require File.join(__DIR__(caller.first), path)
9
+ unless method_defined?(:__DIR__)
10
+ alias_method :__DIR__, :__DIR_REL__
11
11
  end
12
12
 
13
+ unless method_defined?(:require_relative)
14
+ def require_relative(path)
15
+ require File.join(__DIR_REL__(caller.first), path)
16
+ end
17
+ end
13
18
  end
14
19
 
15
20
  class Module
16
- def self.autoload_relative(name, filename)
17
- autoload name, File.join(__DIR__(caller.first), filename)
21
+ unless method_defined?(:autoload_relative)
22
+ def autoload_relative(name, filename)
23
+ autoload name, File.join(__DIR_REL__(caller.first), filename)
24
+ end
18
25
  end
19
26
  end
20
27
 
21
28
  class String
22
- def ~@
23
- File.expand_path(File.join(__DIR__(caller.first), self))
29
+ unless method_defined?(:~@)
30
+ def ~@
31
+ File.expand_path(File.join(__DIR_REL__(caller.first), self))
32
+ end
24
33
  end
25
34
  end
@@ -0,0 +1,29 @@
1
+ describe 'Dirge' do
2
+ it "should resolve a path" do
3
+ (~'test:2test/test').should == File.expand_path(File.join(File.dirname(__FILE__), 'test:2test', 'test'))
4
+ end
5
+
6
+ it 'should require a relative path' do
7
+ proc {
8
+ require_relative 'test:2test/test'
9
+ }.should raise_error(RuntimeError, 'okay okay, you included me')
10
+ end
11
+
12
+ it 'should autoload a relative path' do
13
+ proc {
14
+ mod = Module.new do
15
+ autoload_relative :TestingTime, 'test:2test/test'
16
+ end
17
+ mod::TestingTime
18
+ }.should raise_error(RuntimeError, 'okay okay, you included me')
19
+ end
20
+
21
+ it "should define __DIR__" do
22
+ __DIR__.should == File.expand_path(File.dirname(__FILE__))
23
+ end
24
+
25
+ it "should define __DIR__ with a custom caller" do
26
+ __DIR__('testing/test.rb:3').should == File.expand_path('testing')
27
+ end
28
+
29
+ end
@@ -0,0 +1 @@
1
+ raise 'okay okay, you included me'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-20 00:00:00 -08:00
12
+ date: 2009-11-21 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -54,5 +54,6 @@ rubygems_version: 1.3.5
54
54
  signing_key:
55
55
  specification_version: 3
56
56
  summary: Relative require, relative autoload and __DIR__
57
- test_files: []
58
-
57
+ test_files:
58
+ - spec/dirge_spec.rb
59
+ - spec/test:2test/test.rb