Class: Breakpoint::CommandBundle::Client

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

Overview

Proxy to a Breakpoint client. Lets you directly execute code in the context of the client.

Instance Method Summary collapse

Constructor Details

#initialize(eval_handler) ⇒ Client

:nodoc:



142
143
144
145
# File 'lib/breakpoint.rb', line 142

def initialize(eval_handler) # :nodoc:

  eval_handler.untaint
  @eval_handler = eval_handler
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Will execute the specified statement at the client.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/breakpoint.rb', line 168

def method_missing(method, *args, &block)
  if args.empty? and not block
    result = eval "#{method}"
  else
    # This is a bit ugly. The alternative would be using an

    # eval context instead of an eval handler for executing

    # the code at the client. The problem with that approach

    # is that we would have to handle special expressions

    # like "self", "nil" or constants ourself which is hard.

    remote = eval %{
      result = lambda { |block, *args| self.send(#{method.inspect}, *args, &block) }
      def result.call_with_block(*args, &block)
        call(block, *args)
      end
      result
    }
    remote.call_with_block(*args, &block)
  end

  return result
end

Instance Method Details

#eval(code) ⇒ Object

Executes the specified code at the client.



153
154
155
# File 'lib/breakpoint.rb', line 153

def eval(code)
  @eval_handler.call(code)
end

#require(*args, &block) ⇒ Object

Need to work around an odd RubyGems issue that causes it to not load libraries…



159
160
161
162
163
164
165
# File 'lib/breakpoint.rb', line 159

def require(*args, &block)
  begin
    method_missing(:require__, *args, &block)
  rescue LoadError
    method_missing(:require, *args, &block)
  end
end