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.



222
223
224
# File 'lib/sunspot/util.rb', line 222

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



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/sunspot/util.rb', line 230

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



203
204
205
206
207
208
209
# File 'lib/sunspot/util.rb', line 203

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

Instance Method Details

#idObject



226
227
228
# File 'lib/sunspot/util.rb', line 226

def id
  @__calling_context__.__send__(:id)
end