lazy_load 0.0.2 → 0.0.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
1
 
2
+ HEAD
3
+
4
+
5
+
6
+ 0.0.3
7
+ alias #map to #dep
8
+ # group method
9
+
10
+
2
11
  0.0.2
3
12
  Initial version
data/README.md CHANGED
@@ -56,7 +56,7 @@ Notice how, when a block is used, it must return the constant. The help message
56
56
 
57
57
  ### Errors
58
58
 
59
- Referencing constant beneath `LazyLoad` for which there is no mapping, resuslts in the usual `NameError`. Referencing an unavailable constant typically gives a `LazyLoad::DependencyError`, which conveniently is also a subclass of `NameError`.
59
+ Referencing a constant beneath `LazyLoad` for which there is no mapping resuslts in the usual `NameError`. Referencing an unavailable constant typically gives a `LazyLoad::DependencyError`, which conveniently is also a subclass of `NameError`.
60
60
 
61
61
 
62
62
  ### Best available
data/lib/lazy_load.rb CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  module LazyLoad
5
5
 
6
- VERSION = '0.0.2'
6
+ VERSION = '0.0.3'
7
7
 
8
8
  class DependencyError < NameError; end
9
9
 
@@ -12,6 +12,7 @@ module LazyLoad
12
12
  def reset!
13
13
  @messages = {}
14
14
  @actions = {}
15
+ @groups = {}
15
16
  self
16
17
  end
17
18
 
@@ -27,6 +28,12 @@ module LazyLoad
27
28
  ArgumentError, "missing require path or callback")
28
29
  end
29
30
 
31
+ def group(name, *constants)
32
+ @groups[name] = constants
33
+ end
34
+
35
+ alias :dep :map
36
+
30
37
  def unmap(name)
31
38
  @messages.delete(name)
32
39
  @actions.delete(name)
@@ -56,7 +63,7 @@ module LazyLoad
56
63
  # list of constant names.
57
64
  #
58
65
  def best(*names)
59
- names.each do |name|
66
+ expand_groups(names).each do |name|
60
67
  begin
61
68
  return const_get(name)
62
69
  rescue NameError; end
@@ -64,6 +71,13 @@ module LazyLoad
64
71
  const_get(names.first)
65
72
  end
66
73
  alias :first_available :best
74
+ alias :[] :best
75
+
76
+ def expand_groups(names)
77
+ names.map do |name|
78
+ @groups[name] || name
79
+ end.flatten
80
+ end
67
81
 
68
82
  end
69
83
 
@@ -12,6 +12,7 @@ class LazyLoadTest < TestCase
12
12
  LazyLoad.map(:Unavailable) do
13
13
  raise LazyLoad::DependencyError, 'not available'
14
14
  end
15
+ LazyLoad.group(:test_grp, :Bogus, :Unavailable, :Message)
15
16
  yield
16
17
  LazyLoad.reset!
17
18
  end
@@ -96,6 +97,12 @@ class LazyLoadTest < TestCase
96
97
  end
97
98
  end
98
99
  end
100
+
101
+ test 'groups' do
102
+ with_mappings do
103
+ assert_equal 'love', LazyLoad[:test_grp]
104
+ end
105
+ end
99
106
 
100
107
  end
101
108
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jostein Berre Eliassen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-06 00:00:00 +02:00
17
+ date: 2011-06-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20