Class: Sunspot::Util::ContextBoundDelegate

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/util.rb

Constant Summary collapse

BASIC_METHODS =

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, calling_context) ⇒ ContextBoundDelegate

Returns a new instance of ContextBoundDelegate.



236
237
238
# File 'lib/sunspot/util.rb', line 236

def initialize(receiver, calling_context)
  @__receiver__, @__calling_context__ = receiver, calling_context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/sunspot/util.rb', line 240

def method_missing(method, *args, &block)
  begin
    @__receiver__.send(method.to_sym, *args, &block)
  rescue ::NoMethodError => e
    begin
      @__calling_context__.send(method.to_sym, *args, &block)
    rescue ::NoMethodError
      raise(e)
    end
  end
end

Class Method Details

.instance_eval_with_context(receiver, &block) ⇒ Object



217
218
219
220
221
222
223
# File 'lib/sunspot/util.rb', line 217

def instance_eval_with_context(receiver, &block)
  calling_context = eval('self', block.binding)
  if parent_calling_context = calling_context.instance_eval{@__calling_context__}
    calling_context = parent_calling_context
  end
  new(receiver, calling_context).instance_eval(&block)
end