Class: ShellEvalContext

Inherits:
Object show all
Defined in:
lib/roby/app/scripts/shell.rb

Constant Summary collapse

WHITELISTED_METHODS =
%i[actions wtf? cancel safe unsafe safe? help]
.freeze

Instance Method Summary collapse

Constructor Details

#initialize(interface, interface_m, send_q: ::Queue.new, results_q: ::Queue.new) ⇒ ShellEvalContext

Returns a new instance of ShellEvalContext.



121
122
123
124
125
126
# File 'lib/roby/app/scripts/shell.rb', line 121

def initialize(interface, interface_m, send_q: ::Queue.new, results_q: ::Queue.new)
    @__interface = interface
    @__interface_m = interface_m
    @__send = send_q
    @__results = results_q
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/roby/app/scripts/shell.rb', line 132

def method_missing(m, *args, &block)
    if WHITELISTED_METHODS.include?(m)
        return @__interface.send(m, *args, &block)
    end

    @__send.push(::Kernel.lambda do
        @__interface.send(m, *args, &block)
    end)
    result, error = @__results.pop
    if error
        raise error
    elsif result.kind_of?(@__interface_m::ShellSubcommand)
        ::ShellEvalContext.new(
            result, @__interface_m, send_q: @__send, results_q: @__results
        )
    else
        result
    end
end

Instance Method Details

#process_pendingObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/roby/app/scripts/shell.rb', line 152

def process_pending
    loop do
        begin
            command = @__send.pop(true)
            begin
                result = command.call
                @__results.push([result, nil])
            rescue ::Exception => e
                @__results.push([nil, e])
            end
        rescue ::ThreadError
            break
        end
    end
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/roby/app/scripts/shell.rb', line 128

def respond_to_missing?(m, include_private)
    @__interface.respond_to?(m, include_private)
end