Skip to content
This repository
Browse code

- active_support/delegation

  • Loading branch information...
commit 0f7ec556866b1ff4ac63545cf48f3aa04dc5d230 1 parent b959af6
Florian R. Hanke authored November 27, 2012

Showing 51 changed files with 243 additions and 223 deletions. Show diff stats Hide diff stats

  1. 1  server/lib/picky.rb
  2. 6  server/lib/picky/bundle.rb
  3. 22  server/lib/picky/categories.rb
  4. 3  server/lib/picky/categories_convenience.rb
  5. 4  server/lib/picky/categories_indexed.rb
  6. 8  server/lib/picky/categories_indexing.rb
  7. 14  server/lib/picky/categories_realtime.rb
  8. 8  server/lib/picky/extensions/class.rb
  9. 18  server/lib/picky/extensions/module.rb
  10. 12  server/lib/picky/index.rb
  11. 4  server/lib/picky/index_convenience.rb
  12. 10  server/lib/picky/index_indexed.rb
  13. 8  server/lib/picky/index_indexing.rb
  14. 14  server/lib/picky/index_realtime.rb
  15. 4  server/lib/picky/indexers/base.rb
  16. 29  server/lib/picky/indexes.rb
  17. 4  server/lib/picky/indexes_convenience.rb
  18. 7  server/lib/picky/indexes_indexed.rb
  19. 8  server/lib/picky/indexes_indexing.rb
  20. 2  server/lib/picky/query/allocation.rb
  21. 14  server/lib/picky/query/allocations.rb
  22. 3  server/lib/picky/query/boosts.rb
  23. 6  server/lib/picky/query/combinations.rb
  24. 4  server/lib/picky/query/indexes.rb
  25. 2  server/lib/picky/query/token.rb
  26. 4  server/lib/picky/query/tokens.rb
  27. 2  server/lib/picky/rack/harakiri.rb
  28. 4  server/lib/picky/results.rb
  29. 10  server/lib/picky/search.rb
  30. 88  server/lib/picky/wrappers/bundle/delegators.rb
  31. 2  server/lib/picky/wrappers/bundle/wrapper.rb
  32. 2  server/spec/lib/backends/backend_spec.rb
  33. 2  server/spec/lib/backends/memory/json_spec.rb
  34. 2  server/spec/lib/backends/memory/marshal_spec.rb
  35. 2  server/spec/lib/backends/redis/float_spec.rb
  36. 2  server/spec/lib/backends/redis/string_spec.rb
  37. 4  server/spec/lib/backends/sqlite/array_spec.rb
  38. 2  server/spec/lib/backends/sqlite/value_spec.rb
  39. 2  server/spec/lib/category_indexing_spec.rb
  40. 49  server/spec/lib/extensions/module_spec.rb
  41. 4  server/spec/lib/index_indexed_spec.rb
  42. 2  server/spec/lib/index_spec.rb
  43. 2  server/spec/lib/indexers/base_spec.rb
  44. 4  server/spec/lib/indexes_indexing_spec.rb
  45. 6  server/spec/lib/query/allocation_spec.rb
  46. 12  server/spec/lib/query/allocations_spec.rb
  47. 2  server/spec/lib/query/combinations_spec.rb
  48. 26  server/spec/lib/query/tokens_spec.rb
  49. 4  server/spec/lib/results_spec.rb
  50. 8  server/spec/lib/search_spec.rb
  51. 4  server/spec/lib/sinatra_spec.rb
1  server/lib/picky.rb
@@ -20,7 +20,6 @@ class << self
20 20
   #
21 21
   # TODO Remove active support.
22 22
   #
23  
-  require 'active_support/core_ext/module/delegation'
24 23
   require 'active_support/core_ext/logger'
25 24
   require 'active_support/core_ext/object/blank'
26 25
   require 'active_support/core_ext/enumerable'
6  server/lib/picky/bundle.rb
@@ -41,8 +41,8 @@ class Bundle
41 41
                   :partial_strategy,
42 42
                   :similarity_strategy
43 43
 
44  
-    delegate :[], :[]=,        :to => :configuration
45  
-    delegate :index_directory, :to => :category
  44
+    forward :[], :[]=,        :to => :configuration
  45
+    forward :index_directory, :to => :category
46 46
     
47 47
     # TODO Move the strategies into options.
48 48
     #
@@ -142,7 +142,7 @@ def similar text
142 142
       end
143 143
     end
144 144
 
145  
-    # If a key format is set, use it, else delegate to the category.
  145
+    # If a key format is set, use it, else forward to the category.
146 146
     #
147 147
     def key_format
148 148
       @key_format || @category.key_format
22  server/lib/picky/categories.rb
@@ -4,18 +4,18 @@ class Categories
4 4
 
5 5
     attr_reader :categories, :category_hash
6 6
 
7  
-    delegate :each,
8  
-             :first,
9  
-             :map,
10  
-             :to => :categories
  7
+    forward :each,
  8
+            :first,
  9
+            :map,
  10
+            :to => :categories
11 11
 
12  
-    each_delegate :cache,
13  
-                  :dump,
14  
-                  :empty,
15  
-                  :inject,
16  
-                  :reindex,
17  
-                  :reset_backend,
18  
-                  :to => :categories
  12
+    each_forward :cache,
  13
