code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def test_kb
omit_if(jruby?)
omit_if(!$stdout.tty?) # don't run the test unless it stands a chance of validity.
EM.run do
EM.open_keyboard KbHandler
EM::Timer.new(1) { EM.stop }
end
end
|
This test doesn't actually do anything useful but is here to
illustrate the usage. If you removed the timer and ran this test
by itself on a console, and then typed into the console, it would
work.
I don't know how to get the test harness to simulate actual keystrokes.
When someone figures that out, then we can make this a real test.
|
test_kb
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_kb.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_kb.rb
|
Apache-2.0
|
def test_run_run
EM.run {
EM.run {
EM.next_tick {EM.stop}
}
}
end
|
This illustrates the solution to a long-standing problem.
It's now possible to correctly nest calls to EM#run.
See the source code commentary for EM#run for more info.
|
test_run_run
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_next_tick.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_next_tick.rb
|
Apache-2.0
|
def test_run_run_2
a = proc {EM.stop}
b = proc {assert true}
EM.run a, b
end
|
We now support an additional parameter for EM#run.
You can pass two procs to EM#run now. The first is executed as the normal
run block. The second (if given) is scheduled for execution after the
reactor loop completes.
The reason for supporting this is subtle. There has always been an expectation
that EM#run doesn't return until after the reactor loop ends. But now it's
possible to nest calls to EM#run, which means that a nested call WILL
RETURN. In order to write code that will run correctly either way, it's
recommended to put any code which must execute after the reactor completes
in the second parameter.
|
test_run_run_2
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_next_tick.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_next_tick.rb
|
Apache-2.0
|
def test_run_run_3
a = []
EM.run {
EM.run proc {EM.stop}, proc {a << 2}
a << 1
}
assert_equal( [1,2], a )
end
|
This illustrates that EM#run returns when it's called nested.
This isn't a feature, rather it's something to be wary of when writing code
that must run correctly even if EM#run is called while a reactor is already
running.
|
test_run_run_3
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_next_tick.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_next_tick.rb
|
Apache-2.0
|
def test_em_pause_connection_not_implemented
assert true
end
|
Because some rubies will complain if a TestCase class has no tests
|
test_em_pause_connection_not_implemented
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pause.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pause.rb
|
Apache-2.0
|
def test_em_pending_connect_timeout_not_implemented
assert true
end
|
Because some rubies will complain if a TestCase class has no tests
|
test_em_pending_connect_timeout_not_implemented
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pending_connect_timeout.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pending_connect_timeout.rb
|
Apache-2.0
|
def test_contents
pool.add :res
assert_equal [:res], pool.contents
# Assert that modifying the contents list does not affect the pools
# contents.
pool.contents.delete(:res)
assert_equal [:res], pool.contents
end
|
Contents is only to be used for inspection of the pool!
|
test_contents
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pool.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pool.rb
|
Apache-2.0
|
def test_deferrable_child_process
ls = ""
EM.run {
d = EM::DeferrableChildProcess.open( "ls -ltr" )
d.callback {|data_from_child|
ls = data_from_child
EM.stop
}
}
assert( ls.length > 0)
end
|
EM::DeferrableChildProcess is a sugaring of a common use-case
involving EM::popen.
Call the #open method on EM::DeferrableChildProcess, passing
a command-string. #open immediately returns an EM::Deferrable
object. It also schedules the forking of a child process, which
will execute the command passed to #open.
When the forked child terminates, the Deferrable will be signalled
and execute its callbacks, passing the data that the child process
wrote to stdout.
|
test_deferrable_child_process
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_processes.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_processes.rb
|
Apache-2.0
|
def test_em_popen_unsupported
assert true
end
|
Because some rubies will complain if a TestCase class has no tests
|
test_em_popen_unsupported
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_processes.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_processes.rb
|
Apache-2.0
|
def test_em_start_proxy_not_implemented
assert !EM.respond_to?(:start_proxy)
end
|
Because some rubies will complain if a TestCase class has no tests
|
test_em_start_proxy_not_implemented
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_proxy_connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_proxy_connection.rb
|
Apache-2.0
|
def test_exception_handling_releases_resources
exception = Class.new(StandardError)
2.times do
assert_raises(exception) do
EM.run do
EM.start_server "127.0.0.1", @port
raise exception
end
end
end
end
|
These tests are intended to exercise problems that come up in the
pure-Ruby implementation. However, we DON'T constrain them such that
they only run in pure-Ruby. These tests need to work identically in
any implementation.
-------------------------------------
The EM reactor needs to run down open connections and release other resources
when it stops running. Make sure this happens even if user code throws a Ruby
exception.
If exception handling is incorrect, the second test will fail with a no-bind error
because the TCP server opened in the first test will not have been closed.
|
test_exception_handling_releases_resources
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pure.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_pure.rb
|
Apache-2.0
|
def test_a_pair
pend('FIXME: this test is broken on Windows') if windows?
EM.run {
d = EM::DNS::Resolver.resolve "yahoo.com"
d.errback { |err| assert false, "failed to resolve yahoo.com: #{err}" }
d.callback { |r|
assert_kind_of(Array, r)
assert r.size > 1, "returned #{r.size} results: #{r.inspect}"
EM.stop
}
}
end
|
There isn't a public DNS entry like 'example.com' with an A rrset
|
test_a_pair
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_resolver.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_resolver.rb
|
Apache-2.0
|
def test_em_send_file_data_not_implemented
assert !EM.respond_to?(:send_file_data)
end
|
Because some rubies will complain if a TestCase class has no tests
|
test_em_send_file_data_not_implemented
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_send_file.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_send_file.rb
|
Apache-2.0
|
def test_stop
x = nil
EM.run {
s = EM.spawn {EM.stop}
s.notify
x = true
}
assert x
end
|
Spawn a process that simply stops the reactor.
Assert that the notification runs after the block that calls it.
|
test_stop
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_multiparms
val = 5
EM.run {
s = EM.spawn {|v1,v2| val *= (v1 + v2); EM.stop}
s.notify 3,4
}
assert_equal( 35, val )
end
|
Pass multiple parameters to a spawned process.
|
test_multiparms
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_race
x = 0
EM.run {
s = EM.spawn {x *= 2; EM.stop}
s.notify
x = 2
}
assert_equal( 4, x)
end
|
This test demonstrates that a notification does not happen immediately,
but rather is scheduled sometime after the current code path completes.
|
test_race
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_fibonacci
x = 1
y = 1
EM.run {
s = EM.spawn {x,y = y,x+y}
25.times {s.notify}
t = EM.spawn {EM.stop}
t.notify
}
assert_equal( 121393, x)
assert_equal( 196418, y)
end
|
Spawn a process and notify it 25 times to run fibonacci
on a pair of global variables.
|
test_fibonacci
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_another_fibonacci
x = 1
y = 1
EM.run {
25.times {
s = EM.spawn {x,y = y,x+y}
s.notify
}
t = EM.spawn {EM.stop}
t.notify
}
assert_equal( 121393, x)
assert_equal( 196418, y)
end
|
This one spawns 25 distinct processes, and notifies each one once,
rather than notifying a single process 25 times.
|
test_another_fibonacci
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_fibonacci_chain
a,b = nil
EM.run {
nextpid = EM.spawn {|x,y|
a,b = x,y
EM.stop
}
25.times {
n = nextpid
nextpid = EM.spawn {|x,y| n.notify( y, x+y )}
}
nextpid.notify( 1, 1 )
}
assert_equal( 121393, a)
assert_equal( 196418, b)
end
|
Make a chain of processes that notify each other in turn
with intermediate fibonacci results. The final process in
the chain stops the loop and returns the result.
|
test_fibonacci_chain
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_yield
a = 0
EM.run {
n = EM.spawn {
a += 10
EM.yield {
a += 20
EM.yield {
a += 30
EM.stop
}
}
}
n.notify
n.notify
n.notify
}
assert_equal( 60, a )
end
|
EM#yield gives a spawed process to yield control to other processes
(in other words, to stop running), and to specify a different code block
that will run on its next notification.
|
test_yield
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_yield_and_notify
a = 0
EM.run {
n = EM.spawn {
a += 10
EM.yield_and_notify {
a += 20
EM.yield_and_notify {
a += 30
EM.stop
}
}
}
n.notify
}
assert_equal( 60, a )
end
|
EM#yield_and_notify behaves like EM#yield, except that it also notifies the
yielding process. This may sound trivial, since the yield block will run very
shortly after with no action by the program, but this actually can be very useful,
because it causes the reactor core to execute once before the yielding process
gets control back. So it can be used to allow heavily-used network connections
to clear buffers, or allow other processes to process their notifications.
Notice in this test code that only a simple notify is needed at the bottom
of the initial block. Even so, all of the yielded blocks will execute.
|
test_yield_and_notify
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_resume
EM.run {
n = EM.spawn {EM.stop}
n.resume
}
assert true
end
|
resume is an alias for notify.
|
test_resume
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_run
EM.run {
(EM.spawn {EM.stop}).run
}
assert true
end
|
run is an idiomatic alias for notify.
|
test_run
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_ping_pong
n_pongs = 0
EM.run {
pong = EM.spawn {|x, ping|
n_pongs += 1
ping.notify( x-1 )
}
ping = EM.spawn {|x|
if x > 0
pong.notify x, self
else
EM.stop
end
}
ping.notify 3
}
assert_equal( 3, n_pongs )
end
|
Clones the ping-pong example from the Erlang tutorial, in much less code.
Illustrates that a spawned block executes in the context of a SpawnableObject.
(Meaning, we can pass self as a parameter to another process that can then
notify us.)
|
test_ping_pong
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_self_notify
n = 0
EM.run {
pid = EM.spawn {|x|
if x > 0
n += x
notify( x-1 )
else
EM.stop
end
}
pid.notify 3
}
assert_equal( 6, n )
end
|
Illustrates that you can call notify inside a notification, and it will cause
the currently-executing process to be re-notified. Of course, the new notification
won't run until sometime after the current one completes.
|
test_self_notify
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_spawn.rb
|
Apache-2.0
|
def test_connect_timeout
conn = nil
EM.run do
conn = EM.connect '192.0.2.0', 80, StubConnection
conn.pending_connect_timeout = 1
end
assert_equal Errno::ETIMEDOUT, conn.error
end
|
RFC 5737 Address Blocks Reserved for Documentation
|
test_connect_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_unbind_reason.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_unbind_reason.rb
|
Apache-2.0
|
def encode(string)
if string.encoding.name == 'ASCII-8BIT'
data = string.dup
data.force_encoding('UTF-8')
unless data.valid_encoding?
raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
end
else
data = string.encode('UTF-8')
end
data
end
|
workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
|
encode
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/encoding.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/encoding.rb
|
Apache-2.0
|
def exec(source, options = {})
raise NotImplementedError
end
|
Evaluates the +source+ in the context of a function body and returns the
returned value.
context.exec("return 1") # => 1
context.exec("1") # => nil (nothing was returned)
|
exec
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/runtime.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/runtime.rb
|
Apache-2.0
|
def eval(source, options = {})
raise NotImplementedError
end
|
Evaluates the +source+ as an expression and returns the result.
context.eval("1") # => 1
context.eval("return 1") # => Raises SyntaxError
|
eval
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/runtime.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/runtime.rb
|
Apache-2.0
|
def call(source, *args)
raise NotImplementedError
end
|
Evaluates +source+ as an expression (which should be of type
+function+), and calls the function with the given arguments.
The function will be evaluated with the global object as +this+.
context.call("function(a, b) { return a + b }", 1, 1) # => 2
context.call("CoffeeScript.compile", "1 + 1")
|
call
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/runtime.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/execjs-2.8.1/lib/execjs/runtime.rb
|
Apache-2.0
|
def new(url = nil, options = {}, &block)
options = Utils.deep_merge(default_connection_options, options)
Faraday::Connection.new(url, options, &block)
end
|
Initializes a new {Connection}.
@param url [String,Hash] The optional String base URL to use as a prefix
for all requests. Can also be the options Hash. Any of these
values will be set on every request made, unless overridden
for a specific request.
@param options [Hash]
@option options [String] :url Base URL
@option options [Hash] :params Hash of unencoded URI query params.
@option options [Hash] :headers Hash of unencoded HTTP headers.
@option options [Hash] :request Hash of request options.
@option options [Hash] :ssl Hash of SSL options.
@option options [Hash] :proxy Hash of Proxy options.
@return [Faraday::Connection]
@example With an URL argument
Faraday.new 'http://faraday.com'
# => Faraday::Connection to http://faraday.com
@example With an URL argument and an options hash
Faraday.new 'http://faraday.com', params: { page: 1 }
# => Faraday::Connection to http://faraday.com?page=1
@example With everything in an options hash
Faraday.new url: 'http://faraday.com',
params: { page: 1 }
# => Faraday::Connection to http://faraday.com?page=1
|
new
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
Apache-2.0
|
def default_connection
@default_connection ||= Connection.new(default_connection_options)
end
|
@overload default_connection
Gets the default connection used for simple scripts.
@return [Faraday::Connection] a connection configured with
the default_adapter.
@overload default_connection=(connection)
@param connection [Faraday::Connection]
Sets the default {Faraday::Connection} for simple scripts that
access the Faraday constant directly, such as
<code>Faraday.get "https://faraday.com"</code>.
|
default_connection
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
Apache-2.0
|
def default_connection_options
@default_connection_options ||= ConnectionOptions.new
end
|
Gets the default connection options used when calling {Faraday#new}.
@return [Faraday::ConnectionOptions]
|
default_connection_options
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
Apache-2.0
|
def method_missing(name, *args, &block)
if default_connection.respond_to?(name)
default_connection.send(name, *args, &block)
else
super
end
end
|
Internal: Proxies method calls on the Faraday constant to
.default_connection.
|
method_missing
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday.rb
|
Apache-2.0
|
def connection(env)
conn = build_connection(env)
return conn unless block_given?
yield conn
end
|
Yields or returns an adapter's configured connection. Depends on
#build_connection being defined on this adapter.
@param env [Faraday::Env, Hash] The env object for a faraday request.
@return The return value of the given block, or the HTTP connection object
if no block is given.
|
connection
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter.rb
|
Apache-2.0
|
def request_timeout(type, options)
key = TIMEOUT_KEYS.fetch(type) do
msg = "Expected :read, :write, :open. Got #{type.inspect} :("
raise ArgumentError, msg
end
options[key] || options[:timeout]
end
|
Fetches either a read, write, or open timeout setting. Defaults to the
:timeout value if a more specific one is not given.
@param type [Symbol] Describes which timeout setting to get: :read,
:write, or :open.
@param options [Hash] Hash containing Symbol keys like :timeout,
:read_timeout, :write_timeout, or :open_timeout
@return [Integer, nil] Timeout duration in seconds, or nil if no timeout
has been set.
|
request_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter.rb
|
Apache-2.0
|
def initialize(url = nil, options = nil)
options = ConnectionOptions.from(options)
if url.is_a?(Hash) || url.is_a?(ConnectionOptions)
options = Utils.deep_merge(options, url)
url = options.url
end
@parallel_manager = nil
@headers = Utils::Headers.new
@params = Utils::ParamsHash.new
@options = options.request
@ssl = options.ssl
@default_parallel_manager = options.parallel_manager
@manual_proxy = nil
@builder = options.builder || begin
# pass an empty block to Builder so it doesn't assume default middleware
options.new_builder(block_given? ? proc { |b| } : nil)
end
self.url_prefix = url || 'http:/'
@params.update(options.params) if options.params
@headers.update(options.headers) if options.headers
initialize_proxy(url, options)
yield(self) if block_given?
@headers[:user_agent] ||= USER_AGENT
end
|
Initializes a new Faraday::Connection.
@param url [URI, String] URI or String base URL to use as a prefix for all
requests (optional).
@param options [Hash, Faraday::ConnectionOptions]
@option options [URI, String] :url ('http:/') URI or String base URL
@option options [Hash<String => String>] :params URI query unencoded
key/value pairs.
@option options [Hash<String => String>] :headers Hash of unencoded HTTP
header key/value pairs.
@option options [Hash] :request Hash of request options.
@option options [Hash] :ssl Hash of SSL options.
@option options [Hash, URI, String] :proxy proxy options, either as a URL
or as a Hash
@option options [URI, String] :proxy[:uri]
@option options [String] :proxy[:user]
@option options [String] :proxy[:password]
@yield [self] after all setup has been done
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def options(*args)
return @options if args.empty?
url, params, headers = *args
run_request(:options, url, nil, headers) do |request|
request.params.update(params) if params
yield request if block_given?
end
end
|
@overload options()
Returns current Connection options.
@overload options(url, params = nil, headers = nil)
Makes an OPTIONS HTTP request to the given URL.
@param url [String, URI, nil] String base URL to sue as a prefix for all requests.
@param params [Hash, nil] Hash of URI query unencoded key/value pairs.
@param headers [Hash, nil] unencoded HTTP header key/value pairs.
@example
conn.options '/items/1'
@yield [Faraday::Request] for further request customizations
@return [Faraday::Response]
|
options
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def default_parallel_manager
@default_parallel_manager ||= begin
adapter = @builder.adapter.klass if @builder.adapter
if support_parallel?(adapter)
adapter.setup_parallel_manager
elsif block_given?
yield
end
end
end
|
Check if the adapter is parallel-capable.
@yield if the adapter isn't parallel-capable, or if no adapter is set yet.
@return [Object, nil] a parallel manager or nil if yielded
@api private
|
default_parallel_manager
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def in_parallel(manager = nil)
@parallel_manager = manager || default_parallel_manager do
warn 'Warning: `in_parallel` called but no parallel-capable adapter ' \
'on Faraday stack'
warn caller[2, 10].join("\n")
nil
end
yield
@parallel_manager&.run
ensure
@parallel_manager = nil
end
|
Sets up the parallel manager to make a set of requests.
@param manager [Object] The parallel manager that this Connection's
Adapter uses.
@yield a block to execute multiple requests.
@return [void]
|
in_parallel
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def build_url(url = nil, extra_params = nil)
uri = build_exclusive_url(url)
query_values = params.dup.merge_query(uri.query, options.params_encoder)
query_values.update(extra_params) if extra_params
uri.query =
if query_values.empty?
nil
else
query_values.to_query(options.params_encoder)
end
uri
end
|
Takes a relative url for a request and combines it with the defaults
set on the connection instance.
@param url [String, URI, nil]
@param extra_params [Hash]
@example
conn = Faraday::Connection.new { ... }
conn.url_prefix = "https://httpbingo.org/api?token=abc"
conn.scheme # => https
conn.path_prefix # => "/api"
conn.build_url("nigiri?page=2")
# => https://httpbingo.org/api/nigiri?token=abc&page=2
conn.build_url("nigiri", page: 2)
# => https://httpbingo.org/api/nigiri?token=abc&page=2
|
build_url
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def run_request(method, url, body, headers)
unless METHODS.include?(method)
raise ArgumentError, "unknown http method: #{method}"
end
request = build_request(method) do |req|
req.options.proxy = proxy_for_request(url)
req.url(url) if url
req.headers.update(headers) if headers
req.body = body if body
yield(req) if block_given?
end
builder.build_response(self, request)
end
|
Builds and runs the Faraday::Request.
@param method [Symbol] HTTP method.
@param url [String, URI, nil] String or URI to access.
@param body [String, nil] The request body that will eventually be converted to
a string.
@param headers [Hash, nil] unencoded HTTP header key/value pairs.
@return [Faraday::Response]
|
run_request
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def build_request(method)
Request.create(method) do |req|
req.params = params.dup
req.headers = headers.dup
req.options = options.dup
yield(req) if block_given?
end
end
|
Creates and configures the request object.
@param method [Symbol]
@yield [Faraday::Request] if block given
@return [Faraday::Request]
|
build_request
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
url = nil if url.respond_to?(:empty?) && url.empty?
base = url_prefix.dup
if url && !base.path.end_with?('/')
base.path = "#{base.path}/" # ensure trailing slash
end
url = url.to_s.gsub(':', '%3A') if URI.parse(url.to_s).opaque
uri = url ? base + url : base
if params
uri.query = params.to_query(params_encoder || options.params_encoder)
end
uri.query = nil if uri.query && uri.query.empty?
uri
end
|
Build an absolute URL based on url_prefix.
@param url [String, URI, nil]
@param params [Faraday::Utils::ParamsHash] A Faraday::Utils::ParamsHash to
replace the query values
of the resulting url (default: nil).
@return [URI]
|
build_exclusive_url
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def dup
self.class.new(build_exclusive_url,
headers: headers.dup,
params: params.dup,
builder: builder.dup,
ssl: ssl.dup,
request: options.dup)
end
|
Creates a duplicate of this Faraday::Connection.
@api private
@return [Faraday::Connection]
|
dup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def with_uri_credentials(uri)
return unless uri.user && uri.password
yield(Utils.unescape(uri.user), Utils.unescape(uri.password))
end
|
Yields username and password extracted from a URI if they both exist.
@param uri [URI]
@yield [username, password] any username and password
@yieldparam username [String] any username from URI
@yieldparam password [String] any password from URI
@return [void]
@api private
|
with_uri_credentials
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/connection.rb
|
Apache-2.0
|
def exc_msg_and_response!(exc, response = nil)
if @response.nil? && @wrapped_exception.nil?
@wrapped_exception, msg, @response = exc_msg_and_response(exc, response)
return msg
end
exc.to_s
end
|
Pulls out potential parent exception and response hash, storing them in
instance variables.
exc - Either an Exception, a string message, or a response hash.
response - Hash
:status - Optional integer HTTP response status
:headers - String key/value hash of HTTP response header
values.
:body - Optional string HTTP response body.
:request - Hash
:method - Symbol with the request HTTP method.
:url - URI object with the url requested.
:url_path - String with the url path requested.
:params - String key/value hash of query params
present in the request.
:headers - String key/value hash of HTTP request
header values.
:body - String HTTP request body.
If a subclass has to call this, then it should pass a string message
to `super`. See NilStatusError.
|
exc_msg_and_response!
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/error.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/error.rb
|
Apache-2.0
|
def exc_msg_and_response(exc, response = nil)
return [exc, exc.message, response] if exc.respond_to?(:backtrace)
return [nil, "the server responded with status #{exc[:status]}", exc] \
if exc.respond_to?(:each_key)
[nil, exc.to_s, response]
end
|
Pulls out potential parent exception and response hash.
|
exc_msg_and_response
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/error.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/error.rb
|
Apache-2.0
|
def register_middleware(**mappings)
middleware_mutex do
registered_middleware.update(mappings)
end
end
|
Register middleware class(es) on the current module.
@param mappings [Hash] Middleware mappings from a lookup symbol to a middleware class.
@return [void]
@example Lookup by a constant
module Faraday
class Whatever < Middleware
# Middleware looked up by :foo returns Faraday::Whatever::Foo.
register_middleware(foo: Whatever)
end
end
|
register_middleware
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/middleware_registry.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/middleware_registry.rb
|
Apache-2.0
|
def lookup_middleware(key)
load_middleware(key) ||
raise(Faraday::Error, "#{key.inspect} is not registered on #{self}")
end
|
Lookup middleware class with a registered Symbol shortcut.
@param key [Symbol] key for the registered middleware.
@return [Class] a middleware Class.
@raise [Faraday::Error] if given key is not registered
@example
module Faraday
class Whatever < Middleware
register_middleware(foo: Whatever)
end
end
Faraday::Middleware.lookup_middleware(:foo)
# => Faraday::Whatever
|
lookup_middleware
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/middleware_registry.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/middleware_registry.rb
|
Apache-2.0
|
def build_response(connection, request)
app.call(build_env(connection, request))
end
|
Processes a Request into a Response by passing it through this Builder's
middleware stack.
@param connection [Faraday::Connection]
@param request [Faraday::Request]
@return [Faraday::Response]
|
build_response
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/rack_builder.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/rack_builder.rb
|
Apache-2.0
|
def app
@app ||= begin
lock!
ensure_adapter!
to_app
end
end
|
The "rack app" wrapped in middleware. All requests are sent here.
The builder is responsible for creating the app object. After this,
the builder gets locked to ensure no further modifications are made
to the middleware stack.
Returns an object that responds to `call` and returns a Response.
|
app
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/rack_builder.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/rack_builder.rb
|
Apache-2.0
|
def build_env(connection, request)
exclusive_url = connection.build_exclusive_url(
request.path, request.params,
request.options.params_encoder
)
Env.new(request.http_method, request.body, exclusive_url,
request.options, request.headers, connection.ssl,
connection.parallel_manager)
end
|
ENV Keys
:http_method - a symbolized request HTTP method (:get, :post)
:body - the request body that will eventually be converted to a string.
:url - URI instance for the current request.
:status - HTTP response status code
:request_headers - hash of HTTP Headers to be sent to the server
:response_headers - Hash of HTTP headers from the server
:parallel_manager - sent if the connection is in parallel mode
:request - Hash of options for configuring the request.
:timeout - open/read timeout Integer in seconds
:open_timeout - read timeout Integer in seconds
:proxy - Hash of proxy options
:uri - Proxy Server URI
:user - Proxy server username
:password - Proxy server password
:ssl - Hash of options for configuring SSL requests.
|
build_env
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/rack_builder.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/rack_builder.rb
|
Apache-2.0
|
def url(path, params = nil)
if path.respond_to? :query
if (query = path.query)
path = path.dup
path.query = nil
end
else
anchor_index = path.index('#')
path = path.slice(0, anchor_index) unless anchor_index.nil?
path, query = path.split('?', 2)
end
self.path = path
self.params.merge_query query, options.params_encoder
self.params.update(params) if params
end
|
Update path and params.
@param path [URI, String]
@param params [Hash, nil]
@return [void]
|
url
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
Apache-2.0
|
def marshal_dump
{
http_method: http_method,
body: body,
headers: headers,
path: path,
params: params,
options: options
}
end
|
Marshal serialization support.
@return [Hash] the hash ready to be serialized in Marshal.
|
marshal_dump
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
Apache-2.0
|
def marshal_load(serialised)
self.http_method = serialised[:http_method]
self.body = serialised[:body]
self.headers = serialised[:headers]
self.path = serialised[:path]
self.params = serialised[:params]
self.options = serialised[:options]
end
|
Marshal serialization support.
Restores the instance variables according to the +serialised+.
@param serialised [Hash] the serialised object.
|
marshal_load
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
Apache-2.0
|
def to_env(connection)
Env.new(http_method, body, connection.build_exclusive_url(path, params),
options, headers, connection.ssl, connection.parallel_manager)
end
|
@return [Env] the Env for this Request
|
to_env
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request.rb
|
Apache-2.0
|
def apply_request(request_env)
raise "response didn't finish yet" unless finished?
@env = Env.from(request_env).update(@env)
self
end
|
Expand the env with more properties, without overriding existing ones.
Useful for applying request params after restoring a marshalled Response.
|
apply_request
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/response.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/response.rb
|
Apache-2.0
|
def normalize_path(url)
url = URI(url)
(url.path.start_with?('/') ? url.path : "/#{url.path}") +
(url.query ? "?#{sort_query_params(url.query)}" : '')
end
|
Receives a String or URI and returns just
the path with the query string sorted.
|
normalize_path
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/utils.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/utils.rb
|
Apache-2.0
|
def verify_stubbed_calls
failed_stubs = []
@stack.each do |method, stubs|
next if stubs.empty?
failed_stubs.concat(
stubs.map do |stub|
"Expected #{method} #{stub}."
end
)
end
raise failed_stubs.join(' ') unless failed_stubs.empty?
end
|
Raises an error if any of the stubbed calls have not been made.
|
verify_stubbed_calls
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter/test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter/test.rb
|
Apache-2.0
|
def matches?(stack, env)
stack.each do |stub|
match_result, meta = stub.matches?(env)
return stub, meta if match_result
end
nil
end
|
@param stack [Hash]
@param env [Faraday::Env]
|
matches?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter/test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/adapter/test.rb
|
Apache-2.0
|
def encode(params)
return nil if params.nil?
unless params.is_a?(Array)
unless params.respond_to?(:to_hash)
raise TypeError, "Can't convert #{params.class} into Hash."
end
params = params.to_hash
params = params.map do |key, value|
key = key.to_s if key.is_a?(Symbol)
[key, value]
end
# Only to be used for non-Array inputs. Arrays should preserve order.
params.sort! if @sort_params
end
# The params have form [['key1', 'value1'], ['key2', 'value2']].
buffer = +''
params.each do |parent, value|
encoded_parent = escape(parent)
buffer << "#{encode_pair(encoded_parent, value)}&"
end
buffer.chop
end
|
@param params [nil, Array, #to_hash] parameters to be encoded
@return [String] the encoded params
@raise [TypeError] if params can not be converted to a Hash
|
encode
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/encoders/nested_params_encoder.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/encoders/nested_params_encoder.rb
|
Apache-2.0
|
def decode(query)
return nil if query.nil?
params = {}
query.split('&').each do |pair|
next if pair.empty?
key, value = pair.split('=', 2)
key = unescape(key)
value = unescape(value.tr('+', ' ')) if value
decode_pair(key, value, params)
end
dehash(params, 0)
end
|
@param query [nil, String]
@return [Array<Array, String>] the decoded params
@raise [TypeError] if the nesting is incorrect
|
decode
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/encoders/nested_params_encoder.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/encoders/nested_params_encoder.rb
|
Apache-2.0
|
def dehash(hash, depth)
hash.each do |key, value|
hash[key] = dehash(value, depth + 1) if value.is_a?(Hash)
end
if depth.positive? && !hash.empty? && hash.keys.all? { |k| k =~ /^\d+$/ }
hash.sort.map(&:last)
else
hash
end
end
|
Internal: convert a nested hash with purely numeric keys into an array.
FIXME: this is not compatible with Rack::Utils.parse_nested_query
@!visibility private
|
dehash
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/encoders/nested_params_encoder.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/encoders/nested_params_encoder.rb
|
Apache-2.0
|
def needs_body?
!body && MethodsWithBodies.include?(method)
end
|
@return [Boolean] true if there's no body yet, and the method is in the
set of {MethodsWithBodies}.
|
needs_body?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/options/env.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/options/env.rb
|
Apache-2.0
|
def clear_body
request_headers[ContentLength] = '0'
self.body = +''
end
|
Sets content length to zero and the body to the empty string.
|
clear_body
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/options/env.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/options/env.rb
|
Apache-2.0
|
def verify?
verify != false
end
|
@return [Boolean] true if should verify
|
verify?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/options/ssl_options.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/options/ssl_options.rb
|
Apache-2.0
|
def initialize(app, type, *params)
@type = type
@params = params
super(app)
end
|
@param app [#call]
@param type [String, Symbol] Type of Authorization
@param params [Array<String, Proc, #call>] parameters to build the Authorization header.
If the type is `:basic`, then these can be a login and password pair.
Otherwise, a single value is expected that will be appended after the type.
This value can be a proc or an object responding to `.call`, in which case
it will be invoked on each request.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/authorization.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/authorization.rb
|
Apache-2.0
|
def header_from(type, env, *params)
if type.to_s.casecmp('basic').zero? && params.size == 2
Utils.basic_header_from(*params)
elsif params.size != 1
raise ArgumentError, "Unexpected params received (got #{params.size} instead of 1)"
else
value = params.first
if (value.is_a?(Proc) && value.arity == 1) || (value.respond_to?(:call) && value.method(:call).arity == 1)
value = value.call(env)
elsif value.is_a?(Proc) || value.respond_to?(:call)
value = value.call
end
"#{type} #{value}"
end
end
|
@param type [String, Symbol]
@param env [Faraday::Env]
@param params [Array]
@return [String] a header value
|
header_from
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/authorization.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/authorization.rb
|
Apache-2.0
|
def initialize(app, options = nil)
super(app)
@name, @instrumenter = Options.from(options)
.values_at(:name, :instrumenter)
end
|
Instruments requests using Active Support.
Measures time spent only for synchronous requests.
@example Using ActiveSupport::Notifications to measure time spent
for Faraday requests.
ActiveSupport::Notifications
.subscribe('request.faraday') do |name, starts, ends, _, env|
url = env[:url]
http_method = env[:method].to_s.upcase
duration = ends - starts
$stderr.puts '[%s] %s %s (%.3f s)' %
[url.host, http_method, url.request_uri, duration]
end
@param app [#call]
@param options [nil, Hash] Options hash
@option options [String] :name ('request.faraday')
Name of the instrumenter
@option options [Class] :instrumenter (ActiveSupport::Notifications)
Active Support instrumenter class.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/instrumentation.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/instrumentation.rb
|
Apache-2.0
|
def call(env)
match_content_type(env) do |data|
params = Faraday::Utils::ParamsHash[data]
env.body = params.to_query(env.params_encoder)
end
@app.call env
end
|
Encodes as "application/x-www-form-urlencoded" if not already encoded or
of another type.
@param env [Faraday::Env]
|
call
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
Apache-2.0
|
def match_content_type(env)
return unless process_request?(env)
env.request_headers[CONTENT_TYPE] ||= self.class.mime_type
return if env.body.respond_to?(:to_str) || env.body.respond_to?(:read)
yield(env.body)
end
|
@param env [Faraday::Env]
@yield [request_body] Body of the request
|
match_content_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
Apache-2.0
|
def process_request?(env)
type = request_type(env)
env.body && (type.empty? || (type == self.class.mime_type))
end
|
@param env [Faraday::Env]
@return [Boolean] True if the request has a body and its Content-Type is
urlencoded.
|
process_request?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
Apache-2.0
|
def request_type(env)
type = env.request_headers[CONTENT_TYPE].to_s
type = type.split(';', 2).first if type.index(';')
type
end
|
@param env [Faraday::Env]
@return [String]
|
request_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/request/url_encoded.rb
|
Apache-2.0
|
def initialize_copy(other)
super
@names = other.names.dup
end
|
on dup/clone, we need to duplicate @names hash
|
initialize_copy
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/utils/headers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/faraday-2.7.4/lib/faraday/utils/headers.rb
|
Apache-2.0
|
def initialize(ptr, proc=nil, &block)
super(ptr.type_size, ptr)
raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \
|| ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer)
@releaser = if proc
if not proc.respond_to?(:call)
raise RuntimeError.new("proc must be callable")
end
CallableReleaser.new(ptr, proc)
else
if not self.class.respond_to?(:release)
raise RuntimeError.new("no release method defined")
end
DefaultReleaser.new(ptr, self.class)
end
ObjectSpace.define_finalizer(self, @releaser)
self
end
|
@overload initialize(pointer, method)
@param pointer [Pointer]
@param method [Method]
@return [self]
The passed Method will be invoked at GC time.
@overload initialize(pointer, proc)
@param pointer [Pointer]
@return [self]
The passed Proc will be invoked at GC time (SEE WARNING BELOW!)
@note WARNING: passing a proc _may_ cause your pointer to never be
GC'd, unless you're careful to avoid trapping a reference to the
pointer in the proc. See the test specs for examples.
@overload initialize(pointer) { |p| ... }
@param pointer [Pointer]
@yieldparam [Pointer] p +pointer+ passed to the block
@return [self]
The passed block will be invoked at GC time.
@note
WARNING: passing a block will cause your pointer to never be GC'd.
This is bad.
@overload initialize(pointer)
@param pointer [Pointer]
@return [self]
The pointer's release() class method will be invoked at GC time.
@note The safest, and therefore preferred, calling
idiom is to pass a Method as the second parameter. Example usage:
class PointerHelper
def self.release(pointer)
...
end
end
p = AutoPointer.new(other_pointer, PointerHelper.method(:release))
The above code will cause PointerHelper#release to be invoked at GC time.
@note
The last calling idiom (only one parameter) is generally only
going to be useful if you subclass {AutoPointer}, and override
#release, which by default does nothing.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
|
Apache-2.0
|
def initialize(ptr, proc)
@ptr = ptr
@proc = proc
@autorelease = true
end
|
@param [Pointer] ptr
@param [#call] proc
@return [nil]
A new instance of Releaser.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
|
Apache-2.0
|
def call(*args)
release(@ptr) if @autorelease && @ptr
end
|
@param args
Release pointer if +autorelease+ is set.
|
call
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
|
Apache-2.0
|
def native_type(type = nil)
if type
@native_type = FFI.find_type(type)
else
native_type = @native_type
unless native_type
raise NotImplementedError, 'native_type method not overridden and no native_type set'
end
native_type
end
end
|
Get native type.
@overload native_type(type)
@param [String, Symbol, Type] type
@return [Type]
Get native type from +type+.
@overload native_type
@raise {NotImplementedError} This method must be overriden.
|
native_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/data_converter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/data_converter.rb
|
Apache-2.0
|
def find(query)
if @tagged_enums.has_key?(query)
@tagged_enums[query]
else
@all_enums.detect { |enum| enum.symbols.include?(query) }
end
end
|
@param query enum tag or part of an enum name
@return [Enum]
Find a {Enum} in collection.
|
find
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def initialize(*args)
@native_type = args.first.kind_of?(FFI::Type) ? args.shift : Type::INT
info, @tag = *args
@kv_map = Hash.new
unless info.nil?
last_cst = nil
value = 0
info.each do |i|
case i
when Symbol
raise ArgumentError, "duplicate enum key" if @kv_map.has_key?(i)
@kv_map[i] = value
last_cst = i
value += 1
when Integer
@kv_map[last_cst] = i
value = i+1
end
end
end
@vk_map = @kv_map.invert
end
|
@overload initialize(info, tag=nil)
@param [nil, Enumerable] info
@param [nil, Symbol] tag enum tag
@overload initialize(native_type, info, tag=nil)
@param [FFI::Type] native_type Native type for new Enum
@param [nil, Enumerable] info symbols and values for new Enum
@param [nil, Symbol] tag name of new Enum
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def to_native(val, ctx)
@kv_map[val] || if val.is_a?(Integer)
val
elsif val.respond_to?(:to_int)
val.to_int
else
raise ArgumentError, "invalid enum value, #{val.inspect}"
end
end
|
@param [Symbol, Integer, #to_int] val
@param ctx unused
@return [Integer] value of a enum symbol
|
to_native
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def from_native(val, ctx)
@vk_map[val] || val
end
|
@param val
@return symbol name if it exists for +val+.
|
from_native
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def initialize(*args)
@native_type = args.first.kind_of?(FFI::Type) ? args.shift : Type::INT
info, @tag = *args
@kv_map = Hash.new
unless info.nil?
last_cst = nil
value = 0
info.each do |i|
case i
when Symbol
raise ArgumentError, "duplicate bitmask key" if @kv_map.has_key?(i)
@kv_map[i] = 1 << value
last_cst = i
value += 1
when Integer
raise ArgumentError, "bitmask index should be positive" if i<0
@kv_map[last_cst] = 1 << i
value = i+1
end
end
end
@vk_map = @kv_map.invert
end
|
@overload initialize(info, tag=nil)
@param [nil, Enumerable] info symbols and bit rank for new Bitmask
@param [nil, Symbol] tag name of new Bitmask
@overload initialize(native_type, info, tag=nil)
@param [FFI::Type] native_type Native type for new Bitmask
@param [nil, Enumerable] info symbols and bit rank for new Bitmask
@param [nil, Symbol] tag name of new Bitmask
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def to_native(query, ctx)
return 0 if query.nil?
flat_query = [query].flatten
flat_query.inject(0) do |val, o|
case o
when Symbol
v = @kv_map[o]
raise ArgumentError, "invalid bitmask value, #{o.inspect}" unless v
val |= v
when Integer
val |= o
when ->(obj) { obj.respond_to?(:to_int) }
val |= o.to_int
else
raise ArgumentError, "invalid bitmask value, #{o.inspect}"
end
end
end
|
Get the native value of a bitmask
@overload to_native(query, ctx)
@param [Symbol, Integer, #to_int] query
@param ctx unused
@return [Integer] value of a bitmask
@overload to_native(query, ctx)
@param [Array<Symbol, Integer, #to_int>] query
@param ctx unused
@return [Integer] value of a bitmask
|
to_native
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def from_native(val, ctx)
list = @kv_map.select { |_, v| v & val != 0 }.keys
# If there are unmatch flags,
# return them in an integer,
# else information can be lost.
# Similar to Enum behavior.
remainder = val ^ list.inject(0) do |tmp, o|
v = @kv_map[o]
if v then tmp |= v else tmp end
end
list.push remainder unless remainder == 0
return list
end
|
@param [Integer] val
@param ctx unused
@return [Array<Symbol, Integer>] list of symbol names corresponding to val, plus an optional remainder if some bits don't match any constant
|
from_native
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/enum.rb
|
Apache-2.0
|
def ffi_lib(*names)
raise LoadError.new("library names list must not be empty") if names.empty?
lib_flags = defined?(@ffi_lib_flags) ? @ffi_lib_flags : FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL
ffi_libs = names.map do |name|
if name == FFI::CURRENT_PROCESS
FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)
else
libnames = (name.is_a?(::Array) ? name : [ name ]).map(&:to_s).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
lib = nil
errors = {}
libnames.each do |libname|
begin
orig = libname
lib = FFI::DynamicLibrary.open(libname, lib_flags)
break if lib
rescue Exception => ex
ldscript = false
if ex.message =~ /(([^ \t()])+\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short|invalid file format)/
if File.binread($1) =~ /(?:GROUP|INPUT) *\( *([^ \)]+)/
libname = $1
ldscript = true
end
end
if ldscript
retry
else
# TODO better library lookup logic
unless libname.start_with?("/") || FFI::Platform.windows?
path = ['/usr/lib/','/usr/local/lib/','/opt/local/lib/', '/opt/homebrew/lib/'].find do |pth|
File.exist?(pth + libname)
end
if path
libname = path + libname
retry
end
end
libr = (orig == libname ? orig : "#{orig} #{libname}")
errors[libr] = ex
end
end
end
if lib.nil?
raise LoadError.new(errors.values.join(".\n"))
end
# return the found lib
lib
end
end
@ffi_libs = ffi_libs
end
|
@param [Array] names names of libraries to load
@return [Array<DynamicLibrary>]
@raise {LoadError} if a library cannot be opened
Load native libraries.
|
ffi_lib
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb
|
Apache-2.0
|
def ffi_convention(convention = nil)
@ffi_convention ||= :default
@ffi_convention = convention if convention
@ffi_convention
end
|
Set the calling convention for {#attach_function} and {#callback}
@see http://en.wikipedia.org/wiki/Stdcall#stdcall
@note +:stdcall+ is typically used for attaching Windows API functions
@param [Symbol] convention one of +:default+, +:stdcall+
@return [Symbol] the new calling convention
|
ffi_convention
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb
|
Apache-2.0
|
def ffi_libraries
raise LoadError.new("no library specified") if !defined?(@ffi_libs) || @ffi_libs.empty?
@ffi_libs
end
|
@see #ffi_lib
@return [Array<FFI::DynamicLibrary>] array of currently loaded FFI libraries
@raise [LoadError] if no libraries have been loaded (using {#ffi_lib})
Get FFI libraries loaded using {#ffi_lib}.
|
ffi_libraries
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb
|
Apache-2.0
|
def initialize(pointer=nil)
raise NoMethodError, "release() not implemented for class #{self}" unless self.class.respond_to? :release
raise ArgumentError, "Must supply a pointer to memory for the Struct" unless pointer
super AutoPointer.new(pointer, self.class.method(:release))
end
|
@overload initialize(pointer)
@param [Pointer] pointer
Create a new ManagedStruct which will invoke the class method #release on
@overload initialize
A new instance of FFI::ManagedStruct.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/managedstruct.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/managedstruct.rb
|
Apache-2.0
|
def read_string(len=nil)
if len
return ''.b if len == 0
get_bytes(0, len)
else
get_string(0)
end
end
|
@param [nil,Numeric] len length of string to return
@return [String]
Read pointer's contents as a string, or the first +len+ bytes of the
equivalent string if +len+ is not +nil+.
|
read_string
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def read_string_length(len)
get_bytes(0, len)
end
|
@param [Numeric] len length of string to return
@return [String]
Read the first +len+ bytes of pointer's contents as a string.
Same as:
ptr.read_string(len) # with len not nil
|
read_string_length
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def write_string_length(str, len)
put_bytes(0, str, 0, len)
end
|
@param [String] str string to write
@param [Numeric] len length of string to return
@return [self]
Write +len+ first bytes of +str+ in pointer's contents.
Same as:
ptr.write_string(str, len) # with len not nil
|
write_string_length
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def write_string(str, len=nil)
len = str.bytesize unless len
# Write the string data without NUL termination
put_bytes(0, str, 0, len)
end
|
@param [String] str string to write
@param [Numeric] len length of string to return
@return [self]
Write +str+ in pointer's contents, or first +len+ bytes if
+len+ is not +nil+.
|
write_string
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def read_array_of_type(type, reader, length)
ary = []
size = FFI.type_size(type)
tmp = self
length.times { |j|
ary << tmp.send(reader)
tmp += size unless j == length-1 # avoid OOB
}
ary
end
|
@param [Type] type type of data to read from pointer's contents
@param [Symbol] reader method to send to +self+ to read +type+
@param [Numeric] length
@return [Array]
Read an array of +type+ of length +length+.
@example
ptr.read_array_of_type(TYPE_UINT8, :read_uint8, 4) # -> [1, 2, 3, 4]
|
read_array_of_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def write_array_of_type(type, writer, ary)
size = FFI.type_size(type)
ary.each_with_index { |val, i|
break unless i < self.size
self.send(writer, i * size, val)
}
self
end
|
@param [Type] type type of data to write to pointer's contents
@param [Symbol] writer method to send to +self+ to write +type+
@param [Array] ary
@return [self]
Write +ary+ in pointer's contents as +type+.
@example
ptr.write_array_of_type(TYPE_UINT8, :put_uint8, [1, 2, 3 ,4])
|
write_array_of_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def read(type)
get(type, 0)
end
|
@param [Symbol,Type] type of data to read
@return [Object]
Read pointer's contents as +type+
Same as:
ptr.get(type, 0)
|
read
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def write(type, value)
put(type, 0, value)
end
|
@param [Symbol,Type] type of data to read
@param [Object] value to write
@return [nil]
Write +value+ of type +type+ to pointer's content
Same as:
ptr.put(type, 0)
|
write
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/pointer.rb
|
Apache-2.0
|
def values
members.map { |m| self[m] }
end
|
@return [Array]
Get array of values from Struct fields.
|
values
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/struct.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/struct.rb
|
Apache-2.0
|
def clear
pointer.clear
self
end
|
Clear the struct content.
@return [self]
|
clear
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/struct.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ffi-1.15.5/lib/ffi/struct.rb
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.