Class: Vangrail::ScoreProviders::Command
- Defined in:
- lib/vangrail/score_provider.rb
Overview
One JSON request on stdin and one JSON response on stdout.
Defined Under Namespace
Classes: OutputLimit
Constant Summary collapse
- READ_CHUNK =
16 * 1024
- TERMINATION_GRACE =
0.1
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#inherit_environment ⇒ Object
readonly
Returns the value of attribute inherit_environment.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(command:, timeout: DEFAULT_TIMEOUT, environment: {}, inherit_environment: false, **options) ⇒ Command
constructor
A new instance of Command.
- #score(text, side:, **context) ⇒ Object
Constructor Details
#initialize(command:, timeout: DEFAULT_TIMEOUT, environment: {}, inherit_environment: false, **options) ⇒ Command
Returns a new instance of Command.
117 118 119 120 121 122 123 124 125 |
# File 'lib/vangrail/score_provider.rb', line 117 def initialize(command:, timeout: DEFAULT_TIMEOUT, environment: {}, inherit_environment: false, **) super(**) @command = Array(command).map(&:to_s).freeze @timeout = positive_timeout(timeout) @environment = environment.to_h { |name, value| [name.to_s, value.to_s] }.freeze @inherit_environment = !!inherit_environment # rubocop:disable Style/DoubleNegation raise ArgumentError, 'command is required' if @command.empty? || @command.any?(&:empty?) end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
115 116 117 |
# File 'lib/vangrail/score_provider.rb', line 115 def command @command end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
115 116 117 |
# File 'lib/vangrail/score_provider.rb', line 115 def environment @environment end |
#inherit_environment ⇒ Object (readonly)
Returns the value of attribute inherit_environment.
115 116 117 |
# File 'lib/vangrail/score_provider.rb', line 115 def inherit_environment @inherit_environment end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
115 116 117 |
# File 'lib/vangrail/score_provider.rb', line 115 def timeout @timeout end |
Instance Method Details
#score(text, side:, **context) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/vangrail/score_provider.rb', line 127 def score(text, side:, **context) _payload, input = request_payload(text, side, context) output, status = execute(input) raise ProtocolError, exit_reason(status) unless status.success? response_payload(parse(output)) end |