+                 :dump,
  14
+                 :empty,
  15
+                 :inject,
  16
+                 :reindex,
  17
+                 :reset_backend,
  18
+                 :to => :categories
19 19
 
20 20
     # A list of indexed categories.
21 21
     #
3  server/lib/picky/categories_convenience.rb
@@ -4,8 +4,7 @@ module Picky
4 4
   #
5 5
   class Categories
6 6
 
7  
-    each_delegate :each_bundle,
8  
-                  :to => :categories
  7
+    each_forward :each_bundle, :to => :categories
9 8
 
10 9
     def each_category &block
11 10
       categories.each &block
4  server/lib/picky/categories_indexed.rb
@@ -2,9 +2,7 @@ module Picky
2 2
 
3 3
   class Categories
4 4
 
5  
-    each_delegate :load,
6  
-                  :analyze,
7  
-                  :to => :categories
  5
+    each_forward :load, :analyze, :to => :categories
8 6
 
9 7
     # Return all possible combinations for the given token.
10 8
     #
8  server/lib/picky/categories_indexing.rb
@@ -4,10 +4,10 @@ class Categories
4 4
 
5 5
     include Helpers::Indexing
6 6
 
7  
-    each_delegate :cache,
8  
-                  :clear,
9  
-                  :prepare,
10  
-                  :to => :categories
  7
+    each_forward :cache,
  8
+                 :clear,
  9
+                 :prepare,
  10
+                 :to => :categories
11 11
   end
12 12
 
13 13
 end
14  server/lib/picky/categories_realtime.rb
@@ -2,13 +2,13 @@ module Picky
2 2
 
3 3
   class Categories
4 4
 
5  
-    each_delegate :remove,
6  
-                  :add,
7  
-                  :replace,
8  
-                  :replace_from,
9  
-                  :clear_realtime,
10  
-                  :build_realtime_mapping,
11  
-                  :to => :categories
  5
+    each_forward :remove,
  6
+                 :add,
  7
+                 :replace,
  8
+                 :replace_from,
  9
+                 :clear_realtime,
  10
+                 :build_realtime_mapping,
  11
+                 :to => :categories
12 12
 
13 13
   end
14 14
 
8  server/lib/picky/extensions/class.rb
@@ -2,11 +2,11 @@
2 2
 #
3 3
 class Class
4 4
 
5  
-  def instance_delegate *method_names
  5
+  def instance_forward *method_names
6 6
     method_names.each do |method_name|
7  
-      module_eval(<<-DELEGATION, "(__DELEGATION__)", 1)
8  
-def self.#{method_name}(*args, &block)\n  self.instance.#{method_name}(*args, &block)\nend
9  
-DELEGATION
  7
+      module_eval(<<-FORWARDING, "(__INSTANCE_FORWARDING__)", 1)
  8
+def self.#{method_name}(*args, &block)\n  self.instance.#{method_name}(*args, &block)\nend\n
  9
+FORWARDING
10 10
     end
11 11
   end
12 12
 
18  server/lib/picky/extensions/module.rb
... ...
@@ -1,14 +1,24 @@
1 1
 # The original Module class.
2 2
 #
3 3
 class Module
4  
-
5  
-  def each_delegate *methods
  4
+  
  5
+  def forward *methods
  6
+    options = methods.pop
  7
+    unless options.is_a?(Hash) && to = options[:to]
  8
+      raise ArgumentError, "Forwarding needs a target. Supply an options hash with a :to key as the last argument (e.g. forward :something, :to => :an_array_reader)."
  9
+    end
  10
+    methods.each do |method|
  11
+      module_eval("def #{method}(*args, &block)\n#{to}.__send__(#{method.inspect}, *args, &block)\nend\n", "(__FORWARDING__)", 1)
  12
+    end
  13
+  end
  14
+  
  15
+  def each_forward *methods
6 16
     options = methods.pop
7 17
     unless options.is_a?(Hash) && to = options[:to]
8  
-      raise ArgumentError, "Multi delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :something, :to => :an_array_reader)."
  18
+      raise ArgumentError, "Multi forwarding needs a target. Supply an options hash with a :to key as the last argument (e.g. each_forward :something, :to => :an_array_reader)."
9 19
     end
10 20
     methods.each do |method|
11  
-      module_eval("def #{method}(*args, &block)\n#{to}.each{ |t| t.__send__(#{method.inspect}, *args, &block) }\nend\n", "(__DELEGATION__)", 1)
  21
+      module_eval("def #{method}(*args, &block)\n#{to}.each{ |t| t.__send__(#{method.inspect}, *args, &block) }\nend\n", "(__MULTI_FORWARDING__)", 1)
12 22
     end
13 23
   end
14 24
 
12  server/lib/picky/index.rb
@@ -89,12 +89,12 @@ class Index
89 89
     attr_reader :name,
90 90
                 :categories
91 91
 
92  
-    delegate :[],
93  
-             :dump,
94  
-             :each,
95  
-             :inject,
96  
-             :reset_backend,
97  
-             :to => :categories
  92
+    forward :[],
  93
+            :dump,
  94
+            :each,
  95
+            :inject,
  96
+            :reset_backend,
  97
+            :to => :categories
98 98
 
99 99
     # Create a new index with a given source.
100 100
     #
