repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.long_poll
def long_poll(routing_keys, ack, &handler) raise ArgumentError, "Block missing" unless block_given? params = { :wait_time => @options[:listen_timeout] - 5, :timestamp => Time.now.to_f } params[:routing_keys] = routing_keys if routing_keys params[:ack] = ack if ack && ack.any? ...
ruby
def long_poll(routing_keys, ack, &handler) raise ArgumentError, "Block missing" unless block_given? params = { :wait_time => @options[:listen_timeout] - 5, :timestamp => Time.now.to_f } params[:routing_keys] = routing_keys if routing_keys params[:ack] = ack if ack && ack.any? ...
[ "def", "long_poll", "(", "routing_keys", ",", "ack", ",", "&", "handler", ")", "raise", "ArgumentError", ",", "\"Block missing\"", "unless", "block_given?", "params", "=", "{", ":wait_time", "=>", "@options", "[", ":listen_timeout", "]", "-", "5", ",", ":times...
Make long-polling request to receive one or more events Do not return until an event is received or the polling times out or fails @param [Array, NilClass] routing_keys as strings to assist router in delivering event to interested parties @param [Array, NilClass] ack UUIDs for events received on previous poll ...
[ "Make", "long", "-", "polling", "request", "to", "receive", "one", "or", "more", "events", "Do", "not", "return", "until", "an", "event", "is", "received", "or", "the", "polling", "times", "out", "or", "fails" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L584-L609
train
rightscale/right_agent
lib/right_agent/clients/router_client.rb
RightScale.RouterClient.process_long_poll
def process_long_poll(result) case result when Exceptions::Unauthorized, Exceptions::ConnectivityFailure, Exceptions::RetryableError, Exceptions::InternalServerError # Reset connect_interval otherwise long-poll and WebSocket connect attempts will continue to backoff @connect_interval = CONNE...
ruby
def process_long_poll(result) case result when Exceptions::Unauthorized, Exceptions::ConnectivityFailure, Exceptions::RetryableError, Exceptions::InternalServerError # Reset connect_interval otherwise long-poll and WebSocket connect attempts will continue to backoff @connect_interval = CONNE...
[ "def", "process_long_poll", "(", "result", ")", "case", "result", "when", "Exceptions", "::", "Unauthorized", ",", "Exceptions", "::", "ConnectivityFailure", ",", "Exceptions", "::", "RetryableError", ",", "Exceptions", "::", "InternalServerError", "@connect_interval", ...
Process result from long-polling attempt Not necessary to log failure since should already have been done by underlying HTTP client @param [Array, NilClass] result from long-polling attempt @return [Array, NilClass] result for long-polling attempt
[ "Process", "result", "from", "long", "-", "polling", "attempt", "Not", "necessary", "to", "log", "failure", "since", "should", "already", "have", "been", "done", "by", "underlying", "HTTP", "client" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/router_client.rb#L617-L634
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.init
def init(type, auth_client, options) raise ArgumentError, "Auth client does not support server type #{type.inspect}" unless auth_client.respond_to?(type.to_s + "_url") raise ArgumentError, ":api_version option missing" unless options[:api_version] @type = type @auth_client = auth_client @h...
ruby
def init(type, auth_client, options) raise ArgumentError, "Auth client does not support server type #{type.inspect}" unless auth_client.respond_to?(type.to_s + "_url") raise ArgumentError, ":api_version option missing" unless options[:api_version] @type = type @auth_client = auth_client @h...
[ "def", "init", "(", "type", ",", "auth_client", ",", "options", ")", "raise", "ArgumentError", ",", "\"Auth client does not support server type #{type.inspect}\"", "unless", "auth_client", ".", "respond_to?", "(", "type", ".", "to_s", "+", "\"_url\"", ")", "raise", ...
Set configuration of this client and initialize HTTP access @param [Symbol] type of server for use in obtaining URL from auth_client, e.g., :router @param [AuthClient] auth_client providing authorization session for HTTP requests @option options [String] :server_name for use in reporting errors, e.g., RightNet @o...
[ "Set", "configuration", "of", "this", "client", "and", "initialize", "HTTP", "access" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L86-L105
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.create_http_client
def create_http_client close_http_client("reconnecting") url = @auth_client.send(@type.to_s + "_url") Log.info("Connecting to #{@options[:server_name]} via #{url.inspect}") options = {:server_name => @options[:server_name]} options[:api_version] = @options[:api_version] if @options[:api_ve...
ruby
def create_http_client close_http_client("reconnecting") url = @auth_client.send(@type.to_s + "_url") Log.info("Connecting to #{@options[:server_name]} via #{url.inspect}") options = {:server_name => @options[:server_name]} options[:api_version] = @options[:api_version] if @options[:api_ve...
[ "def", "create_http_client", "close_http_client", "(", "\"reconnecting\"", ")", "url", "=", "@auth_client", ".", "send", "(", "@type", ".", "to_s", "+", "\"_url\"", ")", "Log", ".", "info", "(", "\"Connecting to #{@options[:server_name]} via #{url.inspect}\"", ")", "o...
Create HTTP client If there is an existing client, close it first @return [TrueClass] always true @return [BalancedHttpClient] client
[ "Create", "HTTP", "client", "If", "there", "is", "an", "existing", "client", "close", "it", "first" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L227-L236
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.close_http_client
def close_http_client(reason) @http_client.close(reason) if @http_client true rescue StandardError => e ErrorTracker.log(self, "Failed closing connection", e) false end
ruby
def close_http_client(reason) @http_client.close(reason) if @http_client true rescue StandardError => e ErrorTracker.log(self, "Failed closing connection", e) false end
[ "def", "close_http_client", "(", "reason", ")", "@http_client", ".", "close", "(", "reason", ")", "if", "@http_client", "true", "rescue", "StandardError", "=>", "e", "ErrorTracker", ".", "log", "(", "self", ",", "\"Failed closing connection\"", ",", "e", ")", ...
Close HTTP client persistent connections @param [String] reason for closing @return [Boolean] false if failed, otherwise true
[ "Close", "HTTP", "client", "persistent", "connections" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L243-L249
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.check_health
def check_health begin @http_client.check_health self.state = :connected rescue BalancedHttpClient::NotResponding => e ErrorTracker.log(self, "Failed #{@options[:server_name]} health check", e.nested_exception) self.state = :disconnected rescue StandardError => e ...
ruby
def check_health begin @http_client.check_health self.state = :connected rescue BalancedHttpClient::NotResponding => e ErrorTracker.log(self, "Failed #{@options[:server_name]} health check", e.nested_exception) self.state = :disconnected rescue StandardError => e ...
[ "def", "check_health", "begin", "@http_client", ".", "check_health", "self", ".", "state", "=", ":connected", "rescue", "BalancedHttpClient", "::", "NotResponding", "=>", "e", "ErrorTracker", ".", "log", "(", "self", ",", "\"Failed #{@options[:server_name]} health check...
Check health of RightApi directly without applying RequestBalancer Do not check whether HTTP client exists @return [Symbol] RightApi client state
[ "Check", "health", "of", "RightApi", "directly", "without", "applying", "RequestBalancer", "Do", "not", "check", "whether", "HTTP", "client", "exists" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L263-L274
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.reconnect
def reconnect unless @reconnecting @reconnecting = true if EM.reactor_running? @stats["reconnects"].update("initiate") @reconnect_timer = EM_S::PeriodicTimer.new(rand(@options[:reconnect_interval])) do begin reconnect_once rescue Exception...
ruby
def reconnect unless @reconnecting @reconnecting = true if EM.reactor_running? @stats["reconnects"].update("initiate") @reconnect_timer = EM_S::PeriodicTimer.new(rand(@options[:reconnect_interval])) do begin reconnect_once rescue Exception...
[ "def", "reconnect", "unless", "@reconnecting", "@reconnecting", "=", "true", "if", "EM", ".", "reactor_running?", "@stats", "[", "\"reconnects\"", "]", ".", "update", "(", "\"initiate\"", ")", "@reconnect_timer", "=", "EM_S", "::", "PeriodicTimer", ".", "new", "...
If EventMachine reactor is running, begin attempting to periodically reconnect with server by checking health. Randomize initial attempt to reduce server spiking. If EventMachine reactor is NOT running, attempt to reconnect once and raise any exception that is encountered. @return [TrueClass] always true
[ "If", "EventMachine", "reactor", "is", "running", "begin", "attempting", "to", "periodically", "reconnect", "with", "server", "by", "checking", "health", ".", "Randomize", "initial", "attempt", "to", "reduce", "server", "spiking", "." ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L284-L306
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.make_request
def make_request(verb, path, params = {}, type = nil, options = {}) raise Exceptions::Terminating if state == :closed started_at = Time.now time_to_live = (options[:time_to_live] && options[:time_to_live] > 0) ? options[:time_to_live] : nil expires_at = started_at + [time_to_live || @options[:re...
ruby
def make_request(verb, path, params = {}, type = nil, options = {}) raise Exceptions::Terminating if state == :closed started_at = Time.now time_to_live = (options[:time_to_live] && options[:time_to_live] > 0) ? options[:time_to_live] : nil expires_at = started_at + [time_to_live || @options[:re...
[ "def", "make_request", "(", "verb", ",", "path", ",", "params", "=", "{", "}", ",", "type", "=", "nil", ",", "options", "=", "{", "}", ")", "raise", "Exceptions", "::", "Terminating", "if", "state", "==", ":closed", "started_at", "=", "Time", ".", "n...
Make request via HTTP. Attempt to reconnect first if disconnected and EM reactor is not running. Rely on underlying HTTP client to log request and response. Retry request if response indicates to or if there are connectivity failures. There are also several timeouts involved: - Underlying BalancedHttpClient conn...
[ "Make", "request", "via", "HTTP", ".", "Attempt", "to", "reconnect", "first", "if", "disconnected", "and", "EM", "reactor", "is", "not", "running", ".", "Rely", "on", "underlying", "HTTP", "client", "to", "log", "request", "and", "response", ".", "Retry", ...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L367-L394
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.handle_exception
def handle_exception(exception, type, request_uuid, expires_at, attempts) result = request_uuid if exception.respond_to?(:http_code) case exception.http_code when 301, 302 # MovedPermanently, Found handle_redirect(exception, type, request_uuid) when 401 # Unauthorized ...
ruby
def handle_exception(exception, type, request_uuid, expires_at, attempts) result = request_uuid if exception.respond_to?(:http_code) case exception.http_code when 301, 302 # MovedPermanently, Found handle_redirect(exception, type, request_uuid) when 401 # Unauthorized ...
[ "def", "handle_exception", "(", "exception", ",", "type", ",", "request_uuid", ",", "expires_at", ",", "attempts", ")", "result", "=", "request_uuid", "if", "exception", ".", "respond_to?", "(", ":http_code", ")", "case", "exception", ".", "http_code", "when", ...
Examine exception to determine whether to setup retry, raise new exception, or re-raise @param [StandardError] exception raised @param [String] action from request type @param [String] type of request for use in logging @param [String] request_uuid originally created for this request @param [Time] expires_at time...
[ "Examine", "exception", "to", "determine", "whether", "to", "setup", "retry", "raise", "new", "exception", "or", "re", "-", "raise" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L412-L438
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.handle_redirect
def handle_redirect(redirect, type, request_uuid) Log.info("Received REDIRECT #{redirect} for #{type} request <#{request_uuid}>") if redirect.respond_to?(:response) && (location = redirect.response.headers[:location]) && !location.empty? Log.info("Requesting auth client to handle redirect to #{locat...
ruby
def handle_redirect(redirect, type, request_uuid) Log.info("Received REDIRECT #{redirect} for #{type} request <#{request_uuid}>") if redirect.respond_to?(:response) && (location = redirect.response.headers[:location]) && !location.empty? Log.info("Requesting auth client to handle redirect to #{locat...
[ "def", "handle_redirect", "(", "redirect", ",", "type", ",", "request_uuid", ")", "Log", ".", "info", "(", "\"Received REDIRECT #{redirect} for #{type} request <#{request_uuid}>\"", ")", "if", "redirect", ".", "respond_to?", "(", ":response", ")", "&&", "(", "location...
Treat redirect response as indication that no longer accessing the correct shard Handle it by informing auth client so that it can re-authorize Do not retry, but tell client to with the expectation that re-auth will correct the situation @param [RestClient::MovedPermanently, RestClient::Found] redirect exception ra...
[ "Treat", "redirect", "response", "as", "indication", "that", "no", "longer", "accessing", "the", "correct", "shard", "Handle", "it", "by", "informing", "auth", "client", "so", "that", "it", "can", "re", "-", "authorize", "Do", "not", "retry", "but", "tell", ...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L452-L463
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.handle_retry_with
def handle_retry_with(retry_result, type, request_uuid, expires_at, attempts) case (interval = retry_interval(expires_at, attempts, 1)) when nil @stats["request failures"].update("#{type} - retry") raise Exceptions::RetryableError.new(retry_result.http_body, retry_result) when 0 ...
ruby
def handle_retry_with(retry_result, type, request_uuid, expires_at, attempts) case (interval = retry_interval(expires_at, attempts, 1)) when nil @stats["request failures"].update("#{type} - retry") raise Exceptions::RetryableError.new(retry_result.http_body, retry_result) when 0 ...
[ "def", "handle_retry_with", "(", "retry_result", ",", "type", ",", "request_uuid", ",", "expires_at", ",", "attempts", ")", "case", "(", "interval", "=", "retry_interval", "(", "expires_at", ",", "attempts", ",", "1", ")", ")", "when", "nil", "@stats", "[", ...
Handle retry response by retrying it only once This indicates the request was received but a retryable error prevented it from being processed; the retry responsibility may be passed on If retrying, this function does not return until it is time to retry @param [RestClient::RetryWith] retry_result exception raised...
[ "Handle", "retry", "response", "by", "retrying", "it", "only", "once", "This", "indicates", "the", "request", "was", "received", "but", "a", "retryable", "error", "prevented", "it", "from", "being", "processed", ";", "the", "retry", "responsibility", "may", "b...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L479-L494
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.handle_not_responding
def handle_not_responding(not_responding, type, request_uuid, expires_at, attempts) case (interval = retry_interval(expires_at, attempts)) when nil @stats["request failures"].update("#{type} - no result") self.state = :disconnected raise Exceptions::ConnectivityFailure.new(not_respon...
ruby
def handle_not_responding(not_responding, type, request_uuid, expires_at, attempts) case (interval = retry_interval(expires_at, attempts)) when nil @stats["request failures"].update("#{type} - no result") self.state = :disconnected raise Exceptions::ConnectivityFailure.new(not_respon...
[ "def", "handle_not_responding", "(", "not_responding", ",", "type", ",", "request_uuid", ",", "expires_at", ",", "attempts", ")", "case", "(", "interval", "=", "retry_interval", "(", "expires_at", ",", "attempts", ")", ")", "when", "nil", "@stats", "[", "\"req...
Handle not responding response by determining whether okay to retry If request is being retried, this function does not return until it is time to retry @param [BalancedHttpClient::NotResponding] not_responding exception indicating targeted server is too busy or out of service @param [String] type of request for...
[ "Handle", "not", "responding", "response", "by", "determining", "whether", "okay", "to", "retry", "If", "request", "is", "being", "retried", "this", "function", "does", "not", "return", "until", "it", "is", "time", "to", "retry" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L510-L526
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.retry_interval
def retry_interval(expires_at, attempts, max_retries = nil) if @options[:retry_enabled] if max_retries.nil? || attempts <= max_retries interval = @options[:retry_intervals][attempts - 1] || @options[:retry_intervals][-1] ((Time.now + interval) < expires_at) ? interval : 0 else ...
ruby
def retry_interval(expires_at, attempts, max_retries = nil) if @options[:retry_enabled] if max_retries.nil? || attempts <= max_retries interval = @options[:retry_intervals][attempts - 1] || @options[:retry_intervals][-1] ((Time.now + interval) < expires_at) ? interval : 0 else ...
[ "def", "retry_interval", "(", "expires_at", ",", "attempts", ",", "max_retries", "=", "nil", ")", "if", "@options", "[", ":retry_enabled", "]", "if", "max_retries", ".", "nil?", "||", "attempts", "<=", "max_retries", "interval", "=", "@options", "[", ":retry_i...
Determine time interval before next retry @param [Time] expires_at time for request @param [Integer] attempts so far @param [Integer] max_retries @return [Integer, NilClass] retry interval with 0 meaning no try and nil meaning retry disabled
[ "Determine", "time", "interval", "before", "next", "retry" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L535-L544
train
rightscale/right_agent
lib/right_agent/clients/base_retry_client.rb
RightScale.BaseRetryClient.wait
def wait(interval) if @options[:non_blocking] fiber = Fiber.current EM.add_timer(interval) { fiber.resume } Fiber.yield else sleep(interval) end true end
ruby
def wait(interval) if @options[:non_blocking] fiber = Fiber.current EM.add_timer(interval) { fiber.resume } Fiber.yield else sleep(interval) end true end
[ "def", "wait", "(", "interval", ")", "if", "@options", "[", ":non_blocking", "]", "fiber", "=", "Fiber", ".", "current", "EM", ".", "add_timer", "(", "interval", ")", "{", "fiber", ".", "resume", "}", "Fiber", ".", "yield", "else", "sleep", "(", "inter...
Wait the specified interval in non-blocking fashion if possible @param [Numeric] interval to wait @return [TrueClass] always true
[ "Wait", "the", "specified", "interval", "in", "non", "-", "blocking", "fashion", "if", "possible" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/base_retry_client.rb#L551-L560
train
rightscale/right_agent
lib/right_agent/retryable_request.rb
RightScale.RetryableRequest.handle_response
def handle_response(r) return true if @done @raw_response = r res = result_from(r) if res.success? if @cancel_timer @cancel_timer.cancel @cancel_timer = nil end @done = true succeed(res.content) else reason = res.content i...
ruby
def handle_response(r) return true if @done @raw_response = r res = result_from(r) if res.success? if @cancel_timer @cancel_timer.cancel @cancel_timer = nil end @done = true succeed(res.content) else reason = res.content i...
[ "def", "handle_response", "(", "r", ")", "return", "true", "if", "@done", "@raw_response", "=", "r", "res", "=", "result_from", "(", "r", ")", "if", "res", ".", "success?", "if", "@cancel_timer", "@cancel_timer", ".", "cancel", "@cancel_timer", "=", "nil", ...
Process request response and retry if needed === Parameters r(Result):: Request result === Return true:: Always return true
[ "Process", "request", "response", "and", "retry", "if", "needed" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/retryable_request.rb#L151-L193
train
rightscale/right_agent
lib/right_agent/serialize/secure_serializer.rb
RightScale.SecureSerializer.dump
def dump(obj, encrypt = nil) must_encrypt = encrypt || @encrypt serialize_format = if obj.respond_to?(:send_version) && can_handle_msgpack_result?(obj.send_version) @serializer.format else :json end encode_format = serialize_format == :json ? :pem : :der msg = @serial...
ruby
def dump(obj, encrypt = nil) must_encrypt = encrypt || @encrypt serialize_format = if obj.respond_to?(:send_version) && can_handle_msgpack_result?(obj.send_version) @serializer.format else :json end encode_format = serialize_format == :json ? :pem : :der msg = @serial...
[ "def", "dump", "(", "obj", ",", "encrypt", "=", "nil", ")", "must_encrypt", "=", "encrypt", "||", "@encrypt", "serialize_format", "=", "if", "obj", ".", "respond_to?", "(", ":send_version", ")", "&&", "can_handle_msgpack_result?", "(", "obj", ".", "send_versio...
Initialize serializer, must be called prior to using it === Parameters serializer(Serializer):: Object serializer identity(String):: Serialized identity associated with serialized messages store(Object):: Credentials store exposing certificates used for encryption (:get_target), signature validation (:get_signe...
[ "Initialize", "serializer", "must", "be", "called", "prior", "to", "using", "it" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/serialize/secure_serializer.rb#L90-L110
train
rightscale/right_agent
lib/right_agent/serialize/secure_serializer.rb
RightScale.SecureSerializer.load
def load(msg, id = nil) msg = @serializer.load(msg) sig = Signature.from_data(msg['signature']) certs = @store.get_signer(msg['id']) raise MissingCertificate.new("Could not find a certificate for signer #{msg['id']}") unless certs certs = [ certs ] unless certs.respond_to?(:any?) ra...
ruby
def load(msg, id = nil) msg = @serializer.load(msg) sig = Signature.from_data(msg['signature']) certs = @store.get_signer(msg['id']) raise MissingCertificate.new("Could not find a certificate for signer #{msg['id']}") unless certs certs = [ certs ] unless certs.respond_to?(:any?) ra...
[ "def", "load", "(", "msg", ",", "id", "=", "nil", ")", "msg", "=", "@serializer", ".", "load", "(", "msg", ")", "sig", "=", "Signature", ".", "from_data", "(", "msg", "[", "'signature'", "]", ")", "certs", "=", "@store", ".", "get_signer", "(", "ms...
Decrypt, authorize signature, and unserialize message Use x.509 certificate store for decrypting and validating signature === Parameters msg(String):: Serialized and optionally encrypted object using MessagePack or JSON id(String|nil):: Optional identifier of source of data for use in determining who is the rec...
[ "Decrypt", "authorize", "signature", "and", "unserialize", "message", "Use", "x", ".", "509", "certificate", "store", "for", "decrypting", "and", "validating", "signature" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/serialize/secure_serializer.rb#L127-L144
train
rightscale/right_agent
lib/right_agent/core_payload_types/right_script_attachment.rb
RightScale.RightScriptAttachment.fill_out
def fill_out(session) session['scope'] = "attachments" if @digest session['resource'] = @digest else session['resource'] = to_hash session['url'] = @url session['etag'] = @etag end @token = session.to_s end
ruby
def fill_out(session) session['scope'] = "attachments" if @digest session['resource'] = @digest else session['resource'] = to_hash session['url'] = @url session['etag'] = @etag end @token = session.to_s end
[ "def", "fill_out", "(", "session", ")", "session", "[", "'scope'", "]", "=", "\"attachments\"", "if", "@digest", "session", "[", "'resource'", "]", "=", "@digest", "else", "session", "[", "'resource'", "]", "=", "to_hash", "session", "[", "'url'", "]", "="...
Fill out the session cookie appropriately for this attachment.
[ "Fill", "out", "the", "session", "cookie", "appropriately", "for", "this", "attachment", "." ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/core_payload_types/right_script_attachment.rb#L68-L78
train
rightscale/right_agent
lib/right_agent/command/command_parser.rb
RightScale.CommandParser.parse_chunk
def parse_chunk(chunk) @buildup << chunk chunks = @buildup.split(CommandSerializer::SEPARATOR, -1) if (do_call = chunks.size > 1) commands = [] (0..chunks.size - 2).each do |i| begin commands << CommandSerializer.load(chunks[i]) rescue StandardError => e...
ruby
def parse_chunk(chunk) @buildup << chunk chunks = @buildup.split(CommandSerializer::SEPARATOR, -1) if (do_call = chunks.size > 1) commands = [] (0..chunks.size - 2).each do |i| begin commands << CommandSerializer.load(chunks[i]) rescue StandardError => e...
[ "def", "parse_chunk", "(", "chunk", ")", "@buildup", "<<", "chunk", "chunks", "=", "@buildup", ".", "split", "(", "CommandSerializer", "::", "SEPARATOR", ",", "-", "1", ")", "if", "(", "do_call", "=", "chunks", ".", "size", ">", "1", ")", "commands", "...
Register callback block === Block Block that will get called back whenever a command is successfully parsed === Raise (ArgumentError): If block is missing Parse given input May cause multiple callbacks if multiple commands are successfully parsed Callback happens in next EM tick === Parameters chunk(String)...
[ "Register", "callback", "block" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/command/command_parser.rb#L51-L83
train
rightscale/right_agent
spec/spec_helper.rb
RightScale.SpecHelper.issue_cert
def issue_cert test_dn = { 'C' => 'US', 'ST' => 'California', 'L' => 'Santa Barbara', 'O' => 'Agent', 'OU' => 'Certification Services', 'CN' => 'Agent test' } dn = DistinguishedName.new(test_dn) key = RsaKeyPa...
ruby
def issue_cert test_dn = { 'C' => 'US', 'ST' => 'California', 'L' => 'Santa Barbara', 'O' => 'Agent', 'OU' => 'Certification Services', 'CN' => 'Agent test' } dn = DistinguishedName.new(test_dn) key = RsaKeyPa...
[ "def", "issue_cert", "test_dn", "=", "{", "'C'", "=>", "'US'", ",", "'ST'", "=>", "'California'", ",", "'L'", "=>", "'Santa Barbara'", ",", "'O'", "=>", "'Agent'", ",", "'OU'", "=>", "'Certification Services'", ",", "'CN'", "=>", "'Agent test'", "}", "dn", ...
Create test certificate
[ "Create", "test", "certificate" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/spec/spec_helper.rb#L57-L67
train
rightscale/right_agent
lib/right_agent/dispatcher.rb
RightScale.Dispatcher.dispatch
def dispatch(request) token = request.token actor, method, idempotent = route(request) received_at = @request_stats.update(method, (token if request.is_a?(Request))) if (dup = duplicate?(request, method, idempotent)) raise DuplicateRequest, dup end unless (result = expired?(r...
ruby
def dispatch(request) token = request.token actor, method, idempotent = route(request) received_at = @request_stats.update(method, (token if request.is_a?(Request))) if (dup = duplicate?(request, method, idempotent)) raise DuplicateRequest, dup end unless (result = expired?(r...
[ "def", "dispatch", "(", "request", ")", "token", "=", "request", ".", "token", "actor", ",", "method", ",", "idempotent", "=", "route", "(", "request", ")", "received_at", "=", "@request_stats", ".", "update", "(", "method", ",", "(", "token", "if", "req...
Route request to appropriate actor for servicing Reject requests whose TTL has expired or that are duplicates of work already dispatched === Parameters request(Request|Push):: Packet containing request header(AMQP::Frame::Header|nil):: Request header containing ack control === Return (Result|nil):: Result of re...
[ "Route", "request", "to", "appropriate", "actor", "for", "servicing", "Reject", "requests", "whose", "TTL", "has", "expired", "or", "that", "are", "duplicates", "of", "work", "already", "dispatched" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/dispatcher.rb#L86-L100
train
rightscale/right_agent
lib/right_agent/dispatcher.rb
RightScale.Dispatcher.stats
def stats(reset = false) stats = { "dispatched cache" => (@dispatched_cache.stats if @dispatched_cache), "dispatch failures" => @dispatch_failure_stats.all, "rejects" => @reject_stats.all, "requests" => @request_stats.all } reset_stats if reset ...
ruby
def stats(reset = false) stats = { "dispatched cache" => (@dispatched_cache.stats if @dispatched_cache), "dispatch failures" => @dispatch_failure_stats.all, "rejects" => @reject_stats.all, "requests" => @request_stats.all } reset_stats if reset ...
[ "def", "stats", "(", "reset", "=", "false", ")", "stats", "=", "{", "\"dispatched cache\"", "=>", "(", "@dispatched_cache", ".", "stats", "if", "@dispatched_cache", ")", ",", "\"dispatch failures\"", "=>", "@dispatch_failure_stats", ".", "all", ",", "\"rejects\"",...
Get dispatcher statistics === Parameters reset(Boolean):: Whether to reset the statistics after getting the current ones === Return stats(Hash):: Current statistics: "dispatched cache"(Hash|nil):: Number of dispatched requests cached and age of youngest and oldest, or nil if empty "dispatch failures"(H...
[ "Get", "dispatcher", "statistics" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/dispatcher.rb#L118-L127
train
rightscale/right_agent
lib/right_agent/dispatcher.rb
RightScale.Dispatcher.expired?
def expired?(request, method) if (expires_at = request.expires_at) && expires_at > 0 && (now = Time.now.to_i) >= expires_at @reject_stats.update("expired (#{method})") Log.info("REJECT EXPIRED <#{request.token}> from #{request.from} TTL #{RightSupport::Stats.elapsed(now - expires_at)} ago") ...
ruby
def expired?(request, method) if (expires_at = request.expires_at) && expires_at > 0 && (now = Time.now.to_i) >= expires_at @reject_stats.update("expired (#{method})") Log.info("REJECT EXPIRED <#{request.token}> from #{request.from} TTL #{RightSupport::Stats.elapsed(now - expires_at)} ago") ...
[ "def", "expired?", "(", "request", ",", "method", ")", "if", "(", "expires_at", "=", "request", ".", "expires_at", ")", "&&", "expires_at", ">", "0", "&&", "(", "now", "=", "Time", ".", "now", ".", "to_i", ")", ">=", "expires_at", "@reject_stats", ".",...
Determine if request TTL has expired === Parameters request(Push|Request):: Request to be checked method(String):: Actor method requested to be performed === Return (OperationResult|nil):: Error result if expired, otherwise nil
[ "Determine", "if", "request", "TTL", "has", "expired" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/dispatcher.rb#L150-L161
train
rightscale/right_agent
lib/right_agent/dispatcher.rb
RightScale.Dispatcher.duplicate?
def duplicate?(request, method, idempotent) if !idempotent && @dispatched_cache if (serviced_by = @dispatched_cache.serviced_by(request.token)) from_retry = "" else from_retry = "retry " request.tries.each { |t| break if (serviced_by = @dispatched_cache.serviced_by(t)...
ruby
def duplicate?(request, method, idempotent) if !idempotent && @dispatched_cache if (serviced_by = @dispatched_cache.serviced_by(request.token)) from_retry = "" else from_retry = "retry " request.tries.each { |t| break if (serviced_by = @dispatched_cache.serviced_by(t)...
[ "def", "duplicate?", "(", "request", ",", "method", ",", "idempotent", ")", "if", "!", "idempotent", "&&", "@dispatched_cache", "if", "(", "serviced_by", "=", "@dispatched_cache", ".", "serviced_by", "(", "request", ".", "token", ")", ")", "from_retry", "=", ...
Determine whether this request is a duplicate === Parameters request(Request|Push):: Packet containing request method(String):: Actor method requested to be performed idempotent(Boolean):: Whether this method is idempotent === Return (String|nil):: Messaging describing who already serviced request if it is a du...
[ "Determine", "whether", "this", "request", "is", "a", "duplicate" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/dispatcher.rb#L172-L187
train
rightscale/right_agent
lib/right_agent/dispatcher.rb
RightScale.Dispatcher.route
def route(request) prefix, method = request.type.split('/')[1..-1] method ||= :index method = method.to_sym actor = @registry.actor_for(prefix) if actor.nil? || !actor.respond_to?(method) raise InvalidRequestType, "Unknown actor or method for dispatching request <#{request.token}> ...
ruby
def route(request) prefix, method = request.type.split('/')[1..-1] method ||= :index method = method.to_sym actor = @registry.actor_for(prefix) if actor.nil? || !actor.respond_to?(method) raise InvalidRequestType, "Unknown actor or method for dispatching request <#{request.token}> ...
[ "def", "route", "(", "request", ")", "prefix", ",", "method", "=", "request", ".", "type", ".", "split", "(", "'/'", ")", "[", "1", "..", "-", "1", "]", "method", "||=", ":index", "method", "=", "method", ".", "to_sym", "actor", "=", "@registry", "...
Use request type to route request to actor and an associated method === Parameters request(Push|Request):: Packet containing request === Return (Array):: Actor name, method name, and whether method is idempotent === Raise InvalidRequestType:: If the request cannot be routed to an actor
[ "Use", "request", "type", "to", "route", "request", "to", "actor", "and", "an", "associated", "method" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/dispatcher.rb#L199-L208
train
rightscale/right_agent
lib/right_agent/dispatcher.rb
RightScale.Dispatcher.perform
def perform(request, actor, method, idempotent) @dispatched_cache.store(request.token) if @dispatched_cache && !idempotent if actor.method(method).arity.abs == 1 actor.send(method, request.payload) else actor.send(method, request.payload, request) end rescue StandardError => ...
ruby
def perform(request, actor, method, idempotent) @dispatched_cache.store(request.token) if @dispatched_cache && !idempotent if actor.method(method).arity.abs == 1 actor.send(method, request.payload) else actor.send(method, request.payload, request) end rescue StandardError => ...
[ "def", "perform", "(", "request", ",", "actor", ",", "method", ",", "idempotent", ")", "@dispatched_cache", ".", "store", "(", "request", ".", "token", ")", "if", "@dispatched_cache", "&&", "!", "idempotent", "if", "actor", ".", "method", "(", "method", ")...
Perform requested action === Parameters request(Push|Request):: Packet containing request token(String):: Unique identity token for request method(String):: Actor method requested to be performed idempotent(Boolean):: Whether this method is idempotent === Return (OperationResult):: Result from performing a req...
[ "Perform", "requested", "action" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/dispatcher.rb#L220-L231
train
rightscale/right_agent
lib/right_agent/security/certificate.rb
RightScale.Certificate.save
def save(file) File.open(file, "w") do |f| f.write(@raw_cert.to_pem) end true end
ruby
def save(file) File.open(file, "w") do |f| f.write(@raw_cert.to_pem) end true end
[ "def", "save", "(", "file", ")", "File", ".", "open", "(", "file", ",", "\"w\"", ")", "do", "|", "f", "|", "f", ".", "write", "(", "@raw_cert", ".", "to_pem", ")", "end", "true", "end" ]
Save certificate to file in PEM format === Parameters file(String):: File path name === Return true:: Always return true
[ "Save", "certificate", "to", "file", "in", "PEM", "format" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/security/certificate.rb#L84-L89
train
rightscale/right_agent
lib/right_agent/history.rb
RightScale.History.load
def load events = [] File.open(@history, "r") { |f| events = f.readlines.map { |l| JSON.legacy_load(l) } } if File.readable?(@history) events end
ruby
def load events = [] File.open(@history, "r") { |f| events = f.readlines.map { |l| JSON.legacy_load(l) } } if File.readable?(@history) events end
[ "def", "load", "events", "=", "[", "]", "File", ".", "open", "(", "@history", ",", "\"r\"", ")", "{", "|", "f", "|", "events", "=", "f", ".", "readlines", ".", "map", "{", "|", "l", "|", "JSON", ".", "legacy_load", "(", "l", ")", "}", "}", "i...
Load events from history file === Return events(Array):: List of historical events with each being a hash of :time(Integer):: Time in seconds in Unix-epoch when event occurred :pid(Integer):: Process id of agent recording the event :event(Object):: Event object in the form String or {String => Object}, ...
[ "Load", "events", "from", "history", "file" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/history.rb#L63-L67
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.map_request
def map_request(type, payload, options) verb, path = API_MAP[type] raise ArgumentError, "Unsupported request type: #{type}" if path.nil? actor, action = type.split("/")[1..-1] path, params, request_options = parameterize(actor, action, payload, path) if action == "query_tags" map_q...
ruby
def map_request(type, payload, options) verb, path = API_MAP[type] raise ArgumentError, "Unsupported request type: #{type}" if path.nil? actor, action = type.split("/")[1..-1] path, params, request_options = parameterize(actor, action, payload, path) if action == "query_tags" map_q...
[ "def", "map_request", "(", "type", ",", "payload", ",", "options", ")", "verb", ",", "path", "=", "API_MAP", "[", "type", "]", "raise", "ArgumentError", ",", "\"Unsupported request type: #{type}\"", "if", "path", ".", "nil?", "actor", ",", "action", "=", "ty...
Convert request to RightApi form and then make request via HTTP @param [String] type of request as path specifying actor and action @param [Hash, NilClass] payload for request @option options [String] :request_uuid uniquely identifying this request @option options [Numeric] :time_to_live seconds before request ex...
[ "Convert", "request", "to", "RightApi", "form", "and", "then", "make", "request", "via", "HTTP" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L192-L202
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.map_response
def map_response(response, path) case path when "/audit_entries" # Convert returned audit entry href to audit ID response.sub!(/^.*\/api\/audit_entries\//, "") if response.is_a?(String) when "/tags/by_resource", "/tags/by_tag" # Extract tags for each instance resource from resp...
ruby
def map_response(response, path) case path when "/audit_entries" # Convert returned audit entry href to audit ID response.sub!(/^.*\/api\/audit_entries\//, "") if response.is_a?(String) when "/tags/by_resource", "/tags/by_tag" # Extract tags for each instance resource from resp...
[ "def", "map_response", "(", "response", ",", "path", ")", "case", "path", "when", "\"/audit_entries\"", "response", ".", "sub!", "(", "/", "\\/", "\\/", "\\/", "/", ",", "\"\"", ")", "if", "response", ".", "is_a?", "(", "String", ")", "when", "\"/tags/by...
Convert response from request into required form where necessary @param [Object] response received @param [String] path in URI for desired resource @return [Object] converted response
[ "Convert", "response", "from", "request", "into", "required", "form", "where", "necessary" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L210-L230
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.map_query_tags
def map_query_tags(verb, params, action, options) response = {} hrefs = params[:resource_hrefs] || [] hrefs.concat(query_by_tag(verb, params[:tags], action, options)) if params[:tags] response = query_by_resource(verb, hrefs, action, options) if hrefs.any? response end
ruby
def map_query_tags(verb, params, action, options) response = {} hrefs = params[:resource_hrefs] || [] hrefs.concat(query_by_tag(verb, params[:tags], action, options)) if params[:tags] response = query_by_resource(verb, hrefs, action, options) if hrefs.any? response end
[ "def", "map_query_tags", "(", "verb", ",", "params", ",", "action", ",", "options", ")", "response", "=", "{", "}", "hrefs", "=", "params", "[", ":resource_hrefs", "]", "||", "[", "]", "hrefs", ".", "concat", "(", "query_by_tag", "(", "verb", ",", "par...
Convert tag query request into one or more API requests and then convert responses Currently only retrieving "instances" resources @param [Symbol] verb for HTTP REST request @param [Hash] params for HTTP request @param [String] action from request type @param [Hash] options augmenting or overriding default option...
[ "Convert", "tag", "query", "request", "into", "one", "or", "more", "API", "requests", "and", "then", "convert", "responses", "Currently", "only", "retrieving", "instances", "resources" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L241-L247
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.query_by_tag
def query_by_tag(verb, tags, action, options) path = "/tags/by_tag" params = {:tags => tags, :match_all => false, :resource_type => "instances"} map_response(make_request(verb, path, params, action, options), path).keys end
ruby
def query_by_tag(verb, tags, action, options) path = "/tags/by_tag" params = {:tags => tags, :match_all => false, :resource_type => "instances"} map_response(make_request(verb, path, params, action, options), path).keys end
[ "def", "query_by_tag", "(", "verb", ",", "tags", ",", "action", ",", "options", ")", "path", "=", "\"/tags/by_tag\"", "params", "=", "{", ":tags", "=>", "tags", ",", ":match_all", "=>", "false", ",", ":resource_type", "=>", "\"instances\"", "}", "map_respons...
Query API for resources with specified tags @param [Symbol] verb for HTTP REST request @param [Array] tags that all resources retrieved must have @param [String] action from request type @param [Hash] options augmenting or overriding default options for HTTP request @return [Array] resource hrefs
[ "Query", "API", "for", "resources", "with", "specified", "tags" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L257-L261
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.query_by_resource
def query_by_resource(verb, hrefs, action, options) path = "/tags/by_resource" params = {:resource_hrefs => hrefs} map_response(make_request(verb, path, params, action, options), path) end
ruby
def query_by_resource(verb, hrefs, action, options) path = "/tags/by_resource" params = {:resource_hrefs => hrefs} map_response(make_request(verb, path, params, action, options), path) end
[ "def", "query_by_resource", "(", "verb", ",", "hrefs", ",", "action", ",", "options", ")", "path", "=", "\"/tags/by_resource\"", "params", "=", "{", ":resource_hrefs", "=>", "hrefs", "}", "map_response", "(", "make_request", "(", "verb", ",", "path", ",", "p...
Query API for tags associated with a set of resources @param [Symbol] verb for HTTP REST request @param [Array] hrefs for resources whose tags are to be retrieved @param [String] action from request type @param [Hash] options augmenting or overriding default options for HTTP request @return [Hash] tags retrieved...
[ "Query", "API", "for", "tags", "associated", "with", "a", "set", "of", "resources" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L271-L275
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.parameterize
def parameterize(actor, action, payload, path) options = {} params = {} if actor == "auditor" path = path.sub(/:id/, payload[:audit_id].to_s || "") params = parameterize_audit(action, payload) options = {:filter_params => AUDIT_FILTER_PARAMS} elsif actor == "router" && ac...
ruby
def parameterize(actor, action, payload, path) options = {} params = {} if actor == "auditor" path = path.sub(/:id/, payload[:audit_id].to_s || "") params = parameterize_audit(action, payload) options = {:filter_params => AUDIT_FILTER_PARAMS} elsif actor == "router" && ac...
[ "def", "parameterize", "(", "actor", ",", "action", ",", "payload", ",", "path", ")", "options", "=", "{", "}", "params", "=", "{", "}", "if", "actor", "==", "\"auditor\"", "path", "=", "path", ".", "sub", "(", "/", "/", ",", "payload", "[", ":audi...
Convert payload to HTTP parameters @param [String] actor from request type @param [String] action from request type @param [Hash, NilClass] payload for request @param [String] path in URI for desired resource @return [Array] path string and parameters and options hashes
[ "Convert", "payload", "to", "HTTP", "parameters" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L285-L304
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.parameterize_audit
def parameterize_audit(action, payload) params = {} summary = non_blank(payload[:summary]) detail = non_blank(payload[:detail]) case action when "create_entry" params[:audit_entry] = {:auditee_href => @self_href} params[:audit_entry][:summary] = truncate(summary, MAX_AUDIT_...
ruby
def parameterize_audit(action, payload) params = {} summary = non_blank(payload[:summary]) detail = non_blank(payload[:detail]) case action when "create_entry" params[:audit_entry] = {:auditee_href => @self_href} params[:audit_entry][:summary] = truncate(summary, MAX_AUDIT_...
[ "def", "parameterize_audit", "(", "action", ",", "payload", ")", "params", "=", "{", "}", "summary", "=", "non_blank", "(", "payload", "[", ":summary", "]", ")", "detail", "=", "non_blank", "(", "payload", "[", ":detail", "]", ")", "case", "action", "whe...
Translate audit request payload to HTTP parameters Truncate audit summary to MAX_AUDIT_SUMMARY_LENGTH, the limit imposed by RightApi @param [String] action requested: create_entry or update_entry @param [Hash] payload from submitted request @return [Hash] HTTP request parameters @raise [ArgumentError] unknown r...
[ "Translate", "audit", "request", "payload", "to", "HTTP", "parameters", "Truncate", "audit", "summary", "to", "MAX_AUDIT_SUMMARY_LENGTH", "the", "limit", "imposed", "by", "RightApi" ]
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L315-L339
train
rightscale/right_agent
lib/right_agent/clients/api_client.rb
RightScale.ApiClient.truncate
def truncate(value, max_length) raise ArgumentError, "max_length must be greater than 3" if max_length <= 3 if value.is_a?(String) && value.bytesize > max_length max_truncated = max_length - 3 truncated = value[0, max_truncated] while truncated.bytesize > max_truncated do t...
ruby
def truncate(value, max_length) raise ArgumentError, "max_length must be greater than 3" if max_length <= 3 if value.is_a?(String) && value.bytesize > max_length max_truncated = max_length - 3 truncated = value[0, max_truncated] while truncated.bytesize > max_truncated do t...
[ "def", "truncate", "(", "value", ",", "max_length", ")", "raise", "ArgumentError", ",", "\"max_length must be greater than 3\"", "if", "max_length", "<=", "3", "if", "value", ".", "is_a?", "(", "String", ")", "&&", "value", ".", "bytesize", ">", "max_length", ...
Truncate string if it exceeds maximum length Do length check with bytesize rather than size since this method is only intended for use with ruby 1.9 and above, otherwise multi-byte characters could cause this code to be too lenient @param [String, NilClass] value to be truncated @param [Integer] max_length allowe...
[ "Truncate", "string", "if", "it", "exceeds", "maximum", "length", "Do", "length", "check", "with", "bytesize", "rather", "than", "size", "since", "this", "method", "is", "only", "intended", "for", "use", "with", "ruby", "1", ".", "9", "and", "above", "othe...
64c68c162692f0a70543d10def5e4bf56505bd82
https://github.com/rightscale/right_agent/blob/64c68c162692f0a70543d10def5e4bf56505bd82/lib/right_agent/clients/api_client.rb#L352-L364
train
KatanaCode/kirigami
lib/kirigami/image.rb
Kirigami.Image.cut!
def cut! create_backup_copy MiniMagick::Tool::Mogrify.new do |mogrify| mogrify.resize(max_size) mogrify.strip if jpeg? mogrify.colorspace(Kirigami.config.jpeg_colorspace) mogrify.sampling_factor(Kirigami.config.jpeg_sampling_factor) mogrify.interlace(Kir...
ruby
def cut! create_backup_copy MiniMagick::Tool::Mogrify.new do |mogrify| mogrify.resize(max_size) mogrify.strip if jpeg? mogrify.colorspace(Kirigami.config.jpeg_colorspace) mogrify.sampling_factor(Kirigami.config.jpeg_sampling_factor) mogrify.interlace(Kir...
[ "def", "cut!", "create_backup_copy", "MiniMagick", "::", "Tool", "::", "Mogrify", ".", "new", "do", "|", "mogrify", "|", "mogrify", ".", "resize", "(", "max_size", ")", "mogrify", ".", "strip", "if", "jpeg?", "mogrify", ".", "colorspace", "(", "Kirigami", ...
Create a new Image max_size - An ImageSize to specify the size and name of image. Cuts the File down to size! Creates a backup copy first, if required.
[ "Create", "a", "new", "Image" ]
191b8756869b09ad5a9afd4f30fc3c07e8373318
https://github.com/KatanaCode/kirigami/blob/191b8756869b09ad5a9afd4f30fc3c07e8373318/lib/kirigami/image.rb#L28-L41
train
Phybbit/dataflow-rb
lib/dataflow/schema_mixin.rb
Dataflow.SchemaMixin.infer_schema
def infer_schema(samples_count: 0, extended: false) if db_backend == :postgresql # Experimental sch = db_adapter.client.schema(read_dataset_name).to_h sch = sch.reject{ |k, v| k == :_id }.map { |k,v| [k, {type: v[:type].to_s}] }.to_h self.inferred_schema = sch save ...
ruby
def infer_schema(samples_count: 0, extended: false) if db_backend == :postgresql # Experimental sch = db_adapter.client.schema(read_dataset_name).to_h sch = sch.reject{ |k, v| k == :_id }.map { |k,v| [k, {type: v[:type].to_s}] }.to_h self.inferred_schema = sch save ...
[ "def", "infer_schema", "(", "samples_count", ":", "0", ",", "extended", ":", "false", ")", "if", "db_backend", "==", ":postgresql", "sch", "=", "db_adapter", ".", "client", ".", "schema", "(", "read_dataset_name", ")", ".", "to_h", "sch", "=", "sch", ".", ...
if this change, update the regex that use the character directly in this mixin Generate a schema based on this collection's records. We evaluate the schema of each record and then merge all the information together. @param extended [Boolean] Set to true to keep each field as a basic type. Set to false to re...
[ "if", "this", "change", "update", "the", "regex", "that", "use", "the", "character", "directly", "in", "this", "mixin", "Generate", "a", "schema", "based", "on", "this", "collection", "s", "records", ".", "We", "evaluate", "the", "schema", "of", "each", "r...
6cedf006983f6ed1c72ccff5104bd47de38dd4f3
https://github.com/Phybbit/dataflow-rb/blob/6cedf006983f6ed1c72ccff5104bd47de38dd4f3/lib/dataflow/schema_mixin.rb#L13-L51
train
mumuki/mumukit-assistant
lib/mumukit/assistant.rb
Mumukit.Assistant.assist_with
def assist_with(submission) @rules .select { |it| it.matches?(submission) } .map { |it| it.message_for(submission.attemps_count) } end
ruby
def assist_with(submission) @rules .select { |it| it.matches?(submission) } .map { |it| it.message_for(submission.attemps_count) } end
[ "def", "assist_with", "(", "submission", ")", "@rules", ".", "select", "{", "|", "it", "|", "it", ".", "matches?", "(", "submission", ")", "}", ".", "map", "{", "|", "it", "|", "it", ".", "message_for", "(", "submission", ".", "attemps_count", ")", "...
Provides tips for the student for the given submission, based on the `rules`.
[ "Provides", "tips", "for", "the", "student", "for", "the", "given", "submission", "based", "on", "the", "rules", "." ]
a776ec594a209f3d04fc918426297adf30504f25
https://github.com/mumuki/mumukit-assistant/blob/a776ec594a209f3d04fc918426297adf30504f25/lib/mumukit/assistant.rb#L21-L25
train
danielsdeleo/deep_merge
lib/deep_merge/rails_compat.rb
DeepMerge.RailsCompat.ko_deeper_merge!
def ko_deeper_merge!(source, options = {}) default_opts = {:knockout_prefix => "--", :preserve_unmergeables => false} DeepMerge::deep_merge!(source, self, default_opts.merge(options)) end
ruby
def ko_deeper_merge!(source, options = {}) default_opts = {:knockout_prefix => "--", :preserve_unmergeables => false} DeepMerge::deep_merge!(source, self, default_opts.merge(options)) end
[ "def", "ko_deeper_merge!", "(", "source", ",", "options", "=", "{", "}", ")", "default_opts", "=", "{", ":knockout_prefix", "=>", "\"--\"", ",", ":preserve_unmergeables", "=>", "false", "}", "DeepMerge", "::", "deep_merge!", "(", "source", ",", "self", ",", ...
ko_hash_merge! will merge and knockout elements prefixed with DEFAULT_FIELD_KNOCKOUT_PREFIX
[ "ko_hash_merge!", "will", "merge", "and", "knockout", "elements", "prefixed", "with", "DEFAULT_FIELD_KNOCKOUT_PREFIX" ]
9b15cc77c5954eebf67365d4f24ca44a9e2b2ca7
https://github.com/danielsdeleo/deep_merge/blob/9b15cc77c5954eebf67365d4f24ca44a9e2b2ca7/lib/deep_merge/rails_compat.rb#L6-L9
train
rails/activerecord-deprecated_finders
lib/active_record/deprecated_finders/base.rb
ActiveRecord.DeprecatedFinders.with_exclusive_scope
def with_exclusive_scope(method_scoping = {}, &block) if method_scoping.values.any? { |e| e.is_a?(ActiveRecord::Relation) } raise ArgumentError, <<-MSG New finder API can not be used with_exclusive_scope. You can either call unscoped to get an anonymous scope not bound to the default_scope: User.unscoped...
ruby
def with_exclusive_scope(method_scoping = {}, &block) if method_scoping.values.any? { |e| e.is_a?(ActiveRecord::Relation) } raise ArgumentError, <<-MSG New finder API can not be used with_exclusive_scope. You can either call unscoped to get an anonymous scope not bound to the default_scope: User.unscoped...
[ "def", "with_exclusive_scope", "(", "method_scoping", "=", "{", "}", ",", "&", "block", ")", "if", "method_scoping", ".", "values", ".", "any?", "{", "|", "e", "|", "e", ".", "is_a?", "(", "ActiveRecord", "::", "Relation", ")", "}", "raise", "ArgumentErr...
Works like with_scope, but discards any nested properties.
[ "Works", "like", "with_scope", "but", "discards", "any", "nested", "properties", "." ]
041c83c9dce8e17b8e1216adfaff48cc9debac02
https://github.com/rails/activerecord-deprecated_finders/blob/041c83c9dce8e17b8e1216adfaff48cc9debac02/lib/active_record/deprecated_finders/base.rb#L124-L140
train
rdp/ruby_gnuplot
lib/gnuplot.rb
Gnuplot.Plot.set
def set ( var, value = "" ) value = "\"#{value}\"" if QUOTED.include? var unless value =~ /^'.*'$/ @settings << [ :set, var, value ] end
ruby
def set ( var, value = "" ) value = "\"#{value}\"" if QUOTED.include? var unless value =~ /^'.*'$/ @settings << [ :set, var, value ] end
[ "def", "set", "(", "var", ",", "value", "=", "\"\"", ")", "value", "=", "\"\\\"#{value}\\\"\"", "if", "QUOTED", ".", "include?", "var", "unless", "value", "=~", "/", "/", "@settings", "<<", "[", ":set", ",", "var", ",", "value", "]", "end" ]
Set a variable to the given value. +Var+ must be a gnuplot variable and +value+ must be the value to set it to. Automatic quoting will be performed if the variable requires it. This is overloaded by the +method_missing+ method so see that for more readable code.
[ "Set", "a", "variable", "to", "the", "given", "value", ".", "+", "Var", "+", "must", "be", "a", "gnuplot", "variable", "and", "+", "value", "+", "must", "be", "the", "value", "to", "set", "it", "to", ".", "Automatic", "quoting", "will", "be", "perfor...
79eb51b46ae1a659292d3d4cc15c8a0e321a1c3e
https://github.com/rdp/ruby_gnuplot/blob/79eb51b46ae1a659292d3d4cc15c8a0e321a1c3e/lib/gnuplot.rb#L127-L130
train
potatosalad/ruby-jose
lib/jose/jwt.rb
JOSE.JWT.merge
def merge(object) object = case object when JOSE::Map, Hash object when String JOSE.decode(object) when JOSE::JWT object.to_map else raise ArgumentError, "'object' must be a Hash, String, or JOSE::JWT" end return JOSE::JWT.from_map(self.to_map.me...
ruby
def merge(object) object = case object when JOSE::Map, Hash object when String JOSE.decode(object) when JOSE::JWT object.to_map else raise ArgumentError, "'object' must be a Hash, String, or JOSE::JWT" end return JOSE::JWT.from_map(self.to_map.me...
[ "def", "merge", "(", "object", ")", "object", "=", "case", "object", "when", "JOSE", "::", "Map", ",", "Hash", "object", "when", "String", "JOSE", ".", "decode", "(", "object", ")", "when", "JOSE", "::", "JWT", "object", ".", "to_map", "else", "raise",...
Merges object into current map. @param [JOSE::Map, Hash, String, JOSE::JWT] object @return [JOSE::JWT]
[ "Merges", "object", "into", "current", "map", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwt.rb#L243-L255
train
potatosalad/ruby-jose
lib/jose/jwk.rb
JOSE.JWK.block_encrypt
def block_encrypt(plain_text, jwe = nil) jwe ||= block_encryptor return JOSE::JWE.block_encrypt(self, plain_text, jwe) end
ruby
def block_encrypt(plain_text, jwe = nil) jwe ||= block_encryptor return JOSE::JWE.block_encrypt(self, plain_text, jwe) end
[ "def", "block_encrypt", "(", "plain_text", ",", "jwe", "=", "nil", ")", "jwe", "||=", "block_encryptor", "return", "JOSE", "::", "JWE", ".", "block_encrypt", "(", "self", ",", "plain_text", ",", "jwe", ")", "end" ]
Encrypts the `plain_text` using the `jwk` and algorithms specified by the `jwe`. @see JOSE::JWE.block_encrypt @param [String] plain_text @param [JOSE::JWE] jwe @return [JOSE::EncryptedMap]
[ "Encrypts", "the", "plain_text", "using", "the", "jwk", "and", "algorithms", "specified", "by", "the", "jwe", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwk.rb#L644-L647
train
potatosalad/ruby-jose
lib/jose/jwk.rb
JOSE.JWK.box_decrypt
def box_decrypt(encrypted, public_jwk = nil) if public_jwk return JOSE::JWE.block_decrypt([public_jwk, self], encrypted) else return JOSE::JWE.block_decrypt(self, encrypted) end end
ruby
def box_decrypt(encrypted, public_jwk = nil) if public_jwk return JOSE::JWE.block_decrypt([public_jwk, self], encrypted) else return JOSE::JWE.block_decrypt(self, encrypted) end end
[ "def", "box_decrypt", "(", "encrypted", ",", "public_jwk", "=", "nil", ")", "if", "public_jwk", "return", "JOSE", "::", "JWE", ".", "block_decrypt", "(", "[", "public_jwk", ",", "self", "]", ",", "encrypted", ")", "else", "return", "JOSE", "::", "JWE", "...
Key Agreement decryption of the `encrypted` binary or map using `my_private_jwk`. @see JOSE::JWK.box_encrypt @see JOSE::JWE.block_decrypt @param [JOSE::EncryptedBinary, JOSE::EncryptedMap] encrypted @param [JOSE::JWK] public_jwk @return [[String, JOSE::JWE]]
[ "Key", "Agreement", "decryption", "of", "the", "encrypted", "binary", "or", "map", "using", "my_private_jwk", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwk.rb#L687-L693
train
potatosalad/ruby-jose
lib/jose/jwk.rb
JOSE.JWK.box_encrypt
def box_encrypt(plain_text, jwk_secret = nil, jwe = nil) epk_secret = nil jwk_public = self if jwk_secret.nil? epk_secret = jwk_secret = jwk_public.generate_key end if not jwk_secret.is_a?(JOSE::JWK) jwk_secret = JOSE::JWK.from(jwk_secret) end if jwe.nil? ...
ruby
def box_encrypt(plain_text, jwk_secret = nil, jwe = nil) epk_secret = nil jwk_public = self if jwk_secret.nil? epk_secret = jwk_secret = jwk_public.generate_key end if not jwk_secret.is_a?(JOSE::JWK) jwk_secret = JOSE::JWK.from(jwk_secret) end if jwe.nil? ...
[ "def", "box_encrypt", "(", "plain_text", ",", "jwk_secret", "=", "nil", ",", "jwe", "=", "nil", ")", "epk_secret", "=", "nil", "jwk_public", "=", "self", "if", "jwk_secret", ".", "nil?", "epk_secret", "=", "jwk_secret", "=", "jwk_public", ".", "generate_key"...
Key Agreement encryption of `plain_text` by generating an ephemeral private key based on `other_public_jwk` curve. If no private key has been specified in `my_private_key`, it generates an ephemeral private key based on other public key curve. @see JOSE::JWK.box_decrypt @see JOSE::JWE.block_encrypt @param [String...
[ "Key", "Agreement", "encryption", "of", "plain_text", "by", "generating", "an", "ephemeral", "private", "key", "based", "on", "other_public_jwk", "curve", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwk.rb#L720-L751
train
potatosalad/ruby-jose
lib/jose/jwk.rb
JOSE.JWK.shared_secret
def shared_secret(other_jwk) other_jwk = from(other_jwk) if not other_jwk.is_a?(JOSE::JWK) raise ArgumentError, "key types must match" if other_jwk.kty.class != kty.class raise ArgumentError, "key type does not support shared secret computations" if not kty.respond_to?(:derive_key) return kty.de...
ruby
def shared_secret(other_jwk) other_jwk = from(other_jwk) if not other_jwk.is_a?(JOSE::JWK) raise ArgumentError, "key types must match" if other_jwk.kty.class != kty.class raise ArgumentError, "key type does not support shared secret computations" if not kty.respond_to?(:derive_key) return kty.de...
[ "def", "shared_secret", "(", "other_jwk", ")", "other_jwk", "=", "from", "(", "other_jwk", ")", "if", "not", "other_jwk", ".", "is_a?", "(", "JOSE", "::", "JWK", ")", "raise", "ArgumentError", ",", "\"key types must match\"", "if", "other_jwk", ".", "kty", "...
Computes the shared secret between two keys. Currently only works for `"EC"` keys and `"OKP"` keys with `"crv"` set to `"X25519"` or `"X448"`. @param [JOSE::JWK] other_jwk @return [String]
[ "Computes", "the", "shared", "secret", "between", "two", "keys", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwk.rb#L875-L880
train
potatosalad/ruby-jose
lib/jose/jwk.rb
JOSE.JWK.sign
def sign(plain_text, jws = nil, header = nil) jws ||= signer return JOSE::JWS.sign(self, plain_text, jws, header) end
ruby
def sign(plain_text, jws = nil, header = nil) jws ||= signer return JOSE::JWS.sign(self, plain_text, jws, header) end
[ "def", "sign", "(", "plain_text", ",", "jws", "=", "nil", ",", "header", "=", "nil", ")", "jws", "||=", "signer", "return", "JOSE", "::", "JWS", ".", "sign", "(", "self", ",", "plain_text", ",", "jws", ",", "header", ")", "end" ]
Signs the `plain_text` using the `jwk` and the default signer algorithm `jws` for the key type. @see JOSE::JWS.sign @param [String] plain_text @param [JOSE::JWS] jws @param [JOSE::Map] header @return [JOSE::SignedMap]
[ "Signs", "the", "plain_text", "using", "the", "jwk", "and", "the", "default", "signer", "algorithm", "jws", "for", "the", "key", "type", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwk.rb#L905-L908
train
potatosalad/ruby-jose
lib/jose/jws.rb
JOSE.JWS.sign
def sign(jwk, plain_text, header = nil) protected_binary = JOSE.urlsafe_encode64(to_binary) payload = JOSE.urlsafe_encode64(plain_text) signing_input = signing_input(plain_text, protected_binary) signature = JOSE.urlsafe_encode64(alg.sign(jwk, signing_input)) return signature_to_map(payloa...
ruby
def sign(jwk, plain_text, header = nil) protected_binary = JOSE.urlsafe_encode64(to_binary) payload = JOSE.urlsafe_encode64(plain_text) signing_input = signing_input(plain_text, protected_binary) signature = JOSE.urlsafe_encode64(alg.sign(jwk, signing_input)) return signature_to_map(payloa...
[ "def", "sign", "(", "jwk", ",", "plain_text", ",", "header", "=", "nil", ")", "protected_binary", "=", "JOSE", ".", "urlsafe_encode64", "(", "to_binary", ")", "payload", "=", "JOSE", ".", "urlsafe_encode64", "(", "plain_text", ")", "signing_input", "=", "sig...
Signs the `plain_text` using the `jwk` and algorithm specified by the `jws`. @see JOSE::JWS.sign @param [JOSE::JWK] jwk @param [String] plain_text @param [JOSE::Map, Hash] header @return [JOSE::SignedMap]
[ "Signs", "the", "plain_text", "using", "the", "jwk", "and", "algorithm", "specified", "by", "the", "jws", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jws.rb#L572-L578
train
potatosalad/ruby-jose
lib/jose/jws.rb
JOSE.JWS.verify
def verify(jwk, plain_text, signature, protected_binary = nil) protected_binary ||= JOSE.urlsafe_encode64(to_binary) signing_input = signing_input(plain_text, protected_binary) return alg.verify(jwk, signing_input, signature), plain_text, self end
ruby
def verify(jwk, plain_text, signature, protected_binary = nil) protected_binary ||= JOSE.urlsafe_encode64(to_binary) signing_input = signing_input(plain_text, protected_binary) return alg.verify(jwk, signing_input, signature), plain_text, self end
[ "def", "verify", "(", "jwk", ",", "plain_text", ",", "signature", ",", "protected_binary", "=", "nil", ")", "protected_binary", "||=", "JOSE", ".", "urlsafe_encode64", "(", "to_binary", ")", "signing_input", "=", "signing_input", "(", "plain_text", ",", "protect...
Verifies the `signature` using the `jwk`, `plain_text`, and `protected_binary`. @see JOSE::JWS.verify @see JOSE::JWS.verify_strict @param [JOSE::JWK] jwk @param [String] plain_text @param [String] signature @param [String] protected_binary @return [[Boolean, String, JOSE::JWS]]
[ "Verifies", "the", "signature", "using", "the", "jwk", "plain_text", "and", "protected_binary", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jws.rb#L645-L649
train
potatosalad/ruby-jose
lib/jose/jwa.rb
JOSE.JWA.supports
def supports jwe_enc = __jwe_enc_support_check__([ 'A128GCM', 'A192GCM', 'A256GCM', 'A128CBC-HS256', 'A192CBC-HS384', 'A256CBC-HS512' ]) jwe_alg = __jwe_alg_support_check__([ ['A128GCMKW', :block], ['A192GCMKW', :block], ['A256GCM...
ruby
def supports jwe_enc = __jwe_enc_support_check__([ 'A128GCM', 'A192GCM', 'A256GCM', 'A128CBC-HS256', 'A192CBC-HS384', 'A256CBC-HS512' ]) jwe_alg = __jwe_alg_support_check__([ ['A128GCMKW', :block], ['A192GCMKW', :block], ['A256GCM...
[ "def", "supports", "jwe_enc", "=", "__jwe_enc_support_check__", "(", "[", "'A128GCM'", ",", "'A192GCM'", ",", "'A256GCM'", ",", "'A128CBC-HS256'", ",", "'A192CBC-HS384'", ",", "'A256CBC-HS512'", "]", ")", "jwe_alg", "=", "__jwe_alg_support_check__", "(", "[", "[", ...
Returns the current listing of supported JOSE algorithms. !!!ruby JOSE::JWA.supports # => {:jwe=> # {:alg=> # ["A128GCMKW", # "A192GCMKW", # "A256GCMKW", # "A128KW", # "A192KW", # "A256KW", # "ECDH-ES", # "ECDH-ES+A128...
[ "Returns", "the", "current", "listing", "of", "supported", "JOSE", "algorithms", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwa.rb#L123-L197
train
potatosalad/ruby-jose
lib/jose/jwe.rb
JOSE.JWE.block_decrypt
def block_decrypt(key, aad, cipher_text, cipher_tag, encrypted_key, iv) cek = key_decrypt(key, encrypted_key) return uncompress(enc.block_decrypt([aad, cipher_text, cipher_tag], cek, iv)) end
ruby
def block_decrypt(key, aad, cipher_text, cipher_tag, encrypted_key, iv) cek = key_decrypt(key, encrypted_key) return uncompress(enc.block_decrypt([aad, cipher_text, cipher_tag], cek, iv)) end
[ "def", "block_decrypt", "(", "key", ",", "aad", ",", "cipher_text", ",", "cipher_tag", ",", "encrypted_key", ",", "iv", ")", "cek", "=", "key_decrypt", "(", "key", ",", "encrypted_key", ")", "return", "uncompress", "(", "enc", ".", "block_decrypt", "(", "[...
Decrypts the `cipher_text` binary using the `key`, `aad`, `cipher_tag`, `encrypted_key`, and `iv`. @see JOSE::JWE.block_decrypt @param [JOSE::JWK, [JOSE::JWK, JOSE::JWK]] key @param [String] aad @param [String] cipher_text @param [String] cipher_tag @param [String] encrypted_key @param [String] iv @return [[Str...
[ "Decrypts", "the", "cipher_text", "binary", "using", "the", "key", "aad", "cipher_tag", "encrypted_key", "and", "iv", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwe.rb#L600-L603
train
potatosalad/ruby-jose
lib/jose/jwe.rb
JOSE.JWE.block_encrypt
def block_encrypt(key, block, cek = nil, iv = nil) jwe = self if cek.nil? cek, jwe = next_cek(key) end iv ||= jwe.next_iv aad, plain_text = block if plain_text.nil? plain_text = aad aad = nil end encrypted_key, jwe = jwe.key_encrypt(key, cek) ...
ruby
def block_encrypt(key, block, cek = nil, iv = nil) jwe = self if cek.nil? cek, jwe = next_cek(key) end iv ||= jwe.next_iv aad, plain_text = block if plain_text.nil? plain_text = aad aad = nil end encrypted_key, jwe = jwe.key_encrypt(key, cek) ...
[ "def", "block_encrypt", "(", "key", ",", "block", ",", "cek", "=", "nil", ",", "iv", "=", "nil", ")", "jwe", "=", "self", "if", "cek", ".", "nil?", "cek", ",", "jwe", "=", "next_cek", "(", "key", ")", "end", "iv", "||=", "jwe", ".", "next_iv", ...
Encrypts the `block` binary using the `key`, `cek`, and `iv`. @see JOSE::JWE.block_encrypt @param [JOSE::JWK, [JOSE::JWK, JOSE::JWK]] key @param [String, [String, String]] block @param [String] cek @param [String] iv @return [JOSE::EncryptedMap]
[ "Encrypts", "the", "block", "binary", "using", "the", "key", "cek", "and", "iv", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwe.rb#L639-L674
train
potatosalad/ruby-jose
lib/jose/jwe.rb
JOSE.JWE.key_encrypt
def key_encrypt(key, decrypted_key) encrypted_key, new_alg = alg.key_encrypt(key, enc, decrypted_key) new_jwe = JOSE::JWE.from_map(to_map) new_jwe.alg = new_alg return encrypted_key, new_jwe end
ruby
def key_encrypt(key, decrypted_key) encrypted_key, new_alg = alg.key_encrypt(key, enc, decrypted_key) new_jwe = JOSE::JWE.from_map(to_map) new_jwe.alg = new_alg return encrypted_key, new_jwe end
[ "def", "key_encrypt", "(", "key", ",", "decrypted_key", ")", "encrypted_key", ",", "new_alg", "=", "alg", ".", "key_encrypt", "(", "key", ",", "enc", ",", "decrypted_key", ")", "new_jwe", "=", "JOSE", "::", "JWE", ".", "from_map", "(", "to_map", ")", "ne...
Encrypts the `decrypted_key` using the `key` and the `"alg"` and `"enc"` specified by the `jwe`. @param [JOSE::JWK, [JOSE::JWK]] key @param [String] decrypted_key @return [[String, JOSE::JWE]]
[ "Encrypts", "the", "decrypted_key", "using", "the", "key", "and", "the", "alg", "and", "enc", "specified", "by", "the", "jwe", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwe.rb#L865-L870
train
potatosalad/ruby-jose
lib/jose/jwe.rb
JOSE.JWE.next_cek
def next_cek(key) decrypted_key, new_alg = alg.next_cek(key, enc) new_jwe = JOSE::JWE.from_map(to_map) new_jwe.alg = new_alg return decrypted_key, new_jwe end
ruby
def next_cek(key) decrypted_key, new_alg = alg.next_cek(key, enc) new_jwe = JOSE::JWE.from_map(to_map) new_jwe.alg = new_alg return decrypted_key, new_jwe end
[ "def", "next_cek", "(", "key", ")", "decrypted_key", ",", "new_alg", "=", "alg", ".", "next_cek", "(", "key", ",", "enc", ")", "new_jwe", "=", "JOSE", "::", "JWE", ".", "from_map", "(", "to_map", ")", "new_jwe", ".", "alg", "=", "new_alg", "return", ...
Returns the next `cek` using the `jwk` and the `"alg"` and `"enc"` specified by the `jwe`. @param [JOSE::JWK, [JOSE::JWK, JOSE::JWK]] key @return [[String, JOSE::JWE]]
[ "Returns", "the", "next", "cek", "using", "the", "jwk", "and", "the", "alg", "and", "enc", "specified", "by", "the", "jwe", "." ]
e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0
https://github.com/potatosalad/ruby-jose/blob/e1be589b889f1e59ac233a5d19a3fa13f1e4b8a0/lib/jose/jwe.rb#L940-L945
train
tas50/stove
lib/stove/validator.rb
Stove.Validator.run
def run(cookbook, options = {}) log.info("Running validations for `#{klass.id}.#{id}'") inside(cookbook) do instance = klass.new(cookbook, options) unless result = instance.instance_eval(&block) log.debug("Validation failed, result: #{result.inspect}") # Convert the cla...
ruby
def run(cookbook, options = {}) log.info("Running validations for `#{klass.id}.#{id}'") inside(cookbook) do instance = klass.new(cookbook, options) unless result = instance.instance_eval(&block) log.debug("Validation failed, result: #{result.inspect}") # Convert the cla...
[ "def", "run", "(", "cookbook", ",", "options", "=", "{", "}", ")", "log", ".", "info", "(", "\"Running validations for `#{klass.id}.#{id}'\"", ")", "inside", "(", "cookbook", ")", "do", "instance", "=", "klass", ".", "new", "(", "cookbook", ",", "options", ...
Create a new validator object. @param [~Class] klass the class that created this validator @param [Symbol] id the identifier or field this validator runs against @param [Proc] block the block to execute to see if the validation passes Execute this validation in the context of the creating class, inside ...
[ "Create", "a", "new", "validator", "object", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/validator.rb#L51-L66
train
tas50/stove
lib/stove/packager.rb
Stove.Packager.tar
def tar(root, slip) io = StringIO.new('', 'r+b') Gem::Package::TarWriter.new(io) do |tar| slip.each do |original_file, tarball_file| mode = File.stat(original_file).mode if File.directory?(original_file) tar.mkdir(tarball_file, mode) else tar.ad...
ruby
def tar(root, slip) io = StringIO.new('', 'r+b') Gem::Package::TarWriter.new(io) do |tar| slip.each do |original_file, tarball_file| mode = File.stat(original_file).mode if File.directory?(original_file) tar.mkdir(tarball_file, mode) else tar.ad...
[ "def", "tar", "(", "root", ",", "slip", ")", "io", "=", "StringIO", ".", "new", "(", "''", ",", "'r+b'", ")", "Gem", "::", "Package", "::", "TarWriter", ".", "new", "(", "io", ")", "do", "|", "tar", "|", "slip", ".", "each", "do", "|", "origina...
Create a tar file from the given root and packaging slip @param [String] root the root where the tar files are being created @param [Hash<String, String>] slip the map from physical file path to tarball file path @return [StringIO] the io object that contains the tarball contents
[ "Create", "a", "tar", "file", "from", "the", "given", "root", "and", "packaging", "slip" ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/packager.rb#L116-L134
train
tas50/stove
lib/stove/cli.rb
Stove.Cli.option_parser
def option_parser @option_parser ||= OptionParser.new do |opts| opts.banner = 'Usage: stove [OPTIONS]' opts.separator '' opts.separator 'Plugins:' opts.on('--no-git', 'Do not use the git plugin. Skips tagging if specified.') do options[:no_git] = true end ...
ruby
def option_parser @option_parser ||= OptionParser.new do |opts| opts.banner = 'Usage: stove [OPTIONS]' opts.separator '' opts.separator 'Plugins:' opts.on('--no-git', 'Do not use the git plugin. Skips tagging if specified.') do options[:no_git] = true end ...
[ "def", "option_parser", "@option_parser", "||=", "OptionParser", ".", "new", "do", "|", "opts", "|", "opts", ".", "banner", "=", "'Usage: stove [OPTIONS]'", "opts", ".", "separator", "''", "opts", ".", "separator", "'Plugins:'", "opts", ".", "on", "(", "'--no-...
The option parser for handling command line flags. @return [OptionParser]
[ "The", "option", "parser", "for", "handling", "command", "line", "flags", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/cli.rb#L82-L169
train
tas50/stove
lib/stove/cli.rb
Stove.Cli.options
def options @options ||= { # Upload options :endpoint => nil, :username => Config.username, :key => Config.key, :extended_metadata => true, :ssl_verify => true, # Git options :remote => 'origin', :branc...
ruby
def options @options ||= { # Upload options :endpoint => nil, :username => Config.username, :key => Config.key, :extended_metadata => true, :ssl_verify => true, # Git options :remote => 'origin', :branc...
[ "def", "options", "@options", "||=", "{", ":endpoint", "=>", "nil", ",", ":username", "=>", "Config", ".", "username", ",", ":key", "=>", "Config", ".", "key", ",", ":extended_metadata", "=>", "true", ",", ":ssl_verify", "=>", "true", ",", ":remote", "=>",...
The options to pass to the cookbook. Includes default values that are manipulated by the option parser. @return [Hash]
[ "The", "options", "to", "pass", "to", "the", "cookbook", ".", "Includes", "default", "values", "that", "are", "manipulated", "by", "the", "option", "parser", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/cli.rb#L175-L197
train
tas50/stove
lib/stove/supermarket.rb
Stove.Supermarket.upload
def upload(cookbook, extended_metadata = false) connection.post('cookbooks', { 'tarball' => cookbook.tarball(extended_metadata), # This is for legacy, backwards-compatability reasons. The new # Supermarket site does not require a category, but many of the testing # tools still as...
ruby
def upload(cookbook, extended_metadata = false) connection.post('cookbooks', { 'tarball' => cookbook.tarball(extended_metadata), # This is for legacy, backwards-compatability reasons. The new # Supermarket site does not require a category, but many of the testing # tools still as...
[ "def", "upload", "(", "cookbook", ",", "extended_metadata", "=", "false", ")", "connection", ".", "post", "(", "'cookbooks'", ",", "{", "'tarball'", "=>", "cookbook", ".", "tarball", "(", "extended_metadata", ")", ",", "'cookbook'", "=>", "JSON", ".", "fast_...
Upload a cookbook to the community site. @param [Cookbook] cookbook the cookbook to upload
[ "Upload", "a", "cookbook", "to", "the", "community", "site", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/supermarket.rb#L53-L63
train
tas50/stove
lib/stove/supermarket.rb
Stove.Supermarket.connection
def connection @connection ||= ChefAPI::Connection.new do |conn| conn.endpoint = ENV['STOVE_ENDPOINT'] || Config.endpoint || DEFAULT_ENDPOINT conn.client = ENV['STOVE_USERNAME'] || Config.username conn.key = ENV['STOVE_KEY'] || Config.key conn.ssl_v...
ruby
def connection @connection ||= ChefAPI::Connection.new do |conn| conn.endpoint = ENV['STOVE_ENDPOINT'] || Config.endpoint || DEFAULT_ENDPOINT conn.client = ENV['STOVE_USERNAME'] || Config.username conn.key = ENV['STOVE_KEY'] || Config.key conn.ssl_v...
[ "def", "connection", "@connection", "||=", "ChefAPI", "::", "Connection", ".", "new", "do", "|", "conn", "|", "conn", ".", "endpoint", "=", "ENV", "[", "'STOVE_ENDPOINT'", "]", "||", "Config", ".", "endpoint", "||", "DEFAULT_ENDPOINT", "conn", ".", "client",...
The ChefAPI connection object with lots of pretty middleware.
[ "The", "ChefAPI", "connection", "object", "with", "lots", "of", "pretty", "middleware", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/supermarket.rb#L70-L77
train
tas50/stove
lib/stove/artifactory.rb
Stove.Artifactory.upload
def upload(cookbook, extended_metadata = false) # Artifactory doesn't prevent uploading over an existing release in # some cases so let's check for that. Seriously never do this, go delete # and then re-upload if you have to. response = request(:get, "api/v1/cookbooks/#{cookbook.name}/versions/#...
ruby
def upload(cookbook, extended_metadata = false) # Artifactory doesn't prevent uploading over an existing release in # some cases so let's check for that. Seriously never do this, go delete # and then re-upload if you have to. response = request(:get, "api/v1/cookbooks/#{cookbook.name}/versions/#...
[ "def", "upload", "(", "cookbook", ",", "extended_metadata", "=", "false", ")", "response", "=", "request", "(", ":get", ",", "\"api/v1/cookbooks/#{cookbook.name}/versions/#{cookbook.version}\"", ")", "unless", "response", ".", "code", "==", "'404'", "||", "(", "resp...
Upload a cookbook to an Artifactory server. @param [Cookbook] cookbook the cookbook to upload
[ "Upload", "a", "cookbook", "to", "an", "Artifactory", "server", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/artifactory.rb#L13-L31
train
tas50/stove
lib/stove/artifactory.rb
Stove.Artifactory.connection
def connection @connection ||= begin uri = URI(Config.artifactory.strip) # Open the HTTP connection to artifactory. http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == 'https' http.use_ssl = true # Mimic the behavior of the Cookbook uploader for SSL verifi...
ruby
def connection @connection ||= begin uri = URI(Config.artifactory.strip) # Open the HTTP connection to artifactory. http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == 'https' http.use_ssl = true # Mimic the behavior of the Cookbook uploader for SSL verifi...
[ "def", "connection", "@connection", "||=", "begin", "uri", "=", "URI", "(", "Config", ".", "artifactory", ".", "strip", ")", "http", "=", "Net", "::", "HTTP", ".", "new", "(", "uri", ".", "host", ",", "uri", ".", "port", ")", "if", "uri", ".", "sch...
Create an HTTP connect to the Artifactory server. @return [Net::HTTP]
[ "Create", "an", "HTTP", "connect", "to", "the", "Artifactory", "server", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/artifactory.rb#L40-L54
train
tas50/stove
lib/stove/artifactory.rb
Stove.Artifactory.request
def request(method, path, &block) uri_string = Config.artifactory.strip # Make sure we end up with the right number of separators. uri_string << '/' unless uri_string.end_with?('/') uri_string << path uri = URI(uri_string) request = Net::HTTP.const_get(method.to_s.capitalize).new(uri...
ruby
def request(method, path, &block) uri_string = Config.artifactory.strip # Make sure we end up with the right number of separators. uri_string << '/' unless uri_string.end_with?('/') uri_string << path uri = URI(uri_string) request = Net::HTTP.const_get(method.to_s.capitalize).new(uri...
[ "def", "request", "(", "method", ",", "path", ",", "&", "block", ")", "uri_string", "=", "Config", ".", "artifactory", ".", "strip", "uri_string", "<<", "'/'", "unless", "uri_string", ".", "end_with?", "(", "'/'", ")", "uri_string", "<<", "path", "uri", ...
Send an HTTP request to the Artifactory server. @param [Symbol] method HTTP method to use @param [String] path URI path to request @param [Proc] block Optional block to set request values @return [Net::HTTPResponse]
[ "Send", "an", "HTTP", "request", "to", "the", "Artifactory", "server", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/artifactory.rb#L70-L80
train
tas50/stove
lib/stove/cookbook.rb
Stove.Cookbook.released?
def released? Supermarket.cookbook(name, version) true rescue ChefAPI::Error::HTTPNotFound false end
ruby
def released? Supermarket.cookbook(name, version) true rescue ChefAPI::Error::HTTPNotFound false end
[ "def", "released?", "Supermarket", ".", "cookbook", "(", "name", ",", "version", ")", "true", "rescue", "ChefAPI", "::", "Error", "::", "HTTPNotFound", "false", "end" ]
Deterine if this cookbook version is released on the Supermarket @warn This is a fairly expensive operation and the result cannot be reliably cached! @return [Boolean] true if this cookbook at the current version exists on the community site, false otherwise
[ "Deterine", "if", "this", "cookbook", "version", "is", "released", "on", "the", "Supermarket" ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/cookbook.rb#L84-L89
train
tas50/stove
lib/stove/filter.rb
Stove.Filter.run
def run(cookbook, options = {}) log.info(message) instance = klass.new(cookbook, options) inside(cookbook) do instance.instance_eval(&block) end end
ruby
def run(cookbook, options = {}) log.info(message) instance = klass.new(cookbook, options) inside(cookbook) do instance.instance_eval(&block) end end
[ "def", "run", "(", "cookbook", ",", "options", "=", "{", "}", ")", "log", ".", "info", "(", "message", ")", "instance", "=", "klass", ".", "new", "(", "cookbook", ",", "options", ")", "inside", "(", "cookbook", ")", "do", "instance", ".", "instance_e...
Create a new filter object. @param [~Plugin::Base] klass the class that created this filter @param [String] message the message given by the filter @param [Proc] block the block captured by this filter Execute this filter in the context of the creating class, inside the given cookbook's path. @param ...
[ "Create", "a", "new", "filter", "object", "." ]
cb66538c5d7f4885de829ef664361d7a33cc8370
https://github.com/tas50/stove/blob/cb66538c5d7f4885de829ef664361d7a33cc8370/lib/stove/filter.rb#L51-L58
train
kwatch/erubis
lib/erubis/evaluator.rb
Erubis.RubyEvaluator.evaluate
def evaluate(_context=Context.new) _context = Context.new(_context) if _context.is_a?(Hash) #return _context.instance_eval(@src, @filename || '(erubis)') #@_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)') @_proc ||= eval("proc { #{@src} }", binding(), @filename ...
ruby
def evaluate(_context=Context.new) _context = Context.new(_context) if _context.is_a?(Hash) #return _context.instance_eval(@src, @filename || '(erubis)') #@_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)') @_proc ||= eval("proc { #{@src} }", binding(), @filename ...
[ "def", "evaluate", "(", "_context", "=", "Context", ".", "new", ")", "_context", "=", "Context", ".", "new", "(", "_context", ")", "if", "_context", ".", "is_a?", "(", "Hash", ")", "@_proc", "||=", "eval", "(", "\"proc { #{@src} }\"", ",", "binding", "("...
invoke context.instance_eval(@src)
[ "invoke", "context", ".", "instance_eval", "(" ]
14d3eab57fbc361312c8f3af350cbf9a5bafce17
https://github.com/kwatch/erubis/blob/14d3eab57fbc361312c8f3af350cbf9a5bafce17/lib/erubis/evaluator.rb#L69-L75
train
kwatch/erubis
lib/erubis/evaluator.rb
Erubis.RubyEvaluator.def_method
def def_method(object, method_name, filename=nil) m = object.is_a?(Module) ? :module_eval : :instance_eval object.__send__(m, "def #{method_name}; #{@src}; end", filename || @filename || '(erubis)') end
ruby
def def_method(object, method_name, filename=nil) m = object.is_a?(Module) ? :module_eval : :instance_eval object.__send__(m, "def #{method_name}; #{@src}; end", filename || @filename || '(erubis)') end
[ "def", "def_method", "(", "object", ",", "method_name", ",", "filename", "=", "nil", ")", "m", "=", "object", ".", "is_a?", "(", "Module", ")", "?", ":module_eval", ":", ":instance_eval", "object", ".", "__send__", "(", "m", ",", "\"def #{method_name}; #{@sr...
if object is an Class or Module then define instance method to it, else define singleton method to it.
[ "if", "object", "is", "an", "Class", "or", "Module", "then", "define", "instance", "method", "to", "it", "else", "define", "singleton", "method", "to", "it", "." ]
14d3eab57fbc361312c8f3af350cbf9a5bafce17
https://github.com/kwatch/erubis/blob/14d3eab57fbc361312c8f3af350cbf9a5bafce17/lib/erubis/evaluator.rb#L79-L82
train
kwatch/erubis
lib/erubis/converter.rb
Erubis.Converter.convert
def convert(input) codebuf = "" # or [] @preamble.nil? ? add_preamble(codebuf) : (@preamble && (codebuf << @preamble)) convert_input(codebuf, input) @postamble.nil? ? add_postamble(codebuf) : (@postamble && (codebuf << @postamble)) @_proc = nil # clear cached proc object return...
ruby
def convert(input) codebuf = "" # or [] @preamble.nil? ? add_preamble(codebuf) : (@preamble && (codebuf << @preamble)) convert_input(codebuf, input) @postamble.nil? ? add_postamble(codebuf) : (@postamble && (codebuf << @postamble)) @_proc = nil # clear cached proc object return...
[ "def", "convert", "(", "input", ")", "codebuf", "=", "\"\"", "@preamble", ".", "nil?", "?", "add_preamble", "(", "codebuf", ")", ":", "(", "@preamble", "&&", "(", "codebuf", "<<", "@preamble", ")", ")", "convert_input", "(", "codebuf", ",", "input", ")",...
convert input string into target language
[ "convert", "input", "string", "into", "target", "language" ]
14d3eab57fbc361312c8f3af350cbf9a5bafce17
https://github.com/kwatch/erubis/blob/14d3eab57fbc361312c8f3af350cbf9a5bafce17/lib/erubis/converter.rb#L33-L40
train
kwatch/erubis
lib/erubis/converter.rb
Erubis.Converter.detect_spaces_at_bol
def detect_spaces_at_bol(text, is_bol) lspace = nil if text.empty? lspace = "" if is_bol elsif text[-1] == ?\n lspace = "" else rindex = text.rindex(?\n) if rindex s = text[rindex+1..-1] if s =~ /\A[ \t]*\z/ lspace = s #...
ruby
def detect_spaces_at_bol(text, is_bol) lspace = nil if text.empty? lspace = "" if is_bol elsif text[-1] == ?\n lspace = "" else rindex = text.rindex(?\n) if rindex s = text[rindex+1..-1] if s =~ /\A[ \t]*\z/ lspace = s #...
[ "def", "detect_spaces_at_bol", "(", "text", ",", "is_bol", ")", "lspace", "=", "nil", "if", "text", ".", "empty?", "lspace", "=", "\"\"", "if", "is_bol", "elsif", "text", "[", "-", "1", "]", "==", "?\\n", "lspace", "=", "\"\"", "else", "rindex", "=", ...
detect spaces at beginning of line
[ "detect", "spaces", "at", "beginning", "of", "line" ]
14d3eab57fbc361312c8f3af350cbf9a5bafce17
https://github.com/kwatch/erubis/blob/14d3eab57fbc361312c8f3af350cbf9a5bafce17/lib/erubis/converter.rb#L47-L72
train
kwatch/erubis
lib/erubis/engine.rb
Erubis.Engine.process
def process(input, context=nil, filename=nil) code = convert(input) filename ||= '(erubis)' if context.is_a?(Binding) return eval(code, context, filename) else context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(code, filename) end ...
ruby
def process(input, context=nil, filename=nil) code = convert(input) filename ||= '(erubis)' if context.is_a?(Binding) return eval(code, context, filename) else context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(code, filename) end ...
[ "def", "process", "(", "input", ",", "context", "=", "nil", ",", "filename", "=", "nil", ")", "code", "=", "convert", "(", "input", ")", "filename", "||=", "'(erubis)'", "if", "context", ".", "is_a?", "(", "Binding", ")", "return", "eval", "(", "code",...
helper method to convert and evaluate input text with context object. context may be Binding, Hash, or Object.
[ "helper", "method", "to", "convert", "and", "evaluate", "input", "text", "with", "context", "object", ".", "context", "may", "be", "Binding", "Hash", "or", "Object", "." ]
14d3eab57fbc361312c8f3af350cbf9a5bafce17
https://github.com/kwatch/erubis/blob/14d3eab57fbc361312c8f3af350cbf9a5bafce17/lib/erubis/engine.rb#L72-L81
train
kwatch/erubis
lib/erubis/engine.rb
Erubis.Engine.process_proc
def process_proc(proc_obj, context=nil, filename=nil) if context.is_a?(Binding) filename ||= '(erubis)' return eval(proc_obj, context, filename) else context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(&proc_obj) end end
ruby
def process_proc(proc_obj, context=nil, filename=nil) if context.is_a?(Binding) filename ||= '(erubis)' return eval(proc_obj, context, filename) else context = Context.new(context) if context.is_a?(Hash) return context.instance_eval(&proc_obj) end end
[ "def", "process_proc", "(", "proc_obj", ",", "context", "=", "nil", ",", "filename", "=", "nil", ")", "if", "context", ".", "is_a?", "(", "Binding", ")", "filename", "||=", "'(erubis)'", "return", "eval", "(", "proc_obj", ",", "context", ",", "filename", ...
helper method evaluate Proc object with contect object. context may be Binding, Hash, or Object.
[ "helper", "method", "evaluate", "Proc", "object", "with", "contect", "object", ".", "context", "may", "be", "Binding", "Hash", "or", "Object", "." ]
14d3eab57fbc361312c8f3af350cbf9a5bafce17
https://github.com/kwatch/erubis/blob/14d3eab57fbc361312c8f3af350cbf9a5bafce17/lib/erubis/engine.rb#L88-L96
train
larskanis/libusb
lib/libusb/device.rb
LIBUSB.Device.open
def open ppHandle = FFI::MemoryPointer.new :pointer res = Call.libusb_open(@pDev, ppHandle) LIBUSB.raise_error res, "in libusb_open" if res!=0 handle = DevHandle.new self, ppHandle.read_pointer return handle unless block_given? begin yield handle ensure handle.c...
ruby
def open ppHandle = FFI::MemoryPointer.new :pointer res = Call.libusb_open(@pDev, ppHandle) LIBUSB.raise_error res, "in libusb_open" if res!=0 handle = DevHandle.new self, ppHandle.read_pointer return handle unless block_given? begin yield handle ensure handle.c...
[ "def", "open", "ppHandle", "=", "FFI", "::", "MemoryPointer", ".", "new", ":pointer", "res", "=", "Call", ".", "libusb_open", "(", "@pDev", ",", "ppHandle", ")", "LIBUSB", ".", "raise_error", "res", ",", "\"in libusb_open\"", "if", "res!", "=", "0", "handl...
Open the device and obtain a device handle. A handle allows you to perform I/O on the device in question. This is a non-blocking function; no requests are sent over the bus. If called with a block, the handle is passed to the block and is closed when the block has finished. You need proper device access: * Lin...
[ "Open", "the", "device", "and", "obtain", "a", "device", "handle", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/device.rb#L55-L66
train
larskanis/libusb
lib/libusb/device.rb
LIBUSB.Device.max_packet_size
def max_packet_size(endpoint) endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress res = Call.libusb_get_max_packet_size(@pDev, endpoint) LIBUSB.raise_error res, "in libusb_get_max_packet_size" unless res>=0 res end
ruby
def max_packet_size(endpoint) endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress res = Call.libusb_get_max_packet_size(@pDev, endpoint) LIBUSB.raise_error res, "in libusb_get_max_packet_size" unless res>=0 res end
[ "def", "max_packet_size", "(", "endpoint", ")", "endpoint", "=", "endpoint", ".", "bEndpointAddress", "if", "endpoint", ".", "respond_to?", ":bEndpointAddress", "res", "=", "Call", ".", "libusb_get_max_packet_size", "(", "@pDev", ",", "endpoint", ")", "LIBUSB", "....
Convenience function to retrieve the wMaxPacketSize value for a particular endpoint in the active device configuration. @param [Endpoint, Fixnum] endpoint (address of) the endpoint in question @return [Fixnum] the wMaxPacketSize value
[ "Convenience", "function", "to", "retrieve", "the", "wMaxPacketSize", "value", "for", "a", "particular", "endpoint", "in", "the", "active", "device", "configuration", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/device.rb#L156-L161
train
larskanis/libusb
lib/libusb/device.rb
LIBUSB.Device.max_iso_packet_size
def max_iso_packet_size(endpoint) endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress res = Call.libusb_get_max_iso_packet_size(@pDev, endpoint) LIBUSB.raise_error res, "in libusb_get_max_iso_packet_size" unless res>=0 res end
ruby
def max_iso_packet_size(endpoint) endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress res = Call.libusb_get_max_iso_packet_size(@pDev, endpoint) LIBUSB.raise_error res, "in libusb_get_max_iso_packet_size" unless res>=0 res end
[ "def", "max_iso_packet_size", "(", "endpoint", ")", "endpoint", "=", "endpoint", ".", "bEndpointAddress", "if", "endpoint", ".", "respond_to?", ":bEndpointAddress", "res", "=", "Call", ".", "libusb_get_max_iso_packet_size", "(", "@pDev", ",", "endpoint", ")", "LIBUS...
Calculate the maximum packet size which a specific endpoint is capable is sending or receiving in the duration of 1 microframe. Only the active configution is examined. The calculation is based on the wMaxPacketSize field in the endpoint descriptor as described in section 9.6.6 in the USB 2.0 specifications. If ...
[ "Calculate", "the", "maximum", "packet", "size", "which", "a", "specific", "endpoint", "is", "capable", "is", "sending", "or", "receiving", "in", "the", "duration", "of", "1", "microframe", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/device.rb#L182-L187
train
larskanis/libusb
lib/libusb/device.rb
LIBUSB.Device.config_descriptor
def config_descriptor(index) ppConfig = FFI::MemoryPointer.new :pointer res = Call.libusb_get_config_descriptor(@pDev, index, ppConfig) LIBUSB.raise_error res, "in libusb_get_config_descriptor" if res!=0 pConfig = ppConfig.read_pointer config = Configuration.new(self, pConfig) config...
ruby
def config_descriptor(index) ppConfig = FFI::MemoryPointer.new :pointer res = Call.libusb_get_config_descriptor(@pDev, index, ppConfig) LIBUSB.raise_error res, "in libusb_get_config_descriptor" if res!=0 pConfig = ppConfig.read_pointer config = Configuration.new(self, pConfig) config...
[ "def", "config_descriptor", "(", "index", ")", "ppConfig", "=", "FFI", "::", "MemoryPointer", ".", "new", ":pointer", "res", "=", "Call", ".", "libusb_get_config_descriptor", "(", "@pDev", ",", "index", ",", "ppConfig", ")", "LIBUSB", ".", "raise_error", "res"...
Obtain a config descriptor of the device. @param [Fixnum] index number of the config descriptor @return Configuration
[ "Obtain", "a", "config", "descriptor", "of", "the", "device", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/device.rb#L193-L200
train
larskanis/libusb
lib/libusb/device.rb
LIBUSB.Device.configurations
def configurations configs = [] bNumConfigurations.times do |config_index| begin configs << config_descriptor(config_index) rescue RuntimeError # On Windows some devices don't return it's configuration. end end configs end
ruby
def configurations configs = [] bNumConfigurations.times do |config_index| begin configs << config_descriptor(config_index) rescue RuntimeError # On Windows some devices don't return it's configuration. end end configs end
[ "def", "configurations", "configs", "=", "[", "]", "bNumConfigurations", ".", "times", "do", "|", "config_index", "|", "begin", "configs", "<<", "config_descriptor", "(", "config_index", ")", "rescue", "RuntimeError", "end", "end", "configs", "end" ]
Return configurations of the device. @return [Array<Configuration>]
[ "Return", "configurations", "of", "the", "device", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/device.rb#L337-L347
train
larskanis/libusb
lib/libusb/eventmachine.rb
LIBUSB.Context.eventmachine_register
def eventmachine_register @eventmachine_attached_fds = {} @eventmachine_timer = nil pollfds = self.pollfds if pollfds pollfds.each do |pollfd| eventmachine_add_pollfd(pollfd) end self.on_pollfd_added do |pollfd| eventmachine_add_pollfd(pollfd) end self.on...
ruby
def eventmachine_register @eventmachine_attached_fds = {} @eventmachine_timer = nil pollfds = self.pollfds if pollfds pollfds.each do |pollfd| eventmachine_add_pollfd(pollfd) end self.on_pollfd_added do |pollfd| eventmachine_add_pollfd(pollfd) end self.on...
[ "def", "eventmachine_register", "@eventmachine_attached_fds", "=", "{", "}", "@eventmachine_timer", "=", "nil", "pollfds", "=", "self", ".", "pollfds", "if", "pollfds", "pollfds", ".", "each", "do", "|", "pollfd", "|", "eventmachine_add_pollfd", "(", "pollfd", ")"...
Register libusb's file descriptors and timeouts to EventMachine. @example require 'libusb/eventmachine' context = LIBUSB::Context.new EventMachine.run do context.eventmachine_register end @see DevHandle#eventmachine_bulk_transfer DevHandle#eventmachine_control_transfer DevHandle#eventmachi...
[ "Register", "libusb", "s", "file", "descriptors", "and", "timeouts", "to", "EventMachine", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/eventmachine.rb#L34-L58
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.claim_interface
def claim_interface(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_claim_interface(@pHandle, interface) LIBUSB.raise_error res, "in libusb_claim_interface" if res!=0 return self unless block_given? begin yield self ...
ruby
def claim_interface(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_claim_interface(@pHandle, interface) LIBUSB.raise_error res, "in libusb_claim_interface" if res!=0 return self unless block_given? begin yield self ...
[ "def", "claim_interface", "(", "interface", ")", "interface", "=", "interface", ".", "bInterfaceNumber", "if", "interface", ".", "respond_to?", ":bInterfaceNumber", "res", "=", "Call", ".", "libusb_claim_interface", "(", "@pHandle", ",", "interface", ")", "LIBUSB", ...
Claim an interface on a given device handle. You must claim the interface you wish to use before you can perform I/O on any of its endpoints. It is legal to attempt to claim an already-claimed interface, in which case libusb just returns without doing anything. Claiming of interfaces is a purely logical operati...
[ "Claim", "an", "interface", "on", "a", "given", "device", "handle", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L76-L86
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.set_configuration
def set_configuration(configuration) configuration = configuration.bConfigurationValue if configuration.respond_to? :bConfigurationValue res = Call.libusb_set_configuration(@pHandle, configuration || -1) LIBUSB.raise_error res, "in libusb_set_configuration" if res!=0 end
ruby
def set_configuration(configuration) configuration = configuration.bConfigurationValue if configuration.respond_to? :bConfigurationValue res = Call.libusb_set_configuration(@pHandle, configuration || -1) LIBUSB.raise_error res, "in libusb_set_configuration" if res!=0 end
[ "def", "set_configuration", "(", "configuration", ")", "configuration", "=", "configuration", ".", "bConfigurationValue", "if", "configuration", ".", "respond_to?", ":bConfigurationValue", "res", "=", "Call", ".", "libusb_set_configuration", "(", "@pHandle", ",", "confi...
Set the active configuration for a device. The operating system may or may not have already set an active configuration on the device. It is up to your application to ensure the correct configuration is selected before you attempt to claim interfaces and perform other operations. If you call this function on a de...
[ "Set", "the", "active", "configuration", "for", "a", "device", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L133-L137
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.set_interface_alt_setting
def set_interface_alt_setting(setting_or_interface_number, alternate_setting=nil) alternate_setting ||= setting_or_interface_number.bAlternateSetting if setting_or_interface_number.respond_to? :bAlternateSetting setting_or_interface_number = setting_or_interface_number.bInterfaceNumber if setting_or_interfa...
ruby
def set_interface_alt_setting(setting_or_interface_number, alternate_setting=nil) alternate_setting ||= setting_or_interface_number.bAlternateSetting if setting_or_interface_number.respond_to? :bAlternateSetting setting_or_interface_number = setting_or_interface_number.bInterfaceNumber if setting_or_interfa...
[ "def", "set_interface_alt_setting", "(", "setting_or_interface_number", ",", "alternate_setting", "=", "nil", ")", "alternate_setting", "||=", "setting_or_interface_number", ".", "bAlternateSetting", "if", "setting_or_interface_number", ".", "respond_to?", ":bAlternateSetting", ...
Activate an alternate setting for an interface. The interface must have been previously claimed with {DevHandle#claim_interface}. You should always use this function rather than formulating your own SET_INTERFACE control request. This is because the underlying operating system needs to know when such changes happ...
[ "Activate", "an", "alternate", "setting", "for", "an", "interface", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L154-L159
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.kernel_driver_active?
def kernel_driver_active?(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_kernel_driver_active(@pHandle, interface) LIBUSB.raise_error res, "in libusb_kernel_driver_active" unless res>=0 return res==1 end
ruby
def kernel_driver_active?(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_kernel_driver_active(@pHandle, interface) LIBUSB.raise_error res, "in libusb_kernel_driver_active" unless res>=0 return res==1 end
[ "def", "kernel_driver_active?", "(", "interface", ")", "interface", "=", "interface", ".", "bInterfaceNumber", "if", "interface", ".", "respond_to?", ":bInterfaceNumber", "res", "=", "Call", ".", "libusb_kernel_driver_active", "(", "@pHandle", ",", "interface", ")", ...
Determine if a kernel driver is active on an interface. If a kernel driver is active, you cannot claim the interface, and libusb will be unable to perform I/O. @param [Interface, Fixnum] interface the interface to check or it's bInterfaceNumber @return [Boolean]
[ "Determine", "if", "a", "kernel", "driver", "is", "active", "on", "an", "interface", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L257-L262
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.detach_kernel_driver
def detach_kernel_driver(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_detach_kernel_driver(@pHandle, interface) LIBUSB.raise_error res, "in libusb_detach_kernel_driver" if res!=0 end
ruby
def detach_kernel_driver(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_detach_kernel_driver(@pHandle, interface) LIBUSB.raise_error res, "in libusb_detach_kernel_driver" if res!=0 end
[ "def", "detach_kernel_driver", "(", "interface", ")", "interface", "=", "interface", ".", "bInterfaceNumber", "if", "interface", ".", "respond_to?", ":bInterfaceNumber", "res", "=", "Call", ".", "libusb_detach_kernel_driver", "(", "@pHandle", ",", "interface", ")", ...
Detach a kernel driver from an interface. If successful, you will then be able to claim the interface and perform I/O. @param [Interface, Fixnum] interface the interface to detach the driver from or it's bInterfaceNumber
[ "Detach", "a", "kernel", "driver", "from", "an", "interface", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L270-L274
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.bulk_transfer
def bulk_transfer(args={}, &block) timeout = args.delete(:timeout) || 1000 endpoint = args.delete(:endpoint) || raise(ArgumentError, "no endpoint given") endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress if endpoint&ENDPOINT_IN != 0 dataIn = args.delete(:data...
ruby
def bulk_transfer(args={}, &block) timeout = args.delete(:timeout) || 1000 endpoint = args.delete(:endpoint) || raise(ArgumentError, "no endpoint given") endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress if endpoint&ENDPOINT_IN != 0 dataIn = args.delete(:data...
[ "def", "bulk_transfer", "(", "args", "=", "{", "}", ",", "&", "block", ")", "timeout", "=", "args", ".", "delete", "(", ":timeout", ")", "||", "1000", "endpoint", "=", "args", ".", "delete", "(", ":endpoint", ")", "||", "raise", "(", "ArgumentError", ...
Perform a USB bulk transfer. When called without a block, the transfer is done synchronously - so all events are handled internally and the sent/received data will be returned after completion or an exception will be raised. When called with a block, the method returns immediately after submitting the transfer. Y...
[ "Perform", "a", "USB", "bulk", "transfer", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L375-L398
train
larskanis/libusb
lib/libusb/dev_handle.rb
LIBUSB.DevHandle.control_transfer
def control_transfer(args={}, &block) bmRequestType = args.delete(:bmRequestType) || raise(ArgumentError, "param :bmRequestType not given") bRequest = args.delete(:bRequest) || raise(ArgumentError, "param :bRequest not given") wValue = args.delete(:wValue) || raise(ArgumentError, "param :wValue not gi...
ruby
def control_transfer(args={}, &block) bmRequestType = args.delete(:bmRequestType) || raise(ArgumentError, "param :bmRequestType not given") bRequest = args.delete(:bRequest) || raise(ArgumentError, "param :bRequest not given") wValue = args.delete(:wValue) || raise(ArgumentError, "param :wValue not gi...
[ "def", "control_transfer", "(", "args", "=", "{", "}", ",", "&", "block", ")", "bmRequestType", "=", "args", ".", "delete", "(", ":bmRequestType", ")", "||", "raise", "(", "ArgumentError", ",", "\"param :bmRequestType not given\"", ")", "bRequest", "=", "args"...
Perform a USB control transfer. When called without a block, the transfer is done synchronously - so all events are handled internally and the sent/received data will be returned after completion or an exception will be raised. When called with a block, the method returns immediately after submitting the transfer....
[ "Perform", "a", "USB", "control", "transfer", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/dev_handle.rb#L500-L526
train
larskanis/libusb
lib/libusb/bos.rb
LIBUSB.Bos.device_capabilities
def device_capabilities pp_ext = FFI::MemoryPointer.new :pointer caps = [] # Capabilities are appended to the bos header ptr = pointer + offset_of(:dev_capability) bNumDeviceCaps.times do cap = DeviceCapability.new self, ptr.read_pointer case cap.bDevCapabilityType ...
ruby
def device_capabilities pp_ext = FFI::MemoryPointer.new :pointer caps = [] # Capabilities are appended to the bos header ptr = pointer + offset_of(:dev_capability) bNumDeviceCaps.times do cap = DeviceCapability.new self, ptr.read_pointer case cap.bDevCapabilityType ...
[ "def", "device_capabilities", "pp_ext", "=", "FFI", "::", "MemoryPointer", ".", "new", ":pointer", "caps", "=", "[", "]", "ptr", "=", "pointer", "+", "offset_of", "(", ":dev_capability", ")", "bNumDeviceCaps", ".", "times", "do", "cap", "=", "DeviceCapability"...
bNumDeviceCap Device Capability Descriptors @return [Array<Bos::DeviceCapability, Bos::Usb20Extension, Bos::SsUsbDeviceCapability, Bos::ContainerId>]
[ "bNumDeviceCap", "Device", "Capability", "Descriptors" ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/bos.rb#L256-L282
train
larskanis/libusb
lib/libusb/transfer.rb
LIBUSB.Transfer.submit!
def submit!(&block) self.callback = block if block_given? # puts "submit transfer #{@transfer.inspect} buffer: #{@transfer[:buffer].inspect} length: #{@transfer[:length].inspect} status: #{@transfer[:status].inspect} callback: #{@transfer[:callback].inspect} dev_handle: #{@transfer[:dev_handle].inspect}" ...
ruby
def submit!(&block) self.callback = block if block_given? # puts "submit transfer #{@transfer.inspect} buffer: #{@transfer[:buffer].inspect} length: #{@transfer[:length].inspect} status: #{@transfer[:status].inspect} callback: #{@transfer[:callback].inspect} dev_handle: #{@transfer[:dev_handle].inspect}" ...
[ "def", "submit!", "(", "&", "block", ")", "self", ".", "callback", "=", "block", "if", "block_given?", "res", "=", "Call", ".", "libusb_submit_transfer", "(", "@transfer", ")", "LIBUSB", ".", "raise_error", "res", ",", "\"in libusb_submit_transfer\"", "if", "r...
Submit a transfer. This function will fire off the USB transfer and then return immediately. This method can be called with block. It is called when the transfer completes, fails, or is cancelled.
[ "Submit", "a", "transfer", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/transfer.rb#L211-L218
train
larskanis/libusb
lib/libusb/transfer.rb
LIBUSB.Transfer.submit_and_wait
def submit_and_wait raise ArgumentError, "#{self.class}#dev_handle not set" unless @dev_handle @completion_flag.completed = false submit! do |tr2| @completion_flag.completed = true end until @completion_flag.completed? begin @dev_handle.device.context.handle_eve...
ruby
def submit_and_wait raise ArgumentError, "#{self.class}#dev_handle not set" unless @dev_handle @completion_flag.completed = false submit! do |tr2| @completion_flag.completed = true end until @completion_flag.completed? begin @dev_handle.device.context.handle_eve...
[ "def", "submit_and_wait", "raise", "ArgumentError", ",", "\"#{self.class}#dev_handle not set\"", "unless", "@dev_handle", "@completion_flag", ".", "completed", "=", "false", "submit!", "do", "|", "tr2", "|", "@completion_flag", ".", "completed", "=", "true", "end", "u...
Submit the transfer and wait until the transfer completes or fails. Inspect {#status} to check for transfer errors.
[ "Submit", "the", "transfer", "and", "wait", "until", "the", "transfer", "completes", "or", "fails", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/transfer.rb#L242-L263
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.handle_events
def handle_events(timeout=nil, completion_flag=nil) if completion_flag && !completion_flag.is_a?(Context::CompletionFlag) raise ArgumentError, "completion_flag is not a CompletionFlag" end if timeout timeval = Call::Timeval.new timeval.in_ms = timeout res = if Call.resp...
ruby
def handle_events(timeout=nil, completion_flag=nil) if completion_flag && !completion_flag.is_a?(Context::CompletionFlag) raise ArgumentError, "completion_flag is not a CompletionFlag" end if timeout timeval = Call::Timeval.new timeval.in_ms = timeout res = if Call.resp...
[ "def", "handle_events", "(", "timeout", "=", "nil", ",", "completion_flag", "=", "nil", ")", "if", "completion_flag", "&&", "!", "completion_flag", ".", "is_a?", "(", "Context", "::", "CompletionFlag", ")", "raise", "ArgumentError", ",", "\"completion_flag is not ...
Handle any pending events in blocking mode. This method must be called when libusb is running asynchronous transfers. This gives libusb the opportunity to reap pending transfers, invoke callbacks, etc. If a zero timeout is passed, this function will handle any already-pending events and then immediately return i...
[ "Handle", "any", "pending", "events", "in", "blocking", "mode", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L195-L215
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.devices
def devices(filter_hash={}) device_list.select do |dev| ( !filter_hash[:bClass] || (dev.bDeviceClass==CLASS_PER_INTERFACE ? dev.settings.map(&:bInterfaceClass).&([filter_hash[:bClass]].flatten).any? : [filter_hash[:bClass]].flatten.include?(dev.bDe...
ruby
def devices(filter_hash={}) device_list.select do |dev| ( !filter_hash[:bClass] || (dev.bDeviceClass==CLASS_PER_INTERFACE ? dev.settings.map(&:bInterfaceClass).&([filter_hash[:bClass]].flatten).any? : [filter_hash[:bClass]].flatten.include?(dev.bDe...
[ "def", "devices", "(", "filter_hash", "=", "{", "}", ")", "device_list", ".", "select", "do", "|", "dev", "|", "(", "!", "filter_hash", "[", ":bClass", "]", "||", "(", "dev", ".", "bDeviceClass", "==", "CLASS_PER_INTERFACE", "?", "dev", ".", "settings", ...
Obtain a list of devices currently attached to the USB system, optionally matching certain criteria. @param [Hash] filter_hash A number of criteria can be defined in key-value pairs. Only devices that equal all given criterions will be returned. If a criterion is not specified or its value is +nil+, any device...
[ "Obtain", "a", "list", "of", "devices", "currently", "attached", "to", "the", "USB", "system", "optionally", "matching", "certain", "criteria", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L248-L265
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.pollfds
def pollfds ppPollfds = Call.libusb_get_pollfds(@ctx) return nil if ppPollfds.null? offs = 0 pollfds = [] while !(pPollfd=ppPollfds.get_pointer(offs)).null? pollfd = Call::Pollfd.new pPollfd pollfds << Pollfd.new(pollfd[:fd], pollfd[:events]) offs += FFI.type_size :...
ruby
def pollfds ppPollfds = Call.libusb_get_pollfds(@ctx) return nil if ppPollfds.null? offs = 0 pollfds = [] while !(pPollfd=ppPollfds.get_pointer(offs)).null? pollfd = Call::Pollfd.new pPollfd pollfds << Pollfd.new(pollfd[:fd], pollfd[:events]) offs += FFI.type_size :...
[ "def", "pollfds", "ppPollfds", "=", "Call", ".", "libusb_get_pollfds", "(", "@ctx", ")", "return", "nil", "if", "ppPollfds", ".", "null?", "offs", "=", "0", "pollfds", "=", "[", "]", "while", "!", "(", "pPollfd", "=", "ppPollfds", ".", "get_pointer", "("...
Retrieve a list of file descriptors that should be polled by your main loop as libusb event sources. As file descriptors are a Unix-specific concept, this function is not available on Windows and will always return +nil+. @return [Array<Pollfd>] list of Pollfd objects, +nil+ on error, +nil+ on platforms wh...
[ "Retrieve", "a", "list", "of", "file", "descriptors", "that", "should", "be", "polled", "by", "your", "main", "loop", "as", "libusb", "event", "sources", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L277-L293
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.next_timeout
def next_timeout timeval = Call::Timeval.new res = Call.libusb_get_next_timeout @ctx, timeval LIBUSB.raise_error res, "in libusb_get_next_timeout" if res<0 res == 1 ? timeval.in_s : nil end
ruby
def next_timeout timeval = Call::Timeval.new res = Call.libusb_get_next_timeout @ctx, timeval LIBUSB.raise_error res, "in libusb_get_next_timeout" if res<0 res == 1 ? timeval.in_s : nil end
[ "def", "next_timeout", "timeval", "=", "Call", "::", "Timeval", ".", "new", "res", "=", "Call", ".", "libusb_get_next_timeout", "@ctx", ",", "timeval", "LIBUSB", ".", "raise_error", "res", ",", "\"in libusb_get_next_timeout\"", "if", "res", "<", "0", "res", "=...
Determine the next internal timeout that libusb needs to handle. You only need to use this function if you are calling poll() or select() or similar on libusb's file descriptors yourself - you do not need to use it if you are calling {#handle_events} directly. You should call this function in your main loop in or...
[ "Determine", "the", "next", "internal", "timeout", "that", "libusb", "needs", "to", "handle", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L318-L323
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.on_pollfd_added
def on_pollfd_added &block @on_pollfd_added = proc do |fd, events, _| pollfd = Pollfd.new fd, events block.call pollfd end Call.libusb_set_pollfd_notifiers @ctx, @on_pollfd_added, @on_pollfd_removed, nil end
ruby
def on_pollfd_added &block @on_pollfd_added = proc do |fd, events, _| pollfd = Pollfd.new fd, events block.call pollfd end Call.libusb_set_pollfd_notifiers @ctx, @on_pollfd_added, @on_pollfd_removed, nil end
[ "def", "on_pollfd_added", "&", "block", "@on_pollfd_added", "=", "proc", "do", "|", "fd", ",", "events", ",", "_", "|", "pollfd", "=", "Pollfd", ".", "new", "fd", ",", "events", "block", ".", "call", "pollfd", "end", "Call", ".", "libusb_set_pollfd_notifie...
Register a notification block for file descriptor additions. This block will be invoked for every new file descriptor that libusb uses as an event source. Note that file descriptors may have been added even before you register these notifiers (e.g. at {Context#initialize} time). @yieldparam [Pollfd] pollfd The...
[ "Register", "a", "notification", "block", "for", "file", "descriptor", "additions", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L334-L340
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.on_pollfd_removed
def on_pollfd_removed &block @on_pollfd_removed = proc do |fd, _| pollfd = Pollfd.new fd block.call pollfd end Call.libusb_set_pollfd_notifiers @ctx, @on_pollfd_added, @on_pollfd_removed, nil end
ruby
def on_pollfd_removed &block @on_pollfd_removed = proc do |fd, _| pollfd = Pollfd.new fd block.call pollfd end Call.libusb_set_pollfd_notifiers @ctx, @on_pollfd_added, @on_pollfd_removed, nil end
[ "def", "on_pollfd_removed", "&", "block", "@on_pollfd_removed", "=", "proc", "do", "|", "fd", ",", "_", "|", "pollfd", "=", "Pollfd", ".", "new", "fd", "block", ".", "call", "pollfd", "end", "Call", ".", "libusb_set_pollfd_notifiers", "@ctx", ",", "@on_pollf...
Register a notification block for file descriptor removals. This block will be invoked for every removed file descriptor that libusb uses as an event source. Note that the removal notifier may be called during {Context#exit} (e.g. when it is closing file descriptors that were opened and added to the poll set at ...
[ "Register", "a", "notification", "block", "for", "file", "descriptor", "removals", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L353-L359
train
larskanis/libusb
lib/libusb/context.rb
LIBUSB.Context.on_hotplug_event
def on_hotplug_event(args={}, &block) events = args.delete(:events) || (HOTPLUG_EVENT_DEVICE_ARRIVED | HOTPLUG_EVENT_DEVICE_LEFT) flags = args.delete(:flags) || 0 vendor_id = args.delete(:vendor_id) || HOTPLUG_MATCH_ANY product_id = args.delete(:product_id) || HOTPLUG_MATCH_ANY dev_class =...
ruby
def on_hotplug_event(args={}, &block) events = args.delete(:events) || (HOTPLUG_EVENT_DEVICE_ARRIVED | HOTPLUG_EVENT_DEVICE_LEFT) flags = args.delete(:flags) || 0 vendor_id = args.delete(:vendor_id) || HOTPLUG_MATCH_ANY product_id = args.delete(:product_id) || HOTPLUG_MATCH_ANY dev_class =...
[ "def", "on_hotplug_event", "(", "args", "=", "{", "}", ",", "&", "block", ")", "events", "=", "args", ".", "delete", "(", ":events", ")", "||", "(", "HOTPLUG_EVENT_DEVICE_ARRIVED", "|", "HOTPLUG_EVENT_DEVICE_LEFT", ")", "flags", "=", "args", ".", "delete", ...
Register a hotplug event notification. Register a callback with the {LIBUSB::Context}. The callback will fire when a matching event occurs on a matching device. The callback is armed until either it is deregistered with {HotplugCallback#deregister} or the supplied block returns +:finish+ to indicate it is finished...
[ "Register", "a", "hotplug", "event", "notification", "." ]
ddeaa43f6cde868171fa08744e6c95e96a594766
https://github.com/larskanis/libusb/blob/ddeaa43f6cde868171fa08744e6c95e96a594766/lib/libusb/context.rb#L396-L433
train
mayoral/telegrammer
lib/telegrammer/bot.rb
Telegrammer.Bot.send_message
def send_message(params) extra_params_validation = { text: { required: true, class: [String] }, parse_mode: { required: false, class: [String] }, disable_web_page_preview: { required: false, class: [TrueClass, FalseClass] } } send_something(:message, params, extra_params_valid...
ruby
def send_message(params) extra_params_validation = { text: { required: true, class: [String] }, parse_mode: { required: false, class: [String] }, disable_web_page_preview: { required: false, class: [TrueClass, FalseClass] } } send_something(:message, params, extra_params_valid...
[ "def", "send_message", "(", "params", ")", "extra_params_validation", "=", "{", "text", ":", "{", "required", ":", "true", ",", "class", ":", "[", "String", "]", "}", ",", "parse_mode", ":", "{", "required", ":", "false", ",", "class", ":", "[", "Strin...
Send text messages to a user or group chat. @param [Hash] params hash of paramers to send to the sendMessage API operation. @option params [Integer,String] :chat_id Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername). @option params [String] :text Requi...
[ "Send", "text", "messages", "to", "a", "user", "or", "group", "chat", "." ]
be85007a647fcebec7e0b5ed1ff86f4dd924a62a
https://github.com/mayoral/telegrammer/blob/be85007a647fcebec7e0b5ed1ff86f4dd924a62a/lib/telegrammer/bot.rb#L136-L144
train
mayoral/telegrammer
lib/telegrammer/bot.rb
Telegrammer.Bot.forward_message
def forward_message(params) params_validation = { chat_id: { required: true, class: [Fixnum] }, from_chat_id: { required: true, class: [String] }, message_id: { required: true, class: [Fixnum] } } response = api_request('forwardMessage', params, params_validation) Teleg...
ruby
def forward_message(params) params_validation = { chat_id: { required: true, class: [Fixnum] }, from_chat_id: { required: true, class: [String] }, message_id: { required: true, class: [Fixnum] } } response = api_request('forwardMessage', params, params_validation) Teleg...
[ "def", "forward_message", "(", "params", ")", "params_validation", "=", "{", "chat_id", ":", "{", "required", ":", "true", ",", "class", ":", "[", "Fixnum", "]", "}", ",", "from_chat_id", ":", "{", "required", ":", "true", ",", "class", ":", "[", "Stri...
Forward message to a user or group chat. @param [Hash] params hash of paramers to send to the forwardMessage API operation. @option params [Integer,String] :chat_id Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername). @option params [Integer,String] :fr...
[ "Forward", "message", "to", "a", "user", "or", "group", "chat", "." ]
be85007a647fcebec7e0b5ed1ff86f4dd924a62a
https://github.com/mayoral/telegrammer/blob/be85007a647fcebec7e0b5ed1ff86f4dd924a62a/lib/telegrammer/bot.rb#L166-L176
train
mayoral/telegrammer
lib/telegrammer/bot.rb
Telegrammer.Bot.send_photo
def send_photo(params) extra_params_validation = { photo: { required: true, class: [File, String] }, caption: { required: false, class: [String] } } send_something(:photo, params, extra_params_validation) end
ruby
def send_photo(params) extra_params_validation = { photo: { required: true, class: [File, String] }, caption: { required: false, class: [String] } } send_something(:photo, params, extra_params_validation) end
[ "def", "send_photo", "(", "params", ")", "extra_params_validation", "=", "{", "photo", ":", "{", "required", ":", "true", ",", "class", ":", "[", "File", ",", "String", "]", "}", ",", "caption", ":", "{", "required", ":", "false", ",", "class", ":", ...
Sends a photo to a user or group chat. @param [Hash] params hash of paramers to send to the sendPhoto API operation. @option params [Integer,String] :chat_id Required. Unique identifier for the target chat or username of the target channel (in the format @channelusername). @option params [File,String] :photo Requir...
[ "Sends", "a", "photo", "to", "a", "user", "or", "group", "chat", "." ]
be85007a647fcebec7e0b5ed1ff86f4dd924a62a
https://github.com/mayoral/telegrammer/blob/be85007a647fcebec7e0b5ed1ff86f4dd924a62a/lib/telegrammer/bot.rb#L197-L204
train
mayoral/telegrammer
lib/telegrammer/bot.rb
Telegrammer.Bot.send_audio
def send_audio(params) extra_params_validation = { audio: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] }, performer: { required: false, class: [String] }, title: { required: false, class: [String] } } send_something(:audio, p...
ruby
def send_audio(params) extra_params_validation = { audio: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] }, performer: { required: false, class: [String] }, title: { required: false, class: [String] } } send_something(:audio, p...
[ "def", "send_audio", "(", "params", ")", "extra_params_validation", "=", "{", "audio", ":", "{", "required", ":", "true", ",", "class", ":", "[", "File", ",", "String", "]", "}", ",", "duration", ":", "{", "required", ":", "false", ",", "class", ":", ...
Sends audio file to a user or group chat. At this moment, Telegram only allows Ogg files encoded with the OPUS codec. If you need to send another file format, you must use #send_document. @param [Hash] params hash of paramers to send to the sendAudio API operation. @option params [Integer,String] :chat_id Required...
[ "Sends", "audio", "file", "to", "a", "user", "or", "group", "chat", "." ]
be85007a647fcebec7e0b5ed1ff86f4dd924a62a
https://github.com/mayoral/telegrammer/blob/be85007a647fcebec7e0b5ed1ff86f4dd924a62a/lib/telegrammer/bot.rb#L229-L238
train
mayoral/telegrammer
lib/telegrammer/bot.rb
Telegrammer.Bot.send_voice
def send_voice(params) extra_params_validation = { voice: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] } } send_something(:audio, params, extra_params_validation) end
ruby
def send_voice(params) extra_params_validation = { voice: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] } } send_something(:audio, params, extra_params_validation) end
[ "def", "send_voice", "(", "params", ")", "extra_params_validation", "=", "{", "voice", ":", "{", "required", ":", "true", ",", "class", ":", "[", "File", ",", "String", "]", "}", ",", "duration", ":", "{", "required", ":", "false", ",", "class", ":", ...
Sends audio files file to a user or group chat that the users will see as a playable voice message. At this moment, Telegram only allows Ogg files encoded with the OPUS codec. If you need to send another file format, you must use #send_document. @param [Hash] params hash of paramers to send to the sendAudio API ope...
[ "Sends", "audio", "files", "file", "to", "a", "user", "or", "group", "chat", "that", "the", "users", "will", "see", "as", "a", "playable", "voice", "message", "." ]
be85007a647fcebec7e0b5ed1ff86f4dd924a62a
https://github.com/mayoral/telegrammer/blob/be85007a647fcebec7e0b5ed1ff86f4dd924a62a/lib/telegrammer/bot.rb#L261-L268
train