Class: Landescape::Evaluator::Base

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

Direct Known Subclasses

Curses

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statements, window, options = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
# File 'lib/landescape/evaluator.rb', line 12

def initialize(statements, window, options = {})
  @options    = {non_block: false}.merge(options)
  @window     = window
  @statements = statements
end

Instance Attribute Details

#statementsObject (readonly)

Returns the value of attribute statements.



10
11
12
# File 'lib/landescape/evaluator.rb', line 10

def statements
  @statements
end

Class Method Details

.start(statements, window, options = {}) ⇒ Object



5
6
7
# File 'lib/landescape/evaluator.rb', line 5

def start(statements, window, options = {})
  new(statements, window, options).tap(&:start)
end

Instance Method Details

#not_supported(name, *args) ⇒ Object



45
46
47
# File 'lib/landescape/evaluator.rb', line 45

def not_supported(name, *args)
  Landescape.logger.warn %([not supported] #{name}(#{args.join(', ')}))
end

#startObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/landescape/evaluator.rb', line 18

def start
  @eval_thread = Thread.fork {
    loop do
      name, *args =
        begin
          statements.shift(@options[:non_block])
        rescue ThreadError
          Thread.exit
        end

      if self.class.method_defined?(name)
        __send__ name, *args
      else
        not_supported name, *args
      end
    end
  }
end

#stopObject



37
38
39
# File 'lib/landescape/evaluator.rb', line 37

def stop
  @eval_thread.exit if @eval_thread.alive?
end

#unknown(token) ⇒ Object



41
42
43
# File 'lib/landescape/evaluator.rb', line 41

def unknown(token)
  Landescape.logger.warn %([unknown] #{token.inspect})
end