4  server/lib/picky/index_convenience.rb
@@ -4,9 +4,7 @@ module Picky
4 4
   #
5 5
   class Index
6 6
 
7  
-    delegate :each_bundle,
8  
-             :each_category,
9  
-             :to => :categories
  7
+    forward :each_bundle, :each_category, :to => :categories
10 8
 
11 9
   end
12 10
 
10  server/lib/picky/index_indexed.rb
@@ -4,11 +4,11 @@ module Picky
4 4
   #
5 5
   class Index
6 6
 
7  
-    delegate :load,
8  
-             :analyze,
9  
-             :reindex,
10  
-             :possible_combinations,
11  
-             :to => :categories
  7
+    forward :load,
  8
+            :analyze,
  9
+            :reindex,
  10
+            :possible_combinations,
  11
+            :to => :categories
12 12
 
13 13
     # Define how the results of this index are identified.
14 14
     # (Shown in the client, for example)
8  server/lib/picky/index_indexing.rb
@@ -5,11 +5,7 @@ module Picky
5 5
   class Index
6 6
     include Helpers::Indexing
7 7
 
8  
-    # Delegators for indexing.
9  
-    #
10  
-    delegate :cache,
11  
-             :clear,
12  
-             :to => :categories
  8
+    forward :cache, :clear, :to => :categories
13 9
 
14 10
     # Define an index tokenizer on the index.
15 11
     #
@@ -23,7 +19,7 @@ def indexing options = {}
23 19
     # on every category.
24 20
     #
25 21
     # Decides whether to use a parallel indexer or whether to
26  
-    # delegate to each category to prepare themselves.
  22
+    # forward to each category to prepare themselves.
27 23
     #
28 24
     def prepare scheduler = Scheduler.new
29 25
       if source.respond_to?(:each)
14  server/lib/picky/index_realtime.rb
@@ -4,13 +4,13 @@ module Picky
4 4
   #
5 5
   class Index
6 6
 
7  
-    delegate :remove,  # aka "delete".
8  
-             :add,     # aka "insert".
9  
-             :replace, # aka "insert or update". Thus, not called update.
10  
-             :replace_from,
11  
-             :clear_realtime,
12  
-             :build_realtime_mapping,
13  
-             :to => :categories
  7
+    forward :remove,  # aka "delete".
  8
+            :add,     # aka "insert".
  9
+            :replace, # aka "insert or update". Thus, not called update.
  10
+            :replace_from,
  11
+            :clear_realtime,
  12
+            :build_realtime_mapping,
  13
+            :to => :categories
14 14
 
15 15
     # Add at the end.
16 16
     #
4  server/lib/picky/indexers/base.rb
@@ -10,8 +10,8 @@ class Base
10 10
 
11 11
       attr_reader :index_or_category
12 12
 
13  
-      delegate :source,
14  
-               :to => :index_or_category
  13
+      forward :source,
  14
+              :to => :index_or_category
15 15
 
16 16
       def initialize index_or_category
17 17
         @index_or_category = index_or_category
29  server/lib/picky/indexes.rb
@@ -3,7 +3,7 @@ module Picky
3 3
   # Holds all indexes and provides operations
4 4
   # for extracting and working on them.
5 5
   #
6  
-  # Delegates a number of operations to the
  6
+  # Forwards a number of operations to the
7 7
   # indexes.
8 8
   #
9 9
   class Indexes
@@ -11,12 +11,17 @@ class Indexes
11 11
     attr_reader :indexes,
12 12
                 :index_mapping
13 13
 
14  
-    delegate :size,
15  
-             :each,
16  
-             :to => :indexes
17  
-
18  
-    each_delegate :reindex,
19  
-                  :to => :indexes
  14
+    forward :size, :each, :to => :indexes
  15
+    each_forward :reindex, :to => :indexes
  16
+    instance_forward :clear,
  17
+                     :clear_indexes,
  18
+                     :register,
  19
+                     :reindex,
  20
+                     :[],
  21
+                     :to_s,
  22
+                     :size,
  23
+                     :each,
  24
+                     :each_category
20 25
 
21 26
     def initialize *indexes
22 27
       clear_indexes
@@ -32,16 +37,6 @@ def self.identifier
32 37
       name
33 38
     end
34 39
 
35  
-    instance_delegate :clear,
36  
-                      :clear_indexes,
37  
-                      :register,
38  
-                      :reindex,
39  
-                      :[],
40  
-                      :to_s,
41  
-                      :size,
42  
-                      :each,
43  
-                      :each_category
44  
-
45 40
     # Clears the indexes and the mapping.
46 41
     #
47 42
     def clear_indexes
4  server/lib/picky/indexes_convenience.rb
@@ -2,9 +2,7 @@ module Picky
2 2
 
3 3
   class Indexes
4 4
 
5  
-    each_delegate :each_bundle,
6  
-                  :each_category,
7  
-                  :to => :indexes
  5
+    each_forward :each_bundle, :each_category, :to => :indexes
8 6
 
9 7
   end
10 8
 
7  server/lib/picky/indexes_indexed.rb
@@ -4,11 +4,8 @@ module Picky
4 4
   #
5 5
   class Indexes
6 6
 
7  
-    instance_delegate :load,
8  
-                      :analyze
9  
-
10  
-    each_delegate :load,
11  
-                  :to => :indexes
  7
