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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a2fcfe39879e13f8c344cafb95db949dc89d74b
4
- data.tar.gz: caed4964dd127828e91ff3801f2993f38376d1e9
3
+ metadata.gz: 6550bf60079074a0644f6df1401efeff49ea3fa9
4
+ data.tar.gz: 0ce9473dd821156f8ecc5f0b6dea687758ab235c
5
5
  SHA512:
6
- metadata.gz: 787d4dc1ae99279a73e81461ce69f692d904239b113e6ec67e0e7d323ce513201ffd907086ef9156f6f6d2aff0202e2f79424c870134394328c656fac80a0f7f
7
- data.tar.gz: 51eb6e680f7b7fade4e1a9417c618575d67b07677330eecc7b1255531aa2a14dae010fa5c54931b7021d4af6a28647a69b465fc1b38c02b2fcd8ea37a6b8a0ed
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.
@@ -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.mod == mod }
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
@@ -25,6 +25,10 @@ module Truck
25
25
  parent.const_get name
26
26
  end
27
27
 
28
+ def context_for?(other_mod)
29
+ mod == other_mod or other_mod.included_modules.include? mod
30
+ end
31
+
28
32
  def booted?
29
33
  mod ? true : false
30
34
  end
data/lib/truck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Truck
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ntl