Class: RVC::RubyEvaluator

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/rvc/shell.rb

Constant Summary

Constants included from Util

Util::PROGRESS_BAR_LEFT, Util::PROGRESS_BAR_MIDDLE, Util::PROGRESS_BAR_RIGHT, Util::UserError

Instance Method Summary collapse

Methods included from Util

#collect_children, #display_inventory, #err, #interactive?, #lookup, #lookup!, #lookup_single, #lookup_single!, #menu, #progress, #search_path, #single_connection, #system_fg, #tasks, #tcsetpgrp, #terminal_columns

Constructor Details

#initialize(fs) ⇒ RubyEvaluator

Returns a new instance of RubyEvaluator.



193
194
195
196
# File 'lib/rvc/shell.rb', line 193

def initialize fs
  @binding = toplevel
  @fs = fs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *a) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/rvc/shell.rb', line 226

def method_missing sym, *a
  super unless $shell
  str = sym.to_s
  if a.empty?
    if MODULES.member? str
      MODULES[str]
    elsif str =~ /_?([\w\d]+)(!?)/ && objs = $shell.session.get_mark($1)
      if $2 == '!'
        objs
      else
        objs.first
      end
    else
      super
    end
  else
    super
  end
end

Instance Method Details

#connObject



222
223
224
# File 'lib/rvc/shell.rb', line 222

def conn
  @fs.lookup("~@").first
end

#dcObject



218
219
220
# File 'lib/rvc/shell.rb', line 218

def dc
  @fs.lookup("~").first
end

#do_eval(input, file) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/rvc/shell.rb', line 202

def do_eval input, file
  begin
    eval input, @binding, file
  rescue Exception => e
    bt = e.backtrace
    bt = bt.reverse.drop_while { |x| !(x =~ /toplevel/) }.reverse
    bt[-1].gsub! ':in `toplevel\'', ''
    e.set_backtrace bt
    raise
  end
end

#thisObject



214
215
216
# File 'lib/rvc/shell.rb', line 214

def this
  @fs.cur
end

#toplevelObject



198
199
200
# File 'lib/rvc/shell.rb', line 198

def toplevel
  binding
end