+    instance_forward :load, :analyze
  8
+    each_forward :load, :to => :indexes
12 9
 
13 10
   end
14 11
 
8  server/lib/picky/indexes_indexing.rb
@@ -7,13 +7,9 @@ class Indexes
7 7
     extend Helpers::Indexing
8 8
     include Helpers::Indexing
9 9
 
10  
-    instance_delegate :clear,
11  
-                      :tokenizer
  10
+    instance_forward :clear, :tokenizer
12 11
 
13  
-    each_delegate :cache,
14  
-                  :clear,
15  
-                  :prepare,
16  
-                  :to => :indexes
  12
+    each_forward :cache, :clear, :prepare, :to => :indexes
17 13
 
18 14
     # Overrides index from the helper.
19 15
     #
2  server/lib/picky/query/allocation.rb
@@ -108,7 +108,7 @@ def to_result
108 108
 
109 109
       # Json representation of this allocation.
110 110
       #
111  
-      # Note: Delegates to to_result.
  111
+      # Note: Forwards to to_result.
112 112
       #
113 113
       def to_json options = {}
114 114
         MultiJson.encode to_result, options
14  server/lib/picky/query/allocations.rb
@@ -14,13 +14,13 @@ module Query
14 14
     #
15 15
     class Allocations
16 16
 
17  
-      delegate :each,
18  
-               :empty?,
19  
-               :first,
20  
-               :inject,
21  
-               :size,
22  
-               :map,
23  
-               :to => :@allocations
  17
+      forward :each,
  18
+              :empty?,
  19
+              :first,
  20
+              :inject,
  21
+              :size,
  22
+              :map,
  23
+              :to => :@allocations
24 24
 
25 25
       def initialize allocations = []
26 26
         @allocations = allocations
3  server/lib/picky/query/boosts.rb
@@ -25,8 +25,7 @@ class Boosts
25 25
 
26 26
       attr_reader :boosts
27 27
 
28  
-      delegate :empty?,
29  
-               :to => :boosts
  28
+      forward :empty?, :to => :boosts
30 29
 
31 30
       # Needs a Hash of
32 31
       #   [:category_name1, :category_name2] => +3
6  server/lib/picky/query/combinations.rb
@@ -14,9 +14,9 @@ class Combinations
14 14
 
15 15
       attr_reader :combinations
16 16
 
17  
-      delegate :empty?,
18  
-               :inject,
19  
-               :to => :@combinations
  17
+      forward :empty?,
  18
+              :inject,
  19
+              :to => :@combinations
20 20
 
21 21
       def initialize combinations = []
22 22
         @combinations = combinations
4  server/lib/picky/query/indexes.rb
@@ -13,9 +13,7 @@ module Query
13 13
     #
14 14
     class Indexes
15 15
       
16  
-      delegate :size,
17  
-               :first,
18  
-               :to => :@indexes
  16
+      forward :size, :first, :to => :@indexes
19 17
       
20 18
       attr_reader :indexes,
21 19
                   :ignored_categories
2  server/lib/picky/query/token.rb
@@ -15,7 +15,7 @@ class Token
15 15
       attr_writer :similar
16 16
       attr_writer :predefined_categories
17 17
       
18  
-      delegate :blank?, :to => :@text
  18
+      forward :blank?, :to => :@text
19 19
       
20 20
       # Normal initializer.
21 21
       #
4  server/lib/picky/query/tokens.rb
@@ -10,9 +10,9 @@ class Tokens
10 10
 
11 11
       attr_reader :tokens, :ignore_unassigned
12 12
 
13  
-      # Basically delegates to its internal tokens array.
  13
+      # Basically forwards to its internal tokens array.
14 14
       #
15  
-      self.delegate *[Enumerable.instance_methods, :slice!, :[], :uniq!, :last, :reject!, :length, :size, :empty?, :each, :exit, { :to => :@tokens }].flatten
  15
+      forward *[Enumerable.instance_methods, :slice!, :[], :uniq!, :last, :reject!, :length, :size, :empty?, :each, :exit, :to => :@tokens].flatten
16 16
 
17 17
       # Create a new Tokens object with the array of tokens passed in.
18 18
       #
2  server/lib/picky/rack/harakiri.rb
@@ -28,7 +28,7 @@ def initialize app
28 28
 
29 29
     # #call interface method.
30 30
     #
31  
-    # Harakiri is a middleware, so it delegates the the app or
  31
+    # Harakiri is a middleware, so it forwards the the app or
32 32
     # the next middleware after checking if it is time to honorably retire.
33 33
     #
34 34
     def call env
4  server/lib/picky/results.rb
@@ -41,7 +41,7 @@ def prepare! extra_allocations = nil, unique = false
41 41
         allocations.process!(amount, offset, extra_allocations)
42 42
     end
43 43
 
44  
-    # Delegates to allocations.
  44
+    # Forwards to allocations.
45 45
     #
46 46
     # Note that this is an expensive call and
47 47
     # should not be done repeatedly. Just keep
@@ -51,7 +51,7 @@ def ids only = amount
51 51
       allocations.ids only
52 52
     end
53 53
 
54  
-    # The total results. Delegates to the allocations.
  54
+    # The total results. Forwards to the allocations.
55 55
     #
56 56
     def total
