Class: WebCrawler::View::Runner

Inherits:
Base
  • Object
show all
Defined in:
lib/web_crawler/view/runner.rb

Defined Under Namespace

Classes: WorkSpace

Instance Attribute Summary

Attributes inherited from Base

#input

Instance Method Summary collapse

Methods inherited from Base

#draw, #format, #initialize

Constructor Details

This class inherits a constructor from WebCrawler::View::Base

Instance Method Details

#load_console!Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/web_crawler/view/runner.rb', line 38

def load_console! 
  require "irb"
  IRB.init_config nil
  IRB.instance_exec do
    @CONF[:BACK_TRACE_LIMIT] = 1

    @CONF[:PROMPT][:SIMPLE] = { :PROMPT_I => "[\e[1m\e[31mWebCrawler::API\e[0m](%n)>> ",
                                :PROMPT_N => "[\e[1m\e[31mWebCrawler::API\e[0m](%n)>> ",
                                :PROMPT_S => "[\e[1m\e[31mWebCrawler::API\e[0m](%n)*",
                                :PROMPT_C => "(%n)?> ",
                                :RETURN   => "\e[90m#=> %s\n\e[0m" }

    @CONF[:PROMPT_MODE] = :SIMPLE
  end

  irb = IRB::Irb.new IRB::WorkSpace.new(@work_space)


  IRB.instance_exec { @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC] }
  IRB.instance_exec { @CONF[:MAIN_CONTEXT] = irb.context }


  trap("SIGINT") do
    irb.signal_handle
  end

  begin
    catch(:IRB_EXIT) do
      irb.eval_input
    end
  ensure
    IRB.irb_at_exit
  end
end

#renderObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/web_crawler/view/runner.rb', line 24

def render
  unless File.exists? @options['run']
    @options['run'] = File.expand_path @options['run'], FileUtils.pwd
  end

  @work_space = WorkSpace.new
  @work_space.responses = input.freeze
  @work_space.results   = eval(File.open(@options['run'], 'r').read, @work_space.instance_eval("binding"), @options['run'])

  load_console! if @options['console']

  WebCrawler::View.factory(@options['original_format'], @work_space.results, @options).render
end