truck 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/truck/autoloader.rb +1 -1
- data/lib/truck/context.rb +4 -0
- data/lib/truck/version.rb +1 -1
- data/test/integration/autoloading_test.rb +4 -0
- data/test/support/fakes_filesystem.rb +10 -0
- data/test/support/tests_autoloading.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6550bf60079074a0644f6df1401efeff49ea3fa9
|
4
|
+
data.tar.gz: 0ce9473dd821156f8ecc5f0b6dea687758ab235c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ed94e3c7d982d972caa6197cc0c0efb4d25f2cb4737005bc589ae21b8a9435bd63ccc089d7332f4687e568906794a6b89220f9f9746b80feb9280386ebb79e4
|
7
|
+
data.tar.gz: 69070a911e5bd34d27578be9b1a8bab52e9f52e8dae705be85f3ca455810fd2928d388da54f4c632b5999c29188dd53ceaeb8870508d6262069deec8c9b25786
|
data/README.md
CHANGED
@@ -100,6 +100,22 @@ Truck.define_context(
|
|
100
100
|
)
|
101
101
|
```
|
102
102
|
|
103
|
+
### Testing
|
104
|
+
|
105
|
+
You can mix in your contexts into your tests, e.g.:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Truck.define_context :MyContext, root: "/path/to/root"
|
109
|
+
|
110
|
+
class MyTest < Minitest::Test
|
111
|
+
include MyContext
|
112
|
+
|
113
|
+
def test_anything
|
114
|
+
assert MyClass # MyClass is autoloaded within MyContext
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
103
119
|
### Compatibiilty
|
104
120
|
|
105
121
|
Currently, truck has been tested against 2.1.1. It uses refinements internally. The plan is to support recent rubinius releases as well.
|
data/lib/truck/autoloader.rb
CHANGED
@@ -46,7 +46,7 @@ module Truck
|
|
46
46
|
# given "Foo::Bar::Baz", return ["Foo::Bar::Baz", "Foo::Bar", etc.]
|
47
47
|
def fetch_context_and_base_nibbles
|
48
48
|
each_base_nibble.to_a.reverse.reduce [] do |ary, (mod, const)|
|
49
|
-
owner = Truck.contexts.each_value.detect { |c| c.
|
49
|
+
owner = Truck.contexts.each_value.detect { |c| c.context_for? mod }
|
50
50
|
return [owner, ary] if owner
|
51
51
|
ary.map! do |e| e.insert 0, '::'; e.insert 0, const; end
|
52
52
|
ary << const
|
data/lib/truck/context.rb
CHANGED
data/lib/truck/version.rb
CHANGED
@@ -40,4 +40,8 @@ class AutoloadingTest < Minitest::Test
|
|
40
40
|
def test_explicit_autoload_paths
|
41
41
|
assert_equal 'hello from Bar::Z', MultipleAutoloadPaths::A.references_z
|
42
42
|
end
|
43
|
+
|
44
|
+
def test_reference_constants_in_included_class
|
45
|
+
assert_equal 'hello from B::BA', MyApp::IncludesFoo.message
|
46
|
+
end
|
43
47
|
end
|
@@ -179,6 +179,16 @@ module A
|
|
179
179
|
end
|
180
180
|
FILE
|
181
181
|
|
182
|
+
File.write "/my_app/lib/includes_foo.rb", <<-FILE
|
183
|
+
class IncludesFoo
|
184
|
+
include Foo
|
185
|
+
|
186
|
+
def self.message
|
187
|
+
D.new.references_b_ba
|
188
|
+
end
|
189
|
+
end
|
190
|
+
FILE
|
191
|
+
|
182
192
|
Dir.mkdir "/my_app/lib/b"
|
183
193
|
File.write "/my_app/lib/b/ba.rb", <<-FILE
|
184
194
|
module B
|
@@ -2,6 +2,7 @@ module TestsAutoloading
|
|
2
2
|
def setup
|
3
3
|
@foo = Truck.define_context :Foo, root: "/foo"
|
4
4
|
@bar = Truck.define_context :Bar, root: '/bar', parent: :Foo
|
5
|
+
@my_app = Truck.define_context :MyApp, root: "/my_app", autoload_paths: %w(lib)
|
5
6
|
@multi = Truck.define_context :MultipleAutoloadPaths, root: "/", autoload_paths: %w(foo bar)
|
6
7
|
Truck.boot!
|
7
8
|
assert_nil Truck::Autoloader.current_autoloader
|