57 57
       @total ||= allocations.total || 0
10  server/lib/picky/search.rb
@@ -23,10 +23,10 @@ class Search
23 23
     attr_accessor :tokenizer,
24 24
                   :boosts
25 25
 
26  
-    delegate :ignore,
27  
-             :only,
28  
-             :remap_qualifiers,
29  
-             :to => :indexes
  26
+    forward :ignore,
  27
+            :only,
  28
+            :remap_qualifiers,
  29
+            :to => :indexes
30 30
 
31 31
     # Takes:
32 32
     # * A number of indexes
@@ -213,7 +213,7 @@ def execute tokens, ids, offset, original_text = nil, unique = false
213 213
                    unique
214 214
     end
215 215
 
216  
-    # Delegates the tokenizing to the query tokenizer.
  216
+    # Forwards the tokenizing to the query tokenizer.
217 217
     #
218 218
     # Parameters:
219 219
     # * text: The string to tokenize.
88  server/lib/picky/wrappers/bundle/delegators.rb
@@ -6,66 +6,66 @@ module Bundle
6 6
 
7 7
       module Delegator
8 8
 
9  
-        delegate :add,
  9
+        forward :add,
10 10
 
11  
-                 :inverted,
12  
-                 :weights,
13  
-                 :similarity,
14  
-                 :configuration,
  11
+                :inverted,
  12
+                :weights,
  13
+                :similarity,
  14
+                :configuration,
15 15
 
16  
-                 :backup,
17  
-                 :restore,
18  
-                 :delete,
  16
+                :backup,
  17
+                :restore,
  18
+                :delete,
19 19
 
20  
-                 :reset_backend,
  20
+                :reset_backend,
21 21
 
22  
-                 :raise_unless_cache_exists,
23  
-                 :raise_unless_index_exists,
24  
-                 :raise_unless_similarity_exists,
  22
+                :raise_unless_cache_exists,
  23
+                :raise_unless_index_exists,
  24
+                :raise_unless_similarity_exists,
25 25
 
26  
-                 :similar,
  26
+                :similar,
27 27
 
28  
-                 :to => :bundle
  28
+                :to => :bundle
29 29
 
30 30
       end
31 31
 
32 32
       module IndexingDelegator
33 33
 
34  
-        delegate :[]=,
35  
-                 :analyze,
36  
-                 :dump,
37  
-                 :empty,
38  
-                 :empty_configuration,
39  
-                 :generate_caches_from_memory,
40  
-                 :generate_caches_from_source,
41  
-                 :generate_partial_from,
42  
-                 :retrieve,
43  
-                 :size,
44  
-                 :to => :bundle
  34
+        forward :[]=,
  35
+                :analyze,
  36
+                :dump,
  37
+                :empty,
  38
+                :empty_configuration,
  39
+                :generate_caches_from_memory,
  40
+                :generate_caches_from_source,
  41
+                :generate_partial_from,
  42
+                :retrieve,
  43
+                :size,
  44
+                :to => :bundle
45 45
 
46 46
       end
47 47
 
48 48
       module IndexedDelegator
49 49
 
50  
-        delegate :[],
51  
-                 :add_partialized,
52  
-                 :clear,
53  
-                 :clear_inverted,
54  
-                 :clear_weights,
55  
-                 :clear_similarity,
56  
-                 :clear_configuration,
57  
-                 :clear_realtime,
58  
-                 :identifier,
59  
-                 :ids,
60  
-                 :load,
61  
-                 :load_inverted,
62  
-                 :load_weights,
63  
-                 :load_similarity,
64  
-                 :load_configuration,
65  
-                 :name,
66  
-                 :remove,
67  
-                 :weight,
68  
-                 :to => :bundle
  50
+        forward :[],
  51
+                :add_partialized,
  52
+                :clear,
  53
+                :clear_inverted,
  54
+                :clear_weights,
  55
+                :clear_similarity,
  56
+                :clear_configuration,
  57
+                :clear_realtime,
  58
+                :identifier,
  59
+                :ids,
  60
+                :load,
  61
+                :load_inverted,
  62
+                :load_weights,
  63
+                :load_similarity,
  64
+                :load_configuration,
  65
+                :name,
  66
+                :remove,
  67
+                :weight,
  68
+                :to => :bundle
69 69
 
70 70
       end
71 71
 
2  server/lib/picky/wrappers/bundle/wrapper.rb
@@ -6,7 +6,7 @@ module Wrappers
6 6
     #
7 7
     module Bundle
8 8
 
9  
-      # Base wrapper. Just delegates all methods to the bundle.
  9
+      # Base wrapper. Just forwards all methods to the bundle.
10 10
       #
11 11
       class Wrapper
12 12
 
2  server/spec/lib/backends/backend_spec.rb
@@ -5,7 +5,7 @@
5 5
   let(:backend) { described_class.new }
6 6
 
7 7
   describe 'weight' do
8  
-    it 'delegates to the parameter' do
  8
+    it 'forwards to the parameter' do
9 9
       combinations = stub :combinations
10 10
 
11 11
       combinations.should_receive(:score).once.with()
2  server/spec/lib/backends/memory/json_spec.rb
@@ -18,7 +18,7 @@
18 18
     end
19 19
 
20 20
     describe "dump" do
21  
-      it "delegates to the given hash" do
  21
