repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/benchmark/realtime_store.rb | MoreCoreExtensions.BenchmarkRealtimeStore.realtime_block | def realtime_block(key, &block)
hash = current_realtime
if in_realtime_block?
ret = realtime_store(hash, key, &block)
return ret, hash
else
begin
self.current_realtime = hash
begin
ret = realtime_store(hash, key, &block)
return ret, ... | ruby | def realtime_block(key, &block)
hash = current_realtime
if in_realtime_block?
ret = realtime_store(hash, key, &block)
return ret, hash
else
begin
self.current_realtime = hash
begin
ret = realtime_store(hash, key, &block)
return ret, ... | [
"def",
"realtime_block",
"(",
"key",
",",
"&",
"block",
")",
"hash",
"=",
"current_realtime",
"if",
"in_realtime_block?",
"ret",
"=",
"realtime_store",
"(",
"hash",
",",
"key",
",",
"&",
"block",
")",
"return",
"ret",
",",
"hash",
"else",
"begin",
"self",
... | Stores the elapsed real time used to execute the given block for the given
key and returns the hash as well as the result from the block. The hash is
stored globally, keyed on thread id, and is cleared once the topmost nested
call completes. If the hash already has a value for that key, the time is
accumulated.
... | [
"Stores",
"the",
"elapsed",
"real",
"time",
"used",
"to",
"execute",
"the",
"given",
"block",
"for",
"the",
"given",
"key",
"and",
"returns",
"the",
"hash",
"as",
"well",
"as",
"the",
"result",
"from",
"the",
"block",
".",
"The",
"hash",
"is",
"stored",
... | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/benchmark/realtime_store.rb#L52-L77 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/object/namespace.rb | MoreCoreExtensions.ObjectNamespace.in_namespace? | def in_namespace?(val)
val_ns = val.to_s.split("::")
val_ns == (kind_of?(Module) ? namespace : self.class.namespace)[0, val_ns.length]
end | ruby | def in_namespace?(val)
val_ns = val.to_s.split("::")
val_ns == (kind_of?(Module) ? namespace : self.class.namespace)[0, val_ns.length]
end | [
"def",
"in_namespace?",
"(",
"val",
")",
"val_ns",
"=",
"val",
".",
"to_s",
".",
"split",
"(",
"\"::\"",
")",
"val_ns",
"==",
"(",
"kind_of?",
"(",
"Module",
")",
"?",
"namespace",
":",
"self",
".",
"class",
".",
"namespace",
")",
"[",
"0",
",",
"v... | Returns whether or not the object is in the given namespace.
Aaa::Bbb::Ccc::Ddd.in_namespace?(Aaa::Bbb) #=> true
Aaa::Bbb::Ccc::Ddd.new.in_namespace?(Aaa::Bbb) #=> true
Aaa::Bbb::Ccc::Eee.in_namespace?("Aaa::Bbb") #=> true
Aaa::Bbb::Ccc::Eee.in_namespace?(Aaa::Bbb::Ccc::Ddd) #=>... | [
"Returns",
"whether",
"or",
"not",
"the",
"object",
"is",
"in",
"the",
"given",
"namespace",
"."
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/object/namespace.rb#L12-L15 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/array/element_counts.rb | MoreCoreExtensions.ArrayElementCounts.element_counts | def element_counts
each_with_object(Hash.new(0)) do |i, h|
key = block_given? ? yield(i) : i
h[key] += 1
end
end | ruby | def element_counts
each_with_object(Hash.new(0)) do |i, h|
key = block_given? ? yield(i) : i
h[key] += 1
end
end | [
"def",
"element_counts",
"each_with_object",
"(",
"Hash",
".",
"new",
"(",
"0",
")",
")",
"do",
"|",
"i",
",",
"h",
"|",
"key",
"=",
"block_given?",
"?",
"yield",
"(",
"i",
")",
":",
"i",
"h",
"[",
"key",
"]",
"+=",
"1",
"end",
"end"
] | Returns a Hash of each element to the count of those elements. Optionally
pass a block to count by a different criteria.
[1, 2, 3, 1, 3, 1].counts # => {1 => 3, 2 => 1, 3 => 2}
%w(a aa aaa a aaa a).counts { |i| i.length } # => {1 => 3, 2 => 1, 3 => 2} | [
"Returns",
"a",
"Hash",
"of",
"each",
"element",
"to",
"the",
"count",
"of",
"those",
"elements",
".",
"Optionally",
"pass",
"a",
"block",
"to",
"count",
"by",
"a",
"different",
"criteria",
"."
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/array/element_counts.rb#L9-L14 | train |
coub/raml_ruby | lib/raml/node/resource_type.rb | Raml.ResourceType.instantiate | def instantiate(params)
instance = Instance.new( *interpolate(params), @parent )
instance.apply_resource_type
instance
end | ruby | def instantiate(params)
instance = Instance.new( *interpolate(params), @parent )
instance.apply_resource_type
instance
end | [
"def",
"instantiate",
"(",
"params",
")",
"instance",
"=",
"Instance",
".",
"new",
"(",
"*",
"interpolate",
"(",
"params",
")",
",",
"@parent",
")",
"instance",
".",
"apply_resource_type",
"instance",
"end"
] | Instantiate a new resource type with the given parameters.
@param params [Hash] the parameters to interpolate in the resource type.
@return [Raml::ResourceType::Instance] the instantiated resouce type. | [
"Instantiate",
"a",
"new",
"resource",
"type",
"with",
"the",
"given",
"parameters",
"."
] | 4f1ea4c4827693c37e4464f9809509dbdc1c0795 | https://github.com/coub/raml_ruby/blob/4f1ea4c4827693c37e4464f9809509dbdc1c0795/lib/raml/node/resource_type.rb#L14-L18 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/range/step_value.rb | MoreCoreExtensions.RangeStepValue.step_value | def step_value(value)
if block_given?
return if self.begin > self.end
iter = self.begin
loop do
yield iter unless iter == self.end && exclude_end?
break if iter == self.end
iter += value
iter = self.end if iter > self.end
end
self
... | ruby | def step_value(value)
if block_given?
return if self.begin > self.end
iter = self.begin
loop do
yield iter unless iter == self.end && exclude_end?
break if iter == self.end
iter += value
iter = self.end if iter > self.end
end
self
... | [
"def",
"step_value",
"(",
"value",
")",
"if",
"block_given?",
"return",
"if",
"self",
".",
"begin",
">",
"self",
".",
"end",
"iter",
"=",
"self",
".",
"begin",
"loop",
"do",
"yield",
"iter",
"unless",
"iter",
"==",
"self",
".",
"end",
"&&",
"exclude_en... | Iterates over rng, starting with the beginning of rng, incrementing by the
value, and passing that element to the block. Unlike +step+, +step_value+
invokes the + operator to iterate over the range elements. Unless the end is
excluded from the range, the final value of the iteration will always be the
end value, ev... | [
"Iterates",
"over",
"rng",
"starting",
"with",
"the",
"beginning",
"of",
"rng",
"incrementing",
"by",
"the",
"value",
"and",
"passing",
"that",
"element",
"to",
"the",
"block",
".",
"Unlike",
"+",
"step",
"+",
"+",
"step_value",
"+",
"invokes",
"the",
"+",... | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/range/step_value.rb#L23-L41 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/array/inclusions.rb | MoreCoreExtensions.ArrayInclusions.include_any? | def include_any?(*items)
items = items.first if items.length == 1 && items.first.kind_of?(Array)
!(self & items).empty?
end | ruby | def include_any?(*items)
items = items.first if items.length == 1 && items.first.kind_of?(Array)
!(self & items).empty?
end | [
"def",
"include_any?",
"(",
"*",
"items",
")",
"items",
"=",
"items",
".",
"first",
"if",
"items",
".",
"length",
"==",
"1",
"&&",
"items",
".",
"first",
".",
"kind_of?",
"(",
"Array",
")",
"!",
"(",
"self",
"&",
"items",
")",
".",
"empty?",
"end"
... | Returns whether the Array contains any of the items.
[1, 2, 3].include_any?(1, 2) #=> true
[1, 2, 3].include_any?(1, 4) #=> true
[1, 2, 3].include_any?(4, 5) #=> false | [
"Returns",
"whether",
"the",
"Array",
"contains",
"any",
"of",
"the",
"items",
"."
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/array/inclusions.rb#L9-L12 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/array/inclusions.rb | MoreCoreExtensions.ArrayInclusions.include_none? | def include_none?(*items)
items = items.first if items.length == 1 && items.first.kind_of?(Array)
(self & items).empty?
end | ruby | def include_none?(*items)
items = items.first if items.length == 1 && items.first.kind_of?(Array)
(self & items).empty?
end | [
"def",
"include_none?",
"(",
"*",
"items",
")",
"items",
"=",
"items",
".",
"first",
"if",
"items",
".",
"length",
"==",
"1",
"&&",
"items",
".",
"first",
".",
"kind_of?",
"(",
"Array",
")",
"(",
"self",
"&",
"items",
")",
".",
"empty?",
"end"
] | Returns whether the Array contains none of the items.
[1, 2, 3].include_none?(1, 2) #=> false
[1, 2, 3].include_none?(1, 4) #=> false
[1, 2, 3].include_none?(4, 5) #=> true | [
"Returns",
"whether",
"the",
"Array",
"contains",
"none",
"of",
"the",
"items",
"."
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/array/inclusions.rb#L20-L23 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/array/inclusions.rb | MoreCoreExtensions.ArrayInclusions.include_all? | def include_all?(*items)
items = items.first if items.length == 1 && items.first.kind_of?(Array)
(items - self).empty?
end | ruby | def include_all?(*items)
items = items.first if items.length == 1 && items.first.kind_of?(Array)
(items - self).empty?
end | [
"def",
"include_all?",
"(",
"*",
"items",
")",
"items",
"=",
"items",
".",
"first",
"if",
"items",
".",
"length",
"==",
"1",
"&&",
"items",
".",
"first",
".",
"kind_of?",
"(",
"Array",
")",
"(",
"items",
"-",
"self",
")",
".",
"empty?",
"end"
] | Returns whether the Array contains all of the items.
[1, 2, 3].include_all?(1, 2) #=> true
[1, 2, 3].include_all?(1, 4) #=> false
[1, 2, 3].include_all?(4, 5) #=> false | [
"Returns",
"whether",
"the",
"Array",
"contains",
"all",
"of",
"the",
"items",
"."
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/array/inclusions.rb#L31-L34 | train |
thoughtbot/hoptoad_notifier | lib/airbrake/sender.rb | Airbrake.Sender.send_to_airbrake | def send_to_airbrake(data)
logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
http =
Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
new(url.host, url.port)
http.read_timeout = http_read_timeout
http.open_timeout = http_open_timeout
i... | ruby | def send_to_airbrake(data)
logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
http =
Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
new(url.host, url.port)
http.read_timeout = http_read_timeout
http.open_timeout = http_open_timeout
i... | [
"def",
"send_to_airbrake",
"(",
"data",
")",
"logger",
".",
"debug",
"{",
"\"Sending request to #{url.to_s}:\\n#{data}\"",
"}",
"if",
"logger",
"http",
"=",
"Net",
"::",
"HTTP",
"::",
"Proxy",
"(",
"proxy_host",
",",
"proxy_port",
",",
"proxy_user",
",",
"proxy_... | Sends the notice data off to Airbrake for processing.
@param [String] data The XML notice to be sent off | [
"Sends",
"the",
"notice",
"data",
"off",
"to",
"Airbrake",
"for",
"processing",
"."
] | 50c5ca4e87b9086a064053fc6f95d4d097296f77 | https://github.com/thoughtbot/hoptoad_notifier/blob/50c5ca4e87b9086a064053fc6f95d4d097296f77/lib/airbrake/sender.rb#L25-L61 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/object/descendants.rb | MoreCoreExtensions.Descendants.descendant_get | def descendant_get(desc_name)
return self if desc_name == name || desc_name.nil?
klass = descendants.find { |desc| desc.name == desc_name }
raise ArgumentError, "#{desc_name} is not a descendant of #{name}" unless klass
klass
end | ruby | def descendant_get(desc_name)
return self if desc_name == name || desc_name.nil?
klass = descendants.find { |desc| desc.name == desc_name }
raise ArgumentError, "#{desc_name} is not a descendant of #{name}" unless klass
klass
end | [
"def",
"descendant_get",
"(",
"desc_name",
")",
"return",
"self",
"if",
"desc_name",
"==",
"name",
"||",
"desc_name",
".",
"nil?",
"klass",
"=",
"descendants",
".",
"find",
"{",
"|",
"desc",
"|",
"desc",
".",
"name",
"==",
"desc_name",
"}",
"raise",
"Arg... | Retrieve a descendant by its name | [
"Retrieve",
"a",
"descendant",
"by",
"its",
"name"
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/object/descendants.rb#L8-L13 | train |
coub/raml_ruby | lib/raml/node/root.rb | Raml.Root.expand | def expand
unless @expanded
resources.values.each(&:apply_resource_type)
resources.values.each(&:apply_traits)
inline_reference SchemaReference, schemas, @children
@expanded = true
end
end | ruby | def expand
unless @expanded
resources.values.each(&:apply_resource_type)
resources.values.each(&:apply_traits)
inline_reference SchemaReference, schemas, @children
@expanded = true
end
end | [
"def",
"expand",
"unless",
"@expanded",
"resources",
".",
"values",
".",
"each",
"(",
"&",
":apply_resource_type",
")",
"resources",
".",
"values",
".",
"each",
"(",
"&",
":apply_traits",
")",
"inline_reference",
"SchemaReference",
",",
"schemas",
",",
"@childre... | Applies resource types and traits, and inlines schemas. It should be called
before documentation is generated. | [
"Applies",
"resource",
"types",
"and",
"traits",
"and",
"inlines",
"schemas",
".",
"It",
"should",
"be",
"called",
"before",
"documentation",
"is",
"generated",
"."
] | 4f1ea4c4827693c37e4464f9809509dbdc1c0795 | https://github.com/coub/raml_ruby/blob/4f1ea4c4827693c37e4464f9809509dbdc1c0795/lib/raml/node/root.rb#L82-L89 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/array/stretch.rb | MoreCoreExtensions.ArrayStretch.stretch! | def stretch!(*arys)
max_size = (arys + [self]).collect { |a| a.length }.max
self[max_size - 1] = nil unless self.length == max_size
return self
end | ruby | def stretch!(*arys)
max_size = (arys + [self]).collect { |a| a.length }.max
self[max_size - 1] = nil unless self.length == max_size
return self
end | [
"def",
"stretch!",
"(",
"*",
"arys",
")",
"max_size",
"=",
"(",
"arys",
"+",
"[",
"self",
"]",
")",
".",
"collect",
"{",
"|",
"a",
"|",
"a",
".",
"length",
"}",
".",
"max",
"self",
"[",
"max_size",
"-",
"1",
"]",
"=",
"nil",
"unless",
"self",
... | Stretch receiver to be the same size as the longest argument Array. Modifies the receiver in place.
[1, 2].stretch!([3, 4], [5, 6, 7]) #=> [1, 2, nil] | [
"Stretch",
"receiver",
"to",
"be",
"the",
"same",
"size",
"as",
"the",
"longest",
"argument",
"Array",
".",
"Modifies",
"the",
"receiver",
"in",
"place",
"."
] | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/array/stretch.rb#L31-L35 | train |
thoughtbot/hoptoad_notifier | lib/airbrake/notice.rb | Airbrake.Notice.to_xml | def to_xml
builder = Builder::XmlMarkup.new
builder.instruct!
xml = builder.notice(:version => Airbrake::API_VERSION) do |notice|
notice.tag!("api-key", api_key)
notice.notifier do |notifier|
notifier.name(notifier_name)
notifier.version(notifier_version)
... | ruby | def to_xml
builder = Builder::XmlMarkup.new
builder.instruct!
xml = builder.notice(:version => Airbrake::API_VERSION) do |notice|
notice.tag!("api-key", api_key)
notice.notifier do |notifier|
notifier.name(notifier_name)
notifier.version(notifier_version)
... | [
"def",
"to_xml",
"builder",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"builder",
".",
"instruct!",
"xml",
"=",
"builder",
".",
"notice",
"(",
":version",
"=>",
"Airbrake",
"::",
"API_VERSION",
")",
"do",
"|",
"notice",
"|",
"notice",
".",
"tag!",
"(... | Converts the given notice to XML | [
"Converts",
"the",
"given",
"notice",
"to",
"XML"
] | 50c5ca4e87b9086a064053fc6f95d4d097296f77 | https://github.com/thoughtbot/hoptoad_notifier/blob/50c5ca4e87b9086a064053fc6f95d4d097296f77/lib/airbrake/notice.rb#L111-L166 | train |
thoughtbot/hoptoad_notifier | lib/airbrake/notice.rb | Airbrake.Notice.exception_attribute | def exception_attribute(attribute, default = nil, &block)
(exception && from_exception(attribute, &block)) || args[attribute] || default
end | ruby | def exception_attribute(attribute, default = nil, &block)
(exception && from_exception(attribute, &block)) || args[attribute] || default
end | [
"def",
"exception_attribute",
"(",
"attribute",
",",
"default",
"=",
"nil",
",",
"&",
"block",
")",
"(",
"exception",
"&&",
"from_exception",
"(",
"attribute",
",",
"&",
"block",
")",
")",
"||",
"args",
"[",
"attribute",
"]",
"||",
"default",
"end"
] | Gets a property named +attribute+ of an exception, either from an actual
exception or a hash.
If an exception is available, #from_exception will be used. Otherwise,
a key named +attribute+ will be used from the #args.
If no exception or hash key is available, +default+ will be used. | [
"Gets",
"a",
"property",
"named",
"+",
"attribute",
"+",
"of",
"an",
"exception",
"either",
"from",
"an",
"actual",
"exception",
"or",
"a",
"hash",
"."
] | 50c5ca4e87b9086a064053fc6f95d4d097296f77 | https://github.com/thoughtbot/hoptoad_notifier/blob/50c5ca4e87b9086a064053fc6f95d4d097296f77/lib/airbrake/notice.rb#L207-L209 | train |
para-cms/para | app/helpers/para/model_helper.rb | Para.ModelHelper.model_field_mappings | def model_field_mappings(model, options = {})
if Array == options
whitelist_attributes = options
else
whitelist_attributes = options.fetch(:whitelist_attributes, nil)
mappings = options.fetch(:mappings, {})
end
Para::AttributeFieldMappings.new(
model, whitelist_a... | ruby | def model_field_mappings(model, options = {})
if Array == options
whitelist_attributes = options
else
whitelist_attributes = options.fetch(:whitelist_attributes, nil)
mappings = options.fetch(:mappings, {})
end
Para::AttributeFieldMappings.new(
model, whitelist_a... | [
"def",
"model_field_mappings",
"(",
"model",
",",
"options",
"=",
"{",
"}",
")",
"if",
"Array",
"==",
"options",
"whitelist_attributes",
"=",
"options",
"else",
"whitelist_attributes",
"=",
"options",
".",
"fetch",
"(",
":whitelist_attributes",
",",
"nil",
")",
... | Second argument can be the whitelist_attributes array or keyword
arguments. This is to ensure backwards compatibility with old plugins. | [
"Second",
"argument",
"can",
"be",
"the",
"whitelist_attributes",
"array",
"or",
"keyword",
"arguments",
".",
"This",
"is",
"to",
"ensure",
"backwards",
"compatibility",
"with",
"old",
"plugins",
"."
] | 97364cf5ec91225d7f1a7665c47cd65514f2b072 | https://github.com/para-cms/para/blob/97364cf5ec91225d7f1a7665c47cd65514f2b072/app/helpers/para/model_helper.rb#L11-L22 | train |
ManageIQ/more_core_extensions | lib/more_core_extensions/core_ext/module/cache_with_timeout.rb | MoreCoreExtensions.CacheWithTimeout.cache_with_timeout | def cache_with_timeout(method, timeout = nil, &block)
raise "no block given" if block.nil?
raise ArgumentError, "method must be a Symbol" unless method.respond_to?(:to_sym)
key = "#{name}.#{method}".to_sym
$cache_with_timeout_lock.synchronize(:EX) do
$cache_with_timeout[key] = {}
... | ruby | def cache_with_timeout(method, timeout = nil, &block)
raise "no block given" if block.nil?
raise ArgumentError, "method must be a Symbol" unless method.respond_to?(:to_sym)
key = "#{name}.#{method}".to_sym
$cache_with_timeout_lock.synchronize(:EX) do
$cache_with_timeout[key] = {}
... | [
"def",
"cache_with_timeout",
"(",
"method",
",",
"timeout",
"=",
"nil",
",",
"&",
"block",
")",
"raise",
"\"no block given\"",
"if",
"block",
".",
"nil?",
"raise",
"ArgumentError",
",",
"\"method must be a Symbol\"",
"unless",
"method",
".",
"respond_to?",
"(",
... | cache_with_timeout creates singleton methods that cache the
results of the given block, but only for a short amount of time.
If the method is called again after time has passed, then the
cache is cleared and the block is reevaluated. Note that the
cache is only cleared on the next invocation after the time... | [
"cache_with_timeout",
"creates",
"singleton",
"methods",
"that",
"cache",
"the",
"results",
"of",
"the",
"given",
"block",
"but",
"only",
"for",
"a",
"short",
"amount",
"of",
"time",
".",
"If",
"the",
"method",
"is",
"called",
"again",
"after",
"time",
"has"... | 13f97a2a07155354117ea638eb0892fad09d5e44 | https://github.com/ManageIQ/more_core_extensions/blob/13f97a2a07155354117ea638eb0892fad09d5e44/lib/more_core_extensions/core_ext/module/cache_with_timeout.rb#L39-L81 | train |
OTL/rosruby | lib/ros/name.rb | ROS.Name.resolve_name_with_call_id | def resolve_name_with_call_id(caller_id, ns, name, remappings)
name = canonicalize_name(expand_local_name(caller_id, name))
if remappings
remappings.each_pair do |key, value|
if name == canonicalize_name(key)
name = value
end
end
end
if ns
... | ruby | def resolve_name_with_call_id(caller_id, ns, name, remappings)
name = canonicalize_name(expand_local_name(caller_id, name))
if remappings
remappings.each_pair do |key, value|
if name == canonicalize_name(key)
name = value
end
end
end
if ns
... | [
"def",
"resolve_name_with_call_id",
"(",
"caller_id",
",",
"ns",
",",
"name",
",",
"remappings",
")",
"name",
"=",
"canonicalize_name",
"(",
"expand_local_name",
"(",
"caller_id",
",",
"name",
")",
")",
"if",
"remappings",
"remappings",
".",
"each_pair",
"do",
... | expand local, canonicalize, remappings
@param [String] caller_id caller_id
@param [String] ns namespace
@param [String] name target name
@param [Array] remappings name remappings
@return [String] resolved name | [
"expand",
"local",
"canonicalize",
"remappings"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/name.rb#L73-L86 | train |
OTL/rosruby | lib/ros/tcpros/service_server.rb | ROS::TCPROS.ServiceServer.read_and_callback | def read_and_callback(socket)
request = @service_type.request_class.new
response = @service_type.response_class.new
data = read_all(socket)
@byte_received += data.length
request.deserialize(data)
result = @callback.call(request, response)
if result
send_ok_byte(socket)
... | ruby | def read_and_callback(socket)
request = @service_type.request_class.new
response = @service_type.response_class.new
data = read_all(socket)
@byte_received += data.length
request.deserialize(data)
result = @callback.call(request, response)
if result
send_ok_byte(socket)
... | [
"def",
"read_and_callback",
"(",
"socket",
")",
"request",
"=",
"@service_type",
".",
"request_class",
".",
"new",
"response",
"=",
"@service_type",
".",
"response_class",
".",
"new",
"data",
"=",
"read_all",
"(",
"socket",
")",
"@byte_received",
"+=",
"data",
... | main loop of this connection.
read data and do callback.
@param [IO] socket
@return [Boolean] result of callback | [
"main",
"loop",
"of",
"this",
"connection",
".",
"read",
"data",
"and",
"do",
"callback",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/service_server.rb#L73-L90 | train |
OTL/rosruby | lib/ros/tcpros/service_server.rb | ROS::TCPROS.ServiceServer.serve | def serve(socket)
header = read_header(socket)
# not documented protocol?
if header['probe'] == '1'
write_header(socket, build_header)
elsif check_header(header)
write_header(socket, build_header)
read_and_callback(socket)
if header['persistent'] == '1'
... | ruby | def serve(socket)
header = read_header(socket)
# not documented protocol?
if header['probe'] == '1'
write_header(socket, build_header)
elsif check_header(header)
write_header(socket, build_header)
read_and_callback(socket)
if header['persistent'] == '1'
... | [
"def",
"serve",
"(",
"socket",
")",
"header",
"=",
"read_header",
"(",
"socket",
")",
"if",
"header",
"[",
"'probe'",
"]",
"==",
"'1'",
"write_header",
"(",
"socket",
",",
"build_header",
")",
"elsif",
"check_header",
"(",
"header",
")",
"write_header",
"(... | this is called by socket accept
@param [IO] socket given socket | [
"this",
"is",
"called",
"by",
"socket",
"accept"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/service_server.rb#L95-L112 | train |
OTL/rosruby | lib/ros/publisher.rb | ROS.Publisher.add_connection | def add_connection(caller_id) #:nodoc:
connection = TCPROS::Server.new(@caller_id, @topic_name, @topic_type,
:host=>@host,
:latched=>@is_latched,
:last_published_msg=>@last_published_msg)
connec... | ruby | def add_connection(caller_id) #:nodoc:
connection = TCPROS::Server.new(@caller_id, @topic_name, @topic_type,
:host=>@host,
:latched=>@is_latched,
:last_published_msg=>@last_published_msg)
connec... | [
"def",
"add_connection",
"(",
"caller_id",
")",
"connection",
"=",
"TCPROS",
"::",
"Server",
".",
"new",
"(",
"@caller_id",
",",
"@topic_name",
",",
"@topic_type",
",",
":host",
"=>",
"@host",
",",
":latched",
"=>",
"@is_latched",
",",
":last_published_msg",
"... | add tcpros connection as server
@param [String] caller_id caller_id of subscriber
@return [TCPROS::Server] connection object | [
"add",
"tcpros",
"connection",
"as",
"server"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/publisher.rb#L61-L71 | train |
OTL/rosruby | lib/ros/tcpros/server.rb | ROS::TCPROS.Server.publish_msg | def publish_msg(socket, msg)
data = write_msg(socket, msg)
@last_published_msg = msg
# for getBusStats
@byte_sent += data.length
@num_sent += 1
end | ruby | def publish_msg(socket, msg)
data = write_msg(socket, msg)
@last_published_msg = msg
# for getBusStats
@byte_sent += data.length
@num_sent += 1
end | [
"def",
"publish_msg",
"(",
"socket",
",",
"msg",
")",
"data",
"=",
"write_msg",
"(",
"socket",
",",
"msg",
")",
"@last_published_msg",
"=",
"msg",
"@byte_sent",
"+=",
"data",
".",
"length",
"@num_sent",
"+=",
"1",
"end"
] | send a message to reciever
@param [IO] socket socket for writing
@param [Class] msg msg class instance | [
"send",
"a",
"message",
"to",
"reciever"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/server.rb#L65-L71 | train |
OTL/rosruby | lib/ros/tcpros/server.rb | ROS::TCPROS.Server.serve | def serve(socket) #:nodoc:
header = read_header(socket)
if check_header(header)
if header['tcp_nodelay'] == '1'
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
begin
write_header(socket, build_header)
if latching?
if @last_... | ruby | def serve(socket) #:nodoc:
header = read_header(socket)
if check_header(header)
if header['tcp_nodelay'] == '1'
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
begin
write_header(socket, build_header)
if latching?
if @last_... | [
"def",
"serve",
"(",
"socket",
")",
"header",
"=",
"read_header",
"(",
"socket",
")",
"if",
"check_header",
"(",
"header",
")",
"if",
"header",
"[",
"'tcp_nodelay'",
"]",
"==",
"'1'",
"socket",
".",
"setsockopt",
"(",
"Socket",
"::",
"IPPROTO_TCP",
",",
... | this is called if a socket accept a connection.
This is GServer's function
@param [IO] socket given socket | [
"this",
"is",
"called",
"if",
"a",
"socket",
"accept",
"a",
"connection",
".",
"This",
"is",
"GServer",
"s",
"function"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/server.rb#L77-L102 | train |
OTL/rosruby | lib/ros/parameter_manager.rb | ROS.ParameterManager.set_param | def set_param(key, value)
code, message, value = @server.call("setParam", @caller_id, key, value)
case code
when 1
return true
when -1
raise message
else
return false
end
end | ruby | def set_param(key, value)
code, message, value = @server.call("setParam", @caller_id, key, value)
case code
when 1
return true
when -1
raise message
else
return false
end
end | [
"def",
"set_param",
"(",
"key",
",",
"value",
")",
"code",
",",
"message",
",",
"value",
"=",
"@server",
".",
"call",
"(",
"\"setParam\"",
",",
"@caller_id",
",",
"key",
",",
"value",
")",
"case",
"code",
"when",
"1",
"return",
"true",
"when",
"-",
"... | set parameter for 'key'
@param [String] key key of parameter
@param [String, Integer, Float, Boolean] value value of parameter
@return [Boolean] true if succeed
@raise | [
"set",
"parameter",
"for",
"key"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/parameter_manager.rb#L53-L63 | train |
OTL/rosruby | lib/ros/parameter_manager.rb | ROS.ParameterManager.delete_param | def delete_param(key)
code, message, value = @server.call("deleteParam", @caller_id, key)
case code
when 1
return true
else
return false
end
end | ruby | def delete_param(key)
code, message, value = @server.call("deleteParam", @caller_id, key)
case code
when 1
return true
else
return false
end
end | [
"def",
"delete_param",
"(",
"key",
")",
"code",
",",
"message",
",",
"value",
"=",
"@server",
".",
"call",
"(",
"\"deleteParam\"",
",",
"@caller_id",
",",
"key",
")",
"case",
"code",
"when",
"1",
"return",
"true",
"else",
"return",
"false",
"end",
"end"
... | delete parameter 'key'
@param [String] key key for remove
@return [Boolean] return true if success, false if it is not exist | [
"delete",
"parameter",
"key"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/parameter_manager.rb#L69-L77 | train |
OTL/rosruby | lib/ros/parameter_manager.rb | ROS.ParameterManager.search_param | def search_param(key)
code, message, value = @server.call("searchParam", @caller_id, key)
case code
when 1
return value
when -1
raise message
else
return false
end
end | ruby | def search_param(key)
code, message, value = @server.call("searchParam", @caller_id, key)
case code
when 1
return value
when -1
raise message
else
return false
end
end | [
"def",
"search_param",
"(",
"key",
")",
"code",
",",
"message",
",",
"value",
"=",
"@server",
".",
"call",
"(",
"\"searchParam\"",
",",
"@caller_id",
",",
"key",
")",
"case",
"code",
"when",
"1",
"return",
"value",
"when",
"-",
"1",
"raise",
"message",
... | search the all namespace for key
@param [String] key key for search
@return [Array] values | [
"search",
"the",
"all",
"namespace",
"for",
"key"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/parameter_manager.rb#L83-L93 | train |
OTL/rosruby | lib/ros/parameter_manager.rb | ROS.ParameterManager.has_param | def has_param(key)
code, message, value = @server.call("hasParam", @caller_id, key)
case code
when 1
return value
when -1
raise message
else
return false
end
end | ruby | def has_param(key)
code, message, value = @server.call("hasParam", @caller_id, key)
case code
when 1
return value
when -1
raise message
else
return false
end
end | [
"def",
"has_param",
"(",
"key",
")",
"code",
",",
"message",
",",
"value",
"=",
"@server",
".",
"call",
"(",
"\"hasParam\"",
",",
"@caller_id",
",",
"key",
")",
"case",
"code",
"when",
"1",
"return",
"value",
"when",
"-",
"1",
"raise",
"message",
"else... | check if the master has the key
@param [String] key key for check
@return [String, Integer, Float, Boolean] value of key | [
"check",
"if",
"the",
"master",
"has",
"the",
"key"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/parameter_manager.rb#L99-L109 | train |
OTL/rosruby | lib/ros/parameter_manager.rb | ROS.ParameterManager.get_param_names | def get_param_names
code, message, value = @server.call("getParamNames", @caller_id)
case code
when 1
return value
when -1
raise message
else
return false
end
end | ruby | def get_param_names
code, message, value = @server.call("getParamNames", @caller_id)
case code
when 1
return value
when -1
raise message
else
return false
end
end | [
"def",
"get_param_names",
"code",
",",
"message",
",",
"value",
"=",
"@server",
".",
"call",
"(",
"\"getParamNames\"",
",",
"@caller_id",
")",
"case",
"code",
"when",
"1",
"return",
"value",
"when",
"-",
"1",
"raise",
"message",
"else",
"return",
"false",
... | get the all keys of parameters
@return [Array] all keys | [
"get",
"the",
"all",
"keys",
"of",
"parameters"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/parameter_manager.rb#L115-L125 | train |
OTL/rosruby | lib/ros/time.rb | ROS.Time.- | def -(other)
d = ::ROS::Duration.new
d.secs = @secs - other.secs
d.nsecs = @nsecs - other.nsecs
d.canonicalize
end | ruby | def -(other)
d = ::ROS::Duration.new
d.secs = @secs - other.secs
d.nsecs = @nsecs - other.nsecs
d.canonicalize
end | [
"def",
"-",
"(",
"other",
")",
"d",
"=",
"::",
"ROS",
"::",
"Duration",
".",
"new",
"d",
".",
"secs",
"=",
"@secs",
"-",
"other",
".",
"secs",
"d",
".",
"nsecs",
"=",
"@nsecs",
"-",
"other",
".",
"nsecs",
"d",
".",
"canonicalize",
"end"
] | subtract time value.
@param [Time] other
@return [Duration] duration | [
"subtract",
"time",
"value",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/time.rb#L161-L166 | train |
OTL/rosruby | lib/ros/tcpros/service_client.rb | ROS::TCPROS.ServiceClient.call | def call(srv_request, srv_response)
write_header(@socket, build_header)
if check_header(read_header(@socket))
write_msg(@socket, srv_request)
@socket.flush
ok_byte = read_ok_byte
if ok_byte == 1
srv_response.deserialize(read_all(@socket))
return true
end
false
end
false
end | ruby | def call(srv_request, srv_response)
write_header(@socket, build_header)
if check_header(read_header(@socket))
write_msg(@socket, srv_request)
@socket.flush
ok_byte = read_ok_byte
if ok_byte == 1
srv_response.deserialize(read_all(@socket))
return true
end
false
end
false
end | [
"def",
"call",
"(",
"srv_request",
",",
"srv_response",
")",
"write_header",
"(",
"@socket",
",",
"build_header",
")",
"if",
"check_header",
"(",
"read_header",
"(",
"@socket",
")",
")",
"write_msg",
"(",
"@socket",
",",
"srv_request",
")",
"@socket",
".",
"... | call the service by sending srv request message,
and receive response message.
@param [Message] srv_request call with this request
@param [Message] srv_response response is stored in this message
@return [Boolean] result of call | [
"call",
"the",
"service",
"by",
"sending",
"srv",
"request",
"message",
"and",
"receive",
"response",
"message",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/service_client.rb#L59-L72 | train |
OTL/rosruby | lib/ros/master.rb | ROS.Master.kill_same_name_node | def kill_same_name_node(caller_id, api)
delete_api = nil
[@publishers, @subscribers, @services].each do |list|
list.each do |pub|
if pub.caller_id == caller_id and pub.api != api
puts "killing #{caller_id}"
delete_api = pub.api
break
end
... | ruby | def kill_same_name_node(caller_id, api)
delete_api = nil
[@publishers, @subscribers, @services].each do |list|
list.each do |pub|
if pub.caller_id == caller_id and pub.api != api
puts "killing #{caller_id}"
delete_api = pub.api
break
end
... | [
"def",
"kill_same_name_node",
"(",
"caller_id",
",",
"api",
")",
"delete_api",
"=",
"nil",
"[",
"@publishers",
",",
"@subscribers",
",",
"@services",
"]",
".",
"each",
"do",
"|",
"list",
"|",
"list",
".",
"each",
"do",
"|",
"pub",
"|",
"if",
"pub",
"."... | kill old node if the same caller_id node is exits.
@param [String] caller_id new node's caller_id
@param [String] api new node's XMLRPC URI | [
"kill",
"old",
"node",
"if",
"the",
"same",
"caller_id",
"node",
"is",
"exits",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master.rb#L159-L181 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.get_available_port | def get_available_port
server = TCPServer.open(0)
saddr = server.getsockname
port = Socket.unpack_sockaddr_in(saddr)[0]
server.close
port
end | ruby | def get_available_port
server = TCPServer.open(0)
saddr = server.getsockname
port = Socket.unpack_sockaddr_in(saddr)[0]
server.close
port
end | [
"def",
"get_available_port",
"server",
"=",
"TCPServer",
".",
"open",
"(",
"0",
")",
"saddr",
"=",
"server",
".",
"getsockname",
"port",
"=",
"Socket",
".",
"unpack_sockaddr_in",
"(",
"saddr",
")",
"[",
"0",
"]",
"server",
".",
"close",
"port",
"end"
] | get available port number by opening port 0.
@return [Integer] port_num | [
"get",
"available",
"port",
"number",
"by",
"opening",
"port",
"0",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L97-L103 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.wait_for_service | def wait_for_service(service_name, timeout_sec)
begin
timeout(timeout_sec) do
while @is_ok
if @master.lookup_service(service_name)
return true
end
sleep(0.1)
end
end
rescue Timeout::Error
puts "time out for wait se... | ruby | def wait_for_service(service_name, timeout_sec)
begin
timeout(timeout_sec) do
while @is_ok
if @master.lookup_service(service_name)
return true
end
sleep(0.1)
end
end
rescue Timeout::Error
puts "time out for wait se... | [
"def",
"wait_for_service",
"(",
"service_name",
",",
"timeout_sec",
")",
"begin",
"timeout",
"(",
"timeout_sec",
")",
"do",
"while",
"@is_ok",
"if",
"@master",
".",
"lookup_service",
"(",
"service_name",
")",
"return",
"true",
"end",
"sleep",
"(",
"0.1",
")",
... | wait until service is available
@param [String] service_name name of service for waiting
@param [Float] timeout_sec wait for this seconds, then time out
@return [Boolean] true: available, false: time out | [
"wait",
"until",
"service",
"is",
"available"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L118-L134 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.add_service_server | def add_service_server(service_server)
@master.register_service(service_server.service_name,
service_server.service_uri)
service_server.set_manager(self)
@service_servers.push(service_server)
service_server
end | ruby | def add_service_server(service_server)
@master.register_service(service_server.service_name,
service_server.service_uri)
service_server.set_manager(self)
@service_servers.push(service_server)
service_server
end | [
"def",
"add_service_server",
"(",
"service_server",
")",
"@master",
".",
"register_service",
"(",
"service_server",
".",
"service_name",
",",
"service_server",
".",
"service_uri",
")",
"service_server",
".",
"set_manager",
"(",
"self",
")",
"@service_servers",
".",
... | register a service to master,
and add it in the controlling server list.
raise if fail.
@param [ServiceServer] service_server ServiceServer to be added
@return [ServiceServer] service_server | [
"register",
"a",
"service",
"to",
"master",
"and",
"add",
"it",
"in",
"the",
"controlling",
"server",
"list",
".",
"raise",
"if",
"fail",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L142-L148 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.add_subscriber | def add_subscriber(subscriber)
uris = @master.register_subscriber(subscriber.topic_name,
subscriber.topic_type.type)
subscriber.set_manager(self)
uris.each do |publisher_uri|
subscriber.add_connection(publisher_uri)
end
@subscribers.push(sub... | ruby | def add_subscriber(subscriber)
uris = @master.register_subscriber(subscriber.topic_name,
subscriber.topic_type.type)
subscriber.set_manager(self)
uris.each do |publisher_uri|
subscriber.add_connection(publisher_uri)
end
@subscribers.push(sub... | [
"def",
"add_subscriber",
"(",
"subscriber",
")",
"uris",
"=",
"@master",
".",
"register_subscriber",
"(",
"subscriber",
".",
"topic_name",
",",
"subscriber",
".",
"topic_type",
".",
"type",
")",
"subscriber",
".",
"set_manager",
"(",
"self",
")",
"uris",
".",
... | register a subscriber to master. raise if fail.
@param [Subscriber] subscriber Subscriber to be added
@return [Subscriber] subscriber | [
"register",
"a",
"subscriber",
"to",
"master",
".",
"raise",
"if",
"fail",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L155-L164 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.add_parameter_subscriber | def add_parameter_subscriber(subscriber)
subscriber.set_manager(self)
@parameter_subscribers.push(subscriber)
@master.subscribe_param(subscriber.key)
subscriber
end | ruby | def add_parameter_subscriber(subscriber)
subscriber.set_manager(self)
@parameter_subscribers.push(subscriber)
@master.subscribe_param(subscriber.key)
subscriber
end | [
"def",
"add_parameter_subscriber",
"(",
"subscriber",
")",
"subscriber",
".",
"set_manager",
"(",
"self",
")",
"@parameter_subscribers",
".",
"push",
"(",
"subscriber",
")",
"@master",
".",
"subscribe_param",
"(",
"subscriber",
".",
"key",
")",
"subscriber",
"end"... | register callback for paramUpdate
@param [ParameterSubscriber] subscriber ParameterSubscriber instance to be added
@return [ParameterSubscriber] subscriber | [
"register",
"callback",
"for",
"paramUpdate"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L170-L175 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.add_publisher | def add_publisher(publisher)
@master.register_publisher(publisher.topic_name,
publisher.topic_type.type)
publisher.set_manager(self)
@publishers.push(publisher)
publisher
end | ruby | def add_publisher(publisher)
@master.register_publisher(publisher.topic_name,
publisher.topic_type.type)
publisher.set_manager(self)
@publishers.push(publisher)
publisher
end | [
"def",
"add_publisher",
"(",
"publisher",
")",
"@master",
".",
"register_publisher",
"(",
"publisher",
".",
"topic_name",
",",
"publisher",
".",
"topic_type",
".",
"type",
")",
"publisher",
".",
"set_manager",
"(",
"self",
")",
"@publishers",
".",
"push",
"(",... | register a publisher. raise if fail.
@param [Publisher] publisher Publisher instance to be added
@return [Publisher] publisher | [
"register",
"a",
"publisher",
".",
"raise",
"if",
"fail",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L181-L187 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.shutdown_publisher | def shutdown_publisher(publisher)
begin
@master.unregister_publisher(publisher.topic_name)
ensure
@publishers.delete(publisher) do |pub|
raise "publisher not found"
end
publisher.close
end
end | ruby | def shutdown_publisher(publisher)
begin
@master.unregister_publisher(publisher.topic_name)
ensure
@publishers.delete(publisher) do |pub|
raise "publisher not found"
end
publisher.close
end
end | [
"def",
"shutdown_publisher",
"(",
"publisher",
")",
"begin",
"@master",
".",
"unregister_publisher",
"(",
"publisher",
".",
"topic_name",
")",
"ensure",
"@publishers",
".",
"delete",
"(",
"publisher",
")",
"do",
"|",
"pub",
"|",
"raise",
"\"publisher not found\"",... | shutdown a publisher.
@param [Publisher] publisher Publisher to be shutdown | [
"shutdown",
"a",
"publisher",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L201-L210 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.shutdown_subscriber | def shutdown_subscriber(subscriber)
begin
@master.unregister_subscriber(subscriber.topic_name)
@subscribers.delete(subscriber) do |pub|
raise "subscriber not found"
end
ensure
subscriber.close
end
end | ruby | def shutdown_subscriber(subscriber)
begin
@master.unregister_subscriber(subscriber.topic_name)
@subscribers.delete(subscriber) do |pub|
raise "subscriber not found"
end
ensure
subscriber.close
end
end | [
"def",
"shutdown_subscriber",
"(",
"subscriber",
")",
"begin",
"@master",
".",
"unregister_subscriber",
"(",
"subscriber",
".",
"topic_name",
")",
"@subscribers",
".",
"delete",
"(",
"subscriber",
")",
"do",
"|",
"pub",
"|",
"raise",
"\"subscriber not found\"",
"e... | shutdown a subscriber.
@param [Subscriber] subscriber Subscriber to be shutdown | [
"shutdown",
"a",
"subscriber",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L215-L224 | train |
OTL/rosruby | lib/ros/graph_manager.rb | ROS.GraphManager.shutdown_service_server | def shutdown_service_server(service)
begin
@master.unregister_service(service.service_name,
service.service_uri)
@service_servers.delete(service) do |pub|
raise "service_server not found"
end
ensure
service.close
end
end | ruby | def shutdown_service_server(service)
begin
@master.unregister_service(service.service_name,
service.service_uri)
@service_servers.delete(service) do |pub|
raise "service_server not found"
end
ensure
service.close
end
end | [
"def",
"shutdown_service_server",
"(",
"service",
")",
"begin",
"@master",
".",
"unregister_service",
"(",
"service",
".",
"service_name",
",",
"service",
".",
"service_uri",
")",
"@service_servers",
".",
"delete",
"(",
"service",
")",
"do",
"|",
"pub",
"|",
"... | shutdown a service server.
@param [ServiceServer] service ServiceServer to be shutdown | [
"shutdown",
"a",
"service",
"server",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/graph_manager.rb#L229-L239 | train |
OTL/rosruby | lib/ros/tcpros/client.rb | ROS::TCPROS.Client.start | def start
write_header(@socket, build_header)
read_header(@socket)
@thread = Thread.start do
while @is_running
data = read_all(@socket)
msg = @topic_type.new
msg.deserialize(data)
@byte_received += data.length
@msg_queue.push(msg)
end
... | ruby | def start
write_header(@socket, build_header)
read_header(@socket)
@thread = Thread.start do
while @is_running
data = read_all(@socket)
msg = @topic_type.new
msg.deserialize(data)
@byte_received += data.length
@msg_queue.push(msg)
end
... | [
"def",
"start",
"write_header",
"(",
"@socket",
",",
"build_header",
")",
"read_header",
"(",
"@socket",
")",
"@thread",
"=",
"Thread",
".",
"start",
"do",
"while",
"@is_running",
"data",
"=",
"read_all",
"(",
"@socket",
")",
"msg",
"=",
"@topic_type",
".",
... | start recieving data.
The received messages are pushed into a message queue. | [
"start",
"recieving",
"data",
".",
"The",
"received",
"messages",
"are",
"pushed",
"into",
"a",
"message",
"queue",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/client.rb#L68-L80 | train |
OTL/rosruby | lib/ros/tcpros/message.rb | ROS::TCPROS.Message.write_msg | def write_msg(socket, msg)
sio = StringIO.new('', 'r+')
len = msg.serialize(sio)
sio.rewind
data = sio.read
len = data.length
data = [len, data].pack("La#{len}")
socket.write(data)
data
end | ruby | def write_msg(socket, msg)
sio = StringIO.new('', 'r+')
len = msg.serialize(sio)
sio.rewind
data = sio.read
len = data.length
data = [len, data].pack("La#{len}")
socket.write(data)
data
end | [
"def",
"write_msg",
"(",
"socket",
",",
"msg",
")",
"sio",
"=",
"StringIO",
".",
"new",
"(",
"''",
",",
"'r+'",
")",
"len",
"=",
"msg",
".",
"serialize",
"(",
"sio",
")",
"sio",
".",
"rewind",
"data",
"=",
"sio",
".",
"read",
"len",
"=",
"data",
... | write message to socket.
@param [IO] socket socket for writing
@param [Message] msg message for writing
@return [String] wrote data | [
"write",
"message",
"to",
"socket",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/message.rb#L26-L35 | train |
OTL/rosruby | lib/ros/tcpros/message.rb | ROS::TCPROS.Message.read_all | def read_all(socket)
total_bytes = socket.recv(4).unpack("V")[0]
if total_bytes and total_bytes > 0
socket.recv(total_bytes)
else
''
end
end | ruby | def read_all(socket)
total_bytes = socket.recv(4).unpack("V")[0]
if total_bytes and total_bytes > 0
socket.recv(total_bytes)
else
''
end
end | [
"def",
"read_all",
"(",
"socket",
")",
"total_bytes",
"=",
"socket",
".",
"recv",
"(",
"4",
")",
".",
"unpack",
"(",
"\"V\"",
")",
"[",
"0",
"]",
"if",
"total_bytes",
"and",
"total_bytes",
">",
"0",
"socket",
".",
"recv",
"(",
"total_bytes",
")",
"el... | read the size of data and read it from socket.
@param [IO] socket socket for reading
@return [String] received data | [
"read",
"the",
"size",
"of",
"data",
"and",
"read",
"it",
"from",
"socket",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/message.rb#L41-L48 | train |
OTL/rosruby | lib/ros/tcpros/message.rb | ROS::TCPROS.Message.read_header | def read_header(socket)
header = ::ROS::TCPROS::Header.new
header.deserialize(read_all(socket))
header
end | ruby | def read_header(socket)
header = ::ROS::TCPROS::Header.new
header.deserialize(read_all(socket))
header
end | [
"def",
"read_header",
"(",
"socket",
")",
"header",
"=",
"::",
"ROS",
"::",
"TCPROS",
"::",
"Header",
".",
"new",
"header",
".",
"deserialize",
"(",
"read_all",
"(",
"socket",
")",
")",
"header",
"end"
] | read a connection header from socket
@param [String] socket socket for reading
@return [Header] header | [
"read",
"a",
"connection",
"header",
"from",
"socket"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/message.rb#L54-L58 | train |
OTL/rosruby | lib/ros/tcpros/header.rb | ROS::TCPROS.Header.push_data | def push_data(key, value)
if (not key.kind_of?(String)) or (not value.kind_of?(String))
raise ArgumentError::new('header key and value must be string')
end
@data[key] = value
self
end | ruby | def push_data(key, value)
if (not key.kind_of?(String)) or (not value.kind_of?(String))
raise ArgumentError::new('header key and value must be string')
end
@data[key] = value
self
end | [
"def",
"push_data",
"(",
"key",
",",
"value",
")",
"if",
"(",
"not",
"key",
".",
"kind_of?",
"(",
"String",
")",
")",
"or",
"(",
"not",
"value",
".",
"kind_of?",
"(",
"String",
")",
")",
"raise",
"ArgumentError",
"::",
"new",
"(",
"'header key and valu... | initialize with hash
@param [Hash] data
add key-value data to this header.
@param [String] key key for header
@param [String] value value for key
@return [Header] self | [
"initialize",
"with",
"hash"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/header.rb#L30-L36 | train |
OTL/rosruby | lib/ros/tcpros/header.rb | ROS::TCPROS.Header.deserialize | def deserialize(data)
while data.length > 0
len, data = data.unpack('Va*')
msg = data[0..(len-1)]
equal_position = msg.index('=')
key = msg[0..(equal_position-1)]
value = msg[(equal_position+1)..-1]
@data[key] = value
data = data[(len)..-1]
end
s... | ruby | def deserialize(data)
while data.length > 0
len, data = data.unpack('Va*')
msg = data[0..(len-1)]
equal_position = msg.index('=')
key = msg[0..(equal_position-1)]
value = msg[(equal_position+1)..-1]
@data[key] = value
data = data[(len)..-1]
end
s... | [
"def",
"deserialize",
"(",
"data",
")",
"while",
"data",
".",
"length",
">",
"0",
"len",
",",
"data",
"=",
"data",
".",
"unpack",
"(",
"'Va*'",
")",
"msg",
"=",
"data",
"[",
"0",
"..",
"(",
"len",
"-",
"1",
")",
"]",
"equal_position",
"=",
"msg",... | deserialize the data to header.
this does not contain total byte number.
@param [String] data
@return [Header] self | [
"deserialize",
"the",
"data",
"to",
"header",
".",
"this",
"does",
"not",
"contain",
"total",
"byte",
"number",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/header.rb#L51-L62 | train |
OTL/rosruby | lib/ros/tcpros/header.rb | ROS::TCPROS.Header.serialize | def serialize(buff)
serialized_data = ''
@data.each_pair do |key, value|
data_str = key + '=' + value
serialized_data = serialized_data + [data_str.length, data_str].pack('Va*')
end
total_byte = serialized_data.length
return buff.write([total_byte, serialized_data].pack('Va... | ruby | def serialize(buff)
serialized_data = ''
@data.each_pair do |key, value|
data_str = key + '=' + value
serialized_data = serialized_data + [data_str.length, data_str].pack('Va*')
end
total_byte = serialized_data.length
return buff.write([total_byte, serialized_data].pack('Va... | [
"def",
"serialize",
"(",
"buff",
")",
"serialized_data",
"=",
"''",
"@data",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"data_str",
"=",
"key",
"+",
"'='",
"+",
"value",
"serialized_data",
"=",
"serialized_data",
"+",
"[",
"data_str",
".",
"l... | serialize the data into header.
return the byte of the serialized data.
@param [IO] buff where to write data
@return [Integer] byte of serialized data | [
"serialize",
"the",
"data",
"into",
"header",
".",
"return",
"the",
"byte",
"of",
"the",
"serialized",
"data",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/tcpros/header.rb#L78-L86 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.unregister_service | def unregister_service(service, service_api)
code, message, val = @proxy.unregisterService(@caller_id,
service,
service_api)
if code == 1
return true
elsif code == 0
puts message
... | ruby | def unregister_service(service, service_api)
code, message, val = @proxy.unregisterService(@caller_id,
service,
service_api)
if code == 1
return true
elsif code == 0
puts message
... | [
"def",
"unregister_service",
"(",
"service",
",",
"service_api",
")",
"code",
",",
"message",
",",
"val",
"=",
"@proxy",
".",
"unregisterService",
"(",
"@caller_id",
",",
"service",
",",
"service_api",
")",
"if",
"code",
"==",
"1",
"return",
"true",
"elsif",... | unregister a service
@param [String] service name of service
@param [String] service_api service api uri
@return [Boolean] true success
@raise RuntimeError | [
"unregister",
"a",
"service"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L57-L69 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.register_subscriber | def register_subscriber(topic, topic_type)
code, message,val = @proxy.registerSubscriber(@caller_id,
topic,
topic_type,
@slave_uri)
if code == 1
... | ruby | def register_subscriber(topic, topic_type)
code, message,val = @proxy.registerSubscriber(@caller_id,
topic,
topic_type,
@slave_uri)
if code == 1
... | [
"def",
"register_subscriber",
"(",
"topic",
",",
"topic_type",
")",
"code",
",",
"message",
",",
"val",
"=",
"@proxy",
".",
"registerSubscriber",
"(",
"@caller_id",
",",
"topic",
",",
"topic_type",
",",
"@slave_uri",
")",
"if",
"code",
"==",
"1",
"val",
"e... | register a subscriber
@param [String] topic topic name
@param [String] topic_type topic type
@return [Array] URI of current publishers
@raise [RuntimeError] if error | [
"register",
"a",
"subscriber"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L76-L89 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.unregister_subscriber | def unregister_subscriber(topic)
code, message,val = @proxy.unregisterSubscriber(@caller_id,
topic,
@slave_uri)
if code == 1
return true
elsif code == 0
puts message
retu... | ruby | def unregister_subscriber(topic)
code, message,val = @proxy.unregisterSubscriber(@caller_id,
topic,
@slave_uri)
if code == 1
return true
elsif code == 0
puts message
retu... | [
"def",
"unregister_subscriber",
"(",
"topic",
")",
"code",
",",
"message",
",",
"val",
"=",
"@proxy",
".",
"unregisterSubscriber",
"(",
"@caller_id",
",",
"topic",
",",
"@slave_uri",
")",
"if",
"code",
"==",
"1",
"return",
"true",
"elsif",
"code",
"==",
"0... | unregister a subscriber
@param [String] topic name of topic to unregister
@return [Boolean] true
@raise RuntimeError | [
"unregister",
"a",
"subscriber"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L95-L107 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.register_publisher | def register_publisher(topic, topic_type)
code, message, uris = @proxy.registerPublisher(@caller_id,
topic,
topic_type,
@slave_uri)
if code == 1
... | ruby | def register_publisher(topic, topic_type)
code, message, uris = @proxy.registerPublisher(@caller_id,
topic,
topic_type,
@slave_uri)
if code == 1
... | [
"def",
"register_publisher",
"(",
"topic",
",",
"topic_type",
")",
"code",
",",
"message",
",",
"uris",
"=",
"@proxy",
".",
"registerPublisher",
"(",
"@caller_id",
",",
"topic",
",",
"topic_type",
",",
"@slave_uri",
")",
"if",
"code",
"==",
"1",
"uris",
"e... | register a publisher
@param [String] topic topic name of topic
@param [String] topic_type type of topic
@return [Array] URI of current subscribers
@raise RuntimeError | [
"register",
"a",
"publisher"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L114-L124 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.unregister_publisher | def unregister_publisher(topic)
code, message, val = @proxy.unregisterPublisher(@caller_id,
topic,
@slave_uri)
if code == 1
return val
elsif code == 0
puts message
return... | ruby | def unregister_publisher(topic)
code, message, val = @proxy.unregisterPublisher(@caller_id,
topic,
@slave_uri)
if code == 1
return val
elsif code == 0
puts message
return... | [
"def",
"unregister_publisher",
"(",
"topic",
")",
"code",
",",
"message",
",",
"val",
"=",
"@proxy",
".",
"unregisterPublisher",
"(",
"@caller_id",
",",
"topic",
",",
"@slave_uri",
")",
"if",
"code",
"==",
"1",
"return",
"val",
"elsif",
"code",
"==",
"0",
... | unregister a publisher
@param [String] topic name of topic
@return [Boolean] true
@raise RuntimeError | [
"unregister",
"a",
"publisher"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L130-L143 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.subscribe_param | def subscribe_param(key)
code, message, uri = @proxy.subscribeParam(@caller_id, @slave_uri, key)
if code == 1
return true
else
raise message
end
end | ruby | def subscribe_param(key)
code, message, uri = @proxy.subscribeParam(@caller_id, @slave_uri, key)
if code == 1
return true
else
raise message
end
end | [
"def",
"subscribe_param",
"(",
"key",
")",
"code",
",",
"message",
",",
"uri",
"=",
"@proxy",
".",
"subscribeParam",
"(",
"@caller_id",
",",
"@slave_uri",
",",
"key",
")",
"if",
"code",
"==",
"1",
"return",
"true",
"else",
"raise",
"message",
"end",
"end... | this method is not described in the wiki.
subscribe to the parameter key.
@param [String] key name of parameter
@return [Boolean] true
@raise [RuntimeError] if fail | [
"this",
"method",
"is",
"not",
"described",
"in",
"the",
"wiki",
".",
"subscribe",
"to",
"the",
"parameter",
"key",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L151-L158 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.unsubscribe_param | def unsubscribe_param(key)
code, message, uri = @proxy.unsubscribeParam(@caller_id, @slave_uri, key)
if code == 1
return true
else
raise message
end
end | ruby | def unsubscribe_param(key)
code, message, uri = @proxy.unsubscribeParam(@caller_id, @slave_uri, key)
if code == 1
return true
else
raise message
end
end | [
"def",
"unsubscribe_param",
"(",
"key",
")",
"code",
",",
"message",
",",
"uri",
"=",
"@proxy",
".",
"unsubscribeParam",
"(",
"@caller_id",
",",
"@slave_uri",
",",
"key",
")",
"if",
"code",
"==",
"1",
"return",
"true",
"else",
"raise",
"message",
"end",
... | unsubscribe to the parameter key.
this method is not described in the wiki.
@param [String] key name of parameter key
@return [Boolean] true
@raise [RuntimeError] if failt | [
"unsubscribe",
"to",
"the",
"parameter",
"key",
".",
"this",
"method",
"is",
"not",
"described",
"in",
"the",
"wiki",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L166-L173 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.get_published_topics | def get_published_topics(subgraph='')
code, message, topics = @proxy.getPublishedTopics(@caller_id, subgraph)
if code == 1
return topics
elsif
raise message
end
end | ruby | def get_published_topics(subgraph='')
code, message, topics = @proxy.getPublishedTopics(@caller_id, subgraph)
if code == 1
return topics
elsif
raise message
end
end | [
"def",
"get_published_topics",
"(",
"subgraph",
"=",
"''",
")",
"code",
",",
"message",
",",
"topics",
"=",
"@proxy",
".",
"getPublishedTopics",
"(",
"@caller_id",
",",
"subgraph",
")",
"if",
"code",
"==",
"1",
"return",
"topics",
"elsif",
"raise",
"message"... | get the all published topics
@param [String] subgraph namespace for check
@return [Array] topic names.
@raise | [
"get",
"the",
"all",
"published",
"topics"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L191-L198 | train |
OTL/rosruby | lib/ros/master_proxy.rb | ROS.MasterProxy.lookup_service | def lookup_service(service)
code, message, uri = @proxy.lookupService(@caller_id, service)
if code == 1
uri
else
false
end
end | ruby | def lookup_service(service)
code, message, uri = @proxy.lookupService(@caller_id, service)
if code == 1
uri
else
false
end
end | [
"def",
"lookup_service",
"(",
"service",
")",
"code",
",",
"message",
",",
"uri",
"=",
"@proxy",
".",
"lookupService",
"(",
"@caller_id",
",",
"service",
")",
"if",
"code",
"==",
"1",
"uri",
"else",
"false",
"end",
"end"
] | look up a service by name
@param [String] service name of service
@return [String, nil] URI of service if found, nil not found. | [
"look",
"up",
"a",
"service",
"by",
"name"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/master_proxy.rb#L226-L233 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.get_param | def get_param(key, default=nil)
key = expand_local_name(@node_name, key)
param = @parameter.get_param(key)
if param
param
else
default
end
end | ruby | def get_param(key, default=nil)
key = expand_local_name(@node_name, key)
param = @parameter.get_param(key)
if param
param
else
default
end
end | [
"def",
"get_param",
"(",
"key",
",",
"default",
"=",
"nil",
")",
"key",
"=",
"expand_local_name",
"(",
"@node_name",
",",
"key",
")",
"param",
"=",
"@parameter",
".",
"get_param",
"(",
"key",
")",
"if",
"param",
"param",
"else",
"default",
"end",
"end"
] | get the param for key.
You can set default value. That is uesed when the key is not set yet.
@param [String] key key for search the parameters
@param [String, Integer, Float, Boolean] default default value
@return [String, Integer, Float, Boolean] parameter value for key | [
"get",
"the",
"param",
"for",
"key",
".",
"You",
"can",
"set",
"default",
"value",
".",
"That",
"is",
"uesed",
"when",
"the",
"key",
"is",
"not",
"set",
"yet",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L141-L149 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.advertise | def advertise(topic_name, topic_type, options={})
if options[:no_resolve]
name = topic_name
else
name = resolve_name(topic_name)
end
publisher = Publisher.new(@node_name,
name,
topic_type,
... | ruby | def advertise(topic_name, topic_type, options={})
if options[:no_resolve]
name = topic_name
else
name = resolve_name(topic_name)
end
publisher = Publisher.new(@node_name,
name,
topic_type,
... | [
"def",
"advertise",
"(",
"topic_name",
",",
"topic_type",
",",
"options",
"=",
"{",
"}",
")",
"if",
"options",
"[",
":no_resolve",
"]",
"name",
"=",
"topic_name",
"else",
"name",
"=",
"resolve_name",
"(",
"topic_name",
")",
"end",
"publisher",
"=",
"Publis... | start publishing the topic.
@param [String] topic_name name of topic (string)
@param [Class] topic_type topic class
@param [Hash] options :latched, :resolve
@option options [Boolean] :latched (false) latched topic
@option options [Boolean] :resolve (true) resolve topic_name or not. This is for publish /rosout wit... | [
"start",
"publishing",
"the",
"topic",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L195-L209 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.advertise_service | def advertise_service(service_name, service_type, &callback)
server = ::ROS::ServiceServer.new(@node_name,
resolve_name(service_name),
service_type,
callback,
... | ruby | def advertise_service(service_name, service_type, &callback)
server = ::ROS::ServiceServer.new(@node_name,
resolve_name(service_name),
service_type,
callback,
... | [
"def",
"advertise_service",
"(",
"service_name",
",",
"service_type",
",",
"&",
"callback",
")",
"server",
"=",
"::",
"ROS",
"::",
"ServiceServer",
".",
"new",
"(",
"@node_name",
",",
"resolve_name",
"(",
"service_name",
")",
",",
"service_type",
",",
"callbac... | start service server.
@param [String] service_name name of this service (string)
@param [Service] service_type service class
@param [Proc] callback service definition
@return [ServiceServer] ServiceServer instance | [
"start",
"service",
"server",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L218-L227 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.subscribe | def subscribe(topic_name, topic_type, &callback)
sub = Subscriber.new(@node_name,
resolve_name(topic_name),
topic_type,
callback)
@manager.add_subscriber(sub)
trap_signals
sub
end | ruby | def subscribe(topic_name, topic_type, &callback)
sub = Subscriber.new(@node_name,
resolve_name(topic_name),
topic_type,
callback)
@manager.add_subscriber(sub)
trap_signals
sub
end | [
"def",
"subscribe",
"(",
"topic_name",
",",
"topic_type",
",",
"&",
"callback",
")",
"sub",
"=",
"Subscriber",
".",
"new",
"(",
"@node_name",
",",
"resolve_name",
"(",
"topic_name",
")",
",",
"topic_type",
",",
"callback",
")",
"@manager",
".",
"add_subscrib... | start to subscribe a topic.
@param [String] topic_name name of topic (string)
@param [Class] topic_type Topic instance
@return [Subscriber] created Subscriber instance | [
"start",
"to",
"subscribe",
"a",
"topic",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L256-L264 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.subscribe_parameter | def subscribe_parameter(param, &callback)
sub = ParameterSubscriber.new(param, callback)
@manager.add_parameter_subscriber(sub)
sub
end | ruby | def subscribe_parameter(param, &callback)
sub = ParameterSubscriber.new(param, callback)
@manager.add_parameter_subscriber(sub)
sub
end | [
"def",
"subscribe_parameter",
"(",
"param",
",",
"&",
"callback",
")",
"sub",
"=",
"ParameterSubscriber",
".",
"new",
"(",
"param",
",",
"callback",
")",
"@manager",
".",
"add_parameter_subscriber",
"(",
"sub",
")",
"sub",
"end"
] | subscribe to the parameter.
@param [String] param name of parameter to subscribe
@param [Proc] callback callback when parameter updated
@return [ParameterSubscriber] created ParameterSubscriber instance | [
"subscribe",
"to",
"the",
"parameter",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L272-L276 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.convert_if_needed | def convert_if_needed(value) #:nodoc:
if value =~ /^[+-]?\d+\.?\d*$/ # float
value = value.to_f
elsif value =~ /^[+-]?\d+$/ # int
value = value.to_i
else
value
end
end | ruby | def convert_if_needed(value) #:nodoc:
if value =~ /^[+-]?\d+\.?\d*$/ # float
value = value.to_f
elsif value =~ /^[+-]?\d+$/ # int
value = value.to_i
else
value
end
end | [
"def",
"convert_if_needed",
"(",
"value",
")",
"if",
"value",
"=~",
"/",
"\\d",
"\\.",
"\\d",
"/",
"value",
"=",
"value",
".",
"to_f",
"elsif",
"value",
"=~",
"/",
"\\d",
"/",
"value",
"=",
"value",
".",
"to_i",
"else",
"value",
"end",
"end"
] | converts strings if it is float and int numbers.
@example
convert_if_needed('10') # => 10
convert_if_needed('0.1') # => 0.1
convert_if_needed('string') # => 'string'
@param [String] value string
@return [Float, Integer, String] return converted value. | [
"converts",
"strings",
"if",
"it",
"is",
"float",
"and",
"int",
"numbers",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L398-L406 | train |
OTL/rosruby | lib/ros/node.rb | ROS.Node.parse_args | def parse_args(args) #:nodoc:
remapping = {}
for arg in args
splited = arg.split(':=')
if splited.length == 2
key, value = splited
if key == '__name'
@node_name = resolve_name(value)
elsif key == '__ip'
@host = value
elsif key =... | ruby | def parse_args(args) #:nodoc:
remapping = {}
for arg in args
splited = arg.split(':=')
if splited.length == 2
key, value = splited
if key == '__name'
@node_name = resolve_name(value)
elsif key == '__ip'
@host = value
elsif key =... | [
"def",
"parse_args",
"(",
"args",
")",
"remapping",
"=",
"{",
"}",
"for",
"arg",
"in",
"args",
"splited",
"=",
"arg",
".",
"split",
"(",
"':='",
")",
"if",
"splited",
".",
"length",
"==",
"2",
"key",
",",
"value",
"=",
"splited",
"if",
"key",
"==",... | parse all args.
@param [Array] args arguments for parse | [
"parse",
"all",
"args",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/node.rb#L411-L438 | train |
OTL/rosruby | lib/ros/subscriber.rb | ROS.Subscriber.add_connection | def add_connection(uri) #:nodoc:
publisher = SlaveProxy.new(@caller_id, uri)
begin
protocol, host, port = publisher.request_topic(@topic_name, [["TCPROS"]])
if protocol == "TCPROS"
connection = TCPROS::Client.new(host, port, @caller_id, @topic_name, @topic_type, uri, @tcp_no_delay)... | ruby | def add_connection(uri) #:nodoc:
publisher = SlaveProxy.new(@caller_id, uri)
begin
protocol, host, port = publisher.request_topic(@topic_name, [["TCPROS"]])
if protocol == "TCPROS"
connection = TCPROS::Client.new(host, port, @caller_id, @topic_name, @topic_type, uri, @tcp_no_delay)... | [
"def",
"add_connection",
"(",
"uri",
")",
"publisher",
"=",
"SlaveProxy",
".",
"new",
"(",
"@caller_id",
",",
"uri",
")",
"begin",
"protocol",
",",
"host",
",",
"port",
"=",
"publisher",
".",
"request_topic",
"(",
"@topic_name",
",",
"[",
"[",
"\"TCPROS\""... | request topic to master and start connection with publisher.
@param [String] uri uri to connect
@return [TCPROS::Client] new connection | [
"request",
"topic",
"to",
"master",
"and",
"start",
"connection",
"with",
"publisher",
"."
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/subscriber.rb#L75-L94 | train |
OTL/rosruby | lib/ros/subscriber.rb | ROS.Subscriber.get_connection_info | def get_connection_info
info = []
@connections.each do |connection|
info.push([connection.id, connection.target_uri, 'i', connection.protocol, @topic_name])
end
info
end | ruby | def get_connection_info
info = []
@connections.each do |connection|
info.push([connection.id, connection.target_uri, 'i', connection.protocol, @topic_name])
end
info
end | [
"def",
"get_connection_info",
"info",
"=",
"[",
"]",
"@connections",
".",
"each",
"do",
"|",
"connection",
"|",
"info",
".",
"push",
"(",
"[",
"connection",
".",
"id",
",",
"connection",
".",
"target_uri",
",",
"'i'",
",",
"connection",
".",
"protocol",
... | connection information fro slave API
@return [Array] connection info | [
"connection",
"information",
"fro",
"slave",
"API"
] | dc29af423241167ab9060b40366b4616a62c5f11 | https://github.com/OTL/rosruby/blob/dc29af423241167ab9060b40366b4616a62c5f11/lib/ros/subscriber.rb#L115-L121 | train |
dradis/dradis-projects | lib/dradis/plugins/projects/export/v1/template.rb | Dradis::Plugins::Projects::Export::V1.Template.user_email_for_activity | def user_email_for_activity(activity)
return activity.user if activity.user.is_a?(String)
@user_emails ||= begin
User.select([:id, :email]).all.each_with_object({}) do |user, hash|
hash[user.id] = user.email
end
end
@user_emails[activity.user_id]
end | ruby | def user_email_for_activity(activity)
return activity.user if activity.user.is_a?(String)
@user_emails ||= begin
User.select([:id, :email]).all.each_with_object({}) do |user, hash|
hash[user.id] = user.email
end
end
@user_emails[activity.user_id]
end | [
"def",
"user_email_for_activity",
"(",
"activity",
")",
"return",
"activity",
".",
"user",
"if",
"activity",
".",
"user",
".",
"is_a?",
"(",
"String",
")",
"@user_emails",
"||=",
"begin",
"User",
".",
"select",
"(",
"[",
":id",
",",
":email",
"]",
")",
"... | Cache user emails so we don't have to make an extra SQL request
for every activity | [
"Cache",
"user",
"emails",
"so",
"we",
"don",
"t",
"have",
"to",
"make",
"an",
"extra",
"SQL",
"request",
"for",
"every",
"activity"
] | c581357dd9fff7e65afdf30c05ea183c58362207 | https://github.com/dradis/dradis-projects/blob/c581357dd9fff7e65afdf30c05ea183c58362207/lib/dradis/plugins/projects/export/v1/template.rb#L157-L166 | train |
emq/workable | lib/workable/client.rb | Workable.Client.create_job_candidate | def create_job_candidate(candidate, shortcode, stage_slug = nil)
shortcode = "#{shortcode}/#{stage_slug}" if stage_slug
response = post_request("jobs/#{shortcode}/candidates") do |request|
request.body = @transform_from.apply(:candidate, candidate).to_json
end
@transform_to.apply(:cand... | ruby | def create_job_candidate(candidate, shortcode, stage_slug = nil)
shortcode = "#{shortcode}/#{stage_slug}" if stage_slug
response = post_request("jobs/#{shortcode}/candidates") do |request|
request.body = @transform_from.apply(:candidate, candidate).to_json
end
@transform_to.apply(:cand... | [
"def",
"create_job_candidate",
"(",
"candidate",
",",
"shortcode",
",",
"stage_slug",
"=",
"nil",
")",
"shortcode",
"=",
"\"#{shortcode}/#{stage_slug}\"",
"if",
"stage_slug",
"response",
"=",
"post_request",
"(",
"\"jobs/#{shortcode}/candidates\"",
")",
"do",
"|",
"re... | create new candidate for given job
@param candidate [Hash] the candidate data as described in
https://workable.readme.io/docs/job-candidates-create
including the `{"candidate"=>{}}` part
@param shortcode [String] job short code
@param stage_slug [String] optional stage slug
@return [Hash] the candidate in... | [
"create",
"new",
"candidate",
"for",
"given",
"job"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L126-L134 | train |
emq/workable | lib/workable/client.rb | Workable.Client.create_comment | def create_comment(candidate_id, member_id, comment_text, policy = [], attachment = nil)
comment = { body: comment_text, policy: policy, attachment: attachment }
post_request("candidates/#{candidate_id}/comments") do |request|
request.body = { member_id: member_id, comment: comment }.to_json
... | ruby | def create_comment(candidate_id, member_id, comment_text, policy = [], attachment = nil)
comment = { body: comment_text, policy: policy, attachment: attachment }
post_request("candidates/#{candidate_id}/comments") do |request|
request.body = { member_id: member_id, comment: comment }.to_json
... | [
"def",
"create_comment",
"(",
"candidate_id",
",",
"member_id",
",",
"comment_text",
",",
"policy",
"=",
"[",
"]",
",",
"attachment",
"=",
"nil",
")",
"comment",
"=",
"{",
"body",
":",
"comment_text",
",",
"policy",
":",
"policy",
",",
"attachment",
":",
... | create a comment on the candidate's timeline
@param candidate_id [String] the candidate's id
@param member_id [String] id of the member leaving the comment
@param comment_text [String] the comment's text
@param policy [String] option to set the view rights of the comment
@param attachment [Hash] optional attachmen... | [
"create",
"a",
"comment",
"on",
"the",
"candidate",
"s",
"timeline"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L144-L150 | train |
emq/workable | lib/workable/client.rb | Workable.Client.disqualify | def disqualify(candidate_id, member_id, reason = nil)
post_request("candidates/#{candidate_id}/disqualify") do |request|
request.body = { member_id: member_id, disqualification_reason: reason }.to_json
end
end | ruby | def disqualify(candidate_id, member_id, reason = nil)
post_request("candidates/#{candidate_id}/disqualify") do |request|
request.body = { member_id: member_id, disqualification_reason: reason }.to_json
end
end | [
"def",
"disqualify",
"(",
"candidate_id",
",",
"member_id",
",",
"reason",
"=",
"nil",
")",
"post_request",
"(",
"\"candidates/#{candidate_id}/disqualify\"",
")",
"do",
"|",
"request",
"|",
"request",
".",
"body",
"=",
"{",
"member_id",
":",
"member_id",
",",
... | disqualify a candidate
@param candidate_id [String] the candidate's id
@param member_id [String] id of the member performing the disqualification
@param reason [String] why the candidate should be disqualified | [
"disqualify",
"a",
"candidate"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L156-L160 | train |
emq/workable | lib/workable/client.rb | Workable.Client.revert | def revert(candidate_id, member_id)
post_request("candidates/#{candidate_id}/revert") do |request|
request.body = { member_id: member_id }.to_json
end
end | ruby | def revert(candidate_id, member_id)
post_request("candidates/#{candidate_id}/revert") do |request|
request.body = { member_id: member_id }.to_json
end
end | [
"def",
"revert",
"(",
"candidate_id",
",",
"member_id",
")",
"post_request",
"(",
"\"candidates/#{candidate_id}/revert\"",
")",
"do",
"|",
"request",
"|",
"request",
".",
"body",
"=",
"{",
"member_id",
":",
"member_id",
"}",
".",
"to_json",
"end",
"end"
] | revert a candidate's disqualification
@param candidate_id [String] the candidate's id
@param member_id [String] id of the member reverting the disqualification | [
"revert",
"a",
"candidate",
"s",
"disqualification"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L165-L169 | train |
emq/workable | lib/workable/client.rb | Workable.Client.copy | def copy(candidate_id, member_id, shortcode, stage = nil)
body = {
member_id: member_id,
target_job_shortcode: shortcode,
target_stage: stage
}
response = post_request("candidates/#{candidate_id}/copy") do |request|
request.body = body.to_json
end
@transfo... | ruby | def copy(candidate_id, member_id, shortcode, stage = nil)
body = {
member_id: member_id,
target_job_shortcode: shortcode,
target_stage: stage
}
response = post_request("candidates/#{candidate_id}/copy") do |request|
request.body = body.to_json
end
@transfo... | [
"def",
"copy",
"(",
"candidate_id",
",",
"member_id",
",",
"shortcode",
",",
"stage",
"=",
"nil",
")",
"body",
"=",
"{",
"member_id",
":",
"member_id",
",",
"target_job_shortcode",
":",
"shortcode",
",",
"target_stage",
":",
"stage",
"}",
"response",
"=",
... | copy a candidate to another job
@param candidate_id [String] the candidate's id
@param member_id [String] id of the member performing the copy
@param shortcode [String] shortcode of the job that the candidate will be copied to
@param stage [String] stage the candidate should be copied to | [
"copy",
"a",
"candidate",
"to",
"another",
"job"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L176-L188 | train |
emq/workable | lib/workable/client.rb | Workable.Client.move | def move(candidate_id, member_id, stage)
post_request("candidates/#{candidate_id}/move") do |request|
request.body = { member_id: member_id, target_stage: stage }.to_json
end
end | ruby | def move(candidate_id, member_id, stage)
post_request("candidates/#{candidate_id}/move") do |request|
request.body = { member_id: member_id, target_stage: stage }.to_json
end
end | [
"def",
"move",
"(",
"candidate_id",
",",
"member_id",
",",
"stage",
")",
"post_request",
"(",
"\"candidates/#{candidate_id}/move\"",
")",
"do",
"|",
"request",
"|",
"request",
".",
"body",
"=",
"{",
"member_id",
":",
"member_id",
",",
"target_stage",
":",
"sta... | moves a candidate to another stage
@param candidate_id [String] the candidate's id
@param member_id [String] id of the member performing the move
@param stage [String] stage the candidate should be moved to | [
"moves",
"a",
"candidate",
"to",
"another",
"stage"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L213-L217 | train |
emq/workable | lib/workable/client.rb | Workable.Client.create_rating | def create_rating(candidate_id, member_id, comment, score)
body = {
member_id: member_id,
comment: comment,
score: score
}
post_request("candidates/#{candidate_id}/ratings") do |request|
request.body = body.to_json
end
end | ruby | def create_rating(candidate_id, member_id, comment, score)
body = {
member_id: member_id,
comment: comment,
score: score
}
post_request("candidates/#{candidate_id}/ratings") do |request|
request.body = body.to_json
end
end | [
"def",
"create_rating",
"(",
"candidate_id",
",",
"member_id",
",",
"comment",
",",
"score",
")",
"body",
"=",
"{",
"member_id",
":",
"member_id",
",",
"comment",
":",
"comment",
",",
"score",
":",
"score",
"}",
"post_request",
"(",
"\"candidates/#{candidate_i... | creates a rating for a candidate
@param candidate_id [String] the candidate's id
@param member_id [String] id of the member adding the rating
@param comment [String] a comment about the scoring of the candidate
@param score [String] one of 'negative', 'positive', or 'definitely' | [
"creates",
"a",
"rating",
"for",
"a",
"candidate"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L224-L234 | train |
emq/workable | lib/workable/client.rb | Workable.Client.get_request | def get_request(url, params = {})
params = URI.encode_www_form(params.keep_if { |k, v| k && v })
full_url = params.empty? ? url : [url, params].join('?')
do_request(full_url, Net::HTTP::Get)
end | ruby | def get_request(url, params = {})
params = URI.encode_www_form(params.keep_if { |k, v| k && v })
full_url = params.empty? ? url : [url, params].join('?')
do_request(full_url, Net::HTTP::Get)
end | [
"def",
"get_request",
"(",
"url",
",",
"params",
"=",
"{",
"}",
")",
"params",
"=",
"URI",
".",
"encode_www_form",
"(",
"params",
".",
"keep_if",
"{",
"|",
"k",
",",
"v",
"|",
"k",
"&&",
"v",
"}",
")",
"full_url",
"=",
"params",
".",
"empty?",
"?... | do the get request to api | [
"do",
"the",
"get",
"request",
"to",
"api"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L246-L250 | train |
emq/workable | lib/workable/client.rb | Workable.Client.post_request | def post_request(url)
do_request(url, Net::HTTP::Post) do |request|
yield(request) if block_given?
end
end | ruby | def post_request(url)
do_request(url, Net::HTTP::Post) do |request|
yield(request) if block_given?
end
end | [
"def",
"post_request",
"(",
"url",
")",
"do_request",
"(",
"url",
",",
"Net",
"::",
"HTTP",
"::",
"Post",
")",
"do",
"|",
"request",
"|",
"yield",
"(",
"request",
")",
"if",
"block_given?",
"end",
"end"
] | do the post request to api | [
"do",
"the",
"post",
"request",
"to",
"api"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L253-L257 | train |
emq/workable | lib/workable/client.rb | Workable.Client.do_request | def do_request(url, type, &_block)
uri = URI.parse("#{api_url}/#{url}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = type.new(uri.request_uri, headers)
yield request if block_given?
response = http.request(request)
parse!(response)
end | ruby | def do_request(url, type, &_block)
uri = URI.parse("#{api_url}/#{url}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = type.new(uri.request_uri, headers)
yield request if block_given?
response = http.request(request)
parse!(response)
end | [
"def",
"do_request",
"(",
"url",
",",
"type",
",",
"&",
"_block",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"\"#{api_url}/#{url}\"",
")",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
")",
"http",
... | generic part of requesting api | [
"generic",
"part",
"of",
"requesting",
"api"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L260-L272 | train |
emq/workable | lib/workable/client.rb | Workable.Client.parse! | def parse!(response)
case response.code.to_i
when 204, 205
nil
when 200...300
JSON.parse(response.body) if !response.body.to_s.empty?
when 401
fail Errors::NotAuthorized, JSON.parse(response.body)['error']
when 404
fail Errors::NotFound, JSON.parse(response.... | ruby | def parse!(response)
case response.code.to_i
when 204, 205
nil
when 200...300
JSON.parse(response.body) if !response.body.to_s.empty?
when 401
fail Errors::NotAuthorized, JSON.parse(response.body)['error']
when 404
fail Errors::NotFound, JSON.parse(response.... | [
"def",
"parse!",
"(",
"response",
")",
"case",
"response",
".",
"code",
".",
"to_i",
"when",
"204",
",",
"205",
"nil",
"when",
"200",
"...",
"300",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"if",
"!",
"response",
".",
"body",
".",
"t... | parse the api response | [
"parse",
"the",
"api",
"response"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/client.rb#L275-L292 | train |
ONLYOFFICE/onlyoffice_api_gem | lib/teamlab/modules/files.rb | Teamlab.Files.create_txt_in_my_docs | def create_txt_in_my_docs(title, content)
@request.post(%w[@my text], title: title.to_s, content: content.to_s)
end | ruby | def create_txt_in_my_docs(title, content)
@request.post(%w[@my text], title: title.to_s, content: content.to_s)
end | [
"def",
"create_txt_in_my_docs",
"(",
"title",
",",
"content",
")",
"@request",
".",
"post",
"(",
"%w[",
"@my",
"text",
"]",
",",
"title",
":",
"title",
".",
"to_s",
",",
"content",
":",
"content",
".",
"to_s",
")",
"end"
] | region File Creation | [
"region",
"File",
"Creation"
] | 604a21eda5bdb994581b15d6030ed5317724794b | https://github.com/ONLYOFFICE/onlyoffice_api_gem/blob/604a21eda5bdb994581b15d6030ed5317724794b/lib/teamlab/modules/files.rb#L9-L11 | train |
emq/workable | lib/workable/transformation.rb | Workable.Transformation.apply | def apply(mapping, data)
transformation = @mappings[mapping]
return data unless transformation
case data
when nil
data
when Array
data.map { |datas| transformation.call(datas) }
else
transformation.call(data)
end
end | ruby | def apply(mapping, data)
transformation = @mappings[mapping]
return data unless transformation
case data
when nil
data
when Array
data.map { |datas| transformation.call(datas) }
else
transformation.call(data)
end
end | [
"def",
"apply",
"(",
"mapping",
",",
"data",
")",
"transformation",
"=",
"@mappings",
"[",
"mapping",
"]",
"return",
"data",
"unless",
"transformation",
"case",
"data",
"when",
"nil",
"data",
"when",
"Array",
"data",
".",
"map",
"{",
"|",
"datas",
"|",
"... | selects transformation strategy based on the inputs
@param transformation [Method|Proc|nil] the transformation to perform
@param data [Hash|Array|nil] the data to transform
@return [Object|nil]
results of the transformation if given, raw data otherwise | [
"selects",
"transformation",
"strategy",
"based",
"on",
"the",
"inputs"
] | 15b1410e97dd25ef28f6a0938f21efbb168f0ad2 | https://github.com/emq/workable/blob/15b1410e97dd25ef28f6a0938f21efbb168f0ad2/lib/workable/transformation.rb#L12-L24 | train |
dradis/dradis-projects | lib/dradis/plugins/projects/export/template.rb | Dradis::Plugins::Projects::Export.Template.export | def export(args={})
builder = Builder::XmlMarkup.new
builder.instruct!
result = builder.tag!('dradis-template', version: version) do |template_builder|
build_nodes(template_builder)
build_issues(template_builder)
build_methodologies(template_builder)
build_categories(te... | ruby | def export(args={})
builder = Builder::XmlMarkup.new
builder.instruct!
result = builder.tag!('dradis-template', version: version) do |template_builder|
build_nodes(template_builder)
build_issues(template_builder)
build_methodologies(template_builder)
build_categories(te... | [
"def",
"export",
"(",
"args",
"=",
"{",
"}",
")",
"builder",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
"builder",
".",
"instruct!",
"result",
"=",
"builder",
".",
"tag!",
"(",
"'dradis-template'",
",",
"version",
":",
"version",
")",
"do",
"|",
"t... | This method returns an XML representation of current repository which
includes Categories, Nodes and Notes | [
"This",
"method",
"returns",
"an",
"XML",
"representation",
"of",
"current",
"repository",
"which",
"includes",
"Categories",
"Nodes",
"and",
"Notes"
] | c581357dd9fff7e65afdf30c05ea183c58362207 | https://github.com/dradis/dradis-projects/blob/c581357dd9fff7e65afdf30c05ea183c58362207/lib/dradis/plugins/projects/export/template.rb#L5-L17 | train |
toptal/disqus_api | lib/disqus_api/response.rb | DisqusApi.Response.each_resource | def each_resource(&block)
Enumerator.new do |result|
each_page { |resources| resources.each { |resource| result << resource } }
end.each(&block)
end | ruby | def each_resource(&block)
Enumerator.new do |result|
each_page { |resources| resources.each { |resource| result << resource } }
end.each(&block)
end | [
"def",
"each_resource",
"(",
"&",
"block",
")",
"Enumerator",
".",
"new",
"do",
"|",
"result",
"|",
"each_page",
"{",
"|",
"resources",
"|",
"resources",
".",
"each",
"{",
"|",
"resource",
"|",
"result",
"<<",
"resource",
"}",
"}",
"end",
".",
"each",
... | Iterates through each response entry through all pages
@return [Enumerator<Hash>] | [
"Iterates",
"through",
"each",
"response",
"entry",
"through",
"all",
"pages"
] | 818b0c2fd2fbbd7030fb11655bca8204ec3886fd | https://github.com/toptal/disqus_api/blob/818b0c2fd2fbbd7030fb11655bca8204ec3886fd/lib/disqus_api/response.rb#L23-L27 | train |
toptal/disqus_api | lib/disqus_api/response.rb | DisqusApi.Response.each_page | def each_page(&block)
Enumerator.new do |result|
next_response = self
while next_response
result << next_response.body.to_a
next_response = next_response.next
end
end.each(&block)
end | ruby | def each_page(&block)
Enumerator.new do |result|
next_response = self
while next_response
result << next_response.body.to_a
next_response = next_response.next
end
end.each(&block)
end | [
"def",
"each_page",
"(",
"&",
"block",
")",
"Enumerator",
".",
"new",
"do",
"|",
"result",
"|",
"next_response",
"=",
"self",
"while",
"next_response",
"result",
"<<",
"next_response",
".",
"body",
".",
"to_a",
"next_response",
"=",
"next_response",
".",
"ne... | Iterates through every single page
@return [Enumerator<Array<Hash>>] | [
"Iterates",
"through",
"every",
"single",
"page"
] | 818b0c2fd2fbbd7030fb11655bca8204ec3886fd | https://github.com/toptal/disqus_api/blob/818b0c2fd2fbbd7030fb11655bca8204ec3886fd/lib/disqus_api/response.rb#L31-L40 | train |
toptal/disqus_api | lib/disqus_api/request.rb | DisqusApi.Request.perform | def perform(arguments = {})
case type.to_sym
when :post, :get
api.public_send(type, path, @arguments.merge(arguments))
else
raise ArgumentError, "Unregistered request type #{request_type}"
end
end | ruby | def perform(arguments = {})
case type.to_sym
when :post, :get
api.public_send(type, path, @arguments.merge(arguments))
else
raise ArgumentError, "Unregistered request type #{request_type}"
end
end | [
"def",
"perform",
"(",
"arguments",
"=",
"{",
"}",
")",
"case",
"type",
".",
"to_sym",
"when",
":post",
",",
":get",
"api",
".",
"public_send",
"(",
"type",
",",
"path",
",",
"@arguments",
".",
"merge",
"(",
"arguments",
")",
")",
"else",
"raise",
"A... | Returns plain JSON response received from Disqus
@param [Hash] arguments
@return [String] | [
"Returns",
"plain",
"JSON",
"response",
"received",
"from",
"Disqus"
] | 818b0c2fd2fbbd7030fb11655bca8204ec3886fd | https://github.com/toptal/disqus_api/blob/818b0c2fd2fbbd7030fb11655bca8204ec3886fd/lib/disqus_api/request.rb#L34-L41 | train |
zmbacker/enum_help | lib/enum_help/i18n.rb | EnumHelp.I18n.enum | def enum( definitions )
super( definitions )
definitions.each do |name, _|
Helper.define_attr_i18n_method(self, name)
Helper.define_collection_i18n_method(self, name)
end
end | ruby | def enum( definitions )
super( definitions )
definitions.each do |name, _|
Helper.define_attr_i18n_method(self, name)
Helper.define_collection_i18n_method(self, name)
end
end | [
"def",
"enum",
"(",
"definitions",
")",
"super",
"(",
"definitions",
")",
"definitions",
".",
"each",
"do",
"|",
"name",
",",
"_",
"|",
"Helper",
".",
"define_attr_i18n_method",
"(",
"self",
",",
"name",
")",
"Helper",
".",
"define_collection_i18n_method",
"... | overwrite the enum method | [
"overwrite",
"the",
"enum",
"method"
] | 35d3cc5d7a8ce9452f403728020e736ead9621da | https://github.com/zmbacker/enum_help/blob/35d3cc5d7a8ce9452f403728020e736ead9621da/lib/enum_help/i18n.rb#L6-L12 | train |
lanej/cistern | lib/cistern/attributes.rb | Cistern::Attributes.InstanceMethods.requires | def requires(*args)
missing, required = missing_attributes(args)
if missing.length == 1
fail(ArgumentError, "#{missing.keys.first} is required for this operation")
elsif missing.any?
fail(ArgumentError, "#{missing.keys[0...-1].join(', ')} and #{missing.keys[-1]} are required for this ... | ruby | def requires(*args)
missing, required = missing_attributes(args)
if missing.length == 1
fail(ArgumentError, "#{missing.keys.first} is required for this operation")
elsif missing.any?
fail(ArgumentError, "#{missing.keys[0...-1].join(', ')} and #{missing.keys[-1]} are required for this ... | [
"def",
"requires",
"(",
"*",
"args",
")",
"missing",
",",
"required",
"=",
"missing_attributes",
"(",
"args",
")",
"if",
"missing",
".",
"length",
"==",
"1",
"fail",
"(",
"ArgumentError",
",",
"\"#{missing.keys.first} is required for this operation\"",
")",
"elsif... | Require specification of certain attributes
@raise [ArgumentError] if any requested attribute does not have a value
@return [Hash] of matching attributes | [
"Require",
"specification",
"of",
"certain",
"attributes"
] | 15b618020961d397ae78027a317ffd68b8bc5abf | https://github.com/lanej/cistern/blob/15b618020961d397ae78027a317ffd68b8bc5abf/lib/cistern/attributes.rb#L231-L241 | train |
lanej/cistern | lib/cistern/attributes.rb | Cistern::Attributes.InstanceMethods.requires_one | def requires_one(*args)
missing, required = missing_attributes(args)
if missing.length == args.length
fail(ArgumentError, "#{missing.keys[0...-1].join(', ')} or #{missing.keys[-1]} are required for this operation")
end
required
end | ruby | def requires_one(*args)
missing, required = missing_attributes(args)
if missing.length == args.length
fail(ArgumentError, "#{missing.keys[0...-1].join(', ')} or #{missing.keys[-1]} are required for this operation")
end
required
end | [
"def",
"requires_one",
"(",
"*",
"args",
")",
"missing",
",",
"required",
"=",
"missing_attributes",
"(",
"args",
")",
"if",
"missing",
".",
"length",
"==",
"args",
".",
"length",
"fail",
"(",
"ArgumentError",
",",
"\"#{missing.keys[0...-1].join(', ')} or #{missin... | Require specification of one or more attributes.
@raise [ArgumentError] if no requested attributes have values
@return [Hash] of matching attributes | [
"Require",
"specification",
"of",
"one",
"or",
"more",
"attributes",
"."
] | 15b618020961d397ae78027a317ffd68b8bc5abf | https://github.com/lanej/cistern/blob/15b618020961d397ae78027a317ffd68b8bc5abf/lib/cistern/attributes.rb#L247-L255 | train |
esigler/lita-jira | lib/jirahelper/issue.rb | JiraHelper.Issue.fetch_issues | def fetch_issues(jql, suppress_exceptions = false)
client.Issue.jql(jql)
rescue StandardError => e
throw e unless suppress_exceptions
nil
end | ruby | def fetch_issues(jql, suppress_exceptions = false)
client.Issue.jql(jql)
rescue StandardError => e
throw e unless suppress_exceptions
nil
end | [
"def",
"fetch_issues",
"(",
"jql",
",",
"suppress_exceptions",
"=",
"false",
")",
"client",
".",
"Issue",
".",
"jql",
"(",
"jql",
")",
"rescue",
"StandardError",
"=>",
"e",
"throw",
"e",
"unless",
"suppress_exceptions",
"nil",
"end"
] | Leverage the jira-ruby Issue.jql search feature
@param [Type String] jql Valid JQL query
@return [Type Array] 0-m JIRA Issues returned from query | [
"Leverage",
"the",
"jira",
"-",
"ruby",
"Issue",
".",
"jql",
"search",
"feature"
] | bf62e561828cd86c3ce7e29fb9f28f7de3854ed0 | https://github.com/esigler/lita-jira/blob/bf62e561828cd86c3ce7e29fb9f28f7de3854ed0/lib/jirahelper/issue.rb#L18-L23 | train |
greshny/diffbot | lib/diffbot/request.rb | Diffbot.Request.build_request | def build_request(method, query_params={})
query = { token: token }.merge(query_params)
request = { query: query, method: method, headers: {}, mock: @test_mode }
if Diffbot.instrumentor
request.update(
instrumentor: Diffbot.instrumentor,
instrumentor_name: "diffbot"
... | ruby | def build_request(method, query_params={})
query = { token: token }.merge(query_params)
request = { query: query, method: method, headers: {}, mock: @test_mode }
if Diffbot.instrumentor
request.update(
instrumentor: Diffbot.instrumentor,
instrumentor_name: "diffbot"
... | [
"def",
"build_request",
"(",
"method",
",",
"query_params",
"=",
"{",
"}",
")",
"query",
"=",
"{",
"token",
":",
"token",
"}",
".",
"merge",
"(",
"query_params",
")",
"request",
"=",
"{",
"query",
":",
"query",
",",
"method",
":",
"method",
",",
"hea... | Build the hash of options that Excon requires for an HTTP request.
method - A Symbol with the HTTP method (:get, :post, etc).
query_params - Any query parameters to add to the request.
Returns a Hash. | [
"Build",
"the",
"hash",
"of",
"options",
"that",
"Excon",
"requires",
"for",
"an",
"HTTP",
"request",
"."
] | 4e58dadecf53f397172ab85bd0bdd8c29b62b519 | https://github.com/greshny/diffbot/blob/4e58dadecf53f397172ab85bd0bdd8c29b62b519/lib/diffbot/request.rb#L50-L62 | train |
bcoles/ssrf_proxy | lib/ssrf_proxy/server.rb | SSRFProxy.Server.port_open? | def port_open?(ip, port, seconds = 10)
Timeout.timeout(seconds) do
TCPSocket.new(ip, port).close
true
end
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError, Timeout::Error
false
end | ruby | def port_open?(ip, port, seconds = 10)
Timeout.timeout(seconds) do
TCPSocket.new(ip, port).close
true
end
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError, Timeout::Error
false
end | [
"def",
"port_open?",
"(",
"ip",
",",
"port",
",",
"seconds",
"=",
"10",
")",
"Timeout",
".",
"timeout",
"(",
"seconds",
")",
"do",
"TCPSocket",
".",
"new",
"(",
"ip",
",",
"port",
")",
".",
"close",
"true",
"end",
"rescue",
"Errno",
"::",
"ECONNREFUS... | Start the local server and listen for connections
@param [SSRFProxy::HTTP] ssrf A configured SSRFProxy::HTTP object
@param [String] interface Listen interface (Default: 127.0.0.1)
@param [Integer] port Listen port (Default: 8081)
@raise [SSRFProxy::Server::Error::InvalidSsrf]
Invalid SSRFProxy::SSRF objec... | [
"Start",
"the",
"local",
"server",
"and",
"listen",
"for",
"connections"
] | e79da7a449edaa6c898d2f4c9ef443bda93970b5 | https://github.com/bcoles/ssrf_proxy/blob/e79da7a449edaa6c898d2f4c9ef443bda93970b5/lib/ssrf_proxy/server.rb#L123-L130 | train |
bcoles/ssrf_proxy | lib/ssrf_proxy/server.rb | SSRFProxy.Server.handle_connection | def handle_connection(socket)
start_time = Time.now
_, port, host = socket.peeraddr
logger.debug("Client #{host}:#{port} connected")
request = socket.read
logger.debug("Received client request (#{request.length} bytes):\n" \
"#{request}")
response = nil
if r... | ruby | def handle_connection(socket)
start_time = Time.now
_, port, host = socket.peeraddr
logger.debug("Client #{host}:#{port} connected")
request = socket.read
logger.debug("Received client request (#{request.length} bytes):\n" \
"#{request}")
response = nil
if r... | [
"def",
"handle_connection",
"(",
"socket",
")",
"start_time",
"=",
"Time",
".",
"now",
"_",
",",
"port",
",",
"host",
"=",
"socket",
".",
"peeraddr",
"logger",
".",
"debug",
"(",
"\"Client #{host}:#{port} connected\"",
")",
"request",
"=",
"socket",
".",
"re... | Handle client socket connection
@param [Celluloid::IO::TCPSocket] socket client socket | [
"Handle",
"client",
"socket",
"connection"
] | e79da7a449edaa6c898d2f4c9ef443bda93970b5 | https://github.com/bcoles/ssrf_proxy/blob/e79da7a449edaa6c898d2f4c9ef443bda93970b5/lib/ssrf_proxy/server.rb#L180-L233 | train |
bcoles/ssrf_proxy | lib/ssrf_proxy/http.rb | SSRFProxy.HTTP.encode_ip | def encode_ip(url, mode)
return if url.nil?
new_host = nil
host = URI.parse(url.to_s.split('?').first).host.to_s
begin
ip = IPAddress::IPv4.new(host)
rescue
logger.warn("Could not parse requested host as IPv4 address: #{host}")
return url
end
case mode
... | ruby | def encode_ip(url, mode)
return if url.nil?
new_host = nil
host = URI.parse(url.to_s.split('?').first).host.to_s
begin
ip = IPAddress::IPv4.new(host)
rescue
logger.warn("Could not parse requested host as IPv4 address: #{host}")
return url
end
case mode
... | [
"def",
"encode_ip",
"(",
"url",
",",
"mode",
")",
"return",
"if",
"url",
".",
"nil?",
"new_host",
"=",
"nil",
"host",
"=",
"URI",
".",
"parse",
"(",
"url",
".",
"to_s",
".",
"split",
"(",
"'?'",
")",
".",
"first",
")",
".",
"host",
".",
"to_s",
... | Encode IP address of a given URL
@param [String] url target URL
@param [String] mode encoding (int, ipv6, oct, hex, dotted_hex)
@return [String] encoded IP address | [
"Encode",
"IP",
"address",
"of",
"a",
"given",
"URL"
] | e79da7a449edaa6c898d2f4c9ef443bda93970b5 | https://github.com/bcoles/ssrf_proxy/blob/e79da7a449edaa6c898d2f4c9ef443bda93970b5/lib/ssrf_proxy/http.rb#L910-L936 | train |
bcoles/ssrf_proxy | lib/ssrf_proxy/http.rb | SSRFProxy.HTTP.run_rules | def run_rules(url, rules)
str = url.to_s
return str if rules.nil?
rules.each do |rule|
case rule
when 'noproto'
str = str.gsub(%r{^https?://}, '')
when 'nossl', 'http'
str = str.gsub(%r{^https://}, 'http://')
when 'ssl', 'https'
str = str.g... | ruby | def run_rules(url, rules)
str = url.to_s
return str if rules.nil?
rules.each do |rule|
case rule
when 'noproto'
str = str.gsub(%r{^https?://}, '')
when 'nossl', 'http'
str = str.gsub(%r{^https://}, 'http://')
when 'ssl', 'https'
str = str.g... | [
"def",
"run_rules",
"(",
"url",
",",
"rules",
")",
"str",
"=",
"url",
".",
"to_s",
"return",
"str",
"if",
"rules",
".",
"nil?",
"rules",
".",
"each",
"do",
"|",
"rule",
"|",
"case",
"rule",
"when",
"'noproto'",
"str",
"=",
"str",
".",
"gsub",
"(",
... | Run a specified URL through SSRF rules
@param [String] url request URL
@param [String] rules comma separated list of rules
@return [String] modified request URL | [
"Run",
"a",
"specified",
"URL",
"through",
"SSRF",
"rules"
] | e79da7a449edaa6c898d2f4c9ef443bda93970b5 | https://github.com/bcoles/ssrf_proxy/blob/e79da7a449edaa6c898d2f4c9ef443bda93970b5/lib/ssrf_proxy/http.rb#L946-L991 | train |
bcoles/ssrf_proxy | lib/ssrf_proxy/http.rb | SSRFProxy.HTTP.guess_mime | def guess_mime(ext)
content_types = WEBrick::HTTPUtils::DefaultMimeTypes
common_content_types = { 'ico' => 'image/x-icon' }
content_types.merge!(common_content_types)
content_types.each do |k, v|
return v.to_s if ext.eql?(".#{k}")
end
nil
end | ruby | def guess_mime(ext)
content_types = WEBrick::HTTPUtils::DefaultMimeTypes
common_content_types = { 'ico' => 'image/x-icon' }
content_types.merge!(common_content_types)
content_types.each do |k, v|
return v.to_s if ext.eql?(".#{k}")
end
nil
end | [
"def",
"guess_mime",
"(",
"ext",
")",
"content_types",
"=",
"WEBrick",
"::",
"HTTPUtils",
"::",
"DefaultMimeTypes",
"common_content_types",
"=",
"{",
"'ico'",
"=>",
"'image/x-icon'",
"}",
"content_types",
".",
"merge!",
"(",
"common_content_types",
")",
"content_typ... | Guess content type based on file extension
@param [String] ext File extension including dots
@example Return mime type for extension '.png'
guess_mime('favicon.png')
@return [String] content-type value | [
"Guess",
"content",
"type",
"based",
"on",
"file",
"extension"
] | e79da7a449edaa6c898d2f4c9ef443bda93970b5 | https://github.com/bcoles/ssrf_proxy/blob/e79da7a449edaa6c898d2f4c9ef443bda93970b5/lib/ssrf_proxy/http.rb#L1368-L1376 | train |
bcoles/ssrf_proxy | lib/ssrf_proxy/http.rb | SSRFProxy.HTTP.sniff_mime | def sniff_mime(content)
m = MimeMagic.by_magic(content)
return if m.nil?
# Overwrite incorrect mime types
case m.type.to_s
when 'application/xhtml+xml'
return 'text/html'
when 'text/x-csrc'
return 'text/css'
end
m.type
rescue
nil
end | ruby | def sniff_mime(content)
m = MimeMagic.by_magic(content)
return if m.nil?
# Overwrite incorrect mime types
case m.type.to_s
when 'application/xhtml+xml'
return 'text/html'
when 'text/x-csrc'
return 'text/css'
end
m.type
rescue
nil
end | [
"def",
"sniff_mime",
"(",
"content",
")",
"m",
"=",
"MimeMagic",
".",
"by_magic",
"(",
"content",
")",
"return",
"if",
"m",
".",
"nil?",
"case",
"m",
".",
"type",
".",
"to_s",
"when",
"'application/xhtml+xml'",
"return",
"'text/html'",
"when",
"'text/x-csrc'... | Guess content type based on magic bytes
@param [String] content File contents
@return [String] content-type value | [
"Guess",
"content",
"type",
"based",
"on",
"magic",
"bytes"
] | e79da7a449edaa6c898d2f4c9ef443bda93970b5 | https://github.com/bcoles/ssrf_proxy/blob/e79da7a449edaa6c898d2f4c9ef443bda93970b5/lib/ssrf_proxy/http.rb#L1385-L1400 | train |
hunterae/blocks | lib/blocks/renderers/abstract_renderer.rb | Blocks.AbstractRenderer.without_haml_interference | def without_haml_interference(&block)
if defined?(::Haml) && view.instance_variables.include?(:@haml_buffer)
haml_buffer = view.instance_variable_get(:@haml_buffer)
if haml_buffer
was_active = haml_buffer.active?
haml_buffer.active = false
else
haml_buffer = H... | ruby | def without_haml_interference(&block)
if defined?(::Haml) && view.instance_variables.include?(:@haml_buffer)
haml_buffer = view.instance_variable_get(:@haml_buffer)
if haml_buffer
was_active = haml_buffer.active?
haml_buffer.active = false
else
haml_buffer = H... | [
"def",
"without_haml_interference",
"(",
"&",
"block",
")",
"if",
"defined?",
"(",
"::",
"Haml",
")",
"&&",
"view",
".",
"instance_variables",
".",
"include?",
"(",
":@haml_buffer",
")",
"haml_buffer",
"=",
"view",
".",
"instance_variable_get",
"(",
":@haml_buff... | Complete hack to get around issues with Haml
Haml does some hacking to ActionView's with_output_buffer and
output_buffer. In doing so, they make certain assumptions about
the layout and the view template. The Blocks gem doesn't capture
blocks immediately but rather stores them for later capturing.
This can pr... | [
"Complete",
"hack",
"to",
"get",
"around",
"issues",
"with",
"Haml",
"Haml",
"does",
"some",
"hacking",
"to",
"ActionView",
"s",
"with_output_buffer",
"and",
"output_buffer",
".",
"In",
"doing",
"so",
"they",
"make",
"certain",
"assumptions",
"about",
"the",
"... | 17aa1b0f9a68839435d2a2e9bcfdf73a7c62a70e | https://github.com/hunterae/blocks/blob/17aa1b0f9a68839435d2a2e9bcfdf73a7c62a70e/lib/blocks/renderers/abstract_renderer.rb#L51-L67 | train |
thumblemonks/riot | lib/riot/context_helpers.rb | Riot.ContextHelpers.setup | def setup(premium=false, &definition)
setup = Setup.new(&definition)
premium ? @setups.unshift(setup) : @setups.push(setup)
setup
end | ruby | def setup(premium=false, &definition)
setup = Setup.new(&definition)
premium ? @setups.unshift(setup) : @setups.push(setup)
setup
end | [
"def",
"setup",
"(",
"premium",
"=",
"false",
",",
"&",
"definition",
")",
"setup",
"=",
"Setup",
".",
"new",
"(",
"&",
"definition",
")",
"premium",
"?",
"@setups",
".",
"unshift",
"(",
"setup",
")",
":",
"@setups",
".",
"push",
"(",
"setup",
")",
... | Add a setup block.
A setup block defines the topic of the context. There can be multiple setup
blocks; each can access the previous topic through the +topic+ attribute.
context "A string" do
setup { "foo" }
setup { topic * 2 }
asserts(:length).equals(6)
end
If you provide +true+ as the first ... | [
"Add",
"a",
"setup",
"block",
"."
] | e99a8965f2d28730fc863c647ca40b3bffb9e562 | https://github.com/thumblemonks/riot/blob/e99a8965f2d28730fc863c647ca40b3bffb9e562/lib/riot/context_helpers.rb#L20-L24 | train |
amatsuda/rfd | lib/rfd.rb | Rfd.Controller.move_cursor | def move_cursor(row = nil)
if row
if (prev_item = items[current_row])
main.draw_item prev_item
end
page = row / max_items
switch_page page if page != current_page
main.activate_pane row / maxy
@current_row = row
else
@current_row = 0
en... | ruby | def move_cursor(row = nil)
if row
if (prev_item = items[current_row])
main.draw_item prev_item
end
page = row / max_items
switch_page page if page != current_page
main.activate_pane row / maxy
@current_row = row
else
@current_row = 0
en... | [
"def",
"move_cursor",
"(",
"row",
"=",
"nil",
")",
"if",
"row",
"if",
"(",
"prev_item",
"=",
"items",
"[",
"current_row",
"]",
")",
"main",
".",
"draw_item",
"prev_item",
"end",
"page",
"=",
"row",
"/",
"max_items",
"switch_page",
"page",
"if",
"page",
... | Move the cursor to specified row.
The main window and the headers will be updated reflecting the displayed files and directories.
The row number can be out of range of the current page. | [
"Move",
"the",
"cursor",
"to",
"specified",
"row",
"."
] | 403c0bc0ff0a9da1d21220b479d5a42008512b78 | https://github.com/amatsuda/rfd/blob/403c0bc0ff0a9da1d21220b479d5a42008512b78/lib/rfd.rb#L151-L170 | train |
amatsuda/rfd | lib/rfd.rb | Rfd.Controller.cd | def cd(dir = '~', pushd: true)
dir = load_item path: expand_path(dir) unless dir.is_a? Item
unless dir.zip?
Dir.chdir dir
@current_zip = nil
else
@current_zip = dir
end
@dir_history << current_dir if current_dir && pushd
@current_dir, @current_page, @current_r... | ruby | def cd(dir = '~', pushd: true)
dir = load_item path: expand_path(dir) unless dir.is_a? Item
unless dir.zip?
Dir.chdir dir
@current_zip = nil
else
@current_zip = dir
end
@dir_history << current_dir if current_dir && pushd
@current_dir, @current_page, @current_r... | [
"def",
"cd",
"(",
"dir",
"=",
"'~'",
",",
"pushd",
":",
"true",
")",
"dir",
"=",
"load_item",
"path",
":",
"expand_path",
"(",
"dir",
")",
"unless",
"dir",
".",
"is_a?",
"Item",
"unless",
"dir",
".",
"zip?",
"Dir",
".",
"chdir",
"dir",
"@current_zip"... | Change the current directory. | [
"Change",
"the",
"current",
"directory",
"."
] | 403c0bc0ff0a9da1d21220b479d5a42008512b78 | https://github.com/amatsuda/rfd/blob/403c0bc0ff0a9da1d21220b479d5a42008512b78/lib/rfd.rb#L173-L186 | train |
amatsuda/rfd | lib/rfd.rb | Rfd.Controller.ls | def ls
fetch_items_from_filesystem_or_zip
sort_items_according_to_current_direction
@current_page ||= 0
draw_items
move_cursor (current_row ? [current_row, items.size - 1].min : nil)
draw_marked_items
draw_total_items
true
end | ruby | def ls
fetch_items_from_filesystem_or_zip
sort_items_according_to_current_direction
@current_page ||= 0
draw_items
move_cursor (current_row ? [current_row, items.size - 1].min : nil)
draw_marked_items
draw_total_items
true
end | [
"def",
"ls",
"fetch_items_from_filesystem_or_zip",
"sort_items_according_to_current_direction",
"@current_page",
"||=",
"0",
"draw_items",
"move_cursor",
"(",
"current_row",
"?",
"[",
"current_row",
",",
"items",
".",
"size",
"-",
"1",
"]",
".",
"min",
":",
"nil",
"... | Fetch files from current directory.
Then update each windows reflecting the newest information. | [
"Fetch",
"files",
"from",
"current",
"directory",
".",
"Then",
"update",
"each",
"windows",
"reflecting",
"the",
"newest",
"information",
"."
] | 403c0bc0ff0a9da1d21220b479d5a42008512b78 | https://github.com/amatsuda/rfd/blob/403c0bc0ff0a9da1d21220b479d5a42008512b78/lib/rfd.rb#L195-L206 | train |
amatsuda/rfd | lib/rfd.rb | Rfd.Controller.chmod | def chmod(mode = nil)
return unless mode
begin
Integer mode
mode = Integer mode.size == 3 ? "0#{mode}" : mode
rescue ArgumentError
end
FileUtils.chmod mode, selected_items.map(&:path)
ls
end | ruby | def chmod(mode = nil)
return unless mode
begin
Integer mode
mode = Integer mode.size == 3 ? "0#{mode}" : mode
rescue ArgumentError
end
FileUtils.chmod mode, selected_items.map(&:path)
ls
end | [
"def",
"chmod",
"(",
"mode",
"=",
"nil",
")",
"return",
"unless",
"mode",
"begin",
"Integer",
"mode",
"mode",
"=",
"Integer",
"mode",
".",
"size",
"==",
"3",
"?",
"\"0#{mode}\"",
":",
"mode",
"rescue",
"ArgumentError",
"end",
"FileUtils",
".",
"chmod",
"... | Change the file permission of the selected files and directories.
==== Parameters
* +mode+ - Unix chmod string (e.g. +w, g-r, 755, 0644) | [
"Change",
"the",
"file",
"permission",
"of",
"the",
"selected",
"files",
"and",
"directories",
"."
] | 403c0bc0ff0a9da1d21220b479d5a42008512b78 | https://github.com/amatsuda/rfd/blob/403c0bc0ff0a9da1d21220b479d5a42008512b78/lib/rfd.rb#L235-L244 | train |
amatsuda/rfd | lib/rfd.rb | Rfd.Controller.chown | def chown(user_and_group)
return unless user_and_group
user, group = user_and_group.split(':').map {|s| s == '' ? nil : s}
FileUtils.chown user, group, selected_items.map(&:path)
ls
end | ruby | def chown(user_and_group)
return unless user_and_group
user, group = user_and_group.split(':').map {|s| s == '' ? nil : s}
FileUtils.chown user, group, selected_items.map(&:path)
ls
end | [
"def",
"chown",
"(",
"user_and_group",
")",
"return",
"unless",
"user_and_group",
"user",
",",
"group",
"=",
"user_and_group",
".",
"split",
"(",
"':'",
")",
".",
"map",
"{",
"|",
"s",
"|",
"s",
"==",
"''",
"?",
"nil",
":",
"s",
"}",
"FileUtils",
"."... | Change the file owner of the selected files and directories.
==== Parameters
* +user_and_group+ - user name and group name separated by : (e.g. alice, nobody:nobody, :admin) | [
"Change",
"the",
"file",
"owner",
"of",
"the",
"selected",
"files",
"and",
"directories",
"."
] | 403c0bc0ff0a9da1d21220b479d5a42008512b78 | https://github.com/amatsuda/rfd/blob/403c0bc0ff0a9da1d21220b479d5a42008512b78/lib/rfd.rb#L250-L255 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.