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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
mroth/emoji_data.rb | lib/emoji_data/emoji_char.rb | EmojiData.EmojiChar.render | def render(opts = {})
options = {variant_encoding: true}.merge(opts)
#decide whether to use the normal unified ID or the variant for encoding to str
target = (self.variant? && options[:variant_encoding]) ? self.variant : @unified
EmojiChar::unified_to_char(target)
end | ruby | def render(opts = {})
options = {variant_encoding: true}.merge(opts)
#decide whether to use the normal unified ID or the variant for encoding to str
target = (self.variant? && options[:variant_encoding]) ? self.variant : @unified
EmojiChar::unified_to_char(target)
end | [
"def",
"render",
"(",
"opts",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"variant_encoding",
":",
"true",
"}",
".",
"merge",
"(",
"opts",
")",
"target",
"=",
"(",
"self",
".",
"variant?",
"&&",
"options",
"[",
":variant_encoding",
"]",
")",
"?",
"self",
".",
"variant",
":",
"@unified",
"EmojiChar",
"::",
"unified_to_char",
"(",
"target",
")",
"end"
] | Renders an `EmojiChar` to its string glyph representation, suitable for
printing to screen.
@option opts [Boolean] :variant_encoding specify whether the variant
encoding selector should be used to hint to rendering devices that
"graphic" representation should be used. By default, we use this for all
Emoji characters that contain a possible variant.
@return [String] the emoji character rendered to a UTF-8 string | [
"Renders",
"an",
"EmojiChar",
"to",
"its",
"string",
"glyph",
"representation",
"suitable",
"for",
"printing",
"to",
"screen",
"."
] | 3f1885bcdc39c086cb9fda17704ee7ea4360e4ec | https://github.com/mroth/emoji_data.rb/blob/3f1885bcdc39c086cb9fda17704ee7ea4360e4ec/lib/emoji_data/emoji_char.rb#L56-L61 | train |
mroth/emoji_data.rb | lib/emoji_data/emoji_char.rb | EmojiData.EmojiChar.chars | def chars
results = [self.render({variant_encoding: false})]
@variations.each do |variation|
results << EmojiChar::unified_to_char(variation)
end
@chars ||= results
end | ruby | def chars
results = [self.render({variant_encoding: false})]
@variations.each do |variation|
results << EmojiChar::unified_to_char(variation)
end
@chars ||= results
end | [
"def",
"chars",
"results",
"=",
"[",
"self",
".",
"render",
"(",
"{",
"variant_encoding",
":",
"false",
"}",
")",
"]",
"@variations",
".",
"each",
"do",
"|",
"variation",
"|",
"results",
"<<",
"EmojiChar",
"::",
"unified_to_char",
"(",
"variation",
")",
"end",
"@chars",
"||=",
"results",
"end"
] | Returns a list of all possible UTF-8 string renderings of an `EmojiChar`.
E.g., normal, with variant selectors, etc. This is useful if you want to
have all possible values to match against when searching for the emoji in
a string representation.
@return [Array<String>] all possible UTF-8 string renderings | [
"Returns",
"a",
"list",
"of",
"all",
"possible",
"UTF",
"-",
"8",
"string",
"renderings",
"of",
"an",
"EmojiChar",
"."
] | 3f1885bcdc39c086cb9fda17704ee7ea4360e4ec | https://github.com/mroth/emoji_data.rb/blob/3f1885bcdc39c086cb9fda17704ee7ea4360e4ec/lib/emoji_data/emoji_char.rb#L73-L79 | train |
nickcharlton/boxes | lib/boxes/template.rb | Boxes.Template.render | def render(args)
ERB.new(template, nil, '-').result(ERBContext.new(args).get_binding)
end | ruby | def render(args)
ERB.new(template, nil, '-').result(ERBContext.new(args).get_binding)
end | [
"def",
"render",
"(",
"args",
")",
"ERB",
".",
"new",
"(",
"template",
",",
"nil",
",",
"'-'",
")",
".",
"result",
"(",
"ERBContext",
".",
"new",
"(",
"args",
")",
".",
"get_binding",
")",
"end"
] | Load a template with a given name.
@param env [Boxes::Environment] the environment to source templates.
@param name [String] the name of the template.
@return [Boxes::Template] a template instance.
Render the template.
@param args [Hash] the values to set.
@return [String] the rendered template. | [
"Load",
"a",
"template",
"with",
"a",
"given",
"name",
"."
] | d5558d6f2c4f98c6e453f8b960f28c7540433936 | https://github.com/nickcharlton/boxes/blob/d5558d6f2c4f98c6e453f8b960f28c7540433936/lib/boxes/template.rb#L29-L31 | train |
hzamani/parsi-date | lib/parsi-date.rb | Parsi.Date.- | def - x
case x
when Numeric
return self.class.new!(ajd - x, offset)
when Date
return ajd - x.ajd
end
raise TypeError, 'expected numeric or date'
end | ruby | def - x
case x
when Numeric
return self.class.new!(ajd - x, offset)
when Date
return ajd - x.ajd
end
raise TypeError, 'expected numeric or date'
end | [
"def",
"-",
"x",
"case",
"x",
"when",
"Numeric",
"return",
"self",
".",
"class",
".",
"new!",
"(",
"ajd",
"-",
"x",
",",
"offset",
")",
"when",
"Date",
"return",
"ajd",
"-",
"x",
".",
"ajd",
"end",
"raise",
"TypeError",
",",
"'expected numeric or date'",
"end"
] | If +x+ is a Numeric value, create a new Date object that is +x+ days
earlier than the current one.
If +x+ is a Date, return the number of days between the two dates; or,
more precisely, how many days later the current date is than +x+.
If +x+ is neither Numeric nor a Date, a TypeError is raised. | [
"If",
"+",
"x",
"+",
"is",
"a",
"Numeric",
"value",
"create",
"a",
"new",
"Date",
"object",
"that",
"is",
"+",
"x",
"+",
"days",
"earlier",
"than",
"the",
"current",
"one",
"."
] | 63a9a89cd9c7dfc53b2d508993d5b1add2638589 | https://github.com/hzamani/parsi-date/blob/63a9a89cd9c7dfc53b2d508993d5b1add2638589/lib/parsi-date.rb#L500-L508 | train |
hzamani/parsi-date | lib/parsi-date.rb | Parsi.Date.>> | def >> n
y, m = (year * 12 + (mon - 1) + n).divmod(12)
m, = (m + 1) .divmod(1)
d = mday
until jd2 = _valid_civil?(y, m, d)
d -= 1
raise ArgumentError, 'invalid date' unless d > 0
end
self + (jd2 - jd)
end | ruby | def >> n
y, m = (year * 12 + (mon - 1) + n).divmod(12)
m, = (m + 1) .divmod(1)
d = mday
until jd2 = _valid_civil?(y, m, d)
d -= 1
raise ArgumentError, 'invalid date' unless d > 0
end
self + (jd2 - jd)
end | [
"def",
">>",
"n",
"y",
",",
"m",
"=",
"(",
"year",
"*",
"12",
"+",
"(",
"mon",
"-",
"1",
")",
"+",
"n",
")",
".",
"divmod",
"(",
"12",
")",
"m",
",",
"=",
"(",
"m",
"+",
"1",
")",
".",
"divmod",
"(",
"1",
")",
"d",
"=",
"mday",
"until",
"jd2",
"=",
"_valid_civil?",
"(",
"y",
",",
"m",
",",
"d",
")",
"d",
"-=",
"1",
"raise",
"ArgumentError",
",",
"'invalid date'",
"unless",
"d",
">",
"0",
"end",
"self",
"+",
"(",
"jd2",
"-",
"jd",
")",
"end"
] | Return a new Date object that is +n+ months later than the current one.
If the day-of-the-month of the current Date is greater than the last day of
the target month, the day-of-the-month of the returned Date will be the last
day of the target month. | [
"Return",
"a",
"new",
"Date",
"object",
"that",
"is",
"+",
"n",
"+",
"months",
"later",
"than",
"the",
"current",
"one",
"."
] | 63a9a89cd9c7dfc53b2d508993d5b1add2638589 | https://github.com/hzamani/parsi-date/blob/63a9a89cd9c7dfc53b2d508993d5b1add2638589/lib/parsi-date.rb#L570-L579 | train |
paddor/cztop | lib/cztop/config/traversing.rb | CZTop::Config::Traversing.ChildrenAccessor.new | def new(name = nil, value = nil)
config = CZTop::Config.new(name, value, parent: @config)
yield config if block_given?
config
end | ruby | def new(name = nil, value = nil)
config = CZTop::Config.new(name, value, parent: @config)
yield config if block_given?
config
end | [
"def",
"new",
"(",
"name",
"=",
"nil",
",",
"value",
"=",
"nil",
")",
"config",
"=",
"CZTop",
"::",
"Config",
".",
"new",
"(",
"name",
",",
"value",
",",
"parent",
":",
"@config",
")",
"yield",
"config",
"if",
"block_given?",
"config",
"end"
] | Adds a new Config item and yields it, so it can be configured in
a block.
@param name [String] name for new config item
@param value [String] value for new config item
@yieldparam config [Config] the new config item, if block was given
@return [Config] the new config item | [
"Adds",
"a",
"new",
"Config",
"item",
"and",
"yields",
"it",
"so",
"it",
"can",
"be",
"configured",
"in",
"a",
"block",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/config/traversing.rb#L127-L131 | train |
paddor/cztop | lib/cztop/socket.rb | CZTop.Socket.CURVE_client! | def CURVE_client!(client_cert, server_cert)
if server_cert.secret_key
raise SecurityError, "server's secret key not secret"
end
client_cert.apply(self) # NOTE: desired: raises if no secret key in cert
options.CURVE_serverkey = server_cert.public_key
end | ruby | def CURVE_client!(client_cert, server_cert)
if server_cert.secret_key
raise SecurityError, "server's secret key not secret"
end
client_cert.apply(self) # NOTE: desired: raises if no secret key in cert
options.CURVE_serverkey = server_cert.public_key
end | [
"def",
"CURVE_client!",
"(",
"client_cert",
",",
"server_cert",
")",
"if",
"server_cert",
".",
"secret_key",
"raise",
"SecurityError",
",",
"\"server's secret key not secret\"",
"end",
"client_cert",
".",
"apply",
"(",
"self",
")",
"options",
".",
"CURVE_serverkey",
"=",
"server_cert",
".",
"public_key",
"end"
] | Enables CURVE security and makes this socket a CURVE client.
@param client_cert [Certificate] client's certificate, to secure
communication (and be authenticated by the server)
@param server_cert [Certificate] the remote server's certificate, so
this socket is able to authenticate the server
@return [void]
@raise [SecurityError] if the server's secret key is set in server_cert,
which means it's not secret anymore
@raise [SystemCallError] if there's no secret key in client_cert | [
"Enables",
"CURVE",
"security",
"and",
"makes",
"this",
"socket",
"a",
"CURVE",
"client",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/socket.rb#L33-L40 | train |
paddor/cztop | lib/cztop/socket.rb | CZTop.Socket.connect | def connect(endpoint)
rc = ffi_delegate.connect("%s", :string, endpoint)
raise ArgumentError, "incorrect endpoint: %p" % endpoint if rc == -1
end | ruby | def connect(endpoint)
rc = ffi_delegate.connect("%s", :string, endpoint)
raise ArgumentError, "incorrect endpoint: %p" % endpoint if rc == -1
end | [
"def",
"connect",
"(",
"endpoint",
")",
"rc",
"=",
"ffi_delegate",
".",
"connect",
"(",
"\"%s\"",
",",
":string",
",",
"endpoint",
")",
"raise",
"ArgumentError",
",",
"\"incorrect endpoint: %p\"",
"%",
"endpoint",
"if",
"rc",
"==",
"-",
"1",
"end"
] | Connects to an endpoint.
@param endpoint [String]
@return [void]
@raise [ArgumentError] if the endpoint is incorrect | [
"Connects",
"to",
"an",
"endpoint",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/socket.rb#L54-L57 | train |
paddor/cztop | lib/cztop/socket.rb | CZTop.Socket.disconnect | def disconnect(endpoint)
rc = ffi_delegate.disconnect("%s", :string, endpoint)
raise ArgumentError, "incorrect endpoint: %p" % endpoint if rc == -1
end | ruby | def disconnect(endpoint)
rc = ffi_delegate.disconnect("%s", :string, endpoint)
raise ArgumentError, "incorrect endpoint: %p" % endpoint if rc == -1
end | [
"def",
"disconnect",
"(",
"endpoint",
")",
"rc",
"=",
"ffi_delegate",
".",
"disconnect",
"(",
"\"%s\"",
",",
":string",
",",
"endpoint",
")",
"raise",
"ArgumentError",
",",
"\"incorrect endpoint: %p\"",
"%",
"endpoint",
"if",
"rc",
"==",
"-",
"1",
"end"
] | Disconnects from an endpoint.
@param endpoint [String]
@return [void]
@raise [ArgumentError] if the endpoint is incorrect | [
"Disconnects",
"from",
"an",
"endpoint",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/socket.rb#L63-L66 | train |
paddor/cztop | lib/cztop/socket.rb | CZTop.Socket.bind | def bind(endpoint)
rc = ffi_delegate.bind("%s", :string, endpoint)
raise_zmq_err("unable to bind to %p" % endpoint) if rc == -1
@last_tcp_port = rc if rc > 0
end | ruby | def bind(endpoint)
rc = ffi_delegate.bind("%s", :string, endpoint)
raise_zmq_err("unable to bind to %p" % endpoint) if rc == -1
@last_tcp_port = rc if rc > 0
end | [
"def",
"bind",
"(",
"endpoint",
")",
"rc",
"=",
"ffi_delegate",
".",
"bind",
"(",
"\"%s\"",
",",
":string",
",",
"endpoint",
")",
"raise_zmq_err",
"(",
"\"unable to bind to %p\"",
"%",
"endpoint",
")",
"if",
"rc",
"==",
"-",
"1",
"@last_tcp_port",
"=",
"rc",
"if",
"rc",
">",
"0",
"end"
] | Binds to an endpoint.
@note When binding to an automatically selected TCP port, this will set
{#last_tcp_port}.
@param endpoint [String]
@return [void]
@raise [SystemCallError] in case of failure | [
"Binds",
"to",
"an",
"endpoint",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/socket.rb#L85-L89 | train |
paddor/cztop | lib/cztop/socket.rb | CZTop.Socket.unbind | def unbind(endpoint)
rc = ffi_delegate.unbind("%s", :string, endpoint)
raise ArgumentError, "incorrect endpoint: %p" % endpoint if rc == -1
end | ruby | def unbind(endpoint)
rc = ffi_delegate.unbind("%s", :string, endpoint)
raise ArgumentError, "incorrect endpoint: %p" % endpoint if rc == -1
end | [
"def",
"unbind",
"(",
"endpoint",
")",
"rc",
"=",
"ffi_delegate",
".",
"unbind",
"(",
"\"%s\"",
",",
":string",
",",
"endpoint",
")",
"raise",
"ArgumentError",
",",
"\"incorrect endpoint: %p\"",
"%",
"endpoint",
"if",
"rc",
"==",
"-",
"1",
"end"
] | Unbinds from an endpoint.
@param endpoint [String]
@return [void]
@raise [ArgumentError] if the endpoint is incorrect | [
"Unbinds",
"from",
"an",
"endpoint",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/socket.rb#L95-L98 | train |
hawkular/hawkular-client-ruby | lib/hawkular/inventory/inventory_api.rb | Hawkular::Inventory.Client.resource | def resource(id)
hash = http_get(url('/resources/%s', id))
Resource.new(hash)
rescue ::Hawkular::Exception => e
return if e.cause.is_a?(::RestClient::NotFound)
raise
end | ruby | def resource(id)
hash = http_get(url('/resources/%s', id))
Resource.new(hash)
rescue ::Hawkular::Exception => e
return if e.cause.is_a?(::RestClient::NotFound)
raise
end | [
"def",
"resource",
"(",
"id",
")",
"hash",
"=",
"http_get",
"(",
"url",
"(",
"'/resources/%s'",
",",
"id",
")",
")",
"Resource",
".",
"new",
"(",
"hash",
")",
"rescue",
"::",
"Hawkular",
"::",
"Exception",
"=>",
"e",
"return",
"if",
"e",
".",
"cause",
".",
"is_a?",
"(",
"::",
"RestClient",
"::",
"NotFound",
")",
"raise",
"end"
] | Get single resource by id
@return Resource the resource | [
"Get",
"single",
"resource",
"by",
"id"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/inventory/inventory_api.rb#L39-L45 | train |
hawkular/hawkular-client-ruby | lib/hawkular/inventory/inventory_api.rb | Hawkular::Inventory.Client.children_resources | def children_resources(parent_id)
http_get(url('/resources/%s/children', parent_id))['results'].map { |r| Resource.new(r) }
end | ruby | def children_resources(parent_id)
http_get(url('/resources/%s/children', parent_id))['results'].map { |r| Resource.new(r) }
end | [
"def",
"children_resources",
"(",
"parent_id",
")",
"http_get",
"(",
"url",
"(",
"'/resources/%s/children'",
",",
"parent_id",
")",
")",
"[",
"'results'",
"]",
".",
"map",
"{",
"|",
"r",
"|",
"Resource",
".",
"new",
"(",
"r",
")",
"}",
"end"
] | Get childrens of a resource
@return Children of a resource | [
"Get",
"childrens",
"of",
"a",
"resource"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/inventory/inventory_api.rb#L56-L58 | train |
hawkular/hawkular-client-ruby | lib/hawkular/inventory/inventory_api.rb | Hawkular::Inventory.Client.parent | def parent(id)
hash = http_get(url('/resources/%s/parent', id))
Resource.new(hash) if hash
end | ruby | def parent(id)
hash = http_get(url('/resources/%s/parent', id))
Resource.new(hash) if hash
end | [
"def",
"parent",
"(",
"id",
")",
"hash",
"=",
"http_get",
"(",
"url",
"(",
"'/resources/%s/parent'",
",",
"id",
")",
")",
"Resource",
".",
"new",
"(",
"hash",
")",
"if",
"hash",
"end"
] | Get parent of a resource
@return Resource the parent resource, or nil if the provided ID referred to a root resource | [
"Get",
"parent",
"of",
"a",
"resource"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/inventory/inventory_api.rb#L62-L65 | train |
paddor/cztop | lib/cztop/beacon.rb | CZTop.Beacon.configure | def configure(port)
@actor.send_picture("si", :string, "CONFIGURE", :int, port)
ptr = Zstr.recv(@actor)
# NULL if context terminated or interrupted
HasFFIDelegate.raise_zmq_err if ptr.null?
hostname = ptr.read_string
return hostname unless hostname.empty?
raise NotImplementedError, "system doesn't support UDP broadcasts"
end | ruby | def configure(port)
@actor.send_picture("si", :string, "CONFIGURE", :int, port)
ptr = Zstr.recv(@actor)
# NULL if context terminated or interrupted
HasFFIDelegate.raise_zmq_err if ptr.null?
hostname = ptr.read_string
return hostname unless hostname.empty?
raise NotImplementedError, "system doesn't support UDP broadcasts"
end | [
"def",
"configure",
"(",
"port",
")",
"@actor",
".",
"send_picture",
"(",
"\"si\"",
",",
":string",
",",
"\"CONFIGURE\"",
",",
":int",
",",
"port",
")",
"ptr",
"=",
"Zstr",
".",
"recv",
"(",
"@actor",
")",
"HasFFIDelegate",
".",
"raise_zmq_err",
"if",
"ptr",
".",
"null?",
"hostname",
"=",
"ptr",
".",
"read_string",
"return",
"hostname",
"unless",
"hostname",
".",
"empty?",
"raise",
"NotImplementedError",
",",
"\"system doesn't support UDP broadcasts\"",
"end"
] | Run the beacon on the specified UDP port.
@param port [Integer] port number to
@return [String] hostname, which can be used as endpoint for incoming
connections
@raise [Interrupt] if the context was terminated or the process
interrupted
@raise [NotImplementedError] if the system doesn't support UDP broadcasts | [
"Run",
"the",
"beacon",
"on",
"the",
"specified",
"UDP",
"port",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/beacon.rb#L45-L56 | train |
paddor/cztop | lib/cztop/beacon.rb | CZTop.Beacon.publish | def publish(data, interval)
raise ArgumentError, "data too long" if data.bytesize > MAX_BEACON_DATA
@actor.send_picture("sbi", :string, "PUBLISH", :string, data,
:int, data.bytesize, :int, interval)
end | ruby | def publish(data, interval)
raise ArgumentError, "data too long" if data.bytesize > MAX_BEACON_DATA
@actor.send_picture("sbi", :string, "PUBLISH", :string, data,
:int, data.bytesize, :int, interval)
end | [
"def",
"publish",
"(",
"data",
",",
"interval",
")",
"raise",
"ArgumentError",
",",
"\"data too long\"",
"if",
"data",
".",
"bytesize",
">",
"MAX_BEACON_DATA",
"@actor",
".",
"send_picture",
"(",
"\"sbi\"",
",",
":string",
",",
"\"PUBLISH\"",
",",
":string",
",",
"data",
",",
":int",
",",
"data",
".",
"bytesize",
",",
":int",
",",
"interval",
")",
"end"
] | Start broadcasting a beacon.
@param data [String] data to publish
@param interval [Integer] interval in msec
@raise [ArgumentError] if data is longer than {MAX_BEACON_DATA} bytes
@return [void] | [
"Start",
"broadcasting",
"a",
"beacon",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/beacon.rb#L66-L70 | train |
hawkular/hawkular-client-ruby | lib/hawkular/tokens/tokens_api.rb | Hawkular::Token.Client.get_tokens | def get_tokens(credentials = {})
creds = credentials.empty? ? @credentials : credentials
auth_header = { Authorization: base_64_credentials(creds) }
http_get('/secret-store/v1/tokens', auth_header)
end | ruby | def get_tokens(credentials = {})
creds = credentials.empty? ? @credentials : credentials
auth_header = { Authorization: base_64_credentials(creds) }
http_get('/secret-store/v1/tokens', auth_header)
end | [
"def",
"get_tokens",
"(",
"credentials",
"=",
"{",
"}",
")",
"creds",
"=",
"credentials",
".",
"empty?",
"?",
"@credentials",
":",
"credentials",
"auth_header",
"=",
"{",
"Authorization",
":",
"base_64_credentials",
"(",
"creds",
")",
"}",
"http_get",
"(",
"'/secret-store/v1/tokens'",
",",
"auth_header",
")",
"end"
] | Create a new Secret Store client
@param entrypoint [String] base url of Hawkular - e.g http://localhost:8080
@param credentials [Hash{String=>String}] Hash of username, password
@param options [Hash{String=>String}] Additional rest client options
Retrieve the tenant id for the passed credentials.
If no credentials are passed, the ones from the constructor are used
@param credentials [Hash{String=>String}] Hash of username, password, token(optional)
@return [String] tenant id | [
"Create",
"a",
"new",
"Secret",
"Store",
"client"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/tokens/tokens_api.rb#L19-L23 | train |
paddor/cztop | lib/cztop/z85.rb | CZTop.Z85.encode | def encode(input)
raise ArgumentError, "wrong input length" if input.bytesize % 4 > 0
input = input.dup.force_encoding(Encoding::BINARY)
ptr = ffi_delegate.encode(input, input.bytesize)
raise_zmq_err if ptr.null?
z85 = ptr.read_string
z85.encode!(Encoding::ASCII)
return z85
end | ruby | def encode(input)
raise ArgumentError, "wrong input length" if input.bytesize % 4 > 0
input = input.dup.force_encoding(Encoding::BINARY)
ptr = ffi_delegate.encode(input, input.bytesize)
raise_zmq_err if ptr.null?
z85 = ptr.read_string
z85.encode!(Encoding::ASCII)
return z85
end | [
"def",
"encode",
"(",
"input",
")",
"raise",
"ArgumentError",
",",
"\"wrong input length\"",
"if",
"input",
".",
"bytesize",
"%",
"4",
">",
"0",
"input",
"=",
"input",
".",
"dup",
".",
"force_encoding",
"(",
"Encoding",
"::",
"BINARY",
")",
"ptr",
"=",
"ffi_delegate",
".",
"encode",
"(",
"input",
",",
"input",
".",
"bytesize",
")",
"raise_zmq_err",
"if",
"ptr",
".",
"null?",
"z85",
"=",
"ptr",
".",
"read_string",
"z85",
".",
"encode!",
"(",
"Encoding",
"::",
"ASCII",
")",
"return",
"z85",
"end"
] | Encodes to Z85.
@param input [String] possibly binary input data
@return [String] Z85 encoded data as ASCII string
@raise [ArgumentError] if input length isn't divisible by 4 with no
remainder
@raise [SystemCallError] if this fails | [
"Encodes",
"to",
"Z85",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/z85.rb#L55-L63 | train |
paddor/cztop | lib/cztop/z85.rb | CZTop.Z85.decode | def decode(input)
raise ArgumentError, "wrong input length" if input.bytesize % 5 > 0
zchunk = ffi_delegate.decode(input)
raise_zmq_err if zchunk.null?
decoded_string = zchunk.data.read_string(zchunk.size - 1)
return decoded_string
end | ruby | def decode(input)
raise ArgumentError, "wrong input length" if input.bytesize % 5 > 0
zchunk = ffi_delegate.decode(input)
raise_zmq_err if zchunk.null?
decoded_string = zchunk.data.read_string(zchunk.size - 1)
return decoded_string
end | [
"def",
"decode",
"(",
"input",
")",
"raise",
"ArgumentError",
",",
"\"wrong input length\"",
"if",
"input",
".",
"bytesize",
"%",
"5",
">",
"0",
"zchunk",
"=",
"ffi_delegate",
".",
"decode",
"(",
"input",
")",
"raise_zmq_err",
"if",
"zchunk",
".",
"null?",
"decoded_string",
"=",
"zchunk",
".",
"data",
".",
"read_string",
"(",
"zchunk",
".",
"size",
"-",
"1",
")",
"return",
"decoded_string",
"end"
] | Decodes from Z85.
@param input [String] Z85 encoded data
@return [String] original data as binary string
@raise [ArgumentError] if input length isn't divisible by 5 with no
remainder
@raise [SystemCallError] if this fails | [
"Decodes",
"from",
"Z85",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/z85.rb#L71-L77 | train |
flori/protocol | lib/protocol/message.rb | Protocol.Message.to_ruby | def to_ruby(result = '')
if arity
result << " def #{name}("
args = if arity >= 0
(1..arity).map { |i| "x#{i}" }
else
(1..~arity).map { |i| "x#{i}" } << '*rest'
end
if block_expected?
args << '&block'
end
result << args * ', '
result << ") end\n"
else
result << " understand :#{name}\n"
end
end | ruby | def to_ruby(result = '')
if arity
result << " def #{name}("
args = if arity >= 0
(1..arity).map { |i| "x#{i}" }
else
(1..~arity).map { |i| "x#{i}" } << '*rest'
end
if block_expected?
args << '&block'
end
result << args * ', '
result << ") end\n"
else
result << " understand :#{name}\n"
end
end | [
"def",
"to_ruby",
"(",
"result",
"=",
"''",
")",
"if",
"arity",
"result",
"<<",
"\" def #{name}(\"",
"args",
"=",
"if",
"arity",
">=",
"0",
"(",
"1",
"..",
"arity",
")",
".",
"map",
"{",
"|",
"i",
"|",
"\"x#{i}\"",
"}",
"else",
"(",
"1",
"..",
"~",
"arity",
")",
".",
"map",
"{",
"|",
"i",
"|",
"\"x#{i}\"",
"}",
"<<",
"'*rest'",
"end",
"if",
"block_expected?",
"args",
"<<",
"'&block'",
"end",
"result",
"<<",
"args",
"*",
"', '",
"result",
"<<",
"\") end\\n\"",
"else",
"result",
"<<",
"\" understand :#{name}\\n\"",
"end",
"end"
] | Concatenates a method signature as ruby code to the +result+ string and
returns it. | [
"Concatenates",
"a",
"method",
"signature",
"as",
"ruby",
"code",
"to",
"the",
"+",
"result",
"+",
"string",
"and",
"returns",
"it",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/message.rb#L57-L73 | train |
flori/protocol | lib/protocol/message.rb | Protocol.Message.check_class | def check_class(klass)
unless klass.method_defined?(name)
raise NotImplementedErrorCheckError.new(self,
"method '#{name}' not implemented in #{klass}")
end
check_method = klass.instance_method(name)
if arity and (check_arity = check_method.arity) != arity
raise ArgumentErrorCheckError.new(self,
"wrong number of arguments for protocol"\
" in method '#{name}' (#{check_arity} for #{arity}) of #{klass}")
end
if block_expected?
modul = Utilities.find_method_module(name, klass.ancestors)
parser = MethodParser.new(modul, name)
parser.block_arg? or raise BlockCheckError.new(self,
"expected a block argument for #{klass}")
end
arity and wrap_method(klass)
true
end | ruby | def check_class(klass)
unless klass.method_defined?(name)
raise NotImplementedErrorCheckError.new(self,
"method '#{name}' not implemented in #{klass}")
end
check_method = klass.instance_method(name)
if arity and (check_arity = check_method.arity) != arity
raise ArgumentErrorCheckError.new(self,
"wrong number of arguments for protocol"\
" in method '#{name}' (#{check_arity} for #{arity}) of #{klass}")
end
if block_expected?
modul = Utilities.find_method_module(name, klass.ancestors)
parser = MethodParser.new(modul, name)
parser.block_arg? or raise BlockCheckError.new(self,
"expected a block argument for #{klass}")
end
arity and wrap_method(klass)
true
end | [
"def",
"check_class",
"(",
"klass",
")",
"unless",
"klass",
".",
"method_defined?",
"(",
"name",
")",
"raise",
"NotImplementedErrorCheckError",
".",
"new",
"(",
"self",
",",
"\"method '#{name}' not implemented in #{klass}\"",
")",
"end",
"check_method",
"=",
"klass",
".",
"instance_method",
"(",
"name",
")",
"if",
"arity",
"and",
"(",
"check_arity",
"=",
"check_method",
".",
"arity",
")",
"!=",
"arity",
"raise",
"ArgumentErrorCheckError",
".",
"new",
"(",
"self",
",",
"\"wrong number of arguments for protocol\"",
"\" in method '#{name}' (#{check_arity} for #{arity}) of #{klass}\"",
")",
"end",
"if",
"block_expected?",
"modul",
"=",
"Utilities",
".",
"find_method_module",
"(",
"name",
",",
"klass",
".",
"ancestors",
")",
"parser",
"=",
"MethodParser",
".",
"new",
"(",
"modul",
",",
"name",
")",
"parser",
".",
"block_arg?",
"or",
"raise",
"BlockCheckError",
".",
"new",
"(",
"self",
",",
"\"expected a block argument for #{klass}\"",
")",
"end",
"arity",
"and",
"wrap_method",
"(",
"klass",
")",
"true",
"end"
] | Check class +klass+ against this Message instance, and raise a CheckError
exception if necessary. | [
"Check",
"class",
"+",
"klass",
"+",
"against",
"this",
"Message",
"instance",
"and",
"raise",
"a",
"CheckError",
"exception",
"if",
"necessary",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/message.rb#L92-L111 | train |
flori/protocol | lib/protocol/message.rb | Protocol.Message.check_object | def check_object(object)
if !object.respond_to?(name)
raise NotImplementedErrorCheckError.new(self,
"method '#{name}' not responding in #{object}")
end
check_method = object.method(name)
if arity and (check_arity = check_method.arity) != arity
raise ArgumentErrorCheckError.new(self,
"wrong number of arguments for protocol"\
" in method '#{name}' (#{check_arity} for #{arity}) of #{object}")
end
if block_expected?
if object.singleton_methods(false).map { |m| m.to_s } .include?(name)
parser = MethodParser.new(object, name, true)
else
ancestors = object.class.ancestors
modul = Utilities.find_method_module(name, ancestors)
parser = MethodParser.new(modul, name)
end
parser.block_arg? or raise BlockCheckError.new(self,
"expected a block argument for #{object}:#{object.class}")
end
if arity and not protocol === object
object.extend protocol
wrap_method(class << object ; self ; end)
end
true
end | ruby | def check_object(object)
if !object.respond_to?(name)
raise NotImplementedErrorCheckError.new(self,
"method '#{name}' not responding in #{object}")
end
check_method = object.method(name)
if arity and (check_arity = check_method.arity) != arity
raise ArgumentErrorCheckError.new(self,
"wrong number of arguments for protocol"\
" in method '#{name}' (#{check_arity} for #{arity}) of #{object}")
end
if block_expected?
if object.singleton_methods(false).map { |m| m.to_s } .include?(name)
parser = MethodParser.new(object, name, true)
else
ancestors = object.class.ancestors
modul = Utilities.find_method_module(name, ancestors)
parser = MethodParser.new(modul, name)
end
parser.block_arg? or raise BlockCheckError.new(self,
"expected a block argument for #{object}:#{object.class}")
end
if arity and not protocol === object
object.extend protocol
wrap_method(class << object ; self ; end)
end
true
end | [
"def",
"check_object",
"(",
"object",
")",
"if",
"!",
"object",
".",
"respond_to?",
"(",
"name",
")",
"raise",
"NotImplementedErrorCheckError",
".",
"new",
"(",
"self",
",",
"\"method '#{name}' not responding in #{object}\"",
")",
"end",
"check_method",
"=",
"object",
".",
"method",
"(",
"name",
")",
"if",
"arity",
"and",
"(",
"check_arity",
"=",
"check_method",
".",
"arity",
")",
"!=",
"arity",
"raise",
"ArgumentErrorCheckError",
".",
"new",
"(",
"self",
",",
"\"wrong number of arguments for protocol\"",
"\" in method '#{name}' (#{check_arity} for #{arity}) of #{object}\"",
")",
"end",
"if",
"block_expected?",
"if",
"object",
".",
"singleton_methods",
"(",
"false",
")",
".",
"map",
"{",
"|",
"m",
"|",
"m",
".",
"to_s",
"}",
".",
"include?",
"(",
"name",
")",
"parser",
"=",
"MethodParser",
".",
"new",
"(",
"object",
",",
"name",
",",
"true",
")",
"else",
"ancestors",
"=",
"object",
".",
"class",
".",
"ancestors",
"modul",
"=",
"Utilities",
".",
"find_method_module",
"(",
"name",
",",
"ancestors",
")",
"parser",
"=",
"MethodParser",
".",
"new",
"(",
"modul",
",",
"name",
")",
"end",
"parser",
".",
"block_arg?",
"or",
"raise",
"BlockCheckError",
".",
"new",
"(",
"self",
",",
"\"expected a block argument for #{object}:#{object.class}\"",
")",
"end",
"if",
"arity",
"and",
"not",
"protocol",
"===",
"object",
"object",
".",
"extend",
"protocol",
"wrap_method",
"(",
"class",
"<<",
"object",
";",
"self",
";",
"end",
")",
"end",
"true",
"end"
] | Check object +object+ against this Message instance, and raise a
CheckError exception if necessary. | [
"Check",
"object",
"+",
"object",
"+",
"against",
"this",
"Message",
"instance",
"and",
"raise",
"a",
"CheckError",
"exception",
"if",
"necessary",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/message.rb#L190-L217 | train |
mtuchowski/mdspell | lib/mdspell/cli.rb | MdSpell.CLI.files | def files
cli_arguments.each_with_index do |filename, index|
if Dir.exist?(filename)
cli_arguments[index] = Dir["#{filename}/**/*.md"]
end
end
cli_arguments.flatten!
cli_arguments
end | ruby | def files
cli_arguments.each_with_index do |filename, index|
if Dir.exist?(filename)
cli_arguments[index] = Dir["#{filename}/**/*.md"]
end
end
cli_arguments.flatten!
cli_arguments
end | [
"def",
"files",
"cli_arguments",
".",
"each_with_index",
"do",
"|",
"filename",
",",
"index",
"|",
"if",
"Dir",
".",
"exist?",
"(",
"filename",
")",
"cli_arguments",
"[",
"index",
"]",
"=",
"Dir",
"[",
"\"#{filename}/**/*.md\"",
"]",
"end",
"end",
"cli_arguments",
".",
"flatten!",
"cli_arguments",
"end"
] | List of markdown files from argument list. | [
"List",
"of",
"markdown",
"files",
"from",
"argument",
"list",
"."
] | d8232366bbe12261a1e3a7763b0c8aa925d82b85 | https://github.com/mtuchowski/mdspell/blob/d8232366bbe12261a1e3a7763b0c8aa925d82b85/lib/mdspell/cli.rb#L59-L67 | train |
damian/jshint | lib/jshint/lint.rb | Jshint.Lint.lint | def lint
config.javascript_files.each do |file|
file_content = get_file_content_as_json(file)
code = %(
JSHINT(#{file_content}, #{jshint_options}, #{jshint_globals});
return JSHINT.errors;
)
errors[file] = context.exec(code)
end
end | ruby | def lint
config.javascript_files.each do |file|
file_content = get_file_content_as_json(file)
code = %(
JSHINT(#{file_content}, #{jshint_options}, #{jshint_globals});
return JSHINT.errors;
)
errors[file] = context.exec(code)
end
end | [
"def",
"lint",
"config",
".",
"javascript_files",
".",
"each",
"do",
"|",
"file",
"|",
"file_content",
"=",
"get_file_content_as_json",
"(",
"file",
")",
"code",
"=",
"%( JSHINT(#{file_content}, #{jshint_options}, #{jshint_globals}); return JSHINT.errors; )",
"errors",
"[",
"file",
"]",
"=",
"context",
".",
"exec",
"(",
"code",
")",
"end",
"end"
] | Sets up our Linting behaviour
@param config_path [String] The absolute path to a configuration YAML file
@return [void]
Runs JSHint over each file in our search path
@return [void] | [
"Sets",
"up",
"our",
"Linting",
"behaviour"
] | d7dc6f1913bad5927ac0de3e34714ef920e86cbe | https://github.com/damian/jshint/blob/d7dc6f1913bad5927ac0de3e34714ef920e86cbe/lib/jshint/lint.rb#L27-L36 | train |
hawkular/hawkular-client-ruby | lib/hawkular/base_client.rb | Hawkular.BaseClient.generate_query_params | def generate_query_params(params = {})
params = params.reject { |_k, v| v.nil? || ((v.instance_of? Array) && v.empty?) }
return '' if params.empty?
params.inject('?') do |ret, (k, v)|
ret += '&' unless ret == '?'
part = v.instance_of?(Array) ? "#{k}=#{v.join(',')}" : "#{k}=#{v}"
ret + hawk_escape(part)
end
end | ruby | def generate_query_params(params = {})
params = params.reject { |_k, v| v.nil? || ((v.instance_of? Array) && v.empty?) }
return '' if params.empty?
params.inject('?') do |ret, (k, v)|
ret += '&' unless ret == '?'
part = v.instance_of?(Array) ? "#{k}=#{v.join(',')}" : "#{k}=#{v}"
ret + hawk_escape(part)
end
end | [
"def",
"generate_query_params",
"(",
"params",
"=",
"{",
"}",
")",
"params",
"=",
"params",
".",
"reject",
"{",
"|",
"_k",
",",
"v",
"|",
"v",
".",
"nil?",
"||",
"(",
"(",
"v",
".",
"instance_of?",
"Array",
")",
"&&",
"v",
".",
"empty?",
")",
"}",
"return",
"''",
"if",
"params",
".",
"empty?",
"params",
".",
"inject",
"(",
"'?'",
")",
"do",
"|",
"ret",
",",
"(",
"k",
",",
"v",
")",
"|",
"ret",
"+=",
"'&'",
"unless",
"ret",
"==",
"'?'",
"part",
"=",
"v",
".",
"instance_of?",
"(",
"Array",
")",
"?",
"\"#{k}=#{v.join(',')}\"",
":",
"\"#{k}=#{v}\"",
"ret",
"+",
"hawk_escape",
"(",
"part",
")",
"end",
"end"
] | Generate a query string from the passed hash, starting with '?'
Values may be an array, in which case the array values are joined together by `,`.
@param params [Hash] key-values pairs
@return [String] complete query string to append to a base url, '' if no valid params | [
"Generate",
"a",
"query",
"string",
"from",
"the",
"passed",
"hash",
"starting",
"with",
"?",
"Values",
"may",
"be",
"an",
"array",
"in",
"which",
"case",
"the",
"array",
"values",
"are",
"joined",
"together",
"by",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/base_client.rb#L133-L142 | train |
paddor/cztop | lib/cztop/message.rb | CZTop.Message.<< | def <<(frame)
case frame
when String
# NOTE: can't use addstr because the data might be binary
mem = FFI::MemoryPointer.from_string(frame)
rc = ffi_delegate.addmem(mem, mem.size - 1) # without NULL byte
when Frame
rc = ffi_delegate.append(frame.ffi_delegate)
else
raise ArgumentError, "invalid frame: %p" % frame
end
raise_zmq_err unless rc == 0
self
end | ruby | def <<(frame)
case frame
when String
# NOTE: can't use addstr because the data might be binary
mem = FFI::MemoryPointer.from_string(frame)
rc = ffi_delegate.addmem(mem, mem.size - 1) # without NULL byte
when Frame
rc = ffi_delegate.append(frame.ffi_delegate)
else
raise ArgumentError, "invalid frame: %p" % frame
end
raise_zmq_err unless rc == 0
self
end | [
"def",
"<<",
"(",
"frame",
")",
"case",
"frame",
"when",
"String",
"mem",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"from_string",
"(",
"frame",
")",
"rc",
"=",
"ffi_delegate",
".",
"addmem",
"(",
"mem",
",",
"mem",
".",
"size",
"-",
"1",
")",
"when",
"Frame",
"rc",
"=",
"ffi_delegate",
".",
"append",
"(",
"frame",
".",
"ffi_delegate",
")",
"else",
"raise",
"ArgumentError",
",",
"\"invalid frame: %p\"",
"%",
"frame",
"end",
"raise_zmq_err",
"unless",
"rc",
"==",
"0",
"self",
"end"
] | Append a frame to this message.
@param frame [String, Frame] what to append
@raise [ArgumentError] if frame has an invalid type
@raise [SystemCallError] if this fails
@note If you provide a {Frame}, do NOT use that frame afterwards
anymore, as its native counterpart will have been destroyed.
@return [self] so it can be chained | [
"Append",
"a",
"frame",
"to",
"this",
"message",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/message.rb#L88-L101 | train |
paddor/cztop | lib/cztop/message.rb | CZTop.Message.prepend | def prepend(frame)
case frame
when String
# NOTE: can't use pushstr because the data might be binary
mem = FFI::MemoryPointer.from_string(frame)
rc = ffi_delegate.pushmem(mem, mem.size - 1) # without NULL byte
when Frame
rc = ffi_delegate.prepend(frame.ffi_delegate)
else
raise ArgumentError, "invalid frame: %p" % frame
end
raise_zmq_err unless rc == 0
end | ruby | def prepend(frame)
case frame
when String
# NOTE: can't use pushstr because the data might be binary
mem = FFI::MemoryPointer.from_string(frame)
rc = ffi_delegate.pushmem(mem, mem.size - 1) # without NULL byte
when Frame
rc = ffi_delegate.prepend(frame.ffi_delegate)
else
raise ArgumentError, "invalid frame: %p" % frame
end
raise_zmq_err unless rc == 0
end | [
"def",
"prepend",
"(",
"frame",
")",
"case",
"frame",
"when",
"String",
"mem",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"from_string",
"(",
"frame",
")",
"rc",
"=",
"ffi_delegate",
".",
"pushmem",
"(",
"mem",
",",
"mem",
".",
"size",
"-",
"1",
")",
"when",
"Frame",
"rc",
"=",
"ffi_delegate",
".",
"prepend",
"(",
"frame",
".",
"ffi_delegate",
")",
"else",
"raise",
"ArgumentError",
",",
"\"invalid frame: %p\"",
"%",
"frame",
"end",
"raise_zmq_err",
"unless",
"rc",
"==",
"0",
"end"
] | Prepend a frame to this message.
@param frame [String, Frame] what to prepend
@raise [ArgumentError] if frame has an invalid type
@raise [SystemCallError] if this fails
@note If you provide a {Frame}, do NOT use that frame afterwards
anymore, as its native counterpart will have been destroyed.
@return [void] | [
"Prepend",
"a",
"frame",
"to",
"this",
"message",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/message.rb#L110-L122 | train |
paddor/cztop | lib/cztop/message.rb | CZTop.Message.pop | def pop
# NOTE: can't use popstr because the data might be binary
ptr = ffi_delegate.pop
return nil if ptr.null?
Frame.from_ffi_delegate(ptr).to_s
end | ruby | def pop
# NOTE: can't use popstr because the data might be binary
ptr = ffi_delegate.pop
return nil if ptr.null?
Frame.from_ffi_delegate(ptr).to_s
end | [
"def",
"pop",
"ptr",
"=",
"ffi_delegate",
".",
"pop",
"return",
"nil",
"if",
"ptr",
".",
"null?",
"Frame",
".",
"from_ffi_delegate",
"(",
"ptr",
")",
".",
"to_s",
"end"
] | Removes first part from message and returns it as a string.
@return [String, nil] first part, if any, or nil | [
"Removes",
"first",
"part",
"from",
"message",
"and",
"returns",
"it",
"as",
"a",
"string",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/message.rb#L126-L131 | train |
paddor/cztop | lib/cztop/message.rb | CZTop.Message.to_a | def to_a
ffi_delegate = ffi_delegate()
frame = ffi_delegate.first
return [] if frame.null?
arr = [ frame.data.read_bytes(frame.size) ]
while frame = ffi_delegate.next and not frame.null?
arr << frame.data.read_bytes(frame.size)
end
return arr
end | ruby | def to_a
ffi_delegate = ffi_delegate()
frame = ffi_delegate.first
return [] if frame.null?
arr = [ frame.data.read_bytes(frame.size) ]
while frame = ffi_delegate.next and not frame.null?
arr << frame.data.read_bytes(frame.size)
end
return arr
end | [
"def",
"to_a",
"ffi_delegate",
"=",
"ffi_delegate",
"(",
")",
"frame",
"=",
"ffi_delegate",
".",
"first",
"return",
"[",
"]",
"if",
"frame",
".",
"null?",
"arr",
"=",
"[",
"frame",
".",
"data",
".",
"read_bytes",
"(",
"frame",
".",
"size",
")",
"]",
"while",
"frame",
"=",
"ffi_delegate",
".",
"next",
"and",
"not",
"frame",
".",
"null?",
"arr",
"<<",
"frame",
".",
"data",
".",
"read_bytes",
"(",
"frame",
".",
"size",
")",
"end",
"return",
"arr",
"end"
] | Returns all frames as strings in an array. This is useful if for quick
inspection of the message.
@note It'll read all frames in the message and turn them into Ruby
strings. This can be a problem if the message is huge/has huge frames.
@return [Array<String>] all frames | [
"Returns",
"all",
"frames",
"as",
"strings",
"in",
"an",
"array",
".",
"This",
"is",
"useful",
"if",
"for",
"quick",
"inspection",
"of",
"the",
"message",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/message.rb#L144-L155 | train |
paddor/cztop | lib/cztop/message.rb | CZTop.Message.routing_id= | def routing_id=(new_routing_id)
raise ArgumentError unless new_routing_id.is_a? Integer
# need to raise manually, as FFI lacks this feature.
# @see https://github.com/ffi/ffi/issues/473
raise RangeError if new_routing_id < 0
ffi_delegate.set_routing_id(new_routing_id)
end | ruby | def routing_id=(new_routing_id)
raise ArgumentError unless new_routing_id.is_a? Integer
# need to raise manually, as FFI lacks this feature.
# @see https://github.com/ffi/ffi/issues/473
raise RangeError if new_routing_id < 0
ffi_delegate.set_routing_id(new_routing_id)
end | [
"def",
"routing_id",
"=",
"(",
"new_routing_id",
")",
"raise",
"ArgumentError",
"unless",
"new_routing_id",
".",
"is_a?",
"Integer",
"raise",
"RangeError",
"if",
"new_routing_id",
"<",
"0",
"ffi_delegate",
".",
"set_routing_id",
"(",
"new_routing_id",
")",
"end"
] | Sets a new routing ID.
@note This is used when the message is sent to a {CZTop::Socket::SERVER}
socket.
@param new_routing_id [Integer] new routing ID
@raise [ArgumentError] if new routing ID is not an Integer
@raise [RangeError] if new routing ID is out of +uint32_t+ range
@return [new_routing_id] | [
"Sets",
"a",
"new",
"routing",
"ID",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/message.rb#L191-L198 | train |
gverger/ruby-cbc | lib/ruby-cbc/conflict_solver.rb | Cbc.ConflictSolver.first_failing | def first_failing(conflict_set_size, crs, continuous: false, max_iterations: nil)
min_idx = conflict_set_size
max_idx = crs.nb_constraints - 1
loop do
unless max_iterations.nil?
return min_idx..max_idx if max_iterations <= 0
max_iterations -= 1
end
half_constraint_idx = (max_idx + min_idx) / 2
# puts "Refining: [#{min_idx}:#{max_idx}] -> #{half_constraint_idx}"
crs2 = crs.restrict_to_n_constraints(half_constraint_idx + 1)
problem = Problem.from_compressed_row_storage(crs2, continuous: continuous)
if infeasible?(problem)
max_idx = half_constraint_idx
# puts " INFEAS"
else
min_idx = half_constraint_idx + 1
# puts " FEAS"
end
next if max_idx != min_idx
return nil if max_idx > crs.nb_constraints
return min_idx..max_idx
end
# Shouldn't come here if the whole problem is infeasible
nil
end | ruby | def first_failing(conflict_set_size, crs, continuous: false, max_iterations: nil)
min_idx = conflict_set_size
max_idx = crs.nb_constraints - 1
loop do
unless max_iterations.nil?
return min_idx..max_idx if max_iterations <= 0
max_iterations -= 1
end
half_constraint_idx = (max_idx + min_idx) / 2
# puts "Refining: [#{min_idx}:#{max_idx}] -> #{half_constraint_idx}"
crs2 = crs.restrict_to_n_constraints(half_constraint_idx + 1)
problem = Problem.from_compressed_row_storage(crs2, continuous: continuous)
if infeasible?(problem)
max_idx = half_constraint_idx
# puts " INFEAS"
else
min_idx = half_constraint_idx + 1
# puts " FEAS"
end
next if max_idx != min_idx
return nil if max_idx > crs.nb_constraints
return min_idx..max_idx
end
# Shouldn't come here if the whole problem is infeasible
nil
end | [
"def",
"first_failing",
"(",
"conflict_set_size",
",",
"crs",
",",
"continuous",
":",
"false",
",",
"max_iterations",
":",
"nil",
")",
"min_idx",
"=",
"conflict_set_size",
"max_idx",
"=",
"crs",
".",
"nb_constraints",
"-",
"1",
"loop",
"do",
"unless",
"max_iterations",
".",
"nil?",
"return",
"min_idx",
"..",
"max_idx",
"if",
"max_iterations",
"<=",
"0",
"max_iterations",
"-=",
"1",
"end",
"half_constraint_idx",
"=",
"(",
"max_idx",
"+",
"min_idx",
")",
"/",
"2",
"crs2",
"=",
"crs",
".",
"restrict_to_n_constraints",
"(",
"half_constraint_idx",
"+",
"1",
")",
"problem",
"=",
"Problem",
".",
"from_compressed_row_storage",
"(",
"crs2",
",",
"continuous",
":",
"continuous",
")",
"if",
"infeasible?",
"(",
"problem",
")",
"max_idx",
"=",
"half_constraint_idx",
"else",
"min_idx",
"=",
"half_constraint_idx",
"+",
"1",
"end",
"next",
"if",
"max_idx",
"!=",
"min_idx",
"return",
"nil",
"if",
"max_idx",
">",
"crs",
".",
"nb_constraints",
"return",
"min_idx",
"..",
"max_idx",
"end",
"nil",
"end"
] | finds the first constraint from constraints that makes the problem infeasible | [
"finds",
"the",
"first",
"constraint",
"from",
"constraints",
"that",
"makes",
"the",
"problem",
"infeasible"
] | e3dfbc3a9f4bb74c13748c9a0fe924f48de0215c | https://github.com/gverger/ruby-cbc/blob/e3dfbc3a9f4bb74c13748c9a0fe924f48de0215c/lib/ruby-cbc/conflict_solver.rb#L69-L95 | train |
masciugo/genealogy | lib/genealogy/alter_methods.rb | Genealogy.AlterMethods.add_siblings | def add_siblings(*args)
options = args.extract_options!
case options[:half]
when :father
check_incompatible_relationship(:paternal_half_sibling, *args)
when :mother
check_incompatible_relationship(:maternal_half_sibling, *args)
when nil
check_incompatible_relationship(:sibling, *args)
end
transaction do
args.inject(true) do |res,sib|
res &= case options[:half]
when :father
raise LineageGapException, "Can't add paternal halfsiblings without a father" unless father
sib.add_mother(options[:spouse]) if options[:spouse]
sib.add_father(father)
when :mother
raise LineageGapException, "Can't add maternal halfsiblings without a mother" unless mother
sib.add_father(options[:spouse]) if options[:spouse]
sib.add_mother(mother)
when nil
raise LineageGapException, "Can't add siblings without parents" unless father and mother
sib.add_father(father)
sib.add_mother(mother)
else
raise ArgumentError, "Admitted values for :half options are: :father, :mother or nil"
end
end
end
end | ruby | def add_siblings(*args)
options = args.extract_options!
case options[:half]
when :father
check_incompatible_relationship(:paternal_half_sibling, *args)
when :mother
check_incompatible_relationship(:maternal_half_sibling, *args)
when nil
check_incompatible_relationship(:sibling, *args)
end
transaction do
args.inject(true) do |res,sib|
res &= case options[:half]
when :father
raise LineageGapException, "Can't add paternal halfsiblings without a father" unless father
sib.add_mother(options[:spouse]) if options[:spouse]
sib.add_father(father)
when :mother
raise LineageGapException, "Can't add maternal halfsiblings without a mother" unless mother
sib.add_father(options[:spouse]) if options[:spouse]
sib.add_mother(mother)
when nil
raise LineageGapException, "Can't add siblings without parents" unless father and mother
sib.add_father(father)
sib.add_mother(mother)
else
raise ArgumentError, "Admitted values for :half options are: :father, :mother or nil"
end
end
end
end | [
"def",
"add_siblings",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"extract_options!",
"case",
"options",
"[",
":half",
"]",
"when",
":father",
"check_incompatible_relationship",
"(",
":paternal_half_sibling",
",",
"*",
"args",
")",
"when",
":mother",
"check_incompatible_relationship",
"(",
":maternal_half_sibling",
",",
"*",
"args",
")",
"when",
"nil",
"check_incompatible_relationship",
"(",
":sibling",
",",
"*",
"args",
")",
"end",
"transaction",
"do",
"args",
".",
"inject",
"(",
"true",
")",
"do",
"|",
"res",
",",
"sib",
"|",
"res",
"&=",
"case",
"options",
"[",
":half",
"]",
"when",
":father",
"raise",
"LineageGapException",
",",
"\"Can't add paternal halfsiblings without a father\"",
"unless",
"father",
"sib",
".",
"add_mother",
"(",
"options",
"[",
":spouse",
"]",
")",
"if",
"options",
"[",
":spouse",
"]",
"sib",
".",
"add_father",
"(",
"father",
")",
"when",
":mother",
"raise",
"LineageGapException",
",",
"\"Can't add maternal halfsiblings without a mother\"",
"unless",
"mother",
"sib",
".",
"add_father",
"(",
"options",
"[",
":spouse",
"]",
")",
"if",
"options",
"[",
":spouse",
"]",
"sib",
".",
"add_mother",
"(",
"mother",
")",
"when",
"nil",
"raise",
"LineageGapException",
",",
"\"Can't add siblings without parents\"",
"unless",
"father",
"and",
"mother",
"sib",
".",
"add_father",
"(",
"father",
")",
"sib",
".",
"add_mother",
"(",
"mother",
")",
"else",
"raise",
"ArgumentError",
",",
"\"Admitted values for :half options are: :father, :mother or nil\"",
"end",
"end",
"end",
"end"
] | add siblings by assigning same parents to individuals passed as arguments
@overload add_siblings(*siblings,options={})
@param [Object] siblings list of siblings
@param [Hash] options
@option options [Symbol] half :father for paternal half siblings and :mother for maternal half siblings
@option options [Object] spouse if specified, passed individual will be used as mother in case of half sibling
@return [Boolean] | [
"add",
"siblings",
"by",
"assigning",
"same",
"parents",
"to",
"individuals",
"passed",
"as",
"arguments"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/alter_methods.rb#L176-L207 | train |
masciugo/genealogy | lib/genealogy/alter_methods.rb | Genealogy.AlterMethods.remove_siblings | def remove_siblings(*args)
options = args.extract_options!
raise ArgumentError.new("Unknown option value: half: #{options[:half]}.") if (options[:half] and ![:father,:mother].include?(options[:half]))
resulting_indivs = if args.blank?
siblings(options)
else
args & siblings(options)
end
transaction do
resulting_indivs.each do |sib|
case options[:half]
when :father
sib.remove_father
sib.remove_mother if options[:remove_other_parent] == true
when :mother
sib.remove_father if options[:remove_other_parent] == true
sib.remove_mother
when nil
sib.remove_parents
end
end
end
!resulting_indivs.empty? #returned value must be true if self has at least a siblings to affect
end | ruby | def remove_siblings(*args)
options = args.extract_options!
raise ArgumentError.new("Unknown option value: half: #{options[:half]}.") if (options[:half] and ![:father,:mother].include?(options[:half]))
resulting_indivs = if args.blank?
siblings(options)
else
args & siblings(options)
end
transaction do
resulting_indivs.each do |sib|
case options[:half]
when :father
sib.remove_father
sib.remove_mother if options[:remove_other_parent] == true
when :mother
sib.remove_father if options[:remove_other_parent] == true
sib.remove_mother
when nil
sib.remove_parents
end
end
end
!resulting_indivs.empty? #returned value must be true if self has at least a siblings to affect
end | [
"def",
"remove_siblings",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"extract_options!",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Unknown option value: half: #{options[:half]}.\"",
")",
"if",
"(",
"options",
"[",
":half",
"]",
"and",
"!",
"[",
":father",
",",
":mother",
"]",
".",
"include?",
"(",
"options",
"[",
":half",
"]",
")",
")",
"resulting_indivs",
"=",
"if",
"args",
".",
"blank?",
"siblings",
"(",
"options",
")",
"else",
"args",
"&",
"siblings",
"(",
"options",
")",
"end",
"transaction",
"do",
"resulting_indivs",
".",
"each",
"do",
"|",
"sib",
"|",
"case",
"options",
"[",
":half",
"]",
"when",
":father",
"sib",
".",
"remove_father",
"sib",
".",
"remove_mother",
"if",
"options",
"[",
":remove_other_parent",
"]",
"==",
"true",
"when",
":mother",
"sib",
".",
"remove_father",
"if",
"options",
"[",
":remove_other_parent",
"]",
"==",
"true",
"sib",
".",
"remove_mother",
"when",
"nil",
"sib",
".",
"remove_parents",
"end",
"end",
"end",
"!",
"resulting_indivs",
".",
"empty?",
"end"
] | remove siblings by nullifying parents of passed individuals
@overload remove_siblings(*siblings,options={})
@param [Object] siblings list of siblings
@param [Hash] options
@option options [Symbol] half :father for paternal half siblings and :mother for maternal half siblings
@option options [Boolean] remove_other_parent if specified, passed individuals' mother will also be nullified
@return [Boolean] true if at least one sibling was affected, false otherwise | [
"remove",
"siblings",
"by",
"nullifying",
"parents",
"of",
"passed",
"individuals"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/alter_methods.rb#L238-L261 | train |
masciugo/genealogy | lib/genealogy/alter_methods.rb | Genealogy.AlterMethods.add_children | def add_children(*args)
options = args.extract_options!
raise_if_sex_undefined
check_incompatible_relationship(:children, *args)
transaction do
args.inject(true) do |res,child|
res &= case sex_before_type_cast
when gclass.sex_male_value
child.add_mother(options[:spouse]) if options[:spouse]
child.add_father(self)
when gclass.sex_female_value
child.add_father(options[:spouse]) if options[:spouse]
child.add_mother(self)
else
raise SexError, "Sex value not valid for #{self}"
end
end
end
end | ruby | def add_children(*args)
options = args.extract_options!
raise_if_sex_undefined
check_incompatible_relationship(:children, *args)
transaction do
args.inject(true) do |res,child|
res &= case sex_before_type_cast
when gclass.sex_male_value
child.add_mother(options[:spouse]) if options[:spouse]
child.add_father(self)
when gclass.sex_female_value
child.add_father(options[:spouse]) if options[:spouse]
child.add_mother(self)
else
raise SexError, "Sex value not valid for #{self}"
end
end
end
end | [
"def",
"add_children",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"extract_options!",
"raise_if_sex_undefined",
"check_incompatible_relationship",
"(",
":children",
",",
"*",
"args",
")",
"transaction",
"do",
"args",
".",
"inject",
"(",
"true",
")",
"do",
"|",
"res",
",",
"child",
"|",
"res",
"&=",
"case",
"sex_before_type_cast",
"when",
"gclass",
".",
"sex_male_value",
"child",
".",
"add_mother",
"(",
"options",
"[",
":spouse",
"]",
")",
"if",
"options",
"[",
":spouse",
"]",
"child",
".",
"add_father",
"(",
"self",
")",
"when",
"gclass",
".",
"sex_female_value",
"child",
".",
"add_father",
"(",
"options",
"[",
":spouse",
"]",
")",
"if",
"options",
"[",
":spouse",
"]",
"child",
".",
"add_mother",
"(",
"self",
")",
"else",
"raise",
"SexError",
",",
"\"Sex value not valid for #{self}\"",
"end",
"end",
"end",
"end"
] | add children by assigning self as parent
@overload add_children(*children,options={})
@param [Object] children list of children
@param [Hash] options
@option options [Object] spouse if specified, children will have that spouse
@return [Boolean] | [
"add",
"children",
"by",
"assigning",
"self",
"as",
"parent"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/alter_methods.rb#L292-L310 | train |
masciugo/genealogy | lib/genealogy/alter_methods.rb | Genealogy.AlterMethods.remove_children | def remove_children(*args)
options = args.extract_options!
raise_if_sex_undefined
resulting_indivs = if args.blank?
children(options)
else
args & children(options)
end
transaction do
resulting_indivs.each do |child|
if options[:remove_other_parent] == true
child.remove_parents
else
case sex_before_type_cast
when gclass.sex_male_value
child.remove_father
when gclass.sex_female_value
child.remove_mother
else
raise SexError, "Sex value not valid for #{self}"
end
end
end
end
!resulting_indivs.empty? #returned value must be true if self has at least a siblings to affect
end | ruby | def remove_children(*args)
options = args.extract_options!
raise_if_sex_undefined
resulting_indivs = if args.blank?
children(options)
else
args & children(options)
end
transaction do
resulting_indivs.each do |child|
if options[:remove_other_parent] == true
child.remove_parents
else
case sex_before_type_cast
when gclass.sex_male_value
child.remove_father
when gclass.sex_female_value
child.remove_mother
else
raise SexError, "Sex value not valid for #{self}"
end
end
end
end
!resulting_indivs.empty? #returned value must be true if self has at least a siblings to affect
end | [
"def",
"remove_children",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"extract_options!",
"raise_if_sex_undefined",
"resulting_indivs",
"=",
"if",
"args",
".",
"blank?",
"children",
"(",
"options",
")",
"else",
"args",
"&",
"children",
"(",
"options",
")",
"end",
"transaction",
"do",
"resulting_indivs",
".",
"each",
"do",
"|",
"child",
"|",
"if",
"options",
"[",
":remove_other_parent",
"]",
"==",
"true",
"child",
".",
"remove_parents",
"else",
"case",
"sex_before_type_cast",
"when",
"gclass",
".",
"sex_male_value",
"child",
".",
"remove_father",
"when",
"gclass",
".",
"sex_female_value",
"child",
".",
"remove_mother",
"else",
"raise",
"SexError",
",",
"\"Sex value not valid for #{self}\"",
"end",
"end",
"end",
"end",
"!",
"resulting_indivs",
".",
"empty?",
"end"
] | remove children by nullifying the parent corresponding to self
@overload remove_children(*children,options={})
@param [Object] children list of children
@param [Hash] options
@option options [Boolean] remove_other_parent if specified, passed individuals' mother will also be nullified
@return [Boolean] true if at least one child was affected, false otherwise | [
"remove",
"children",
"by",
"nullifying",
"the",
"parent",
"corresponding",
"to",
"self"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/alter_methods.rb#L323-L351 | train |
masciugo/genealogy | lib/genealogy/current_spouse_methods.rb | Genealogy.CurrentSpouseMethods.add_current_spouse | def add_current_spouse(spouse)
raise_unless_current_spouse_enabled
check_incompatible_relationship(:current_spouse,spouse)
if gclass.perform_validation_enabled
self.current_spouse = spouse
spouse.current_spouse = self
transaction do
spouse.save!
save!
end
else
transaction do
self.update_attribute(:current_spouse,spouse)
spouse.update_attribute(:current_spouse,self)
end
end
end | ruby | def add_current_spouse(spouse)
raise_unless_current_spouse_enabled
check_incompatible_relationship(:current_spouse,spouse)
if gclass.perform_validation_enabled
self.current_spouse = spouse
spouse.current_spouse = self
transaction do
spouse.save!
save!
end
else
transaction do
self.update_attribute(:current_spouse,spouse)
spouse.update_attribute(:current_spouse,self)
end
end
end | [
"def",
"add_current_spouse",
"(",
"spouse",
")",
"raise_unless_current_spouse_enabled",
"check_incompatible_relationship",
"(",
":current_spouse",
",",
"spouse",
")",
"if",
"gclass",
".",
"perform_validation_enabled",
"self",
".",
"current_spouse",
"=",
"spouse",
"spouse",
".",
"current_spouse",
"=",
"self",
"transaction",
"do",
"spouse",
".",
"save!",
"save!",
"end",
"else",
"transaction",
"do",
"self",
".",
"update_attribute",
"(",
":current_spouse",
",",
"spouse",
")",
"spouse",
".",
"update_attribute",
"(",
":current_spouse",
",",
"self",
")",
"end",
"end",
"end"
] | add current spouse updating receiver and argument individuals foreign_key in a transaction
@param [Object] spouse
@return [Boolean] | [
"add",
"current",
"spouse",
"updating",
"receiver",
"and",
"argument",
"individuals",
"foreign_key",
"in",
"a",
"transaction"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/current_spouse_methods.rb#L11-L30 | train |
masciugo/genealogy | lib/genealogy/current_spouse_methods.rb | Genealogy.CurrentSpouseMethods.remove_current_spouse | def remove_current_spouse
raise_unless_current_spouse_enabled
if gclass.perform_validation_enabled
ex_current_spouse = current_spouse
current_spouse.current_spouse = nil
self.current_spouse = nil
transaction do
ex_current_spouse.save!
save!
end
else
transaction do
current_spouse.update_attribute(:current_spouse,nil)
self.update_attribute(:current_spouse,nil)
end
end
end | ruby | def remove_current_spouse
raise_unless_current_spouse_enabled
if gclass.perform_validation_enabled
ex_current_spouse = current_spouse
current_spouse.current_spouse = nil
self.current_spouse = nil
transaction do
ex_current_spouse.save!
save!
end
else
transaction do
current_spouse.update_attribute(:current_spouse,nil)
self.update_attribute(:current_spouse,nil)
end
end
end | [
"def",
"remove_current_spouse",
"raise_unless_current_spouse_enabled",
"if",
"gclass",
".",
"perform_validation_enabled",
"ex_current_spouse",
"=",
"current_spouse",
"current_spouse",
".",
"current_spouse",
"=",
"nil",
"self",
".",
"current_spouse",
"=",
"nil",
"transaction",
"do",
"ex_current_spouse",
".",
"save!",
"save!",
"end",
"else",
"transaction",
"do",
"current_spouse",
".",
"update_attribute",
"(",
":current_spouse",
",",
"nil",
")",
"self",
".",
"update_attribute",
"(",
":current_spouse",
",",
"nil",
")",
"end",
"end",
"end"
] | remove current spouse resetting receiver and argument individuals foreign_key in a transaction
@return [Boolean] | [
"remove",
"current",
"spouse",
"resetting",
"receiver",
"and",
"argument",
"individuals",
"foreign_key",
"in",
"a",
"transaction"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/current_spouse_methods.rb#L34-L50 | train |
paddor/cztop | lib/cztop/poller/zpoller.rb | CZTop.Poller::ZPoller.add | def add(reader)
rc = ffi_delegate.add(reader)
raise_zmq_err("unable to add socket %p" % reader) if rc == -1
remember_socket(reader)
end | ruby | def add(reader)
rc = ffi_delegate.add(reader)
raise_zmq_err("unable to add socket %p" % reader) if rc == -1
remember_socket(reader)
end | [
"def",
"add",
"(",
"reader",
")",
"rc",
"=",
"ffi_delegate",
".",
"add",
"(",
"reader",
")",
"raise_zmq_err",
"(",
"\"unable to add socket %p\"",
"%",
"reader",
")",
"if",
"rc",
"==",
"-",
"1",
"remember_socket",
"(",
"reader",
")",
"end"
] | Initializes the Poller. At least one reader has to be given.
@param reader [Socket, Actor] socket to poll for input
@param readers [Socket, Actor] any additional sockets to poll for input
Adds another reader socket to the poller.
@param reader [Socket, Actor] socket to poll for input
@return [void]
@raise [SystemCallError] if this fails | [
"Initializes",
"the",
"Poller",
".",
"At",
"least",
"one",
"reader",
"has",
"to",
"be",
"given",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller/zpoller.rb#L29-L33 | train |
paddor/cztop | lib/cztop/poller/zpoller.rb | CZTop.Poller::ZPoller.remove | def remove(reader)
rc = ffi_delegate.remove(reader)
raise_zmq_err("unable to remove socket %p" % reader) if rc == -1
forget_socket(reader)
end | ruby | def remove(reader)
rc = ffi_delegate.remove(reader)
raise_zmq_err("unable to remove socket %p" % reader) if rc == -1
forget_socket(reader)
end | [
"def",
"remove",
"(",
"reader",
")",
"rc",
"=",
"ffi_delegate",
".",
"remove",
"(",
"reader",
")",
"raise_zmq_err",
"(",
"\"unable to remove socket %p\"",
"%",
"reader",
")",
"if",
"rc",
"==",
"-",
"1",
"forget_socket",
"(",
"reader",
")",
"end"
] | Removes a reader socket from the poller.
@param reader [Socket, Actor] socket to remove
@return [void]
@raise [ArgumentError] if socket was invalid, e.g. it wasn't registered
in this poller
@raise [SystemCallError] if this fails for another reason | [
"Removes",
"a",
"reader",
"socket",
"from",
"the",
"poller",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller/zpoller.rb#L41-L45 | train |
paddor/cztop | lib/cztop/poller/zpoller.rb | CZTop.Poller::ZPoller.wait | def wait(timeout = -1)
ptr = ffi_delegate.wait(timeout)
if ptr.null?
raise Interrupt if ffi_delegate.terminated
return nil
end
return socket_by_ptr(ptr)
end | ruby | def wait(timeout = -1)
ptr = ffi_delegate.wait(timeout)
if ptr.null?
raise Interrupt if ffi_delegate.terminated
return nil
end
return socket_by_ptr(ptr)
end | [
"def",
"wait",
"(",
"timeout",
"=",
"-",
"1",
")",
"ptr",
"=",
"ffi_delegate",
".",
"wait",
"(",
"timeout",
")",
"if",
"ptr",
".",
"null?",
"raise",
"Interrupt",
"if",
"ffi_delegate",
".",
"terminated",
"return",
"nil",
"end",
"return",
"socket_by_ptr",
"(",
"ptr",
")",
"end"
] | Waits and returns the first socket that becomes readable.
@param timeout [Integer] how long to wait in ms, or 0 to avoid
blocking, or -1 to wait indefinitely
@return [Socket, Actor] first socket of interest
@return [nil] if the timeout expired or
@raise [Interrupt] if the timeout expired or | [
"Waits",
"and",
"returns",
"the",
"first",
"socket",
"that",
"becomes",
"readable",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller/zpoller.rb#L53-L60 | train |
mtuchowski/mdspell | lib/mdspell/spell_checker.rb | MdSpell.SpellChecker.typos | def typos
results = []
FFI::Aspell::Speller.open(Configuration[:language]) do |speller|
TextLine.scan(document).each do |line|
line.words.each do |word|
next if ignored? word
unless speller.correct? word
results << Typo.new(line, word, speller.suggestions(word))
end
end
end
end
results
end | ruby | def typos
results = []
FFI::Aspell::Speller.open(Configuration[:language]) do |speller|
TextLine.scan(document).each do |line|
line.words.each do |word|
next if ignored? word
unless speller.correct? word
results << Typo.new(line, word, speller.suggestions(word))
end
end
end
end
results
end | [
"def",
"typos",
"results",
"=",
"[",
"]",
"FFI",
"::",
"Aspell",
"::",
"Speller",
".",
"open",
"(",
"Configuration",
"[",
":language",
"]",
")",
"do",
"|",
"speller",
"|",
"TextLine",
".",
"scan",
"(",
"document",
")",
".",
"each",
"do",
"|",
"line",
"|",
"line",
".",
"words",
".",
"each",
"do",
"|",
"word",
"|",
"next",
"if",
"ignored?",
"word",
"unless",
"speller",
".",
"correct?",
"word",
"results",
"<<",
"Typo",
".",
"new",
"(",
"line",
",",
"word",
",",
"speller",
".",
"suggestions",
"(",
"word",
")",
")",
"end",
"end",
"end",
"end",
"results",
"end"
] | Create a new instance from specified file.
@param filename [String] a name of file to load.
Returns found spelling errors. | [
"Create",
"a",
"new",
"instance",
"from",
"specified",
"file",
"."
] | d8232366bbe12261a1e3a7763b0c8aa925d82b85 | https://github.com/mtuchowski/mdspell/blob/d8232366bbe12261a1e3a7763b0c8aa925d82b85/lib/mdspell/spell_checker.rb#L30-L44 | train |
hawkular/hawkular-client-ruby | lib/hawkular/metrics/metric_api.rb | Hawkular::Metrics.Client.data_by_tags | def data_by_tags(tags, buckets: nil, bucketDuration: nil, # rubocop:disable Naming/VariableName
start: nil, ends: nil)
data = {
tags: tags_param(tags), buckets: buckets, bucketDuration: bucketDuration, start: start, end: ends
}
http_post('metrics/stats/query', data)
end | ruby | def data_by_tags(tags, buckets: nil, bucketDuration: nil, # rubocop:disable Naming/VariableName
start: nil, ends: nil)
data = {
tags: tags_param(tags), buckets: buckets, bucketDuration: bucketDuration, start: start, end: ends
}
http_post('metrics/stats/query', data)
end | [
"def",
"data_by_tags",
"(",
"tags",
",",
"buckets",
":",
"nil",
",",
"bucketDuration",
":",
"nil",
",",
"start",
":",
"nil",
",",
"ends",
":",
"nil",
")",
"data",
"=",
"{",
"tags",
":",
"tags_param",
"(",
"tags",
")",
",",
"buckets",
":",
"buckets",
",",
"bucketDuration",
":",
"bucketDuration",
",",
"start",
":",
"start",
",",
"end",
":",
"ends",
"}",
"http_post",
"(",
"'metrics/stats/query'",
",",
"data",
")",
"end"
] | Retrieve all types of metrics datapoints by tags
@param tags [Hash]
@param buckets [Integer] optional number of buckets
@param bucketDuration [String] optional interval (default no aggregation)
@param starts [Integer] optional timestamp (default now - 8h)
@param ends [Integer] optional timestamp (default now)
@return [Array[Hash]] datapoints | [
"Retrieve",
"all",
"types",
"of",
"metrics",
"datapoints",
"by",
"tags"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/metrics/metric_api.rb#L26-L33 | train |
hawkular/hawkular-client-ruby | lib/hawkular/metrics/metric_api.rb | Hawkular::Metrics.Client.push_data | def push_data(gauges: [], counters: [], availabilities: [], strings: [])
gauges.each { |g| default_timestamp g[:data] }
counters.each { |g| default_timestamp g[:data] }
availabilities.each { |g| default_timestamp g[:data] }
strings.each { |g| default_timestamp g[:data] }
data = { gauges: gauges, counters: counters, availabilities: availabilities, strings: strings }
path = '/metrics/'
path << (@legacy_api ? 'data' : 'raw')
http_post(path, data)
end | ruby | def push_data(gauges: [], counters: [], availabilities: [], strings: [])
gauges.each { |g| default_timestamp g[:data] }
counters.each { |g| default_timestamp g[:data] }
availabilities.each { |g| default_timestamp g[:data] }
strings.each { |g| default_timestamp g[:data] }
data = { gauges: gauges, counters: counters, availabilities: availabilities, strings: strings }
path = '/metrics/'
path << (@legacy_api ? 'data' : 'raw')
http_post(path, data)
end | [
"def",
"push_data",
"(",
"gauges",
":",
"[",
"]",
",",
"counters",
":",
"[",
"]",
",",
"availabilities",
":",
"[",
"]",
",",
"strings",
":",
"[",
"]",
")",
"gauges",
".",
"each",
"{",
"|",
"g",
"|",
"default_timestamp",
"g",
"[",
":data",
"]",
"}",
"counters",
".",
"each",
"{",
"|",
"g",
"|",
"default_timestamp",
"g",
"[",
":data",
"]",
"}",
"availabilities",
".",
"each",
"{",
"|",
"g",
"|",
"default_timestamp",
"g",
"[",
":data",
"]",
"}",
"strings",
".",
"each",
"{",
"|",
"g",
"|",
"default_timestamp",
"g",
"[",
":data",
"]",
"}",
"data",
"=",
"{",
"gauges",
":",
"gauges",
",",
"counters",
":",
"counters",
",",
"availabilities",
":",
"availabilities",
",",
"strings",
":",
"strings",
"}",
"path",
"=",
"'/metrics/'",
"path",
"<<",
"(",
"@legacy_api",
"?",
"'data'",
":",
"'raw'",
")",
"http_post",
"(",
"path",
",",
"data",
")",
"end"
] | Push data for multiple metrics of all supported types
@param gauges [Array]
@param counters [Array]
@param availabilities [Array]
@example push datapoints of 2 counter metrics
client = Hawkular::Metrics::client::new
client.push_data(counters: [{:id => "counter1", :data => [{:value => 1}, {:value => 2}]},
{:id => "counter2", :data => [{:value => 1}, {:value => 3}]}])
@example push gauge and availability datapoints
client.push_data(gauges: [{:id => "gauge1", :data => [{:value => 1}, {:value => 2}]}],
availabilities: [{:id => "avail1", :data => [{:value => "up"}]}]) | [
"Push",
"data",
"for",
"multiple",
"metrics",
"of",
"all",
"supported",
"types"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/metrics/metric_api.rb#L53-L62 | train |
hawkular/hawkular-client-ruby | lib/hawkular/metrics/metric_api.rb | Hawkular::Metrics.Client.query_stats | def query_stats(gauge_ids: [], counter_ids: [], avail_ids: [], rates: false, starts: nil, ends: nil,
bucket_duration: '3600s')
path = '/metrics/stats/query'
metrics = { gauge: gauge_ids, counter: counter_ids, availability: avail_ids }
data = { metrics: metrics, start: starts, end: ends, bucketDuration: bucket_duration }
data['types'] = %w[gauge gauge_rate counter counter_rate availability] if rates
http_post(path, data)
end | ruby | def query_stats(gauge_ids: [], counter_ids: [], avail_ids: [], rates: false, starts: nil, ends: nil,
bucket_duration: '3600s')
path = '/metrics/stats/query'
metrics = { gauge: gauge_ids, counter: counter_ids, availability: avail_ids }
data = { metrics: metrics, start: starts, end: ends, bucketDuration: bucket_duration }
data['types'] = %w[gauge gauge_rate counter counter_rate availability] if rates
http_post(path, data)
end | [
"def",
"query_stats",
"(",
"gauge_ids",
":",
"[",
"]",
",",
"counter_ids",
":",
"[",
"]",
",",
"avail_ids",
":",
"[",
"]",
",",
"rates",
":",
"false",
",",
"starts",
":",
"nil",
",",
"ends",
":",
"nil",
",",
"bucket_duration",
":",
"'3600s'",
")",
"path",
"=",
"'/metrics/stats/query'",
"metrics",
"=",
"{",
"gauge",
":",
"gauge_ids",
",",
"counter",
":",
"counter_ids",
",",
"availability",
":",
"avail_ids",
"}",
"data",
"=",
"{",
"metrics",
":",
"metrics",
",",
"start",
":",
"starts",
",",
"end",
":",
"ends",
",",
"bucketDuration",
":",
"bucket_duration",
"}",
"data",
"[",
"'types'",
"]",
"=",
"%w[",
"gauge",
"gauge_rate",
"counter",
"counter_rate",
"availability",
"]",
"if",
"rates",
"http_post",
"(",
"path",
",",
"data",
")",
"end"
] | Fetch stats for multiple metrics of all supported types
@param gauge_ids [Array[String]] list of gauge ids
@param counter_ids [Array[String]] list of counter ids
@param avail_ids [Array[String]] list of availability ids
@param rates [Boolean] flag to include rates for gauges and counters metrics
@param starts [Integer] optional timestamp (default now - 8h)
@param ends [Integer] optional timestamp (default now)
@param bucket_duration [String] optional interval (default 3600s)
@return [Hash] stats grouped per type
@example
client = Hawkular::Metrics::client::new
client.query_stats(
gauge_ids: ['G1', 'G2'],
counter_ids: ['C2', 'C3'],
avail_ids: ['A2', 'A3'],
starts: 200,
ends: 500,
bucket_duration: '150ms'
) | [
"Fetch",
"stats",
"for",
"multiple",
"metrics",
"of",
"all",
"supported",
"types"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/metrics/metric_api.rb#L83-L90 | train |
hawkular/hawkular-client-ruby | lib/hawkular/metrics/metric_api.rb | Hawkular::Metrics.Client.tags | def tags
tags = []
http_get('/metrics/').map do |g|
next if g['tags'].nil?
g['tags'].map do |k, v|
tags << { k => v }
end
end
tags.uniq!
end | ruby | def tags
tags = []
http_get('/metrics/').map do |g|
next if g['tags'].nil?
g['tags'].map do |k, v|
tags << { k => v }
end
end
tags.uniq!
end | [
"def",
"tags",
"tags",
"=",
"[",
"]",
"http_get",
"(",
"'/metrics/'",
")",
".",
"map",
"do",
"|",
"g",
"|",
"next",
"if",
"g",
"[",
"'tags'",
"]",
".",
"nil?",
"g",
"[",
"'tags'",
"]",
".",
"map",
"do",
"|",
"k",
",",
"v",
"|",
"tags",
"<<",
"{",
"k",
"=>",
"v",
"}",
"end",
"end",
"tags",
".",
"uniq!",
"end"
] | Fetch all tags for metrics definitions
@return [Hash{String=>String}] | [
"Fetch",
"all",
"tags",
"for",
"metrics",
"definitions"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/metrics/metric_api.rb#L94-L104 | train |
bfoz/geometry | lib/geometry/polygon.rb | Geometry.Polygon.outset_bisectors | def outset_bisectors(length)
vertices.zip(spokes).map {|v,b| b ? Edge.new(v, v+(b * length)) : nil}
end | ruby | def outset_bisectors(length)
vertices.zip(spokes).map {|v,b| b ? Edge.new(v, v+(b * length)) : nil}
end | [
"def",
"outset_bisectors",
"(",
"length",
")",
"vertices",
".",
"zip",
"(",
"spokes",
")",
".",
"map",
"{",
"|",
"v",
",",
"b",
"|",
"b",
"?",
"Edge",
".",
"new",
"(",
"v",
",",
"v",
"+",
"(",
"b",
"*",
"length",
")",
")",
":",
"nil",
"}",
"end"
] | Vertex bisectors suitable for outsetting
@param [Number] length The distance to offset by
@return [Array<Edge>] {Edge}s representing the bisectors | [
"Vertex",
"bisectors",
"suitable",
"for",
"outsetting"
] | 3054ccba59f184c172be52a6f0b7cf4a33f617a5 | https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polygon.rb#L287-L289 | train |
apotonick/declarative | lib/declarative/defaults.rb | Declarative.Defaults.call | def call(name, given_options)
# TODO: allow to receive rest of options/block in dynamic block. or, rather, test it as it was already implemented.
evaluated_options = @dynamic_options.(name, given_options)
options = Variables.merge( @static_options, handle_array_and_deprecate(evaluated_options) )
options = Variables.merge( options, handle_array_and_deprecate(given_options) ) # FIXME: given_options is not tested!
end | ruby | def call(name, given_options)
# TODO: allow to receive rest of options/block in dynamic block. or, rather, test it as it was already implemented.
evaluated_options = @dynamic_options.(name, given_options)
options = Variables.merge( @static_options, handle_array_and_deprecate(evaluated_options) )
options = Variables.merge( options, handle_array_and_deprecate(given_options) ) # FIXME: given_options is not tested!
end | [
"def",
"call",
"(",
"name",
",",
"given_options",
")",
"evaluated_options",
"=",
"@dynamic_options",
".",
"(",
"name",
",",
"given_options",
")",
"options",
"=",
"Variables",
".",
"merge",
"(",
"@static_options",
",",
"handle_array_and_deprecate",
"(",
"evaluated_options",
")",
")",
"options",
"=",
"Variables",
".",
"merge",
"(",
"options",
",",
"handle_array_and_deprecate",
"(",
"given_options",
")",
")",
"end"
] | Evaluate defaults and merge given_options into them. | [
"Evaluate",
"defaults",
"and",
"merge",
"given_options",
"into",
"them",
"."
] | 927ecf53fd9b94b85be29a5a0bab115057ecee9b | https://github.com/apotonick/declarative/blob/927ecf53fd9b94b85be29a5a0bab115057ecee9b/lib/declarative/defaults.rb#L20-L26 | train |
paddor/cztop | lib/cztop/certificate.rb | CZTop.Certificate.[]= | def []=(key, value)
if value
ffi_delegate.set_meta(key, "%s", :string, value)
else
ffi_delegate.unset_meta(key)
end
end | ruby | def []=(key, value)
if value
ffi_delegate.set_meta(key, "%s", :string, value)
else
ffi_delegate.unset_meta(key)
end
end | [
"def",
"[]=",
"(",
"key",
",",
"value",
")",
"if",
"value",
"ffi_delegate",
".",
"set_meta",
"(",
"key",
",",
"\"%s\"",
",",
":string",
",",
"value",
")",
"else",
"ffi_delegate",
".",
"unset_meta",
"(",
"key",
")",
"end",
"end"
] | Set metadata.
@param key [String] metadata key
@param value [String] metadata value
@return [value] | [
"Set",
"metadata",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/certificate.rb#L97-L103 | train |
paddor/cztop | lib/cztop/certificate.rb | CZTop.Certificate.meta_keys | def meta_keys
zlist = ffi_delegate.meta_keys
first_key = zlist.first
return [] if first_key.null?
keys = [first_key.read_string]
while key = zlist.next
break if key.null?
keys << key.read_string
end
keys
end | ruby | def meta_keys
zlist = ffi_delegate.meta_keys
first_key = zlist.first
return [] if first_key.null?
keys = [first_key.read_string]
while key = zlist.next
break if key.null?
keys << key.read_string
end
keys
end | [
"def",
"meta_keys",
"zlist",
"=",
"ffi_delegate",
".",
"meta_keys",
"first_key",
"=",
"zlist",
".",
"first",
"return",
"[",
"]",
"if",
"first_key",
".",
"null?",
"keys",
"=",
"[",
"first_key",
".",
"read_string",
"]",
"while",
"key",
"=",
"zlist",
".",
"next",
"break",
"if",
"key",
".",
"null?",
"keys",
"<<",
"key",
".",
"read_string",
"end",
"keys",
"end"
] | Returns meta keys set.
@return [Array<String>] | [
"Returns",
"meta",
"keys",
"set",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/certificate.rb#L107-L117 | train |
mynameisrufus/sorted | lib/sorted/set.rb | Sorted.Set.direction_intersect | def direction_intersect(other_set)
self.class.new.tap do |memo|
unless other_set.keys.empty?
a(memo, other_set)
b(memo, other_set)
end
c(memo)
d(memo, other_set)
end
end | ruby | def direction_intersect(other_set)
self.class.new.tap do |memo|
unless other_set.keys.empty?
a(memo, other_set)
b(memo, other_set)
end
c(memo)
d(memo, other_set)
end
end | [
"def",
"direction_intersect",
"(",
"other_set",
")",
"self",
".",
"class",
".",
"new",
".",
"tap",
"do",
"|",
"memo",
"|",
"unless",
"other_set",
".",
"keys",
".",
"empty?",
"a",
"(",
"memo",
",",
"other_set",
")",
"b",
"(",
"memo",
",",
"other_set",
")",
"end",
"c",
"(",
"memo",
")",
"d",
"(",
"memo",
",",
"other_set",
")",
"end",
"end"
] | Returns a new array containing elements common to the two arrays,
excluding any duplicates.
Any matching keys at matching indexes with the same order will have the
order reversed.
a = Sorted::Set.new([['email', 'asc'], ['name', 'asc']])
b = Sorted::Set.new([['email', 'asc'], ['phone', 'asc']])
s = a.direction_intersect(b)
s.to_a #=> [['email', 'desc'], ['phone', 'asc'], ['name', 'asc']] | [
"Returns",
"a",
"new",
"array",
"containing",
"elements",
"common",
"to",
"the",
"two",
"arrays",
"excluding",
"any",
"duplicates",
"."
] | 6490682f7970e27b692ff0c931f04cf86a52ec0a | https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L43-L52 | train |
mynameisrufus/sorted | lib/sorted/set.rb | Sorted.Set.- | def -(other_set)
self.class.new.tap do |memo|
each do |a|
b = other_set.assoc(a.first)
next if b
memo << a
end
end
end | ruby | def -(other_set)
self.class.new.tap do |memo|
each do |a|
b = other_set.assoc(a.first)
next if b
memo << a
end
end
end | [
"def",
"-",
"(",
"other_set",
")",
"self",
".",
"class",
".",
"new",
".",
"tap",
"do",
"|",
"memo",
"|",
"each",
"do",
"|",
"a",
"|",
"b",
"=",
"other_set",
".",
"assoc",
"(",
"a",
".",
"first",
")",
"next",
"if",
"b",
"memo",
"<<",
"a",
"end",
"end",
"end"
] | Array Difference - Returns a new set that is a copy of the original set,
removing any items that also appear in +other_set+. The order is preserved
from the original set.
set = Sorted::Set.new(['email', 'desc'])
other_set = Sorted::Set.new(['phone', 'asc'])
set - other_set #=> #<Sorted::Set:0x007fafde1ead80> | [
"Array",
"Difference",
"-",
"Returns",
"a",
"new",
"set",
"that",
"is",
"a",
"copy",
"of",
"the",
"original",
"set",
"removing",
"any",
"items",
"that",
"also",
"appear",
"in",
"+",
"other_set",
"+",
".",
"The",
"order",
"is",
"preserved",
"from",
"the",
"original",
"set",
"."
] | 6490682f7970e27b692ff0c931f04cf86a52ec0a | https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L63-L71 | train |
mynameisrufus/sorted | lib/sorted/set.rb | Sorted.Set.a | def a(memo, other)
if keys == other.keys.take(keys.size)
keys.each do |order|
if other.keys.include?(order)
memo << [order, flip_direction(other.assoc(order).last)]
end
end
else
keys.each do |order|
if other.keys.include?(order)
memo << other.assoc(order)
end
end
end
end | ruby | def a(memo, other)
if keys == other.keys.take(keys.size)
keys.each do |order|
if other.keys.include?(order)
memo << [order, flip_direction(other.assoc(order).last)]
end
end
else
keys.each do |order|
if other.keys.include?(order)
memo << other.assoc(order)
end
end
end
end | [
"def",
"a",
"(",
"memo",
",",
"other",
")",
"if",
"keys",
"==",
"other",
".",
"keys",
".",
"take",
"(",
"keys",
".",
"size",
")",
"keys",
".",
"each",
"do",
"|",
"order",
"|",
"if",
"other",
".",
"keys",
".",
"include?",
"(",
"order",
")",
"memo",
"<<",
"[",
"order",
",",
"flip_direction",
"(",
"other",
".",
"assoc",
"(",
"order",
")",
".",
"last",
")",
"]",
"end",
"end",
"else",
"keys",
".",
"each",
"do",
"|",
"order",
"|",
"if",
"other",
".",
"keys",
".",
"include?",
"(",
"order",
")",
"memo",
"<<",
"other",
".",
"assoc",
"(",
"order",
")",
"end",
"end",
"end",
"end"
] | If the order of keys match upto the size of the set then flip them | [
"If",
"the",
"order",
"of",
"keys",
"match",
"upto",
"the",
"size",
"of",
"the",
"set",
"then",
"flip",
"them"
] | 6490682f7970e27b692ff0c931f04cf86a52ec0a | https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L188-L202 | train |
mynameisrufus/sorted | lib/sorted/set.rb | Sorted.Set.b | def b(memo, other)
other.keys.each do |sort|
if keys.include?(sort) && !memo.keys.include?(sort)
memo << other.assoc(sort)
end
end
end | ruby | def b(memo, other)
other.keys.each do |sort|
if keys.include?(sort) && !memo.keys.include?(sort)
memo << other.assoc(sort)
end
end
end | [
"def",
"b",
"(",
"memo",
",",
"other",
")",
"other",
".",
"keys",
".",
"each",
"do",
"|",
"sort",
"|",
"if",
"keys",
".",
"include?",
"(",
"sort",
")",
"&&",
"!",
"memo",
".",
"keys",
".",
"include?",
"(",
"sort",
")",
"memo",
"<<",
"other",
".",
"assoc",
"(",
"sort",
")",
"end",
"end",
"end"
] | Add items from other that are common and not already added | [
"Add",
"items",
"from",
"other",
"that",
"are",
"common",
"and",
"not",
"already",
"added"
] | 6490682f7970e27b692ff0c931f04cf86a52ec0a | https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L205-L211 | train |
mynameisrufus/sorted | lib/sorted/set.rb | Sorted.Set.c | def c(memo)
each do |order|
unless memo.keys.include?(order[0])
memo << order
end
end
end | ruby | def c(memo)
each do |order|
unless memo.keys.include?(order[0])
memo << order
end
end
end | [
"def",
"c",
"(",
"memo",
")",
"each",
"do",
"|",
"order",
"|",
"unless",
"memo",
".",
"keys",
".",
"include?",
"(",
"order",
"[",
"0",
"]",
")",
"memo",
"<<",
"order",
"end",
"end",
"end"
] | Add items not in memo | [
"Add",
"items",
"not",
"in",
"memo"
] | 6490682f7970e27b692ff0c931f04cf86a52ec0a | https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L214-L220 | train |
mynameisrufus/sorted | lib/sorted/set.rb | Sorted.Set.d | def d(memo, other)
other.each do |sort|
unless memo.keys.include?(sort[0])
memo << sort
end
end
end | ruby | def d(memo, other)
other.each do |sort|
unless memo.keys.include?(sort[0])
memo << sort
end
end
end | [
"def",
"d",
"(",
"memo",
",",
"other",
")",
"other",
".",
"each",
"do",
"|",
"sort",
"|",
"unless",
"memo",
".",
"keys",
".",
"include?",
"(",
"sort",
"[",
"0",
"]",
")",
"memo",
"<<",
"sort",
"end",
"end",
"end"
] | Add items from other not in memo | [
"Add",
"items",
"from",
"other",
"not",
"in",
"memo"
] | 6490682f7970e27b692ff0c931f04cf86a52ec0a | https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L223-L229 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.list_triggers | def list_triggers(ids = [], tags = [])
query = generate_query_params 'triggerIds' => ids, 'tags' => tags
sub_url = '/triggers' + query
ret = http_get(sub_url)
val = []
ret.each { |t| val.push(Trigger.new(t)) }
val
end | ruby | def list_triggers(ids = [], tags = [])
query = generate_query_params 'triggerIds' => ids, 'tags' => tags
sub_url = '/triggers' + query
ret = http_get(sub_url)
val = []
ret.each { |t| val.push(Trigger.new(t)) }
val
end | [
"def",
"list_triggers",
"(",
"ids",
"=",
"[",
"]",
",",
"tags",
"=",
"[",
"]",
")",
"query",
"=",
"generate_query_params",
"'triggerIds'",
"=>",
"ids",
",",
"'tags'",
"=>",
"tags",
"sub_url",
"=",
"'/triggers'",
"+",
"query",
"ret",
"=",
"http_get",
"(",
"sub_url",
")",
"val",
"=",
"[",
"]",
"ret",
".",
"each",
"{",
"|",
"t",
"|",
"val",
".",
"push",
"(",
"Trigger",
".",
"new",
"(",
"t",
")",
")",
"}",
"val",
"end"
] | Lists defined triggers in the system
@param [Array] ids List of trigger ids. If provided, limits to the given triggers
@param [Array] tags List of tags. If provided, limits to the given tags. Individual
tags are of the format # key|value. Tags are OR'd together. If a tag-key shows up
more than once, only the last one is accepted
@return [Array<Trigger>] Triggers found | [
"Lists",
"defined",
"triggers",
"in",
"the",
"system"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L37-L46 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.get_single_trigger | def get_single_trigger(trigger_id, full = false)
the_trigger = '/triggers/' + trigger_id
ret = http_get(the_trigger)
trigger = Trigger.new(ret)
if full
ret = http_get(the_trigger + '/conditions')
ret.each { |c| trigger.conditions.push(Trigger::Condition.new(c)) }
ret = http_get(the_trigger + '/dampenings')
ret.each { |c| trigger.dampenings.push(Trigger::Dampening.new(c)) }
end
trigger
end | ruby | def get_single_trigger(trigger_id, full = false)
the_trigger = '/triggers/' + trigger_id
ret = http_get(the_trigger)
trigger = Trigger.new(ret)
if full
ret = http_get(the_trigger + '/conditions')
ret.each { |c| trigger.conditions.push(Trigger::Condition.new(c)) }
ret = http_get(the_trigger + '/dampenings')
ret.each { |c| trigger.dampenings.push(Trigger::Dampening.new(c)) }
end
trigger
end | [
"def",
"get_single_trigger",
"(",
"trigger_id",
",",
"full",
"=",
"false",
")",
"the_trigger",
"=",
"'/triggers/'",
"+",
"trigger_id",
"ret",
"=",
"http_get",
"(",
"the_trigger",
")",
"trigger",
"=",
"Trigger",
".",
"new",
"(",
"ret",
")",
"if",
"full",
"ret",
"=",
"http_get",
"(",
"the_trigger",
"+",
"'/conditions'",
")",
"ret",
".",
"each",
"{",
"|",
"c",
"|",
"trigger",
".",
"conditions",
".",
"push",
"(",
"Trigger",
"::",
"Condition",
".",
"new",
"(",
"c",
")",
")",
"}",
"ret",
"=",
"http_get",
"(",
"the_trigger",
"+",
"'/dampenings'",
")",
"ret",
".",
"each",
"{",
"|",
"c",
"|",
"trigger",
".",
"dampenings",
".",
"push",
"(",
"Trigger",
"::",
"Dampening",
".",
"new",
"(",
"c",
")",
")",
"}",
"end",
"trigger",
"end"
] | Obtains one Trigger definition from the server.
@param [String] trigger_id Id of the trigger to fetch
@param full If true then conditions and dampenings for the trigger are also fetched
@return [Trigger] the selected trigger | [
"Obtains",
"one",
"Trigger",
"definition",
"from",
"the",
"server",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L52-L65 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.create_trigger | def create_trigger(trigger, conditions = [], dampenings = [], _actions = [])
full_trigger = {}
full_trigger[:trigger] = trigger.to_h
conds = []
conditions.each { |c| conds.push(c.to_h) }
full_trigger[:conditions] = conds
damps = []
dampenings.each { |d| damps.push(d.to_h) } unless dampenings.nil?
full_trigger[:dampenings] = damps
http_post 'triggers/trigger', full_trigger
end | ruby | def create_trigger(trigger, conditions = [], dampenings = [], _actions = [])
full_trigger = {}
full_trigger[:trigger] = trigger.to_h
conds = []
conditions.each { |c| conds.push(c.to_h) }
full_trigger[:conditions] = conds
damps = []
dampenings.each { |d| damps.push(d.to_h) } unless dampenings.nil?
full_trigger[:dampenings] = damps
http_post 'triggers/trigger', full_trigger
end | [
"def",
"create_trigger",
"(",
"trigger",
",",
"conditions",
"=",
"[",
"]",
",",
"dampenings",
"=",
"[",
"]",
",",
"_actions",
"=",
"[",
"]",
")",
"full_trigger",
"=",
"{",
"}",
"full_trigger",
"[",
":trigger",
"]",
"=",
"trigger",
".",
"to_h",
"conds",
"=",
"[",
"]",
"conditions",
".",
"each",
"{",
"|",
"c",
"|",
"conds",
".",
"push",
"(",
"c",
".",
"to_h",
")",
"}",
"full_trigger",
"[",
":conditions",
"]",
"=",
"conds",
"damps",
"=",
"[",
"]",
"dampenings",
".",
"each",
"{",
"|",
"d",
"|",
"damps",
".",
"push",
"(",
"d",
".",
"to_h",
")",
"}",
"unless",
"dampenings",
".",
"nil?",
"full_trigger",
"[",
":dampenings",
"]",
"=",
"damps",
"http_post",
"'triggers/trigger'",
",",
"full_trigger",
"end"
] | Creates the trigger definition.
@param [Trigger] trigger The trigger to be created
@param [Array<Condition>] conditions Array of associated conditions
@param [Array<Dampening>] dampenings Array of associated dampenings
@return [Trigger] The newly created trigger | [
"Creates",
"the",
"trigger",
"definition",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L80-L91 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.set_group_conditions | def set_group_conditions(trigger_id, trigger_mode, group_conditions_info)
ret = http_put "triggers/groups/#{trigger_id}/conditions/#{trigger_mode}", group_conditions_info.to_h
conditions = []
ret.each { |c| conditions.push(Trigger::Condition.new(c)) }
conditions
end | ruby | def set_group_conditions(trigger_id, trigger_mode, group_conditions_info)
ret = http_put "triggers/groups/#{trigger_id}/conditions/#{trigger_mode}", group_conditions_info.to_h
conditions = []
ret.each { |c| conditions.push(Trigger::Condition.new(c)) }
conditions
end | [
"def",
"set_group_conditions",
"(",
"trigger_id",
",",
"trigger_mode",
",",
"group_conditions_info",
")",
"ret",
"=",
"http_put",
"\"triggers/groups/#{trigger_id}/conditions/#{trigger_mode}\"",
",",
"group_conditions_info",
".",
"to_h",
"conditions",
"=",
"[",
"]",
"ret",
".",
"each",
"{",
"|",
"c",
"|",
"conditions",
".",
"push",
"(",
"Trigger",
"::",
"Condition",
".",
"new",
"(",
"c",
")",
")",
"}",
"conditions",
"end"
] | Creates the group conditions definitions.
@param [String] trigger_id ID of the group trigger to set conditions
@param [String] trigger_mode Mode of the trigger where conditions are attached (:FIRING, :AUTORESOLVE)
@param [GroupConditionsInfo] group_conditions_info the conditions to set into the group trigger with the mapping
with the data_id members map
@return [Array<Condition>] conditions Array of associated conditions | [
"Creates",
"the",
"group",
"conditions",
"definitions",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L115-L120 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.list_members | def list_members(trigger_id, orphans = false)
ret = http_get "triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}"
ret.collect { |t| Trigger.new(t) }
end | ruby | def list_members(trigger_id, orphans = false)
ret = http_get "triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}"
ret.collect { |t| Trigger.new(t) }
end | [
"def",
"list_members",
"(",
"trigger_id",
",",
"orphans",
"=",
"false",
")",
"ret",
"=",
"http_get",
"\"triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}\"",
"ret",
".",
"collect",
"{",
"|",
"t",
"|",
"Trigger",
".",
"new",
"(",
"t",
")",
"}",
"end"
] | Lists members of a group trigger
@param [String] trigger_id ID of the group trigger to list members
@param [boolean] orphans flag to include orphans
@return [Array<Trigger>] Members found | [
"Lists",
"members",
"of",
"a",
"group",
"trigger"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L142-L145 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.create_group_dampening | def create_group_dampening(dampening)
ret = http_post "triggers/groups/#{dampening.trigger_id}/dampenings", dampening.to_h
Trigger::Dampening.new(ret)
end | ruby | def create_group_dampening(dampening)
ret = http_post "triggers/groups/#{dampening.trigger_id}/dampenings", dampening.to_h
Trigger::Dampening.new(ret)
end | [
"def",
"create_group_dampening",
"(",
"dampening",
")",
"ret",
"=",
"http_post",
"\"triggers/groups/#{dampening.trigger_id}/dampenings\"",
",",
"dampening",
".",
"to_h",
"Trigger",
"::",
"Dampening",
".",
"new",
"(",
"ret",
")",
"end"
] | Creates a dampening for a group trigger
@param [Dampening] dampening the dampening to create
@return [Dampening] the newly created dampening | [
"Creates",
"a",
"dampening",
"for",
"a",
"group",
"trigger"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L150-L153 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.update_group_dampening | def update_group_dampening(dampening)
ret = http_put "triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}", dampening.to_h
Trigger::Dampening.new(ret)
end | ruby | def update_group_dampening(dampening)
ret = http_put "triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}", dampening.to_h
Trigger::Dampening.new(ret)
end | [
"def",
"update_group_dampening",
"(",
"dampening",
")",
"ret",
"=",
"http_put",
"\"triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}\"",
",",
"dampening",
".",
"to_h",
"Trigger",
"::",
"Dampening",
".",
"new",
"(",
"ret",
")",
"end"
] | Updates a dampening for a group trigger
@param [Dampening] dampening the dampening to update
@return [Dampening] the updated dampening | [
"Updates",
"a",
"dampening",
"for",
"a",
"group",
"trigger"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L158-L161 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.create_action | def create_action(plugin, action_id, properties = {})
the_plugin = hawk_escape plugin
# Check if plugin exists
http_get("/plugins/#{the_plugin}")
payload = { actionId: action_id, actionPlugin: plugin, properties: properties }
ret = http_post('/actions', payload)
Trigger::Action.new(ret)
end | ruby | def create_action(plugin, action_id, properties = {})
the_plugin = hawk_escape plugin
# Check if plugin exists
http_get("/plugins/#{the_plugin}")
payload = { actionId: action_id, actionPlugin: plugin, properties: properties }
ret = http_post('/actions', payload)
Trigger::Action.new(ret)
end | [
"def",
"create_action",
"(",
"plugin",
",",
"action_id",
",",
"properties",
"=",
"{",
"}",
")",
"the_plugin",
"=",
"hawk_escape",
"plugin",
"http_get",
"(",
"\"/plugins/#{the_plugin}\"",
")",
"payload",
"=",
"{",
"actionId",
":",
"action_id",
",",
"actionPlugin",
":",
"plugin",
",",
"properties",
":",
"properties",
"}",
"ret",
"=",
"http_post",
"(",
"'/actions'",
",",
"payload",
")",
"Trigger",
"::",
"Action",
".",
"new",
"(",
"ret",
")",
"end"
] | Creates the action.
@param [String] plugin The id of action definition/plugin
@param [String] action_id The id of action
@param [Hash] properties Troperties of action
@return [Action] The newly created action | [
"Creates",
"the",
"action",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L198-L206 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.get_action | def get_action(plugin, action_id)
the_plugin = hawk_escape plugin
the_action_id = hawk_escape action_id
ret = http_get "/actions/#{the_plugin}/#{the_action_id}"
Trigger::Action.new(ret)
end | ruby | def get_action(plugin, action_id)
the_plugin = hawk_escape plugin
the_action_id = hawk_escape action_id
ret = http_get "/actions/#{the_plugin}/#{the_action_id}"
Trigger::Action.new(ret)
end | [
"def",
"get_action",
"(",
"plugin",
",",
"action_id",
")",
"the_plugin",
"=",
"hawk_escape",
"plugin",
"the_action_id",
"=",
"hawk_escape",
"action_id",
"ret",
"=",
"http_get",
"\"/actions/#{the_plugin}/#{the_action_id}\"",
"Trigger",
"::",
"Action",
".",
"new",
"(",
"ret",
")",
"end"
] | Obtains one action of given action plugin from the server.
@param [String] plugin Id of the action plugin
@param [String] action_id Id of the action
@return [Action] the selected trigger | [
"Obtains",
"one",
"action",
"of",
"given",
"action",
"plugin",
"from",
"the",
"server",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L212-L217 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.delete_action | def delete_action(plugin, action_id)
the_plugin = hawk_escape plugin
the_action_id = hawk_escape action_id
http_delete "/actions/#{the_plugin}/#{the_action_id}"
end | ruby | def delete_action(plugin, action_id)
the_plugin = hawk_escape plugin
the_action_id = hawk_escape action_id
http_delete "/actions/#{the_plugin}/#{the_action_id}"
end | [
"def",
"delete_action",
"(",
"plugin",
",",
"action_id",
")",
"the_plugin",
"=",
"hawk_escape",
"plugin",
"the_action_id",
"=",
"hawk_escape",
"action_id",
"http_delete",
"\"/actions/#{the_plugin}/#{the_action_id}\"",
"end"
] | Deletes the action of given action plugin.
@param [String] plugin Id of the action plugin
@param [String] action_id Id of the action | [
"Deletes",
"the",
"action",
"of",
"given",
"action",
"plugin",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L222-L226 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.get_alerts_for_trigger | def get_alerts_for_trigger(trigger_id)
# TODO: add additional filters
return [] unless trigger_id
url = '/?triggerIds=' + trigger_id
ret = http_get(url)
val = []
ret.each { |a| val.push(Alert.new(a)) }
val
end | ruby | def get_alerts_for_trigger(trigger_id)
# TODO: add additional filters
return [] unless trigger_id
url = '/?triggerIds=' + trigger_id
ret = http_get(url)
val = []
ret.each { |a| val.push(Alert.new(a)) }
val
end | [
"def",
"get_alerts_for_trigger",
"(",
"trigger_id",
")",
"return",
"[",
"]",
"unless",
"trigger_id",
"url",
"=",
"'/?triggerIds='",
"+",
"trigger_id",
"ret",
"=",
"http_get",
"(",
"url",
")",
"val",
"=",
"[",
"]",
"ret",
".",
"each",
"{",
"|",
"a",
"|",
"val",
".",
"push",
"(",
"Alert",
".",
"new",
"(",
"a",
")",
")",
"}",
"val",
"end"
] | Obtain the alerts for the Trigger with the passed id
@param [String] trigger_id Id of the trigger that has fired the alerts
@return [Array<Alert>] List of alerts for the trigger. Can be empty | [
"Obtain",
"the",
"alerts",
"for",
"the",
"Trigger",
"with",
"the",
"passed",
"id"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L231-L240 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.alerts | def alerts(criteria: {}, tenants: nil)
query = generate_query_params(criteria)
uri = tenants ? '/admin/alerts/' : '/'
ret = http_get(uri + query, multi_tenants_header(tenants))
val = []
ret.each { |a| val.push(Alert.new(a)) }
val
end | ruby | def alerts(criteria: {}, tenants: nil)
query = generate_query_params(criteria)
uri = tenants ? '/admin/alerts/' : '/'
ret = http_get(uri + query, multi_tenants_header(tenants))
val = []
ret.each { |a| val.push(Alert.new(a)) }
val
end | [
"def",
"alerts",
"(",
"criteria",
":",
"{",
"}",
",",
"tenants",
":",
"nil",
")",
"query",
"=",
"generate_query_params",
"(",
"criteria",
")",
"uri",
"=",
"tenants",
"?",
"'/admin/alerts/'",
":",
"'/'",
"ret",
"=",
"http_get",
"(",
"uri",
"+",
"query",
",",
"multi_tenants_header",
"(",
"tenants",
")",
")",
"val",
"=",
"[",
"]",
"ret",
".",
"each",
"{",
"|",
"a",
"|",
"val",
".",
"push",
"(",
"Alert",
".",
"new",
"(",
"a",
")",
")",
"}",
"val",
"end"
] | List fired alerts
@param [Hash] criteria optional query criteria
@param [Array] tenants optional list of tenants. The elements of the array can be any object
convertible to a string
@return [Array<Alert>] List of alerts in the system. Can be empty | [
"List",
"fired",
"alerts"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L254-L261 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.get_single_alert | def get_single_alert(alert_id)
ret = http_get('/alert/' + alert_id)
val = Alert.new(ret)
val
end | ruby | def get_single_alert(alert_id)
ret = http_get('/alert/' + alert_id)
val = Alert.new(ret)
val
end | [
"def",
"get_single_alert",
"(",
"alert_id",
")",
"ret",
"=",
"http_get",
"(",
"'/alert/'",
"+",
"alert_id",
")",
"val",
"=",
"Alert",
".",
"new",
"(",
"ret",
")",
"val",
"end"
] | Retrieve a single Alert by its id
@param [String] alert_id id of the alert to fetch
@return [Alert] Alert object retrieved | [
"Retrieve",
"a",
"single",
"Alert",
"by",
"its",
"id"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L266-L270 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.resolve_alert | def resolve_alert(alert_id, by = nil, comment = nil)
sub_url = "/resolve/#{alert_id}"
query = generate_query_params 'resolvedBy' => by, 'resolvedNotes' => comment
sub_url += query
http_put(sub_url, {})
true
end | ruby | def resolve_alert(alert_id, by = nil, comment = nil)
sub_url = "/resolve/#{alert_id}"
query = generate_query_params 'resolvedBy' => by, 'resolvedNotes' => comment
sub_url += query
http_put(sub_url, {})
true
end | [
"def",
"resolve_alert",
"(",
"alert_id",
",",
"by",
"=",
"nil",
",",
"comment",
"=",
"nil",
")",
"sub_url",
"=",
"\"/resolve/#{alert_id}\"",
"query",
"=",
"generate_query_params",
"'resolvedBy'",
"=>",
"by",
",",
"'resolvedNotes'",
"=>",
"comment",
"sub_url",
"+=",
"query",
"http_put",
"(",
"sub_url",
",",
"{",
"}",
")",
"true",
"end"
] | Mark one alert as resolved
@param [String] alert_id Id of the alert to resolve
@param [String] by name of the user resolving the alert
@param [String] comment A comment on the resolution | [
"Mark",
"one",
"alert",
"as",
"resolved"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L276-L283 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.create_event | def create_event(id, category, text, extras)
event = {}
event['id'] = id
event['ctime'] = Time.now.to_i * 1000
event['category'] = category
event['text'] = text
event.merge!(extras) { |_key, v1, _v2| v1 }
http_post('/events', event)
end | ruby | def create_event(id, category, text, extras)
event = {}
event['id'] = id
event['ctime'] = Time.now.to_i * 1000
event['category'] = category
event['text'] = text
event.merge!(extras) { |_key, v1, _v2| v1 }
http_post('/events', event)
end | [
"def",
"create_event",
"(",
"id",
",",
"category",
",",
"text",
",",
"extras",
")",
"event",
"=",
"{",
"}",
"event",
"[",
"'id'",
"]",
"=",
"id",
"event",
"[",
"'ctime'",
"]",
"=",
"Time",
".",
"now",
".",
"to_i",
"*",
"1000",
"event",
"[",
"'category'",
"]",
"=",
"category",
"event",
"[",
"'text'",
"]",
"=",
"text",
"event",
".",
"merge!",
"(",
"extras",
")",
"{",
"|",
"_key",
",",
"v1",
",",
"_v2",
"|",
"v1",
"}",
"http_post",
"(",
"'/events'",
",",
"event",
")",
"end"
] | Inject an event into Hawkular-alerts
@param [String] id Id of the event must be unique
@param [String] category Event category for further distinction
@param [String] text Some text to the user
@param [Hash<String,Object>] extras additional parameters | [
"Inject",
"an",
"event",
"into",
"Hawkular",
"-",
"alerts"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L335-L344 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.add_tags | def add_tags(alert_ids, tags)
query = generate_query_params(alertIds: alert_ids, tags: tags)
http_put('/tags' + query, {})
end | ruby | def add_tags(alert_ids, tags)
query = generate_query_params(alertIds: alert_ids, tags: tags)
http_put('/tags' + query, {})
end | [
"def",
"add_tags",
"(",
"alert_ids",
",",
"tags",
")",
"query",
"=",
"generate_query_params",
"(",
"alertIds",
":",
"alert_ids",
",",
"tags",
":",
"tags",
")",
"http_put",
"(",
"'/tags'",
"+",
"query",
",",
"{",
"}",
")",
"end"
] | Add tags to existing Alerts.
@param [Array<numeric>] alert_ids List of alert IDs
@param [Array<String>] tags List of tags. Each tag of format 'name|value'. | [
"Add",
"tags",
"to",
"existing",
"Alerts",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L353-L356 | train |
hawkular/hawkular-client-ruby | lib/hawkular/alerts/alerts_api.rb | Hawkular::Alerts.Client.remove_tags | def remove_tags(alert_ids, tag_names)
query = generate_query_params(alertIds: alert_ids, tagNames: tag_names)
http_delete('/tags' + query)
end | ruby | def remove_tags(alert_ids, tag_names)
query = generate_query_params(alertIds: alert_ids, tagNames: tag_names)
http_delete('/tags' + query)
end | [
"def",
"remove_tags",
"(",
"alert_ids",
",",
"tag_names",
")",
"query",
"=",
"generate_query_params",
"(",
"alertIds",
":",
"alert_ids",
",",
"tagNames",
":",
"tag_names",
")",
"http_delete",
"(",
"'/tags'",
"+",
"query",
")",
"end"
] | Remove tags from existing Alerts.
@param [Array<numeric>] alert_ids List of alert IDs
@param [Array<String>] tag_names List of tag names. | [
"Remove",
"tags",
"from",
"existing",
"Alerts",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L361-L364 | train |
paddor/cztop | lib/cztop/cert_store.rb | CZTop.CertStore.lookup | def lookup(pubkey)
ptr = ffi_delegate.lookup(pubkey)
return nil if ptr.null?
Certificate.from_ffi_delegate(ptr)
end | ruby | def lookup(pubkey)
ptr = ffi_delegate.lookup(pubkey)
return nil if ptr.null?
Certificate.from_ffi_delegate(ptr)
end | [
"def",
"lookup",
"(",
"pubkey",
")",
"ptr",
"=",
"ffi_delegate",
".",
"lookup",
"(",
"pubkey",
")",
"return",
"nil",
"if",
"ptr",
".",
"null?",
"Certificate",
".",
"from_ffi_delegate",
"(",
"ptr",
")",
"end"
] | Initializes a new certificate store.
@param location [String, #to_s, nil] location the path to the
directories to load certificates from, or nil if no certificates need
to be loaded from the disk
Looks up a certificate in the store by its public key.
@param pubkey [String] the public key in question, in Z85 format
@return [Certificate] the matching certificate, if found
@return [nil] if no matching certificate was found | [
"Initializes",
"a",
"new",
"certificate",
"store",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/cert_store.rb#L29-L33 | train |
paddor/cztop | lib/cztop/cert_store.rb | CZTop.CertStore.insert | def insert(cert)
raise ArgumentError unless cert.is_a?(Certificate)
@_inserted_pubkeys ||= Set.new
pubkey = cert.public_key
raise ArgumentError if @_inserted_pubkeys.include? pubkey
ffi_delegate.insert(cert.ffi_delegate)
@_inserted_pubkeys << pubkey
end | ruby | def insert(cert)
raise ArgumentError unless cert.is_a?(Certificate)
@_inserted_pubkeys ||= Set.new
pubkey = cert.public_key
raise ArgumentError if @_inserted_pubkeys.include? pubkey
ffi_delegate.insert(cert.ffi_delegate)
@_inserted_pubkeys << pubkey
end | [
"def",
"insert",
"(",
"cert",
")",
"raise",
"ArgumentError",
"unless",
"cert",
".",
"is_a?",
"(",
"Certificate",
")",
"@_inserted_pubkeys",
"||=",
"Set",
".",
"new",
"pubkey",
"=",
"cert",
".",
"public_key",
"raise",
"ArgumentError",
"if",
"@_inserted_pubkeys",
".",
"include?",
"pubkey",
"ffi_delegate",
".",
"insert",
"(",
"cert",
".",
"ffi_delegate",
")",
"@_inserted_pubkeys",
"<<",
"pubkey",
"end"
] | Inserts a new certificate into the store.
@note The same public key must not be inserted more than once.
@param cert [Certificate] the certificate to insert
@return [void]
@raise [ArgumentError] if the given certificate is not a Certificate
object or has been inserted before already | [
"Inserts",
"a",
"new",
"certificate",
"into",
"the",
"store",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/cert_store.rb#L42-L51 | train |
apotonick/declarative | lib/declarative/heritage.rb | Declarative.Heritage.record | def record(method, *args, &block)
self << {method: method, args: DeepDup.(args), block: block} # DISCUSS: options.dup.
end | ruby | def record(method, *args, &block)
self << {method: method, args: DeepDup.(args), block: block} # DISCUSS: options.dup.
end | [
"def",
"record",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"self",
"<<",
"{",
"method",
":",
"method",
",",
"args",
":",
"DeepDup",
".",
"(",
"args",
")",
",",
"block",
":",
"block",
"}",
"end"
] | Record inheritable assignments for replay in an inheriting class. | [
"Record",
"inheritable",
"assignments",
"for",
"replay",
"in",
"an",
"inheriting",
"class",
"."
] | 927ecf53fd9b94b85be29a5a0bab115057ecee9b | https://github.com/apotonick/declarative/blob/927ecf53fd9b94b85be29a5a0bab115057ecee9b/lib/declarative/heritage.rb#L6-L8 | train |
flori/protocol | lib/protocol/utilities.rb | Protocol.Utilities.find_method_module | def find_method_module(methodname, ancestors)
methodname = methodname.to_s
ancestors.each do |a|
begin
a.instance_method(methodname)
return a
rescue NameError
end
end
nil
end | ruby | def find_method_module(methodname, ancestors)
methodname = methodname.to_s
ancestors.each do |a|
begin
a.instance_method(methodname)
return a
rescue NameError
end
end
nil
end | [
"def",
"find_method_module",
"(",
"methodname",
",",
"ancestors",
")",
"methodname",
"=",
"methodname",
".",
"to_s",
"ancestors",
".",
"each",
"do",
"|",
"a",
"|",
"begin",
"a",
".",
"instance_method",
"(",
"methodname",
")",
"return",
"a",
"rescue",
"NameError",
"end",
"end",
"nil",
"end"
] | This Method tries to find the first module that implements the method
named +methodname+ in the array of +ancestors+. If this fails nil is
returned. | [
"This",
"Method",
"tries",
"to",
"find",
"the",
"first",
"module",
"that",
"implements",
"the",
"method",
"named",
"+",
"methodname",
"+",
"in",
"the",
"array",
"of",
"+",
"ancestors",
"+",
".",
"If",
"this",
"fails",
"nil",
"is",
"returned",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/utilities.rb#L9-L19 | train |
paddor/cztop | lib/cztop/monitor.rb | CZTop.Monitor.listen | def listen(*events)
events.each do |event|
EVENTS.include?(event) or
raise ArgumentError, "invalid event: #{event.inspect}"
end
@actor << [ "LISTEN", *events ]
end | ruby | def listen(*events)
events.each do |event|
EVENTS.include?(event) or
raise ArgumentError, "invalid event: #{event.inspect}"
end
@actor << [ "LISTEN", *events ]
end | [
"def",
"listen",
"(",
"*",
"events",
")",
"events",
".",
"each",
"do",
"|",
"event",
"|",
"EVENTS",
".",
"include?",
"(",
"event",
")",
"or",
"raise",
"ArgumentError",
",",
"\"invalid event: #{event.inspect}\"",
"end",
"@actor",
"<<",
"[",
"\"LISTEN\"",
",",
"*",
"events",
"]",
"end"
] | Configure monitor to listen for specific events.
@param events [String] one or more events from {EVENTS}
@return [void] | [
"Configure",
"monitor",
"to",
"listen",
"for",
"specific",
"events",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/monitor.rb#L63-L69 | train |
damian/jshint | lib/jshint/reporters/junit.rb | Jshint::Reporters.Junit.print_errors_for_code | def print_errors_for_code(code, errors)
name = fetch_error_messages(code, errors)
output << " <testcase classname=\"jshint.#{code}\" name=\"#{escape(name)}\">\n"
errors.each do |error|
output << add_error_message(code, error)
end
output << " </testcase>\n"
output
end | ruby | def print_errors_for_code(code, errors)
name = fetch_error_messages(code, errors)
output << " <testcase classname=\"jshint.#{code}\" name=\"#{escape(name)}\">\n"
errors.each do |error|
output << add_error_message(code, error)
end
output << " </testcase>\n"
output
end | [
"def",
"print_errors_for_code",
"(",
"code",
",",
"errors",
")",
"name",
"=",
"fetch_error_messages",
"(",
"code",
",",
"errors",
")",
"output",
"<<",
"\" <testcase classname=\\\"jshint.#{code}\\\" name=\\\"#{escape(name)}\\\">\\n\"",
"errors",
".",
"each",
"do",
"|",
"error",
"|",
"output",
"<<",
"add_error_message",
"(",
"code",
",",
"error",
")",
"end",
"output",
"<<",
"\" </testcase>\\n\"",
"output",
"end"
] | Appends new error elements to the Report output
@example
<testcase classname="JUnitXmlReporter.constructor" name="should default path to an empty string" time="0.006">
<failure message="test failure">Assertion failed</failure>
</testcase>
@param code [String] The error code
@param errors [Array] The errors for the code
@return [void] | [
"Appends",
"new",
"error",
"elements",
"to",
"the",
"Report",
"output"
] | d7dc6f1913bad5927ac0de3e34714ef920e86cbe | https://github.com/damian/jshint/blob/d7dc6f1913bad5927ac0de3e34714ef920e86cbe/lib/jshint/reporters/junit.rb#L74-L82 | train |
flori/protocol | lib/protocol/protocol_module.rb | Protocol.ProtocolModule.to_ruby | def to_ruby(result = '')
result << "#{name} = Protocol do"
first = true
if messages.empty?
result << "\n"
else
messages.each do |m|
result << "\n"
m.to_ruby(result)
end
end
result << "end\n"
end | ruby | def to_ruby(result = '')
result << "#{name} = Protocol do"
first = true
if messages.empty?
result << "\n"
else
messages.each do |m|
result << "\n"
m.to_ruby(result)
end
end
result << "end\n"
end | [
"def",
"to_ruby",
"(",
"result",
"=",
"''",
")",
"result",
"<<",
"\"#{name} = Protocol do\"",
"first",
"=",
"true",
"if",
"messages",
".",
"empty?",
"result",
"<<",
"\"\\n\"",
"else",
"messages",
".",
"each",
"do",
"|",
"m",
"|",
"result",
"<<",
"\"\\n\"",
"m",
".",
"to_ruby",
"(",
"result",
")",
"end",
"end",
"result",
"<<",
"\"end\\n\"",
"end"
] | Concatenates the protocol as Ruby code to the +result+ string and return
it. At the moment this method only supports method signatures with
generic argument names. | [
"Concatenates",
"the",
"protocol",
"as",
"Ruby",
"code",
"to",
"the",
"+",
"result",
"+",
"string",
"and",
"return",
"it",
".",
"At",
"the",
"moment",
"this",
"method",
"only",
"supports",
"method",
"signatures",
"with",
"generic",
"argument",
"names",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L31-L43 | train |
flori/protocol | lib/protocol/protocol_module.rb | Protocol.ProtocolModule.understand? | def understand?(name, arity = nil)
name = name.to_s
!!find { |m| m.name == name && (!arity || m.arity == arity) }
end | ruby | def understand?(name, arity = nil)
name = name.to_s
!!find { |m| m.name == name && (!arity || m.arity == arity) }
end | [
"def",
"understand?",
"(",
"name",
",",
"arity",
"=",
"nil",
")",
"name",
"=",
"name",
".",
"to_s",
"!",
"!",
"find",
"{",
"|",
"m",
"|",
"m",
".",
"name",
"==",
"name",
"&&",
"(",
"!",
"arity",
"||",
"m",
".",
"arity",
"==",
"arity",
")",
"}",
"end"
] | Returns true if it is required to understand the | [
"Returns",
"true",
"if",
"it",
"is",
"required",
"to",
"understand",
"the"
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L75-L78 | train |
flori/protocol | lib/protocol/protocol_module.rb | Protocol.ProtocolModule.check_failures | def check_failures(object)
check object
rescue CheckFailed => e
return e.errors.map { |e| e.protocol_message }
end | ruby | def check_failures(object)
check object
rescue CheckFailed => e
return e.errors.map { |e| e.protocol_message }
end | [
"def",
"check_failures",
"(",
"object",
")",
"check",
"object",
"rescue",
"CheckFailed",
"=>",
"e",
"return",
"e",
".",
"errors",
".",
"map",
"{",
"|",
"e",
"|",
"e",
".",
"protocol_message",
"}",
"end"
] | Return all messages for whick a check failed. | [
"Return",
"all",
"messages",
"for",
"whick",
"a",
"check",
"failed",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L161-L165 | train |
flori/protocol | lib/protocol/protocol_module.rb | Protocol.ProtocolModule.inherit | def inherit(modul, methodname, block_expected = nil)
Module === modul or
raise TypeError, "expected Module not #{modul.class} as modul argument"
methodnames = methodname.respond_to?(:to_ary) ?
methodname.to_ary :
[ methodname ]
methodnames.each do |methodname|
m = parse_instance_method_signature(modul, methodname)
block_expected and m.block_expected = block_expected
@descriptor.add_message m
end
self
end | ruby | def inherit(modul, methodname, block_expected = nil)
Module === modul or
raise TypeError, "expected Module not #{modul.class} as modul argument"
methodnames = methodname.respond_to?(:to_ary) ?
methodname.to_ary :
[ methodname ]
methodnames.each do |methodname|
m = parse_instance_method_signature(modul, methodname)
block_expected and m.block_expected = block_expected
@descriptor.add_message m
end
self
end | [
"def",
"inherit",
"(",
"modul",
",",
"methodname",
",",
"block_expected",
"=",
"nil",
")",
"Module",
"===",
"modul",
"or",
"raise",
"TypeError",
",",
"\"expected Module not #{modul.class} as modul argument\"",
"methodnames",
"=",
"methodname",
".",
"respond_to?",
"(",
":to_ary",
")",
"?",
"methodname",
".",
"to_ary",
":",
"[",
"methodname",
"]",
"methodnames",
".",
"each",
"do",
"|",
"methodname",
"|",
"m",
"=",
"parse_instance_method_signature",
"(",
"modul",
",",
"methodname",
")",
"block_expected",
"and",
"m",
".",
"block_expected",
"=",
"block_expected",
"@descriptor",
".",
"add_message",
"m",
"end",
"self",
"end"
] | Inherit a method signature from an instance method named +methodname+ of
+modul+. This means that this protocol should understand these instance
methods with their arity and block expectation. Note that automatic
detection of blocks does not work for Ruby methods defined in C. You can
set the +block_expected+ argument if you want to do this manually. | [
"Inherit",
"a",
"method",
"signature",
"from",
"an",
"instance",
"method",
"named",
"+",
"methodname",
"+",
"of",
"+",
"modul",
"+",
".",
"This",
"means",
"that",
"this",
"protocol",
"should",
"understand",
"these",
"instance",
"methods",
"with",
"their",
"arity",
"and",
"block",
"expectation",
".",
"Note",
"that",
"automatic",
"detection",
"of",
"blocks",
"does",
"not",
"work",
"for",
"Ruby",
"methods",
"defined",
"in",
"C",
".",
"You",
"can",
"set",
"the",
"+",
"block_expected",
"+",
"argument",
"if",
"you",
"want",
"to",
"do",
"this",
"manually",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L234-L246 | train |
flori/protocol | lib/protocol/protocol_module.rb | Protocol.ProtocolModule.method_added | def method_added(methodname)
methodname = methodname.to_s
if specification? and methodname !~ /^__protocol_check_/
protocol_check = instance_method(methodname)
parser = MethodParser.new(self, methodname)
if parser.complex?
define_method("__protocol_check_#{methodname}", protocol_check)
understand methodname, protocol_check.arity, parser.block_arg?
else
understand methodname, protocol_check.arity, parser.block_arg?
end
remove_method methodname
else
super
end
end | ruby | def method_added(methodname)
methodname = methodname.to_s
if specification? and methodname !~ /^__protocol_check_/
protocol_check = instance_method(methodname)
parser = MethodParser.new(self, methodname)
if parser.complex?
define_method("__protocol_check_#{methodname}", protocol_check)
understand methodname, protocol_check.arity, parser.block_arg?
else
understand methodname, protocol_check.arity, parser.block_arg?
end
remove_method methodname
else
super
end
end | [
"def",
"method_added",
"(",
"methodname",
")",
"methodname",
"=",
"methodname",
".",
"to_s",
"if",
"specification?",
"and",
"methodname",
"!~",
"/",
"/",
"protocol_check",
"=",
"instance_method",
"(",
"methodname",
")",
"parser",
"=",
"MethodParser",
".",
"new",
"(",
"self",
",",
"methodname",
")",
"if",
"parser",
".",
"complex?",
"define_method",
"(",
"\"__protocol_check_#{methodname}\"",
",",
"protocol_check",
")",
"understand",
"methodname",
",",
"protocol_check",
".",
"arity",
",",
"parser",
".",
"block_arg?",
"else",
"understand",
"methodname",
",",
"protocol_check",
".",
"arity",
",",
"parser",
".",
"block_arg?",
"end",
"remove_method",
"methodname",
"else",
"super",
"end",
"end"
] | Capture all added methods and either leave the implementation in place or
add them to the protocol description. | [
"Capture",
"all",
"added",
"methods",
"and",
"either",
"leave",
"the",
"implementation",
"in",
"place",
"or",
"add",
"them",
"to",
"the",
"protocol",
"description",
"."
] | 528f250f84a46b0f3e6fccf06430ed413c7d994c | https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L274-L289 | train |
paddor/cztop | lib/cztop/actor.rb | CZTop.Actor.<< | def <<(message)
message = Message.coerce(message)
if TERM == message[0]
# NOTE: can't just send this to the actor. The sender might call
# #terminate immediately, which most likely causes a hang due to race
# conditions.
terminate
else
begin
@mtx.synchronize do
raise DeadActorError if not @running
message.send_to(self)
end
rescue IO::EAGAINWaitWritable
# The sndtimeo has been reached.
#
# This should fix the race condition (mainly on JRuby) between
# @running not being set to false yet but the actor handler already
# terminating and thus not able to receive messages anymore.
#
# This shouldn't result in an infinite loop, since it'll stop as
# soon as @running is set to false by #signal_shimmed_handler_death,
# at least when using a Ruby handler.
#
# In case of a C function handler, it MUST NOT crash and only
# terminate when being sent the "$TERM" message using #terminate (so
# #await_handler_death can set
# @running to false).
retry
end
end
self
end | ruby | def <<(message)
message = Message.coerce(message)
if TERM == message[0]
# NOTE: can't just send this to the actor. The sender might call
# #terminate immediately, which most likely causes a hang due to race
# conditions.
terminate
else
begin
@mtx.synchronize do
raise DeadActorError if not @running
message.send_to(self)
end
rescue IO::EAGAINWaitWritable
# The sndtimeo has been reached.
#
# This should fix the race condition (mainly on JRuby) between
# @running not being set to false yet but the actor handler already
# terminating and thus not able to receive messages anymore.
#
# This shouldn't result in an infinite loop, since it'll stop as
# soon as @running is set to false by #signal_shimmed_handler_death,
# at least when using a Ruby handler.
#
# In case of a C function handler, it MUST NOT crash and only
# terminate when being sent the "$TERM" message using #terminate (so
# #await_handler_death can set
# @running to false).
retry
end
end
self
end | [
"def",
"<<",
"(",
"message",
")",
"message",
"=",
"Message",
".",
"coerce",
"(",
"message",
")",
"if",
"TERM",
"==",
"message",
"[",
"0",
"]",
"terminate",
"else",
"begin",
"@mtx",
".",
"synchronize",
"do",
"raise",
"DeadActorError",
"if",
"not",
"@running",
"message",
".",
"send_to",
"(",
"self",
")",
"end",
"rescue",
"IO",
"::",
"EAGAINWaitWritable",
"retry",
"end",
"end",
"self",
"end"
] | Creates a new actor. Either pass a callback directly or a block. The
block will be called for every received message.
In case the given callback is an FFI::Pointer (to a C function), it's
used as-is. It is expected to do the handshake (signal) itself.
@param callback [FFI::Pointer, Proc, #call] pointer to a C function or
just anything callable
@param c_args [FFI::Pointer, nil] args, only useful if callback is an
FFI::Pointer
@yieldparam message [Message]
@yieldparam pipe [Socket::PAIR]
@see #process_messages
Send a message to the actor.
@param message [Object] message to send to the actor, see {Message.coerce}
@return [self] so it's chainable
@raise [DeadActorError] if actor is terminated
@raise [IO::EAGAINWaitWritable, RuntimeError] anything that could be
raised by {Message#send_to}
@note Normally this method is asynchronous, but if the message is
"$TERM", it blocks until the actor is terminated. | [
"Creates",
"a",
"new",
"actor",
".",
"Either",
"pass",
"a",
"callback",
"directly",
"or",
"a",
"block",
".",
"The",
"block",
"will",
"be",
"called",
"for",
"every",
"received",
"message",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/actor.rb#L80-L113 | train |
paddor/cztop | lib/cztop/actor.rb | CZTop.Actor.send_picture | def send_picture(picture, *args)
@mtx.synchronize do
raise DeadActorError if not @running
Zsock.send(ffi_delegate, picture, *args)
end
end | ruby | def send_picture(picture, *args)
@mtx.synchronize do
raise DeadActorError if not @running
Zsock.send(ffi_delegate, picture, *args)
end
end | [
"def",
"send_picture",
"(",
"picture",
",",
"*",
"args",
")",
"@mtx",
".",
"synchronize",
"do",
"raise",
"DeadActorError",
"if",
"not",
"@running",
"Zsock",
".",
"send",
"(",
"ffi_delegate",
",",
"picture",
",",
"*",
"args",
")",
"end",
"end"
] | Sends a message according to a "picture".
@see zsock_send() on http://api.zeromq.org/czmq3-0:zsock
@note Mainly added for {Beacon}. If implemented there, it wouldn't be
thread safe. And it's not that useful to be added to
{SendReceiveMethods}.
@param picture [String] message's part types
@param args [String, Integer, ...] values, in FFI style (each one
preceeded with it's type, like <tt>:string, "foo"</tt>)
@return [void] | [
"Sends",
"a",
"message",
"according",
"to",
"a",
"picture",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/actor.rb#L152-L157 | train |
paddor/cztop | lib/cztop/actor.rb | CZTop.Actor.terminate | def terminate
@mtx.synchronize do
return false if not @running
Message.new(TERM).send_to(self)
await_handler_death
true
end
rescue IO::EAGAINWaitWritable
# same as in #<<
retry
end | ruby | def terminate
@mtx.synchronize do
return false if not @running
Message.new(TERM).send_to(self)
await_handler_death
true
end
rescue IO::EAGAINWaitWritable
# same as in #<<
retry
end | [
"def",
"terminate",
"@mtx",
".",
"synchronize",
"do",
"return",
"false",
"if",
"not",
"@running",
"Message",
".",
"new",
"(",
"TERM",
")",
".",
"send_to",
"(",
"self",
")",
"await_handler_death",
"true",
"end",
"rescue",
"IO",
"::",
"EAGAINWaitWritable",
"retry",
"end"
] | Tells the actor to terminate and waits for it. Idempotent.
@return [Boolean] whether it died just now (+false+ if it was dead
already) | [
"Tells",
"the",
"actor",
"to",
"terminate",
"and",
"waits",
"for",
"it",
".",
"Idempotent",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/actor.rb#L170-L180 | train |
masciugo/genealogy | lib/genealogy/query_methods.rb | Genealogy.QueryMethods.ancestors | def ancestors(options = {})
ids = []
if options[:generations]
raise ArgumentError, ":generations option must be an Integer" unless options[:generations].is_a? Integer
generation_count = 0
generation_ids = parents.compact.map(&:id)
while (generation_count < options[:generations]) && (generation_ids.length > 0)
next_gen_ids = []
ids += generation_ids
until generation_ids.empty?
ids.unshift(generation_ids.shift)
next_gen_ids += gclass.find(ids.first).parents.compact.map(&:id)
end
generation_ids = next_gen_ids
generation_count += 1
end
else
remaining_ids = parents.compact.map(&:id)
until remaining_ids.empty?
ids << remaining_ids.shift
remaining_ids += gclass.find(ids.last).parents.compact.map(&:id)
end
end
gclass.where(id: ids)
end | ruby | def ancestors(options = {})
ids = []
if options[:generations]
raise ArgumentError, ":generations option must be an Integer" unless options[:generations].is_a? Integer
generation_count = 0
generation_ids = parents.compact.map(&:id)
while (generation_count < options[:generations]) && (generation_ids.length > 0)
next_gen_ids = []
ids += generation_ids
until generation_ids.empty?
ids.unshift(generation_ids.shift)
next_gen_ids += gclass.find(ids.first).parents.compact.map(&:id)
end
generation_ids = next_gen_ids
generation_count += 1
end
else
remaining_ids = parents.compact.map(&:id)
until remaining_ids.empty?
ids << remaining_ids.shift
remaining_ids += gclass.find(ids.last).parents.compact.map(&:id)
end
end
gclass.where(id: ids)
end | [
"def",
"ancestors",
"(",
"options",
"=",
"{",
"}",
")",
"ids",
"=",
"[",
"]",
"if",
"options",
"[",
":generations",
"]",
"raise",
"ArgumentError",
",",
"\":generations option must be an Integer\"",
"unless",
"options",
"[",
":generations",
"]",
".",
"is_a?",
"Integer",
"generation_count",
"=",
"0",
"generation_ids",
"=",
"parents",
".",
"compact",
".",
"map",
"(",
"&",
":id",
")",
"while",
"(",
"generation_count",
"<",
"options",
"[",
":generations",
"]",
")",
"&&",
"(",
"generation_ids",
".",
"length",
">",
"0",
")",
"next_gen_ids",
"=",
"[",
"]",
"ids",
"+=",
"generation_ids",
"until",
"generation_ids",
".",
"empty?",
"ids",
".",
"unshift",
"(",
"generation_ids",
".",
"shift",
")",
"next_gen_ids",
"+=",
"gclass",
".",
"find",
"(",
"ids",
".",
"first",
")",
".",
"parents",
".",
"compact",
".",
"map",
"(",
"&",
":id",
")",
"end",
"generation_ids",
"=",
"next_gen_ids",
"generation_count",
"+=",
"1",
"end",
"else",
"remaining_ids",
"=",
"parents",
".",
"compact",
".",
"map",
"(",
"&",
":id",
")",
"until",
"remaining_ids",
".",
"empty?",
"ids",
"<<",
"remaining_ids",
".",
"shift",
"remaining_ids",
"+=",
"gclass",
".",
"find",
"(",
"ids",
".",
"last",
")",
".",
"parents",
".",
"compact",
".",
"map",
"(",
"&",
":id",
")",
"end",
"end",
"gclass",
".",
"where",
"(",
"id",
":",
"ids",
")",
"end"
] | get list of known ancestrors iterateing over parents
@param [Hash] options
@option options [Symbol] generations lets you limit how many generations will be included in the output.
@return [ActiveRecord::Relation] list of ancestors (limited by a number of generations if so indicated) | [
"get",
"list",
"of",
"known",
"ancestrors",
"iterateing",
"over",
"parents"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/query_methods.rb#L133-L157 | train |
masciugo/genealogy | lib/genealogy/query_methods.rb | Genealogy.QueryMethods.descendants | def descendants(options = {})
ids = []
if options[:generations]
generation_count = 0
generation_ids = children.map(&:id)
while (generation_count < options[:generations]) && (generation_ids.length > 0)
next_gen_ids = []
ids += generation_ids
until generation_ids.empty?
ids.unshift(generation_ids.shift)
next_gen_ids += gclass.find(ids.first).children.map(&:id)
end
generation_ids = next_gen_ids
generation_count += 1
end
else
remaining_ids = children.map(&:id)
until remaining_ids.empty?
ids << remaining_ids.shift
remaining_ids += gclass.find(ids.last).children.pluck(:id)
# break if (remaining_ids - ids).empty? can be necessary in case of loop. Idem for ancestors method
end
end
gclass.where(id: ids)
end | ruby | def descendants(options = {})
ids = []
if options[:generations]
generation_count = 0
generation_ids = children.map(&:id)
while (generation_count < options[:generations]) && (generation_ids.length > 0)
next_gen_ids = []
ids += generation_ids
until generation_ids.empty?
ids.unshift(generation_ids.shift)
next_gen_ids += gclass.find(ids.first).children.map(&:id)
end
generation_ids = next_gen_ids
generation_count += 1
end
else
remaining_ids = children.map(&:id)
until remaining_ids.empty?
ids << remaining_ids.shift
remaining_ids += gclass.find(ids.last).children.pluck(:id)
# break if (remaining_ids - ids).empty? can be necessary in case of loop. Idem for ancestors method
end
end
gclass.where(id: ids)
end | [
"def",
"descendants",
"(",
"options",
"=",
"{",
"}",
")",
"ids",
"=",
"[",
"]",
"if",
"options",
"[",
":generations",
"]",
"generation_count",
"=",
"0",
"generation_ids",
"=",
"children",
".",
"map",
"(",
"&",
":id",
")",
"while",
"(",
"generation_count",
"<",
"options",
"[",
":generations",
"]",
")",
"&&",
"(",
"generation_ids",
".",
"length",
">",
"0",
")",
"next_gen_ids",
"=",
"[",
"]",
"ids",
"+=",
"generation_ids",
"until",
"generation_ids",
".",
"empty?",
"ids",
".",
"unshift",
"(",
"generation_ids",
".",
"shift",
")",
"next_gen_ids",
"+=",
"gclass",
".",
"find",
"(",
"ids",
".",
"first",
")",
".",
"children",
".",
"map",
"(",
"&",
":id",
")",
"end",
"generation_ids",
"=",
"next_gen_ids",
"generation_count",
"+=",
"1",
"end",
"else",
"remaining_ids",
"=",
"children",
".",
"map",
"(",
"&",
":id",
")",
"until",
"remaining_ids",
".",
"empty?",
"ids",
"<<",
"remaining_ids",
".",
"shift",
"remaining_ids",
"+=",
"gclass",
".",
"find",
"(",
"ids",
".",
"last",
")",
".",
"children",
".",
"pluck",
"(",
":id",
")",
"end",
"end",
"gclass",
".",
"where",
"(",
"id",
":",
"ids",
")",
"end"
] | get list of known descendants iterateing over children ...
@param [Hash] options
@option options [Symbol] generations lets you limit how many generations will be included in the output.
@return [ActiveRecord::Relation] list of descendants (limited by a number of generations if so indicated) | [
"get",
"list",
"of",
"known",
"descendants",
"iterateing",
"over",
"children",
"..."
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/query_methods.rb#L164-L188 | train |
masciugo/genealogy | lib/genealogy/query_methods.rb | Genealogy.QueryMethods.uncles_and_aunts | def uncles_and_aunts(options={})
relation = case options[:lineage]
when :paternal
[father]
when :maternal
[mother]
else
parents
end
ids = relation.compact.inject([]){|memo,parent| memo |= parent.siblings(half: options[:half]).pluck(:id)}
gclass.where(id: ids)
end | ruby | def uncles_and_aunts(options={})
relation = case options[:lineage]
when :paternal
[father]
when :maternal
[mother]
else
parents
end
ids = relation.compact.inject([]){|memo,parent| memo |= parent.siblings(half: options[:half]).pluck(:id)}
gclass.where(id: ids)
end | [
"def",
"uncles_and_aunts",
"(",
"options",
"=",
"{",
"}",
")",
"relation",
"=",
"case",
"options",
"[",
":lineage",
"]",
"when",
":paternal",
"[",
"father",
"]",
"when",
":maternal",
"[",
"mother",
"]",
"else",
"parents",
"end",
"ids",
"=",
"relation",
".",
"compact",
".",
"inject",
"(",
"[",
"]",
")",
"{",
"|",
"memo",
",",
"parent",
"|",
"memo",
"|=",
"parent",
".",
"siblings",
"(",
"half",
":",
"options",
"[",
":half",
"]",
")",
".",
"pluck",
"(",
":id",
")",
"}",
"gclass",
".",
"where",
"(",
"id",
":",
"ids",
")",
"end"
] | list of uncles and aunts iterating through parents' siblings
@param [Hash] options
@option options [Symbol] lineage to filter by lineage: :paternal or :maternal
@option options [Symbol] half to filter by half siblings (see #siblings)
@return [ActiveRecord::Relation] list of uncles and aunts | [
"list",
"of",
"uncles",
"and",
"aunts",
"iterating",
"through",
"parents",
"siblings"
] | e29eeb1d63cd352d52abf1819ec21659364f90a7 | https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/query_methods.rb#L205-L216 | train |
paddor/cztop | lib/cztop/poller.rb | CZTop.Poller.modify | def modify(socket, events)
ptr = ptr_for_socket(socket)
rc = ZMQ.poller_modify(@poller_ptr, ptr, events)
HasFFIDelegate.raise_zmq_err if rc == -1
remember_socket(socket, events)
end | ruby | def modify(socket, events)
ptr = ptr_for_socket(socket)
rc = ZMQ.poller_modify(@poller_ptr, ptr, events)
HasFFIDelegate.raise_zmq_err if rc == -1
remember_socket(socket, events)
end | [
"def",
"modify",
"(",
"socket",
",",
"events",
")",
"ptr",
"=",
"ptr_for_socket",
"(",
"socket",
")",
"rc",
"=",
"ZMQ",
".",
"poller_modify",
"(",
"@poller_ptr",
",",
"ptr",
",",
"events",
")",
"HasFFIDelegate",
".",
"raise_zmq_err",
"if",
"rc",
"==",
"-",
"1",
"remember_socket",
"(",
"socket",
",",
"events",
")",
"end"
] | Modifies the events of interest for the given socket.
@param socket [Socket, Actor] the socket
@param events [Integer] events you're interested in (see constants in
{ZMQ}
@return [void]
@raise [ArgumentError] if it's not a socket | [
"Modifies",
"the",
"events",
"of",
"interest",
"for",
"the",
"given",
"socket",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L62-L67 | train |
paddor/cztop | lib/cztop/poller.rb | CZTop.Poller.remove | def remove(socket)
ptr = ptr_for_socket(socket)
rc = ZMQ.poller_remove(@poller_ptr, ptr)
HasFFIDelegate.raise_zmq_err if rc == -1
forget_socket(socket)
end | ruby | def remove(socket)
ptr = ptr_for_socket(socket)
rc = ZMQ.poller_remove(@poller_ptr, ptr)
HasFFIDelegate.raise_zmq_err if rc == -1
forget_socket(socket)
end | [
"def",
"remove",
"(",
"socket",
")",
"ptr",
"=",
"ptr_for_socket",
"(",
"socket",
")",
"rc",
"=",
"ZMQ",
".",
"poller_remove",
"(",
"@poller_ptr",
",",
"ptr",
")",
"HasFFIDelegate",
".",
"raise_zmq_err",
"if",
"rc",
"==",
"-",
"1",
"forget_socket",
"(",
"socket",
")",
"end"
] | Removes a previously registered socket. Won't raise if you're
trying to remove a socket that's not registered.
@param socket [Socket, Actor] the socket
@return [void]
@raise [ArgumentError] if it's not a socket | [
"Removes",
"a",
"previously",
"registered",
"socket",
".",
"Won",
"t",
"raise",
"if",
"you",
"re",
"trying",
"to",
"remove",
"a",
"socket",
"that",
"s",
"not",
"registered",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L74-L79 | train |
paddor/cztop | lib/cztop/poller.rb | CZTop.Poller.remove_reader | def remove_reader(socket)
if event_mask_for_socket(socket) == ZMQ::POLLIN
remove(socket)
return
end
raise ArgumentError, "not registered for readability only: %p" % socket
end | ruby | def remove_reader(socket)
if event_mask_for_socket(socket) == ZMQ::POLLIN
remove(socket)
return
end
raise ArgumentError, "not registered for readability only: %p" % socket
end | [
"def",
"remove_reader",
"(",
"socket",
")",
"if",
"event_mask_for_socket",
"(",
"socket",
")",
"==",
"ZMQ",
"::",
"POLLIN",
"remove",
"(",
"socket",
")",
"return",
"end",
"raise",
"ArgumentError",
",",
"\"not registered for readability only: %p\"",
"%",
"socket",
"end"
] | Removes a reader socket that was registered for readability only.
@param socket [Socket, Actor] the socket
@raise [ArgumentError] if it's not registered, not registered for
readability, or registered for more than just readability | [
"Removes",
"a",
"reader",
"socket",
"that",
"was",
"registered",
"for",
"readability",
"only",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L86-L92 | train |
paddor/cztop | lib/cztop/poller.rb | CZTop.Poller.remove_writer | def remove_writer(socket)
if event_mask_for_socket(socket) == ZMQ::POLLOUT
remove(socket)
return
end
raise ArgumentError, "not registered for writability only: %p" % socket
end | ruby | def remove_writer(socket)
if event_mask_for_socket(socket) == ZMQ::POLLOUT
remove(socket)
return
end
raise ArgumentError, "not registered for writability only: %p" % socket
end | [
"def",
"remove_writer",
"(",
"socket",
")",
"if",
"event_mask_for_socket",
"(",
"socket",
")",
"==",
"ZMQ",
"::",
"POLLOUT",
"remove",
"(",
"socket",
")",
"return",
"end",
"raise",
"ArgumentError",
",",
"\"not registered for writability only: %p\"",
"%",
"socket",
"end"
] | Removes a reader socket that was registered for writability only.
@param socket [Socket, Actor] the socket
@raise [ArgumentError] if it's not registered, not registered for
writability, or registered for more than just writability | [
"Removes",
"a",
"reader",
"socket",
"that",
"was",
"registered",
"for",
"writability",
"only",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L99-L105 | train |
paddor/cztop | lib/cztop/poller.rb | CZTop.Poller.wait | def wait(timeout = -1)
rc = ZMQ.poller_wait(@poller_ptr, @event_ptr, timeout)
if rc == -1
case CZMQ::FFI::Errors.errno
# NOTE: ETIMEDOUT for backwards compatibility, although this API is
# still DRAFT.
when Errno::EAGAIN::Errno, Errno::ETIMEDOUT::Errno
return nil
else
HasFFIDelegate.raise_zmq_err
end
end
return Event.new(self, @event_ptr)
end | ruby | def wait(timeout = -1)
rc = ZMQ.poller_wait(@poller_ptr, @event_ptr, timeout)
if rc == -1
case CZMQ::FFI::Errors.errno
# NOTE: ETIMEDOUT for backwards compatibility, although this API is
# still DRAFT.
when Errno::EAGAIN::Errno, Errno::ETIMEDOUT::Errno
return nil
else
HasFFIDelegate.raise_zmq_err
end
end
return Event.new(self, @event_ptr)
end | [
"def",
"wait",
"(",
"timeout",
"=",
"-",
"1",
")",
"rc",
"=",
"ZMQ",
".",
"poller_wait",
"(",
"@poller_ptr",
",",
"@event_ptr",
",",
"timeout",
")",
"if",
"rc",
"==",
"-",
"1",
"case",
"CZMQ",
"::",
"FFI",
"::",
"Errors",
".",
"errno",
"when",
"Errno",
"::",
"EAGAIN",
"::",
"Errno",
",",
"Errno",
"::",
"ETIMEDOUT",
"::",
"Errno",
"return",
"nil",
"else",
"HasFFIDelegate",
".",
"raise_zmq_err",
"end",
"end",
"return",
"Event",
".",
"new",
"(",
"self",
",",
"@event_ptr",
")",
"end"
] | Waits for registered sockets to become readable or writable, depending
on what you're interested in.
@param timeout [Integer] how long to wait in ms, or 0 to avoid blocking,
or -1 to wait indefinitely
@return [Event] the first event of interest
@return [nil] if the timeout expired or
@raise [SystemCallError] if this failed | [
"Waits",
"for",
"registered",
"sockets",
"to",
"become",
"readable",
"or",
"writable",
"depending",
"on",
"what",
"you",
"re",
"interested",
"in",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L115-L128 | train |
hawkular/hawkular-client-ruby | lib/hawkular/operations/operations_api.rb | Hawkular::Operations.Client.invoke_specific_operation | def invoke_specific_operation(operation_payload, operation_name, &callback)
fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil?
required = %i[resourceId feedId]
check_pre_conditions operation_payload, required, &callback
invoke_operation_helper(operation_payload, operation_name, &callback)
end | ruby | def invoke_specific_operation(operation_payload, operation_name, &callback)
fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil?
required = %i[resourceId feedId]
check_pre_conditions operation_payload, required, &callback
invoke_operation_helper(operation_payload, operation_name, &callback)
end | [
"def",
"invoke_specific_operation",
"(",
"operation_payload",
",",
"operation_name",
",",
"&",
"callback",
")",
"fail",
"Hawkular",
"::",
"ArgumentError",
",",
"'Operation must be specified'",
"if",
"operation_name",
".",
"nil?",
"required",
"=",
"%i[",
"resourceId",
"feedId",
"]",
"check_pre_conditions",
"operation_payload",
",",
"required",
",",
"&",
"callback",
"invoke_operation_helper",
"(",
"operation_payload",
",",
"operation_name",
",",
"&",
"callback",
")",
"end"
] | Invokes operation on the WildFly agent that has it's own message type
@param operation_payload [Hash{String=>Object}] a hash containing: resourceId [String] denoting
the resource on which the operation is about to run, feedId [String]
@param operation_name [String] the name of the operation. This must correspond with the message type, they can be
found here https://git.io/v2h1a (Use only the first part of the name without the Request/Response suffix), e.g.
RemoveDatasource (and not RemoveDatasourceRequest)
@param callback [Block] callback that is run after the operation is done | [
"Invokes",
"operation",
"on",
"the",
"WildFly",
"agent",
"that",
"has",
"it",
"s",
"own",
"message",
"type"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L169-L175 | train |
hawkular/hawkular-client-ruby | lib/hawkular/operations/operations_api.rb | Hawkular::Operations.Client.add_deployment | def add_deployment(hash, &callback)
hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true
hash[:force_deploy] = hash.key?(:force_deploy) ? hash[:force_deploy] : false
required = %i[resource_id feed_id destination_file_name binary_content]
check_pre_conditions hash, required, &callback
operation_payload = prepare_payload_hash([:binary_content], hash)
invoke_operation_helper(operation_payload, 'DeployApplication', hash[:binary_content], &callback)
end | ruby | def add_deployment(hash, &callback)
hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true
hash[:force_deploy] = hash.key?(:force_deploy) ? hash[:force_deploy] : false
required = %i[resource_id feed_id destination_file_name binary_content]
check_pre_conditions hash, required, &callback
operation_payload = prepare_payload_hash([:binary_content], hash)
invoke_operation_helper(operation_payload, 'DeployApplication', hash[:binary_content], &callback)
end | [
"def",
"add_deployment",
"(",
"hash",
",",
"&",
"callback",
")",
"hash",
"[",
":enabled",
"]",
"=",
"hash",
".",
"key?",
"(",
":enabled",
")",
"?",
"hash",
"[",
":enabled",
"]",
":",
"true",
"hash",
"[",
":force_deploy",
"]",
"=",
"hash",
".",
"key?",
"(",
":force_deploy",
")",
"?",
"hash",
"[",
":force_deploy",
"]",
":",
"false",
"required",
"=",
"%i[",
"resource_id",
"feed_id",
"destination_file_name",
"binary_content",
"]",
"check_pre_conditions",
"hash",
",",
"required",
",",
"&",
"callback",
"operation_payload",
"=",
"prepare_payload_hash",
"(",
"[",
":binary_content",
"]",
",",
"hash",
")",
"invoke_operation_helper",
"(",
"operation_payload",
",",
"'DeployApplication'",
",",
"hash",
"[",
":binary_content",
"]",
",",
"&",
"callback",
")",
"end"
] | Deploys an archive file into WildFly
@param [Hash] hash Arguments for deployment
@option hash [String] :resource_id ID of the WildFly server into which we deploy
or of the domain controller if we deploy into a server group (in case of domain mode)
@option hash [String] :feed_id feed containing this resource
@option hash [String] :destination_file_name resulting file name
@option hash [String] :binary_content binary content representing the war file
@option hash [String] :enabled whether the deployment should be enabled immediately, or not (default = true)
@option hash [String] :force_deploy whether to replace existing content or not (default = false)
@option hash [String] :server_groups comma-separated list of server groups for the operation (default = ignored)
@param callback [Block] callback that is run after the operation is done | [
"Deploys",
"an",
"archive",
"file",
"into",
"WildFly"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L190-L198 | train |
hawkular/hawkular-client-ruby | lib/hawkular/operations/operations_api.rb | Hawkular::Operations.Client.undeploy | def undeploy(hash, &callback)
hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true
required = %i[resource_id feed_id deployment_name]
check_pre_conditions hash, required, &callback
hash[:destination_file_name] = hash[:deployment_name]
operation_payload = prepare_payload_hash([:deployment_name], hash)
invoke_operation_helper(operation_payload, 'UndeployApplication', &callback)
end | ruby | def undeploy(hash, &callback)
hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true
required = %i[resource_id feed_id deployment_name]
check_pre_conditions hash, required, &callback
hash[:destination_file_name] = hash[:deployment_name]
operation_payload = prepare_payload_hash([:deployment_name], hash)
invoke_operation_helper(operation_payload, 'UndeployApplication', &callback)
end | [
"def",
"undeploy",
"(",
"hash",
",",
"&",
"callback",
")",
"hash",
"[",
":remove_content",
"]",
"=",
"hash",
".",
"key?",
"(",
":remove_content",
")",
"?",
"hash",
"[",
":remove_content",
"]",
":",
"true",
"required",
"=",
"%i[",
"resource_id",
"feed_id",
"deployment_name",
"]",
"check_pre_conditions",
"hash",
",",
"required",
",",
"&",
"callback",
"hash",
"[",
":destination_file_name",
"]",
"=",
"hash",
"[",
":deployment_name",
"]",
"operation_payload",
"=",
"prepare_payload_hash",
"(",
"[",
":deployment_name",
"]",
",",
"hash",
")",
"invoke_operation_helper",
"(",
"operation_payload",
",",
"'UndeployApplication'",
",",
"&",
"callback",
")",
"end"
] | Undeploy a WildFly deployment
@param [Hash] hash Arguments for deployment removal
@option hash [String] :resource_id ID of the WildFly server from which to undeploy the deployment
@option hash [String] :feed_id feed containing this resource
@option hash [String] :deployment_name name of deployment to undeploy
@option hash [String] :remove_content whether to remove the deployment content or not (default = true)
@option hash [String] :server_groups comma-separated list of server groups for the operation (default = ignored)
@param callback [Block] callback that is run after the operation is done | [
"Undeploy",
"a",
"WildFly",
"deployment"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L210-L219 | train |
hawkular/hawkular-client-ruby | lib/hawkular/operations/operations_api.rb | Hawkular::Operations.Client.enable_deployment | def enable_deployment(hash, &callback)
required = %i[resource_id feed_id deployment_name]
check_pre_conditions hash, required, &callback
hash[:destination_file_name] = hash[:deployment_name]
operation_payload = prepare_payload_hash([:deployment_name], hash)
invoke_operation_helper(operation_payload, 'EnableApplication', &callback)
end | ruby | def enable_deployment(hash, &callback)
required = %i[resource_id feed_id deployment_name]
check_pre_conditions hash, required, &callback
hash[:destination_file_name] = hash[:deployment_name]
operation_payload = prepare_payload_hash([:deployment_name], hash)
invoke_operation_helper(operation_payload, 'EnableApplication', &callback)
end | [
"def",
"enable_deployment",
"(",
"hash",
",",
"&",
"callback",
")",
"required",
"=",
"%i[",
"resource_id",
"feed_id",
"deployment_name",
"]",
"check_pre_conditions",
"hash",
",",
"required",
",",
"&",
"callback",
"hash",
"[",
":destination_file_name",
"]",
"=",
"hash",
"[",
":deployment_name",
"]",
"operation_payload",
"=",
"prepare_payload_hash",
"(",
"[",
":deployment_name",
"]",
",",
"hash",
")",
"invoke_operation_helper",
"(",
"operation_payload",
",",
"'EnableApplication'",
",",
"&",
"callback",
")",
"end"
] | Enable a WildFly deployment
@param [Hash] hash Arguments for enable deployment
@option hash [String] :resource_id ID of the WildFly server from which to enable the deployment
@option hash [String] :feed_id feed containing this resource
@option hash [String] :deployment_name name of deployment to enable
@option hash [String] :server_groups comma-separated list of server groups for the operation (default = ignored)
@param callback [Block] callback that is run after the operation is done | [
"Enable",
"a",
"WildFly",
"deployment"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L230-L238 | train |
hawkular/hawkular-client-ruby | lib/hawkular/operations/operations_api.rb | Hawkular::Operations.Client.export_jdr | def export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback)
fail Hawkular::ArgumentError, 'resource_id must be specified' if resource_id.nil?
fail Hawkular::ArgumentError, 'feed_id must be specified' if feed_id.nil?
check_pre_conditions(&callback)
invoke_specific_operation({ resourceId: resource_id,
feedId: feed_id,
deleteImmediately: delete_immediately,
senderRequestId: sender_request_id },
'ExportJdr', &callback)
end | ruby | def export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback)
fail Hawkular::ArgumentError, 'resource_id must be specified' if resource_id.nil?
fail Hawkular::ArgumentError, 'feed_id must be specified' if feed_id.nil?
check_pre_conditions(&callback)
invoke_specific_operation({ resourceId: resource_id,
feedId: feed_id,
deleteImmediately: delete_immediately,
senderRequestId: sender_request_id },
'ExportJdr', &callback)
end | [
"def",
"export_jdr",
"(",
"resource_id",
",",
"feed_id",
",",
"delete_immediately",
"=",
"false",
",",
"sender_request_id",
"=",
"nil",
",",
"&",
"callback",
")",
"fail",
"Hawkular",
"::",
"ArgumentError",
",",
"'resource_id must be specified'",
"if",
"resource_id",
".",
"nil?",
"fail",
"Hawkular",
"::",
"ArgumentError",
",",
"'feed_id must be specified'",
"if",
"feed_id",
".",
"nil?",
"check_pre_conditions",
"(",
"&",
"callback",
")",
"invoke_specific_operation",
"(",
"{",
"resourceId",
":",
"resource_id",
",",
"feedId",
":",
"feed_id",
",",
"deleteImmediately",
":",
"delete_immediately",
",",
"senderRequestId",
":",
"sender_request_id",
"}",
",",
"'ExportJdr'",
",",
"&",
"callback",
")",
"end"
] | Exports the JDR report
@param [String] resource_id ID of the WildFly server
@param [String] feed_id ID of the feed containing the WildFly server
@param [Boolean] delete_immediately specifies whether the temporary file at the remote
server should be deleted. False, by default.
@param callback [Block] callback that is run after the operation is done | [
"Exports",
"the",
"JDR",
"report"
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L330-L340 | train |
hawkular/hawkular-client-ruby | lib/hawkular/operations/operations_api.rb | Hawkular::Operations.Client.update_collection_intervals | def update_collection_intervals(hash, &callback)
required = %i[resourceId feedId metricTypes availTypes]
check_pre_conditions hash, required, &callback
invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback)
end | ruby | def update_collection_intervals(hash, &callback)
required = %i[resourceId feedId metricTypes availTypes]
check_pre_conditions hash, required, &callback
invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback)
end | [
"def",
"update_collection_intervals",
"(",
"hash",
",",
"&",
"callback",
")",
"required",
"=",
"%i[",
"resourceId",
"feedId",
"metricTypes",
"availTypes",
"]",
"check_pre_conditions",
"hash",
",",
"required",
",",
"&",
"callback",
"invoke_specific_operation",
"(",
"hash",
",",
"'UpdateCollectionIntervals'",
",",
"&",
"callback",
")",
"end"
] | Updates the collection intervals.
@param [Hash] hash Arguments for update collection intervals
@option hash {resourceId} a resource managed by the target agent
@option hash {feedId} the related feed ID
@option hash {metricTypes} A map with key=MetricTypeId, value=interval (seconds).
MetricTypeId must be of form MetricTypeSet~MetricTypeName
@option hash {availTypes} A map with key=AvailTypeId, value=interval (seconds).
AvailTypeId must be of form AvailTypeSet~AvailTypeName
@param callback [Block] callback that is run after the operation is done | [
"Updates",
"the",
"collection",
"intervals",
"."
] | 3b07729c2ab359e3199c282e199a3f1699ddc49c | https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L353-L357 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.