+      it "forwards to the given hash" do
22 22
         hash = stub :hash
23 23
 
24 24
         json.should_receive(:dump_json).once.with hash
2  server/spec/lib/backends/memory/marshal_spec.rb
@@ -18,7 +18,7 @@
18 18
     end
19 19
 
20 20
     describe "dump" do
21  
-      it "delegates to the given hash" do
  21
+      it "forwards to the given hash" do
22 22
         hash = stub :hash
23 23
 
24 24
         marshal.should_receive(:dump_marshal).once.with hash
2  server/spec/lib/backends/redis/float_spec.rb
@@ -17,7 +17,7 @@
17 17
   end
18 18
 
19 19
   describe 'member' do
20  
-    it 'delegates to the backend' do
  20
+    it 'forwards to the backend' do
21 21
       client.should_receive(:hget).once.with 'some_namespace', 'some'
22 22
 
23 23
       backend['some']
2  server/spec/lib/backends/redis/string_spec.rb
@@ -17,7 +17,7 @@
17 17
   end
18 18
   
19 19
   describe 'member' do
20  
-    it 'delegates to the backend' do
  20
+    it 'forwards to the backend' do
21 21
       client.should_receive(:hget).once.with :some_namespace, :some_symbol
22 22
       
23 23
       backend[:some_symbol]
4  server/spec/lib/backends/sqlite/array_spec.rb
@@ -8,7 +8,7 @@
8 8
     let(:db) { described_class.new 'spec/temp/some/cache/path/to/file' }
9 9
 
10 10
     describe 'dump' do
11  
-      it 'delegates to the given hash' do
  11
+      it 'forwards to the given hash' do
12 12
         hash = stub :hash
13 13
 
14 14
         db.should_receive(:dump_sqlite).once.with hash
@@ -76,7 +76,7 @@
76 76
     let(:db) { described_class.new 'spec/temp/some/cache/path/to/file', realtime: true }
77 77
 
78 78
     describe 'dump' do
79  
-      it 'delegates to the given hash' do
  79
+      it 'forwards to the given hash' do
80 80
         hash = stub :hash
81 81
 
82 82
         db.should_receive(:dump_sqlite).never
2  server/spec/lib/backends/sqlite/value_spec.rb
@@ -8,7 +8,7 @@
8 8
     let(:db) { described_class.new 'spec/temp/some/cache/path/to/file' }
9 9
 
10 10
     describe 'dump' do
11  
-      it 'delegates to the given hash' do
  11
+      it 'forwards to the given hash' do
12 12
         hash = stub :hash
13 13
 
14 14
         db.should_receive(:dump_sqlite).once.with hash
2  server/spec/lib/category_indexing_spec.rb
@@ -13,7 +13,7 @@
13 13
     let(:partial) { category.partial }
14 14
 
15 15
     describe 'clear' do
16  
-      it 'delegates to both bundles' do
  16
+      it 'forwards to both bundles' do
17 17
         exact.should_receive(:clear).once.with()
18 18
         partial.should_receive(:clear).once.with()
19 19
 
49  server/spec/lib/extensions/module_spec.rb
@@ -2,12 +2,12 @@
2 2
 
3 3
 describe Module do
4 4
 
5  
-  describe 'each_delegate' do
  5
+  describe 'each_forward' do
6 6
     context "with correct params" do
7  
-      before(:each) do
8  
-        @klass = Class.new do
  7
+      let(:klass) do
  8
+        Class.new do
9 9
 
10  
-          each_delegate :bli, :bla, :blu, :to => :@some_enumerable
  10
+          each_forward :bli, :bla, :blu, :to => :@some_enumerable
11 11
 
12 12
           def initialize some_enumerable
13 13
             @some_enumerable = some_enumerable
@@ -17,7 +17,7 @@ def initialize some_enumerable
17 17
       end
18 18
       it 'should send each a bli' do
19 19
         bli = stub :bli
20  
-        delegating = @klass.new [bli, bli, bli, bli]
  20
+        delegating = klass.new [bli, bli, bli, bli]
21 21
 
22 22
         bli.should_receive(:bli).exactly(4).times
23 23
 
@@ -25,10 +25,47 @@ def initialize some_enumerable
25 25
       end
26 26
     end
27 27
     context "without correct params" do
  28
+      it 'should raise an error' do
  29
+        lambda do
  30
+          Class.new do
  31
+            each_forward :bli, :bla, :blu # :to missing
  32
+          end
  33
+        end.should raise_error(ArgumentError)
  34
+      end
  35
+    end
  36
+  end
  37
+  
  38
+  describe 'forward' do
  39
+    context "with correct params" do
  40
+      let(:klass) do
  41
+        Class.new do
  42
+
  43
+          forward :bli, :bla, :blu, :to => :@some_thing
  44
+
  45
+          def initialize some_thing
  46
+            @some_thing = some_thing
  47
+          end
  48
+
  49
+        end
  50
+      end
28 51
       it 'should send each a bli' do
  52
+        bli = stub :bli
  53
+        delegating = klass.new bli
  54
+
  55
+        bli.should_receive(:bli).exactly(1).times
  56
+        bli.should_receive(:bla).exactly(1).times
  57
+        bli.should_receive(:blu).exactly(1).times
  58
+
  59
