smtlaissezfaire-using 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/using.rb +10 -4
  3. data/spec/using_spec.rb +15 -0
  4. metadata +4 -4
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 2
4
+ :patch: 3
data/lib/using.rb CHANGED
@@ -1,10 +1,14 @@
1
- require "facets/string/pathize"
1
+ begin
2
+ require "facets/string/pathize"
3
+ rescue LoadError
4
+ raise LoadError, "You must install the facets gem to use the 'Using' package"
5
+ end
2
6
 
3
7
  module Using
4
8
  unless defined?(LOAD_SCHEMES)
5
9
  LOAD_SCHEMES = [:require, :load, :autoload]
6
10
 
7
- class << self
11
+ module DefaultLoadSchemes
8
12
  def reset_default_load_scheme!
9
13
  @default_load_scheme = nil
10
14
  end
@@ -18,6 +22,8 @@ module Using
18
22
  end
19
23
  end
20
24
 
25
+ extend DefaultLoadSchemes
26
+
21
27
  def load_scheme
22
28
  @load_scheme ||= ::Using.default_load_scheme
23
29
  end
@@ -38,9 +44,9 @@ module Using
38
44
  self.load_scheme = old_scheme
39
45
  end
40
46
 
41
- def using(const_name)
47
+ def using(const_name, options={})
42
48
  path = File.expand_path(caller(1)[0].gsub(/\.rb.*$/, ""))
43
- file_name = const_name.to_s.pathize
49
+ file_name = options[:file] || const_name.to_s.pathize
44
50
 
45
51
  case load_scheme
46
52
  when :require then require File.join(path, file_name)
data/spec/using_spec.rb CHANGED
@@ -63,6 +63,11 @@ describe Using do
63
63
  @obj.should_receive(:require).with("#{file_prefix}/foo_bar")
64
64
  @obj.using :FooBar
65
65
  end
66
+
67
+ it "should allow a custom filename" do
68
+ @obj.should_receive(:require).with("#{file_prefix}/foobar.pb")
69
+ @obj.using :FooBar, :file => "foobar.pb"
70
+ end
66
71
  end
67
72
 
68
73
  describe "with autoload" do
@@ -75,6 +80,11 @@ describe Using do
75
80
  @obj.should_receive(:autoload).with(:Foo, "#{file_prefix}/foo")
76
81
  @obj.using :Foo
77
82
  end
83
+
84
+ it "should allow a custom filename" do
85
+ @obj.should_receive(:autoload).with(:FooBar, "#{file_prefix}/foobar.pb")
86
+ @obj.using :FooBar, :file => "foobar.pb"
87
+ end
78
88
  end
79
89
 
80
90
  describe "when using load" do
@@ -87,6 +97,11 @@ describe Using do
87
97
  @obj.should_receive(:load).with("#{file_prefix}/foo.rb")
88
98
  @obj.using :Foo
89
99
  end
100
+
101
+ it "should allow a custom filename, tacking on .rb" do
102
+ @obj.should_receive(:load).with("#{file_prefix}/foobar.pb.rb")
103
+ @obj.using :FooBar, :file => "foobar.pb"
104
+ end
90
105
  end
91
106
 
92
107
  describe "using a load scheme with a block" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smtlaissezfaire-using
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Taylor
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-08 00:00:00 -07:00
12
+ date: 2009-06-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,7 +30,7 @@ files:
30
30
  - spec/spec_helper.rb
31
31
  - spec/using_spec.rb
32
32
  - README
33
- has_rdoc: true
33
+ has_rdoc: false
34
34
  homepage: http://github.com/smtlaissezfaire/using
35
35
  post_install_message:
36
36
  rdoc_options:
@@ -54,7 +54,7 @@ requirements: []
54
54
  rubyforge_project:
55
55
  rubygems_version: 1.2.0
56
56
  signing_key:
57
- specification_version: 2
57
+ specification_version: 3
58
58
  summary: Ruby File loading made easy
59
59
  test_files:
60
60
  - spec/spec_helper.rb