+        delegating.bli
  60
+        delegating.bla
  61
+        delegating.blu
  62
+      end
  63
+    end
  64
+    context "without correct params" do
  65
+      it 'should raise an error' do
29 66
         lambda do
30 67
           Class.new do
31  
-            each_delegate :bli, :bla, :blu # :to missing
  68
+            forward :bli, :bla, :blu # :to missing
32 69
           end
33 70
         end.should raise_error(ArgumentError)
34 71
       end
4  server/spec/lib/index_indexed_spec.rb
@@ -31,14 +31,14 @@
31 31
     end
32 32
 
33 33
     describe "load" do
34  
-      it "delegates to each category" do
  34
+      it "forwards to each category" do
35 35
         @categories.should_receive(:load).once.with
36 36
 
37 37
         @index.load
38 38
       end
39 39
     end
40 40
     describe "possible_combinations" do
41  
-      it "delegates to the combinator" do
  41
+      it "forwards to the combinator" do
42 42
         @categories.should_receive(:possible_combinations).once.with :some_token
43 43
 
44 44
         @index.possible_combinations :some_token
2  server/spec/lib/index_spec.rb
@@ -63,7 +63,7 @@
63 63
     end
64 64
 
65 65
     describe 'geo_categories' do
66  
-      it 'delegates correctly' do
  66
+      it 'forwards correctly' do
67 67
         api.should_receive(:ranged_category).once.with :some_lat, 0.00898312, from: :some_lat_from
68 68
         api.should_receive(:ranged_category).once.with :some_lng, 0.01796624, from: :some_lng_from
69 69
 
2  server/spec/lib/indexers/base_spec.rb
@@ -12,7 +12,7 @@
12 12
   end
13 13
 
14 14
   describe 'source' do
15  
-    it 'delegates it to the index or category' do
  15
+    it 'forwards it to the index or category' do
16 16
       some_index_or_category.should_receive(:source).once.with
17 17
 
18 18
       indexer.source
4  server/spec/lib/indexes_indexing_spec.rb
@@ -44,7 +44,7 @@
44 44
         indexes.indexes.should == []
45 45
       end
46 46
     end
47  
-    def self.it_delegates_each name
  47
+    def self.it_forwards_each name
48 48
       describe name do
49 49
         it "calls #{name} on each in order" do
50 50
           @index1.should_receive(name).once.with.ordered
@@ -54,7 +54,7 @@ def self.it_delegates_each name
54 54
         end
55 55
       end
56 56
     end
57  
-    it_delegates_each :clear
  57
+    it_forwards_each :clear
58 58
   end
59 59
 
60 60
 end
6  server/spec/lib/query/allocation_spec.rb
@@ -10,7 +10,7 @@
10 10
   end
11 11
 
12 12
   # describe "hash" do
13  
-  #   it "delegates to the combinations" do
  13
+  #   it "forwards to the combinations" do
14 14
   #     @combinations.should_receive(:hash).once.with
15 15
   # 
16 16
   #     @allocation.hash
@@ -34,7 +34,7 @@
34 34
   end
35 35
 
36 36
   describe 'remove' do
37  
-    it 'should delegate to the combinations' do
  37
+    it 'should forward to the combinations' do
38 38
       @combinations.should_receive(:remove).once.with [:some_categories]
39 39
 
40 40
       @allocation.remove [:some_categories]
@@ -205,7 +205,7 @@
205 205
 
206 206
   describe "calculate_score" do
207 207
     context 'non-empty combinations' do
208  
-      it 'should delegate to backend and combinations' do
  208
+      it 'should forward to backend and combinations' do
209 209
         @backend.should_receive(:weight).once.with(@combinations).and_return 1
210 210
         @combinations.should_receive(:boost_for).once.with(:some_boosts).and_return 2
211 211
 
12  server/spec/lib/query/allocations_spec.rb
@@ -287,7 +287,7 @@
287 287
         @allocation = stub :allocation
288 288
         @allocations = described_class.new [@allocation, @allocation, @allocation]
289 289
       end
290  
-      it 'should delegate to each allocation with no params' do
  290
+      it 'should forward to each allocation with no params' do
291 291
         @allocation.should_receive(:to_result).exactly(3).times.with
292 292
 
293 293
         @allocations.to_result
@@ -299,7 +299,7 @@
299 299
         @no_result_allocation = stub :no_results, :to_result => nil
300 300
         @allocations = described_class.new [@allocation, @no_result_allocation, @allocation]
301 301
       end
302  
-      it 'should delegate to each allocation with the same params' do
  302
+      it 'should forward to each allocation with the same params' do
303 303
         @allocations.to_result.should == [:some_result, :some_result]
304 304
       end
305 305
     end
@@ -337,7 +337,7 @@
337 337
       @internal_allocations = mock :internal_allocations
338 338
       @allocations = described_class.new @internal_allocations
339 339
     end
340  
-    it "should delegate to the internal allocations" do
  340
+    it "should forward to the internal allocations" do
341 341
       stub_proc = lambda {}
342 342
       @internal_allocations.should_receive(:each).once.with &stub_proc
343 343
 
@@ -349,7 +349,7 @@
349 349
       @internal_allocations = mock :internal_allocations
350 350
       @allocations = described_class.new @internal_allocations
351 351
     end
352  
-    it "should delegate to the internal allocations" do
  352
+    it "should forward to the internal allocations" do
353 353
       stub_proc = lambda {}
354 354
       @internal_allocations.should_receive(:inject).once.with &stub_proc
355 355
 
@@ -361,7 +361,7 @@
361 361
       @internal_allocations = mock :internal_allocations
362 362
       @allocations = described_class.new @internal_allocations
363 363
     end
364  
-    it "should delegate to the internal allocations array" do
  364
+    it "should forward to the internal allocations array" do
365 365
       @internal_allocations.should_receive(:empty?).once
366 366
       @allocations.empty?
367 367
     end
@@ -373,7 +373,7 @@
373 373
       @no_result_allocation = stub :no_results, :to_result => nil
374 374
       @allocations = described_class.new [@allocation, @no_result_allocation, @allocation]
375 375
     end
376  
-    it "should delegate to the internal allocations array" do
  376
+    it "should forward to the internal allocations array" do
377 377
       @allocations.to_s.should == "[:some_result, :some_result]"
378 378
     end
379 379
   end
2  server/spec/lib/query/combinations_spec.rb
@@ -48,7 +48,7 @@
48 48
   end
49 49
 
50 50
   # describe 'hash' do
51  
-  #   it "delegates to the combinations array" do
  51
+  #   it "forwards to the combinations array" do
52 52
   #     @combinations_ary.should_receive(:hash).once.with
53 53
   # 
54 54
   #     @combinations.hash
26  server/spec/lib/query/tokens_spec.rb
@@ -226,13 +226,13 @@
226 226
     end
227 227
   end
228 228
 
229  
-  def self.it_should_delegate name
  229
+  def self.it_should_forward name
230 230
     describe name do
231 231
       before(:each) do
232 232
         @internal_tokens = mock :internal_tokens
233 233
         @tokens = described_class.new @internal_tokens
234 234
       end
235  
-      it "should delegate #{name} to the internal tokens" do
  235
+      it "should forward #{name} to the internal tokens" do
236 236
         proc_stub = lambda {}
237 237
 
238 238
         @internal_tokens.should_receive(name).once.with &proc_stub
@@ -244,17 +244,17 @@ def self.it_should_delegate name
244 244
   # Reject is tested separately.
245 245
   #
246 246
   (Enumerable.instance_methods - [:reject]).each do |name|
247  
-    it_should_delegate name
  247
+    it_should_forward name
248 248
   end
249  
-  it_should_delegate :slice!
250  
-  it_should_delegate :[]
251  
-  it_should_delegate :uniq!
252  
-  it_should_delegate :last
253  
-  it_should_delegate :length
254  
-  it_should_delegate :reject!
255  
-  it_should_delegate :size
256  
-  it_should_delegate :empty?
257  
-  it_should_delegate :each
258  
-  it_should_delegate :exit
  249
+  it_should_forward :slice!
  250
+  it_should_forward :[]
  251
+  it_should_forward :uniq!
  252
+  it_should_forward :last
  253
+  it_should_forward :length
  254
+  it_should_forward :reject!
  255
+  it_should_forward :size
  256
+  it_should_forward :empty?
  257
+  it_should_forward :each
  258
+  it_should_forward :exit
259 259
 
260 260
 end
4  server/spec/lib/results_spec.rb
@@ -19,12 +19,12 @@
19 19
       @allocations = stub :allocations
20 20
       @results = described_class.new :unimportant, :amount, :unimportant, @allocations
21 21
     end
22  
-    it "delegates" do
  22
+    it "forwards" do
23 23
       @allocations.should_receive(:ids).once.with :anything
24 24
 
25 25
       @results.ids :anything
26 26
     end
27  
-    it "delegates and uses amount if nothing given" do
  27
+    it "forwards and uses amount if nothing given" do
28 28
       @allocations.should_receive(:ids).once.with :amount
29 29
 
30 30
       @results.ids
8  server/spec/lib/search_spec.rb
@@ -14,7 +14,7 @@
14 14
 
15 15
   describe 'tokenized' do
16 16
     let(:search) { described_class.new }
17  
-    it 'delegates to the tokenizer' do
  17
+    it 'forwards to the tokenizer' do
18 18
       tokenizer = stub :tokenizer
19 19
       search.stub! :tokenizer => tokenizer
20 20
 
@@ -88,21 +88,21 @@
88 88
     before(:each) do
89 89
       @search = described_class.new
90 90
     end
91  
-    it "delegates to search_with correctly" do
  91
+    it "forwards to search_with correctly" do
92 92
       @search.stub! :tokenized => :tokens
93 93
 
94 94
       @search.should_receive(:search_with).once.with :tokens, 20, 10, :text, nil
95 95
 
96 96
       @search.search :text, 20, 10
97 97
     end
98  
-    it "delegates to search_with correctly" do
  98
+    it "forwards to search_with correctly" do
99 99
       @search.stub! :tokenized => :tokens
100 100
 
101 101
       @search.should_receive(:search_with).once.with :tokens, 20, 0, :text, nil
102 102
 
103 103
       @search.search :text, 20, 0
104 104
     end
105  
-    it "delegates to search_with correctly" do
  105
+    it "forwards to search_with correctly" do
106 106
       @search.stub! :tokenized => :tokens
107 107