id int32 0 24.9k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
7,800 | sgillesp/taxonomite | lib/taxonomite/tree.rb | Taxonomite.Tree.ancestors | def ancestors
a = Array.new
self.parent._ancestors(a) unless self.parent.nil?
return a
end | ruby | def ancestors
a = Array.new
self.parent._ancestors(a) unless self.parent.nil?
return a
end | [
"def",
"ancestors",
"a",
"=",
"Array",
".",
"new",
"self",
".",
"parent",
".",
"_ancestors",
"(",
"a",
")",
"unless",
"self",
".",
"parent",
".",
"nil?",
"return",
"a",
"end"
] | return all ancestors of this node | [
"return",
"all",
"ancestors",
"of",
"this",
"node"
] | 731b42d0dfa1f52b39d050026f49b2d205407ff8 | https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/tree.rb#L75-L79 |
7,801 | sgillesp/taxonomite | lib/taxonomite/tree.rb | Taxonomite.Tree.move_children_to_parent | def move_children_to_parent
children.each do |c|
self.parent.children << c
c.parent = self.parent # is this necessary?
end
end | ruby | def move_children_to_parent
children.each do |c|
self.parent.children << c
c.parent = self.parent # is this necessary?
end
end | [
"def",
"move_children_to_parent",
"children",
".",
"each",
"do",
"|",
"c",
"|",
"self",
".",
"parent",
".",
"children",
"<<",
"c",
"c",
".",
"parent",
"=",
"self",
".",
"parent",
"# is this necessary?",
"end",
"end"
] | move all children to the parent node
!!! need to perform validations here? | [
"move",
"all",
"children",
"to",
"the",
"parent",
"node",
"!!!",
"need",
"to",
"perform",
"validations",
"here?"
] | 731b42d0dfa1f52b39d050026f49b2d205407ff8 | https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/tree.rb#L123-L128 |
7,802 | sgillesp/taxonomite | lib/taxonomite/tree.rb | Taxonomite.Tree.validate_child! | def validate_child!(ch)
raise InvalidChild.create(self, ch) if (ch == nil)
raise CircularRelation.create(self, ch) if self.descendant_of?(ch)
if base_class.method_defined? :validate_child
self.validate_child(ch) # this should throw an error if not valid
end
end | ruby | def validate_child!(ch)
raise InvalidChild.create(self, ch) if (ch == nil)
raise CircularRelation.create(self, ch) if self.descendant_of?(ch)
if base_class.method_defined? :validate_child
self.validate_child(ch) # this should throw an error if not valid
end
end | [
"def",
"validate_child!",
"(",
"ch",
")",
"raise",
"InvalidChild",
".",
"create",
"(",
"self",
",",
"ch",
")",
"if",
"(",
"ch",
"==",
"nil",
")",
"raise",
"CircularRelation",
".",
"create",
"(",
"self",
",",
"ch",
")",
"if",
"self",
".",
"descendant_of... | perform validation on whether this child is an acceptable child or not?
the base_class must have a method 'validate_child?' to implement domain logic there | [
"perform",
"validation",
"on",
"whether",
"this",
"child",
"is",
"an",
"acceptable",
"child",
"or",
"not?",
"the",
"base_class",
"must",
"have",
"a",
"method",
"validate_child?",
"to",
"implement",
"domain",
"logic",
"there"
] | 731b42d0dfa1f52b39d050026f49b2d205407ff8 | https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/tree.rb#L133-L139 |
7,803 | sgillesp/taxonomite | lib/taxonomite/entity.rb | Taxonomite.Entity.do_setup | def do_setup
if (self.taxonomy_node == nil)
self.taxonomy_node = self.respond_to?(:create_taxonomy_node) ? self.create_taxonomy_node : Taxonomite::Node.new
self.taxonomy_node.owner = self
end
end | ruby | def do_setup
if (self.taxonomy_node == nil)
self.taxonomy_node = self.respond_to?(:create_taxonomy_node) ? self.create_taxonomy_node : Taxonomite::Node.new
self.taxonomy_node.owner = self
end
end | [
"def",
"do_setup",
"if",
"(",
"self",
".",
"taxonomy_node",
"==",
"nil",
")",
"self",
".",
"taxonomy_node",
"=",
"self",
".",
"respond_to?",
"(",
":create_taxonomy_node",
")",
"?",
"self",
".",
"create_taxonomy_node",
":",
"Taxonomite",
"::",
"Node",
".",
"n... | subclasses should overload create_taxonomy_node to create the appropriate Place object and set it up | [
"subclasses",
"should",
"overload",
"create_taxonomy_node",
"to",
"create",
"the",
"appropriate",
"Place",
"object",
"and",
"set",
"it",
"up"
] | 731b42d0dfa1f52b39d050026f49b2d205407ff8 | https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/entity.rb#L28-L33 |
7,804 | carboncalculated/calculated | lib/calculated/service.rb | Calculated.Service.check_response | def check_response(response)
case response.code
when 200, 201
true
when 401
raise Calculated::Session::PermissionDenied.new("Your Request could not be authenticated is your api key valid?")
when 404
raise Calculated::Session::NotFound.new("Resource was not fou... | ruby | def check_response(response)
case response.code
when 200, 201
true
when 401
raise Calculated::Session::PermissionDenied.new("Your Request could not be authenticated is your api key valid?")
when 404
raise Calculated::Session::NotFound.new("Resource was not fou... | [
"def",
"check_response",
"(",
"response",
")",
"case",
"response",
".",
"code",
"when",
"200",
",",
"201",
"true",
"when",
"401",
"raise",
"Calculated",
"::",
"Session",
"::",
"PermissionDenied",
".",
"new",
"(",
"\"Your Request could not be authenticated is your ap... | checking the status code of the response; if we are not authenticated
then authenticate the session
@raise [Calculated::PermissionDenied] if the status code is 403
@raise [Calculated::SessionExpired] if a we get a 401
@raise [Calculated::MissingParameter] if we get something strange | [
"checking",
"the",
"status",
"code",
"of",
"the",
"response",
";",
"if",
"we",
"are",
"not",
"authenticated",
"then",
"authenticate",
"the",
"session"
] | 0234d89b515db26add000f88c594f6d3fb5edd5e | https://github.com/carboncalculated/calculated/blob/0234d89b515db26add000f88c594f6d3fb5edd5e/lib/calculated/service.rb#L34-L47 |
7,805 | ajh/speaky_csv | lib/speaky_csv/attr_import.rb | SpeakyCsv.AttrImport.add_fields | def add_fields(row, attrs)
fields = (@config.fields - @config.export_only_fields).map(&:to_s)
fields.each do |name|
row.has_key? name or next
attrs[name] = row.field name
end
end | ruby | def add_fields(row, attrs)
fields = (@config.fields - @config.export_only_fields).map(&:to_s)
fields.each do |name|
row.has_key? name or next
attrs[name] = row.field name
end
end | [
"def",
"add_fields",
"(",
"row",
",",
"attrs",
")",
"fields",
"=",
"(",
"@config",
".",
"fields",
"-",
"@config",
".",
"export_only_fields",
")",
".",
"map",
"(",
":to_s",
")",
"fields",
".",
"each",
"do",
"|",
"name",
"|",
"row",
".",
"has_key?",
"n... | Adds configured fields to attrs | [
"Adds",
"configured",
"fields",
"to",
"attrs"
] | aa16dd8e7dbe2202523b1a7d35a610c174c3fc21 | https://github.com/ajh/speaky_csv/blob/aa16dd8e7dbe2202523b1a7d35a610c174c3fc21/lib/speaky_csv/attr_import.rb#L66-L72 |
7,806 | ajh/speaky_csv | lib/speaky_csv/attr_import.rb | SpeakyCsv.AttrImport.add_has_manys | def add_has_manys(row, attrs)
headers_length = row.headers.compact.length
pairs_start_on_evens = headers_length.even?
(headers_length..row.fields.length).each do |i|
i.send(pairs_start_on_evens ? :even? : :odd?) || next
row[i] || next
m = row[i].match(/^(\w+)_(\d+)_(\w+)$/)
... | ruby | def add_has_manys(row, attrs)
headers_length = row.headers.compact.length
pairs_start_on_evens = headers_length.even?
(headers_length..row.fields.length).each do |i|
i.send(pairs_start_on_evens ? :even? : :odd?) || next
row[i] || next
m = row[i].match(/^(\w+)_(\d+)_(\w+)$/)
... | [
"def",
"add_has_manys",
"(",
"row",
",",
"attrs",
")",
"headers_length",
"=",
"row",
".",
"headers",
".",
"compact",
".",
"length",
"pairs_start_on_evens",
"=",
"headers_length",
".",
"even?",
"(",
"headers_length",
"..",
"row",
".",
"fields",
".",
"length",
... | Adds configured has manys to attrs | [
"Adds",
"configured",
"has",
"manys",
"to",
"attrs"
] | aa16dd8e7dbe2202523b1a7d35a610c174c3fc21 | https://github.com/ajh/speaky_csv/blob/aa16dd8e7dbe2202523b1a7d35a610c174c3fc21/lib/speaky_csv/attr_import.rb#L75-L99 |
7,807 | ajh/speaky_csv | lib/speaky_csv/attr_import.rb | SpeakyCsv.AttrImport.add_has_ones | def add_has_ones(row, attrs)
@config.has_ones.each do |name,assoc_config|
fields = (assoc_config.fields - assoc_config.export_only_fields).map(&:to_s)
fields.each do |f|
csv_name = "#{name}_#{f}"
row.has_key? csv_name or next
(attrs[name.to_s] ||= {})[f] = row.field "... | ruby | def add_has_ones(row, attrs)
@config.has_ones.each do |name,assoc_config|
fields = (assoc_config.fields - assoc_config.export_only_fields).map(&:to_s)
fields.each do |f|
csv_name = "#{name}_#{f}"
row.has_key? csv_name or next
(attrs[name.to_s] ||= {})[f] = row.field "... | [
"def",
"add_has_ones",
"(",
"row",
",",
"attrs",
")",
"@config",
".",
"has_ones",
".",
"each",
"do",
"|",
"name",
",",
"assoc_config",
"|",
"fields",
"=",
"(",
"assoc_config",
".",
"fields",
"-",
"assoc_config",
".",
"export_only_fields",
")",
".",
"map",
... | Adds configured has ones to attrs | [
"Adds",
"configured",
"has",
"ones",
"to",
"attrs"
] | aa16dd8e7dbe2202523b1a7d35a610c174c3fc21 | https://github.com/ajh/speaky_csv/blob/aa16dd8e7dbe2202523b1a7d35a610c174c3fc21/lib/speaky_csv/attr_import.rb#L102-L111 |
7,808 | asaaki/sjekksum | lib/sjekksum/damm.rb | Sjekksum.Damm.of | def of number
raise_on_type_mismatch number
digits = convert_number_to_digits(number)
digits.reduce(0){ |check, digit| QUASIGROUP[check][digit] }
end | ruby | def of number
raise_on_type_mismatch number
digits = convert_number_to_digits(number)
digits.reduce(0){ |check, digit| QUASIGROUP[check][digit] }
end | [
"def",
"of",
"number",
"raise_on_type_mismatch",
"number",
"digits",
"=",
"convert_number_to_digits",
"(",
"number",
")",
"digits",
".",
"reduce",
"(",
"0",
")",
"{",
"|",
"check",
",",
"digit",
"|",
"QUASIGROUP",
"[",
"check",
"]",
"[",
"digit",
"]",
"}",... | Calculates Damm checksum
@example
Sjekksum::Damm.of(572) #=> 4
@param number [Integer, String] number for which the checksum should be calculated
@return [Integer] calculated checksum | [
"Calculates",
"Damm",
"checksum"
] | 47a21c19dcffc67a3bef11d4f2de7c167fd20087 | https://github.com/asaaki/sjekksum/blob/47a21c19dcffc67a3bef11d4f2de7c167fd20087/lib/sjekksum/damm.rb#L35-L39 |
7,809 | lsegal/yard-sitemap | lib/yard-sitemap.rb | YARD.SitemapGenerator.generate_sitemap | def generate_sitemap(basedir)
sitemap_file = File.join(basedir, 'sitemap.xml')
File.open(sitemap_file, 'w') do |file|
file.write(sitemap_contents(basedir))
end
end | ruby | def generate_sitemap(basedir)
sitemap_file = File.join(basedir, 'sitemap.xml')
File.open(sitemap_file, 'w') do |file|
file.write(sitemap_contents(basedir))
end
end | [
"def",
"generate_sitemap",
"(",
"basedir",
")",
"sitemap_file",
"=",
"File",
".",
"join",
"(",
"basedir",
",",
"'sitemap.xml'",
")",
"File",
".",
"open",
"(",
"sitemap_file",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"file",
".",
"write",
"(",
"sitemap_co... | Generates a sitemap at +basedir+
@param basedir [String] the location where the sitemap should be generated | [
"Generates",
"a",
"sitemap",
"at",
"+",
"basedir",
"+"
] | 4415320713f0143a21283f0ce5ca2323fc203623 | https://github.com/lsegal/yard-sitemap/blob/4415320713f0143a21283f0ce5ca2323fc203623/lib/yard-sitemap.rb#L9-L14 |
7,810 | billychan/simple_activity | lib/simple_activity/services/activity_processor.rb | SimpleActivity.ActivityProcessor.save | def save
if validate_attrs
Activity.create(activity_attrs).tap do |activity|
Callbacks.run(activity)
end
else
warning
end
end | ruby | def save
if validate_attrs
Activity.create(activity_attrs).tap do |activity|
Callbacks.run(activity)
end
else
warning
end
end | [
"def",
"save",
"if",
"validate_attrs",
"Activity",
".",
"create",
"(",
"activity_attrs",
")",
".",
"tap",
"do",
"|",
"activity",
"|",
"Callbacks",
".",
"run",
"(",
"activity",
")",
"end",
"else",
"warning",
"end",
"end"
] | This class is for internal usage. No need to initialize this manually,
instead use controller methods provided.
When being used as automatical way in controller, e.g. as
after_filter, supply the controller
ActivityProcessor.new(self)
If cache options needs to be attached, ensure the second argument
Activi... | [
"This",
"class",
"is",
"for",
"internal",
"usage",
".",
"No",
"need",
"to",
"initialize",
"this",
"manually",
"instead",
"use",
"controller",
"methods",
"provided",
"."
] | fd24768908393e6aeae285834902be05c7b8ce42 | https://github.com/billychan/simple_activity/blob/fd24768908393e6aeae285834902be05c7b8ce42/lib/simple_activity/services/activity_processor.rb#L53-L61 |
7,811 | rack-webprofiler/rack-webprofiler | lib/rack/web_profiler/request.rb | Rack.WebProfiler::Request.http_headers | def http_headers
env.select { |k, _v| (k.start_with?("HTTP_") && k != "HTTP_VERSION") || k == "CONTENT_TYPE" }
.collect { |k, v| [k.sub(/^HTTP_/, ""), v] }
.collect { |k, v| [k.split("_").collect(&:capitalize).join("-"), v] }
end | ruby | def http_headers
env.select { |k, _v| (k.start_with?("HTTP_") && k != "HTTP_VERSION") || k == "CONTENT_TYPE" }
.collect { |k, v| [k.sub(/^HTTP_/, ""), v] }
.collect { |k, v| [k.split("_").collect(&:capitalize).join("-"), v] }
end | [
"def",
"http_headers",
"env",
".",
"select",
"{",
"|",
"k",
",",
"_v",
"|",
"(",
"k",
".",
"start_with?",
"(",
"\"HTTP_\"",
")",
"&&",
"k",
"!=",
"\"HTTP_VERSION\"",
")",
"||",
"k",
"==",
"\"CONTENT_TYPE\"",
"}",
".",
"collect",
"{",
"|",
"k",
",",
... | Get HTTP headers.
@return [Hash] | [
"Get",
"HTTP",
"headers",
"."
] | bdb411fbb41eeddf612bbde91301ff94b3853a12 | https://github.com/rack-webprofiler/rack-webprofiler/blob/bdb411fbb41eeddf612bbde91301ff94b3853a12/lib/rack/web_profiler/request.rb#L7-L11 |
7,812 | rack-webprofiler/rack-webprofiler | lib/rack/web_profiler/request.rb | Rack.WebProfiler::Request.raw | def raw
headers = http_headers.map { |k, v| "#{k}: #{v}\r\n" }.join
format "%s %s %s\r\n%s\r\n%s", request_method.upcase, fullpath, env["SERVER_PROTOCOL"], headers, body_string
end | ruby | def raw
headers = http_headers.map { |k, v| "#{k}: #{v}\r\n" }.join
format "%s %s %s\r\n%s\r\n%s", request_method.upcase, fullpath, env["SERVER_PROTOCOL"], headers, body_string
end | [
"def",
"raw",
"headers",
"=",
"http_headers",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{k}: #{v}\\r\\n\"",
"}",
".",
"join",
"format",
"\"%s %s %s\\r\\n%s\\r\\n%s\"",
",",
"request_method",
".",
"upcase",
",",
"fullpath",
",",
"env",
"[",
"\"SERVER_PROTOC... | Get full HTTP request in HTTP format.
@return [String] | [
"Get",
"full",
"HTTP",
"request",
"in",
"HTTP",
"format",
"."
] | bdb411fbb41eeddf612bbde91301ff94b3853a12 | https://github.com/rack-webprofiler/rack-webprofiler/blob/bdb411fbb41eeddf612bbde91301ff94b3853a12/lib/rack/web_profiler/request.rb#L23-L26 |
7,813 | jduckett/duck_map | lib/duck_map/filter_stack.rb | DuckMap.FilterStack.copy_filter | def copy_filter(filter)
buffer = {exclude: {}, include: {}}
filter[:exclude].each do |part|
buffer[:exclude][part[0]] = part[1].dup
end
filter[:include].each do |part|
buffer[:include][part[0]] = part[1].dup
end
return buffer
end | ruby | def copy_filter(filter)
buffer = {exclude: {}, include: {}}
filter[:exclude].each do |part|
buffer[:exclude][part[0]] = part[1].dup
end
filter[:include].each do |part|
buffer[:include][part[0]] = part[1].dup
end
return buffer
end | [
"def",
"copy_filter",
"(",
"filter",
")",
"buffer",
"=",
"{",
"exclude",
":",
"{",
"}",
",",
"include",
":",
"{",
"}",
"}",
"filter",
"[",
":exclude",
"]",
".",
"each",
"do",
"|",
"part",
"|",
"buffer",
"[",
":exclude",
"]",
"[",
"part",
"[",
"0"... | Copies a filter
@return [Hash] | [
"Copies",
"a",
"filter"
] | c510acfa95e8ad4afb1501366058ae88a73704df | https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/filter_stack.rb#L41-L53 |
7,814 | jduckett/duck_map | lib/duck_map/filter_stack.rb | DuckMap.FilterStack.clear_filter | def clear_filter(section, key)
key = key.kind_of?(Symbol) ? key : key.to_sym
self.current_filter[section][key] = []
return nil
end | ruby | def clear_filter(section, key)
key = key.kind_of?(Symbol) ? key : key.to_sym
self.current_filter[section][key] = []
return nil
end | [
"def",
"clear_filter",
"(",
"section",
",",
"key",
")",
"key",
"=",
"key",
".",
"kind_of?",
"(",
"Symbol",
")",
"?",
"key",
":",
"key",
".",
"to_sym",
"self",
".",
"current_filter",
"[",
"section",
"]",
"[",
"key",
"]",
"=",
"[",
"]",
"return",
"ni... | Clears a single type of filter.
@param [Symbol] section The section of filter to update. :exclude or :include.
@param [Symbol] key The key of filter to update. :actions, :verbs, :names, :controllers.
@return [Nil] | [
"Clears",
"a",
"single",
"type",
"of",
"filter",
"."
] | c510acfa95e8ad4afb1501366058ae88a73704df | https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/filter_stack.rb#L100-L104 |
7,815 | klobuczek/active_node | lib/active_node/graph.rb | ActiveNode.Graph.many? | def many?
if block_given?
to_a.many? { |*block_args| yield(*block_args) }
else
limit_value ? to_a.many? : size > 1
end
end | ruby | def many?
if block_given?
to_a.many? { |*block_args| yield(*block_args) }
else
limit_value ? to_a.many? : size > 1
end
end | [
"def",
"many?",
"if",
"block_given?",
"to_a",
".",
"many?",
"{",
"|",
"*",
"block_args",
"|",
"yield",
"(",
"block_args",
")",
"}",
"else",
"limit_value",
"?",
"to_a",
".",
"many?",
":",
"size",
">",
"1",
"end",
"end"
] | Returns true if there is more than one record. | [
"Returns",
"true",
"if",
"there",
"is",
"more",
"than",
"one",
"record",
"."
] | c95dc0070f4565c8a72fbdf3f5534f16381d10ba | https://github.com/klobuczek/active_node/blob/c95dc0070f4565c8a72fbdf3f5534f16381d10ba/lib/active_node/graph.rb#L93-L99 |
7,816 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.status | def status
output = run("info")
result = output.scan(/^state:\s+([\w]+)|pid:\s+(-?[\d]+)$/).flatten
LXC::Status.new(result.first, result.last)
end | ruby | def status
output = run("info")
result = output.scan(/^state:\s+([\w]+)|pid:\s+(-?[\d]+)$/).flatten
LXC::Status.new(result.first, result.last)
end | [
"def",
"status",
"output",
"=",
"run",
"(",
"\"info\"",
")",
"result",
"=",
"output",
".",
"scan",
"(",
"/",
"\\s",
"\\w",
"\\s",
"\\d",
"/",
")",
".",
"flatten",
"LXC",
"::",
"Status",
".",
"new",
"(",
"result",
".",
"first",
",",
"result",
".",
... | Get current status of container
@return [Hash] hash with :state and :pid attributes | [
"Get",
"current",
"status",
"of",
"container"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L20-L25 |
7,817 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.wait | def wait(state)
if !LXC::Shell.valid_state?(status.state)
raise ArgumentError, "Invalid container state: #{state}"
end
run("wait", "-s", state)
end | ruby | def wait(state)
if !LXC::Shell.valid_state?(status.state)
raise ArgumentError, "Invalid container state: #{state}"
end
run("wait", "-s", state)
end | [
"def",
"wait",
"(",
"state",
")",
"if",
"!",
"LXC",
"::",
"Shell",
".",
"valid_state?",
"(",
"status",
".",
"state",
")",
"raise",
"ArgumentError",
",",
"\"Invalid container state: #{state}\"",
"end",
"run",
"(",
"\"wait\"",
",",
"\"-s\"",
",",
"state",
")",... | Wait for container to change status
@param [String] state name | [
"Wait",
"for",
"container",
"to",
"change",
"status"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L100-L106 |
7,818 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.cpu_usage | def cpu_usage
result = run("cgroup", "cpuacct.usage").to_s.strip
result.empty? ? nil : Float("%.4f" % (result.to_i / 1E9))
end | ruby | def cpu_usage
result = run("cgroup", "cpuacct.usage").to_s.strip
result.empty? ? nil : Float("%.4f" % (result.to_i / 1E9))
end | [
"def",
"cpu_usage",
"result",
"=",
"run",
"(",
"\"cgroup\"",
",",
"\"cpuacct.usage\"",
")",
".",
"to_s",
".",
"strip",
"result",
".",
"empty?",
"?",
"nil",
":",
"Float",
"(",
"\"%.4f\"",
"%",
"(",
"result",
".",
"to_i",
"/",
"1E9",
")",
")",
"end"
] | Get container cpu usage in seconds
@return [Float] | [
"Get",
"container",
"cpu",
"usage",
"in",
"seconds"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L129-L132 |
7,819 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.processes | def processes
raise ContainerError, "Container is not running" if !running?
str = run("ps", "--", "-eo pid,user,%cpu,%mem,args").strip
lines = str.split("\n") ; lines.delete_at(0)
lines.map { |l| parse_process_line(l) }
end | ruby | def processes
raise ContainerError, "Container is not running" if !running?
str = run("ps", "--", "-eo pid,user,%cpu,%mem,args").strip
lines = str.split("\n") ; lines.delete_at(0)
lines.map { |l| parse_process_line(l) }
end | [
"def",
"processes",
"raise",
"ContainerError",
",",
"\"Container is not running\"",
"if",
"!",
"running?",
"str",
"=",
"run",
"(",
"\"ps\"",
",",
"\"--\"",
",",
"\"-eo pid,user,%cpu,%mem,args\"",
")",
".",
"strip",
"lines",
"=",
"str",
".",
"split",
"(",
"\"\\n\... | Get container processes
@return [Array] list of all processes | [
"Get",
"container",
"processes"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L136-L142 |
7,820 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.create | def create(path)
raise ContainerError, "Container already exists." if exists?
if path.is_a?(Hash)
args = "-n #{name}"
if !!path[:config_file]
unless File.exists?(path[:config_file])
raise ArgumentError, "File #{path[:config_file]} does not exist."
end
... | ruby | def create(path)
raise ContainerError, "Container already exists." if exists?
if path.is_a?(Hash)
args = "-n #{name}"
if !!path[:config_file]
unless File.exists?(path[:config_file])
raise ArgumentError, "File #{path[:config_file]} does not exist."
end
... | [
"def",
"create",
"(",
"path",
")",
"raise",
"ContainerError",
",",
"\"Container already exists.\"",
"if",
"exists?",
"if",
"path",
".",
"is_a?",
"(",
"Hash",
")",
"args",
"=",
"\"-n #{name}\"",
"if",
"!",
"!",
"path",
"[",
":config_file",
"]",
"unless",
"Fil... | Create a new container
@param [String] path path to container config file or [Hash] options
@return [Boolean] | [
"Create",
"a",
"new",
"container"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L147-L182 |
7,821 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.clone_to | def clone_to(target)
raise ContainerError, "Container does not exist." unless exists?
if LXC.container(target).exists?
raise ContainerError, "New container already exists."
end
LXC.run("clone", "-o", name, "-n", target)
LXC.container(target)
end | ruby | def clone_to(target)
raise ContainerError, "Container does not exist." unless exists?
if LXC.container(target).exists?
raise ContainerError, "New container already exists."
end
LXC.run("clone", "-o", name, "-n", target)
LXC.container(target)
end | [
"def",
"clone_to",
"(",
"target",
")",
"raise",
"ContainerError",
",",
"\"Container does not exist.\"",
"unless",
"exists?",
"if",
"LXC",
".",
"container",
"(",
"target",
")",
".",
"exists?",
"raise",
"ContainerError",
",",
"\"New container already exists.\"",
"end",
... | Clone to a new container from self
@param [String] target name of new container
@return [LXC::Container] new container instance | [
"Clone",
"to",
"a",
"new",
"container",
"from",
"self"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L187-L196 |
7,822 | sosedoff/lxc-ruby | lib/lxc/container.rb | LXC.Container.clone_from | def clone_from(source)
raise ContainerError, "Container already exists." if exists?
unless LXC.container(source).exists?
raise ContainerError, "Source container does not exist."
end
run("clone", "-o", source)
exists?
end | ruby | def clone_from(source)
raise ContainerError, "Container already exists." if exists?
unless LXC.container(source).exists?
raise ContainerError, "Source container does not exist."
end
run("clone", "-o", source)
exists?
end | [
"def",
"clone_from",
"(",
"source",
")",
"raise",
"ContainerError",
",",
"\"Container already exists.\"",
"if",
"exists?",
"unless",
"LXC",
".",
"container",
"(",
"source",
")",
".",
"exists?",
"raise",
"ContainerError",
",",
"\"Source container does not exist.\"",
"e... | Create a new container from an existing container
@param [String] source name of existing container
@return [Boolean] | [
"Create",
"a",
"new",
"container",
"from",
"an",
"existing",
"container"
] | 6d82c2ae3513789b2856d07a156e9131369f95fe | https://github.com/sosedoff/lxc-ruby/blob/6d82c2ae3513789b2856d07a156e9131369f95fe/lib/lxc/container.rb#L201-L210 |
7,823 | willfore/cp_mgmt_ruby | lib/cp_mgmt/host.rb | CpMgmt.Host.add | def add(name, ip_address, options={})
client = CpMgmt.configuration.client
CpMgmt.logged_in?
params = {name: name, "ip-address": ip_address}
body = params.merge(options).to_json
response = client.post do |req|
req.url '/web_api/add-host'
req.headers['Content-Type'] = 'appl... | ruby | def add(name, ip_address, options={})
client = CpMgmt.configuration.client
CpMgmt.logged_in?
params = {name: name, "ip-address": ip_address}
body = params.merge(options).to_json
response = client.post do |req|
req.url '/web_api/add-host'
req.headers['Content-Type'] = 'appl... | [
"def",
"add",
"(",
"name",
",",
"ip_address",
",",
"options",
"=",
"{",
"}",
")",
"client",
"=",
"CpMgmt",
".",
"configuration",
".",
"client",
"CpMgmt",
".",
"logged_in?",
"params",
"=",
"{",
"name",
":",
"name",
",",
"\"ip-address\"",
":",
"ip_address"... | Adds a host | [
"Adds",
"a",
"host"
] | d25f169561f254bd13cc6fa5afa6b362637c1f65 | https://github.com/willfore/cp_mgmt_ruby/blob/d25f169561f254bd13cc6fa5afa6b362637c1f65/lib/cp_mgmt/host.rb#L4-L17 |
7,824 | willfore/cp_mgmt_ruby | lib/cp_mgmt/host.rb | CpMgmt.Host.show | def show(name)
client = CpMgmt.configuration.client
CpMgmt.logged_in?
body = {name: name}.to_json
response = client.post do |req|
req.url '/web_api/show-host'
req.headers['Content-Type'] = 'application/json'
req.headers['X-chkp-sid'] = ENV.fetch("sid")
req.body =... | ruby | def show(name)
client = CpMgmt.configuration.client
CpMgmt.logged_in?
body = {name: name}.to_json
response = client.post do |req|
req.url '/web_api/show-host'
req.headers['Content-Type'] = 'application/json'
req.headers['X-chkp-sid'] = ENV.fetch("sid")
req.body =... | [
"def",
"show",
"(",
"name",
")",
"client",
"=",
"CpMgmt",
".",
"configuration",
".",
"client",
"CpMgmt",
".",
"logged_in?",
"body",
"=",
"{",
"name",
":",
"name",
"}",
".",
"to_json",
"response",
"=",
"client",
".",
"post",
"do",
"|",
"req",
"|",
"re... | Shows a host | [
"Shows",
"a",
"host"
] | d25f169561f254bd13cc6fa5afa6b362637c1f65 | https://github.com/willfore/cp_mgmt_ruby/blob/d25f169561f254bd13cc6fa5afa6b362637c1f65/lib/cp_mgmt/host.rb#L35-L47 |
7,825 | willfore/cp_mgmt_ruby | lib/cp_mgmt/host.rb | CpMgmt.Host.show_all | def show_all
client = CpMgmt.configuration.client
CpMgmt.logged_in?
response = client.post do |req|
req.url '/web_api/show-hosts'
req.headers['Content-Type'] = 'application/json'
req.headers['X-chkp-sid'] = ENV.fetch("sid")
req.body = "{}"
end
CpMgmt.transf... | ruby | def show_all
client = CpMgmt.configuration.client
CpMgmt.logged_in?
response = client.post do |req|
req.url '/web_api/show-hosts'
req.headers['Content-Type'] = 'application/json'
req.headers['X-chkp-sid'] = ENV.fetch("sid")
req.body = "{}"
end
CpMgmt.transf... | [
"def",
"show_all",
"client",
"=",
"CpMgmt",
".",
"configuration",
".",
"client",
"CpMgmt",
".",
"logged_in?",
"response",
"=",
"client",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/web_api/show-hosts'",
"req",
".",
"headers",
"[",
"'Content-Typ... | Shows all hosts | [
"Shows",
"all",
"hosts"
] | d25f169561f254bd13cc6fa5afa6b362637c1f65 | https://github.com/willfore/cp_mgmt_ruby/blob/d25f169561f254bd13cc6fa5afa6b362637c1f65/lib/cp_mgmt/host.rb#L50-L61 |
7,826 | jarhart/rattler | lib/rattler/runtime/extended_packrat_parser.rb | Rattler::Runtime.ExtendedPackratParser.apply | def apply(match_method_name)
start_pos = @scanner.pos
if m = memo_lr(match_method_name, start_pos)
recall m, match_method_name
else
lr = LR.new(false, match_method_name, nil)
@lr_stack.push lr
m = inject_memo match_method_name, start_pos, lr, start_pos
r... | ruby | def apply(match_method_name)
start_pos = @scanner.pos
if m = memo_lr(match_method_name, start_pos)
recall m, match_method_name
else
lr = LR.new(false, match_method_name, nil)
@lr_stack.push lr
m = inject_memo match_method_name, start_pos, lr, start_pos
r... | [
"def",
"apply",
"(",
"match_method_name",
")",
"start_pos",
"=",
"@scanner",
".",
"pos",
"if",
"m",
"=",
"memo_lr",
"(",
"match_method_name",
",",
"start_pos",
")",
"recall",
"m",
",",
"match_method_name",
"else",
"lr",
"=",
"LR",
".",
"new",
"(",
"false",... | Create a new extended packrat parser to parse +source+.
@param (see PackratParser#initialize)
@option (see PackratParser#initialize)
Apply a rule by dispatching to the given match method. The result of
applying the rule is memoized so that the match method is invoked at most
once at a given parse position. Left-... | [
"Create",
"a",
"new",
"extended",
"packrat",
"parser",
"to",
"parse",
"+",
"source",
"+",
"."
] | 8b4efde2a05e9e790955bb635d4a1a9615893719 | https://github.com/jarhart/rattler/blob/8b4efde2a05e9e790955bb635d4a1a9615893719/lib/rattler/runtime/extended_packrat_parser.rb#L29-L47 |
7,827 | carboncalculated/calculated | lib/calculated/object_template_api_calls.rb | Calculated.ObjectTemplateApiCalls.generic_objects_for_object_template | def generic_objects_for_object_template(name, params = {})
api_call(:get, "/object_templates/#{name}/generic_objects", params) do |response|
Calculated::Models::ObjectTemplate.new(response["object_template"])
end
end | ruby | def generic_objects_for_object_template(name, params = {})
api_call(:get, "/object_templates/#{name}/generic_objects", params) do |response|
Calculated::Models::ObjectTemplate.new(response["object_template"])
end
end | [
"def",
"generic_objects_for_object_template",
"(",
"name",
",",
"params",
"=",
"{",
"}",
")",
"api_call",
"(",
":get",
",",
"\"/object_templates/#{name}/generic_objects\"",
",",
"params",
")",
"do",
"|",
"response",
"|",
"Calculated",
"::",
"Models",
"::",
"Object... | this request will have loaded generic objects for the ready basically
@param [String] name
@param [Hash] params
@return [Calculated::Models::ObjectTemplate] | [
"this",
"request",
"will",
"have",
"loaded",
"generic",
"objects",
"for",
"the",
"ready",
"basically"
] | 0234d89b515db26add000f88c594f6d3fb5edd5e | https://github.com/carboncalculated/calculated/blob/0234d89b515db26add000f88c594f6d3fb5edd5e/lib/calculated/object_template_api_calls.rb#L27-L31 |
7,828 | carboncalculated/calculated | lib/calculated/object_template_api_calls.rb | Calculated.ObjectTemplateApiCalls.relatable_categories_for_object_template | def relatable_categories_for_object_template(name, related_attribute, params = {})
api_call(:get, "/object_templates/#{name}/relatable_categories", params.merge!(:related_attribute => related_attribute)) do |response|
Calculated::Models::ObjectTemplate.new(response["object_template"])
end
end | ruby | def relatable_categories_for_object_template(name, related_attribute, params = {})
api_call(:get, "/object_templates/#{name}/relatable_categories", params.merge!(:related_attribute => related_attribute)) do |response|
Calculated::Models::ObjectTemplate.new(response["object_template"])
end
end | [
"def",
"relatable_categories_for_object_template",
"(",
"name",
",",
"related_attribute",
",",
"params",
"=",
"{",
"}",
")",
"api_call",
"(",
":get",
",",
"\"/object_templates/#{name}/relatable_categories\"",
",",
"params",
".",
"merge!",
"(",
":related_attribute",
"=>"... | this request will have loaded relatable categories for the object template
@param [String] related_attribute
@param [String] name
@param [Hash] params
@return [Calculated::Models::ObjectTemplate] | [
"this",
"request",
"will",
"have",
"loaded",
"relatable",
"categories",
"for",
"the",
"object",
"template"
] | 0234d89b515db26add000f88c594f6d3fb5edd5e | https://github.com/carboncalculated/calculated/blob/0234d89b515db26add000f88c594f6d3fb5edd5e/lib/calculated/object_template_api_calls.rb#L38-L42 |
7,829 | carboncalculated/calculated | lib/calculated/object_template_api_calls.rb | Calculated.ObjectTemplateApiCalls.generic_objects_for_object_template_with_filter | def generic_objects_for_object_template_with_filter(name, filter, params = {})
api_call(:get, "/object_templates/#{name}/generic_objects/filter", params.merge!(:filter => filter)) do |response|
Calculated::Models::ObjectTemplate.new(response["object_template"])
end
end | ruby | def generic_objects_for_object_template_with_filter(name, filter, params = {})
api_call(:get, "/object_templates/#{name}/generic_objects/filter", params.merge!(:filter => filter)) do |response|
Calculated::Models::ObjectTemplate.new(response["object_template"])
end
end | [
"def",
"generic_objects_for_object_template_with_filter",
"(",
"name",
",",
"filter",
",",
"params",
"=",
"{",
"}",
")",
"api_call",
"(",
":get",
",",
"\"/object_templates/#{name}/generic_objects/filter\"",
",",
"params",
".",
"merge!",
"(",
":filter",
"=>",
"filter",... | This will filter the results of the generic objects from a simple text search
note this is not an expancive text search so limit to 1 word searches for best
results
@example
generic_objects_for_object_template_with_filter('airport', 'london')
There is also the usuage of relatable_category_values with the... | [
"This",
"will",
"filter",
"the",
"results",
"of",
"the",
"generic",
"objects",
"from",
"a",
"simple",
"text",
"search",
"note",
"this",
"is",
"not",
"an",
"expancive",
"text",
"search",
"so",
"limit",
"to",
"1",
"word",
"searches",
"for",
"best",
"results"... | 0234d89b515db26add000f88c594f6d3fb5edd5e | https://github.com/carboncalculated/calculated/blob/0234d89b515db26add000f88c594f6d3fb5edd5e/lib/calculated/object_template_api_calls.rb#L64-L68 |
7,830 | postmodern/rprogram | lib/rprogram/program.rb | RProgram.Program.sudo | def sudo(*arguments)
options = case arguments.last
when Hash then arguments.pop
else {}
end
task = SudoTask.new(options.delete(:sudo) || {})
task.command = [@path] + arguments
arguments = task.arguments
arguments << options unless... | ruby | def sudo(*arguments)
options = case arguments.last
when Hash then arguments.pop
else {}
end
task = SudoTask.new(options.delete(:sudo) || {})
task.command = [@path] + arguments
arguments = task.arguments
arguments << options unless... | [
"def",
"sudo",
"(",
"*",
"arguments",
")",
"options",
"=",
"case",
"arguments",
".",
"last",
"when",
"Hash",
"then",
"arguments",
".",
"pop",
"else",
"{",
"}",
"end",
"task",
"=",
"SudoTask",
".",
"new",
"(",
"options",
".",
"delete",
"(",
":sudo",
"... | Runs the program under sudo.
@overload sudo(*arguments)
Run the program under `sudo` with the given arguments.
@param [Array] arguments
Additional arguments to run the program with.
@overload sudo(*arguments,options)
Run the program under `sudo` with the given arguments
and options.
@param [Ar... | [
"Runs",
"the",
"program",
"under",
"sudo",
"."
] | 94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be | https://github.com/postmodern/rprogram/blob/94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be/lib/rprogram/program.rb#L341-L354 |
7,831 | postmodern/rprogram | lib/rprogram/program.rb | RProgram.Program.run_task | def run_task(task,options={})
arguments = task.arguments
arguments << options unless options.empty?
return run(*arguments)
end | ruby | def run_task(task,options={})
arguments = task.arguments
arguments << options unless options.empty?
return run(*arguments)
end | [
"def",
"run_task",
"(",
"task",
",",
"options",
"=",
"{",
"}",
")",
"arguments",
"=",
"task",
".",
"arguments",
"arguments",
"<<",
"options",
"unless",
"options",
".",
"empty?",
"return",
"run",
"(",
"arguments",
")",
"end"
] | Runs the program with the arguments from the given task.
@param [Task, #to_a] task
The task who's arguments will be used to run the program.
@param [Hash] options
Additional options to execute the program with.
@return [true, false]
Specifies the exit status of the program.
@see #run | [
"Runs",
"the",
"program",
"with",
"the",
"arguments",
"from",
"the",
"given",
"task",
"."
] | 94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be | https://github.com/postmodern/rprogram/blob/94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be/lib/rprogram/program.rb#L370-L375 |
7,832 | postmodern/rprogram | lib/rprogram/program.rb | RProgram.Program.sudo_task | def sudo_task(task,options={},&block)
arguments = task.arguments
arguments << options unless options.empty?
return sudo(*arguments,&block)
end | ruby | def sudo_task(task,options={},&block)
arguments = task.arguments
arguments << options unless options.empty?
return sudo(*arguments,&block)
end | [
"def",
"sudo_task",
"(",
"task",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"arguments",
"=",
"task",
".",
"arguments",
"arguments",
"<<",
"options",
"unless",
"options",
".",
"empty?",
"return",
"sudo",
"(",
"arguments",
",",
"block",
")",
... | Runs the program under `sudo` with the arguments from the given task.
@param [Task, #to_a] task
The task who's arguments will be used to run the program.
@param [Hash] options
Spawn options for the program to be ran.
@yield [sudo]
If a block is given, it will be passed the sudo task.
@yieldparam [SudoT... | [
"Runs",
"the",
"program",
"under",
"sudo",
"with",
"the",
"arguments",
"from",
"the",
"given",
"task",
"."
] | 94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be | https://github.com/postmodern/rprogram/blob/94c32a72c98c7310d6e6b767b55ea8b8fbf0c0be/lib/rprogram/program.rb#L399-L404 |
7,833 | jduckett/duck_map | lib/duck_map/mapper.rb | DuckMap.Mapper.sitemap | def sitemap(name = :sitemap, options = {}, &block)
options = name.kind_of?(Hash) ? name : options
name = name.kind_of?(String) || name.kind_of?(Symbol) ? name : :sitemap
config = {controller: :sitemap, url_limit: nil}.merge(options)
sitemap_raw_route_name = "#{name}_sitemap"
sitemap_route... | ruby | def sitemap(name = :sitemap, options = {}, &block)
options = name.kind_of?(Hash) ? name : options
name = name.kind_of?(String) || name.kind_of?(Symbol) ? name : :sitemap
config = {controller: :sitemap, url_limit: nil}.merge(options)
sitemap_raw_route_name = "#{name}_sitemap"
sitemap_route... | [
"def",
"sitemap",
"(",
"name",
"=",
":sitemap",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"=",
"name",
".",
"kind_of?",
"(",
"Hash",
")",
"?",
"name",
":",
"options",
"name",
"=",
"name",
".",
"kind_of?",
"(",
"String",
")",... | Defines a sitemap for a Rails app.
You can find a few examples and apps at:
- (http://www.jeffduckett.com/blog/11/defining-rails-3-x-sitemaps-using-duckmap.html)
- (http://www.jeffduckett.com/blog/12/multiple-sitemap-definitions.html)
@return [Nil] | [
"Defines",
"a",
"sitemap",
"for",
"a",
"Rails",
"app",
"."
] | c510acfa95e8ad4afb1501366058ae88a73704df | https://github.com/jduckett/duck_map/blob/c510acfa95e8ad4afb1501366058ae88a73704df/lib/duck_map/mapper.rb#L21-L124 |
7,834 | medcat/packed_struct | lib/packed_struct/package.rb | PackedStruct.Package.pack | def pack(data)
values = []
data.each do |k, v|
values.push([k, v])
end
mapped_directives = @directives.map(&:name)
values = values.select { |x| mapped_directives.include?(x[0]) }
values.sort! do |a, b|
mapped_directives.index(a[0]) <=> mapped_directives.index(b[0])... | ruby | def pack(data)
values = []
data.each do |k, v|
values.push([k, v])
end
mapped_directives = @directives.map(&:name)
values = values.select { |x| mapped_directives.include?(x[0]) }
values.sort! do |a, b|
mapped_directives.index(a[0]) <=> mapped_directives.index(b[0])... | [
"def",
"pack",
"(",
"data",
")",
"values",
"=",
"[",
"]",
"data",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"values",
".",
"push",
"(",
"[",
"k",
",",
"v",
"]",
")",
"end",
"mapped_directives",
"=",
"@directives",
".",
"map",
"(",
":name",
")... | Packs the given data into a string. The keys of the data
correspond to the names of the directives.
@param data [Hash<Symbol, Object>] the data.
@return [String] the packed data. | [
"Packs",
"the",
"given",
"data",
"into",
"a",
"string",
".",
"The",
"keys",
"of",
"the",
"data",
"correspond",
"to",
"the",
"names",
"of",
"the",
"directives",
"."
] | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/package.rb#L37-L53 |
7,835 | medcat/packed_struct | lib/packed_struct/package.rb | PackedStruct.Package.unpack | def unpack(string)
total = ""
parts = {}
directives.each_with_index do |directive, i|
total << directive.to_s(parts)
parts[directive.name] = string.unpack(total)[i]
end
parts.delete(:null) {}
parts
end | ruby | def unpack(string)
total = ""
parts = {}
directives.each_with_index do |directive, i|
total << directive.to_s(parts)
parts[directive.name] = string.unpack(total)[i]
end
parts.delete(:null) {}
parts
end | [
"def",
"unpack",
"(",
"string",
")",
"total",
"=",
"\"\"",
"parts",
"=",
"{",
"}",
"directives",
".",
"each_with_index",
"do",
"|",
"directive",
",",
"i",
"|",
"total",
"<<",
"directive",
".",
"to_s",
"(",
"parts",
")",
"parts",
"[",
"directive",
".",
... | Unpacks the given string with the directives. Returns a hash
containing the values, with the keys being the names of the
directives.
@param string [String] the packed string.
@return [Hash<Symbol, Object>] the unpacked data. | [
"Unpacks",
"the",
"given",
"string",
"with",
"the",
"directives",
".",
"Returns",
"a",
"hash",
"containing",
"the",
"values",
"with",
"the",
"keys",
"being",
"the",
"names",
"of",
"the",
"directives",
"."
] | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/package.rb#L61-L72 |
7,836 | medcat/packed_struct | lib/packed_struct/package.rb | PackedStruct.Package.fast_unpack | def fast_unpack(string)
out = string.unpack(to_s)
parts = {}
directives.each_with_index do |directive, i|
parts[directive.name] = out[i]
end
parts.delete(:null) {}
parts
end | ruby | def fast_unpack(string)
out = string.unpack(to_s)
parts = {}
directives.each_with_index do |directive, i|
parts[directive.name] = out[i]
end
parts.delete(:null) {}
parts
end | [
"def",
"fast_unpack",
"(",
"string",
")",
"out",
"=",
"string",
".",
"unpack",
"(",
"to_s",
")",
"parts",
"=",
"{",
"}",
"directives",
".",
"each_with_index",
"do",
"|",
"directive",
",",
"i",
"|",
"parts",
"[",
"directive",
".",
"name",
"]",
"=",
"o... | This unpacks the entire string at once. It assumes that none of
the directives will need the values of other directives. If
you're not sure what this means, don't use it.
@param string [String] the packed string.
@return [Hash<Symbol, Object>] the unpacked data. | [
"This",
"unpacks",
"the",
"entire",
"string",
"at",
"once",
".",
"It",
"assumes",
"that",
"none",
"of",
"the",
"directives",
"will",
"need",
"the",
"values",
"of",
"other",
"directives",
".",
"If",
"you",
"re",
"not",
"sure",
"what",
"this",
"means",
"do... | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/package.rb#L99-L109 |
7,837 | medcat/packed_struct | lib/packed_struct/package.rb | PackedStruct.Package.method_missing | def method_missing(method, *arguments, &block)
super if @finalized
if arguments.length == 1 && arguments.first.is_a?(Directive)
arguments.first.add_modifier Modifier.new(method)
else
(directives.push Directive.new(method)).last
end
end | ruby | def method_missing(method, *arguments, &block)
super if @finalized
if arguments.length == 1 && arguments.first.is_a?(Directive)
arguments.first.add_modifier Modifier.new(method)
else
(directives.push Directive.new(method)).last
end
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"super",
"if",
"@finalized",
"if",
"arguments",
".",
"length",
"==",
"1",
"&&",
"arguments",
".",
"first",
".",
"is_a?",
"(",
"Directive",
")",
"arguments",
".",
"firs... | Creates a new directive with the given method and arguments.
@return [Directive] the new directive. | [
"Creates",
"a",
"new",
"directive",
"with",
"the",
"given",
"method",
"and",
"arguments",
"."
] | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/package.rb#L137-L144 |
7,838 | botanicus/nake | lib/nake/file_task.rb | Nake.FileTask.invoke_dependencies | def invoke_dependencies(*args, options)
self.dependencies.each do |name|
if task = self.class[name] # first try if there is a task with given name
task.call(*args, options) # TODO: what about arguments?
elsif File.exist?(name) # if not, then fallback to file
task_will_run?(name... | ruby | def invoke_dependencies(*args, options)
self.dependencies.each do |name|
if task = self.class[name] # first try if there is a task with given name
task.call(*args, options) # TODO: what about arguments?
elsif File.exist?(name) # if not, then fallback to file
task_will_run?(name... | [
"def",
"invoke_dependencies",
"(",
"*",
"args",
",",
"options",
")",
"self",
".",
"dependencies",
".",
"each",
"do",
"|",
"name",
"|",
"if",
"task",
"=",
"self",
".",
"class",
"[",
"name",
"]",
"# first try if there is a task with given name",
"task",
".",
"... | return true if the task need to be executed, false otherwise | [
"return",
"true",
"if",
"the",
"task",
"need",
"to",
"be",
"executed",
"false",
"otherwise"
] | d0ca22c3ce686dc916bdbe5bbd5475a18371a41d | https://github.com/botanicus/nake/blob/d0ca22c3ce686dc916bdbe5bbd5475a18371a41d/lib/nake/file_task.rb#L50-L60 |
7,839 | yaauie/typed-array | lib/typed-array/functions.rb | TypedArray.Functions._ensure_all_items_in_array_are_allowed | def _ensure_all_items_in_array_are_allowed(ary)
# If we're getting an instance of self, accept
return if ary.is_a? self.class
_ensure_item_is_allowed(ary, [Array])
ary.each { |item| _ensure_item_is_allowed(item) }
end | ruby | def _ensure_all_items_in_array_are_allowed(ary)
# If we're getting an instance of self, accept
return if ary.is_a? self.class
_ensure_item_is_allowed(ary, [Array])
ary.each { |item| _ensure_item_is_allowed(item) }
end | [
"def",
"_ensure_all_items_in_array_are_allowed",
"(",
"ary",
")",
"# If we're getting an instance of self, accept",
"return",
"if",
"ary",
".",
"is_a?",
"self",
".",
"class",
"_ensure_item_is_allowed",
"(",
"ary",
",",
"[",
"Array",
"]",
")",
"ary",
".",
"each",
"{"... | Ensure that all items in the passed Array are allowed | [
"Ensure",
"that",
"all",
"items",
"in",
"the",
"passed",
"Array",
"are",
"allowed"
] | 3b92cb3d4c0a294dcf9720f46cbbb086686d2574 | https://github.com/yaauie/typed-array/blob/3b92cb3d4c0a294dcf9720f46cbbb086686d2574/lib/typed-array/functions.rb#L96-L101 |
7,840 | yaauie/typed-array | lib/typed-array/functions.rb | TypedArray.Functions._ensure_item_is_allowed | def _ensure_item_is_allowed(item, expected=nil)
return if item.nil? #allow nil entries
expected ||= self.class.restricted_types
return if expected.any? { |allowed| item.class <= allowed }
raise TypedArray::UnexpectedTypeException.new(expected, item.class)
end | ruby | def _ensure_item_is_allowed(item, expected=nil)
return if item.nil? #allow nil entries
expected ||= self.class.restricted_types
return if expected.any? { |allowed| item.class <= allowed }
raise TypedArray::UnexpectedTypeException.new(expected, item.class)
end | [
"def",
"_ensure_item_is_allowed",
"(",
"item",
",",
"expected",
"=",
"nil",
")",
"return",
"if",
"item",
".",
"nil?",
"#allow nil entries",
"expected",
"||=",
"self",
".",
"class",
".",
"restricted_types",
"return",
"if",
"expected",
".",
"any?",
"{",
"|",
"... | Ensure that the specific item passed is allowed | [
"Ensure",
"that",
"the",
"specific",
"item",
"passed",
"is",
"allowed"
] | 3b92cb3d4c0a294dcf9720f46cbbb086686d2574 | https://github.com/yaauie/typed-array/blob/3b92cb3d4c0a294dcf9720f46cbbb086686d2574/lib/typed-array/functions.rb#L104-L109 |
7,841 | jarhart/rattler | lib/rattler/parsers/sequence.rb | Rattler::Parsers.Sequence.parse | def parse(scanner, rules, scope = ParserScope.empty)
backtracking(scanner) do
if scope = parse_children(scanner, rules, scope.nest)
yield scope if block_given?
parse_result(scope)
end
end
end | ruby | def parse(scanner, rules, scope = ParserScope.empty)
backtracking(scanner) do
if scope = parse_children(scanner, rules, scope.nest)
yield scope if block_given?
parse_result(scope)
end
end
end | [
"def",
"parse",
"(",
"scanner",
",",
"rules",
",",
"scope",
"=",
"ParserScope",
".",
"empty",
")",
"backtracking",
"(",
"scanner",
")",
"do",
"if",
"scope",
"=",
"parse_children",
"(",
"scanner",
",",
"rules",
",",
"scope",
".",
"nest",
")",
"yield",
"... | Try each parser in sequence, and if they all succeed return an array of
captured results, or return +false+ if any parser fails.
@param (see Match#parse)
@return an array of captured results of each parser in sequence, or
+false+ | [
"Try",
"each",
"parser",
"in",
"sequence",
"and",
"if",
"they",
"all",
"succeed",
"return",
"an",
"array",
"of",
"captured",
"results",
"or",
"return",
"+",
"false",
"+",
"if",
"any",
"parser",
"fails",
"."
] | 8b4efde2a05e9e790955bb635d4a1a9615893719 | https://github.com/jarhart/rattler/blob/8b4efde2a05e9e790955bb635d4a1a9615893719/lib/rattler/parsers/sequence.rb#L22-L29 |
7,842 | jduff/herbalist | lib/herbalist/herbalist.rb | Herbalist.Token.get_tag | def get_tag(tag_type)
matches = @tags.select { |m| m.type==tag_type }
return matches.first
end | ruby | def get_tag(tag_type)
matches = @tags.select { |m| m.type==tag_type }
return matches.first
end | [
"def",
"get_tag",
"(",
"tag_type",
")",
"matches",
"=",
"@tags",
".",
"select",
"{",
"|",
"m",
"|",
"m",
".",
"type",
"==",
"tag_type",
"}",
"return",
"matches",
".",
"first",
"end"
] | Return the Tag that matches the given class | [
"Return",
"the",
"Tag",
"that",
"matches",
"the",
"given",
"class"
] | 78743a8082d78f32349049ba0ce73db41c70ad87 | https://github.com/jduff/herbalist/blob/78743a8082d78f32349049ba0ce73db41c70ad87/lib/herbalist/herbalist.rb#L89-L92 |
7,843 | boost/safety_cone | lib/safety_cone/configuration.rb | SafetyCone.Configuration.add | def add(options = {})
self.options = options
raise(ArgumentError, 'Mandatory param :name missing') unless options[:name]
if options[:feature]
features << options
SafetyCone::ViewHelpers.add_method(options[:feature])
else
paths[make_key] = options
end
end | ruby | def add(options = {})
self.options = options
raise(ArgumentError, 'Mandatory param :name missing') unless options[:name]
if options[:feature]
features << options
SafetyCone::ViewHelpers.add_method(options[:feature])
else
paths[make_key] = options
end
end | [
"def",
"add",
"(",
"options",
"=",
"{",
"}",
")",
"self",
".",
"options",
"=",
"options",
"raise",
"(",
"ArgumentError",
",",
"'Mandatory param :name missing'",
")",
"unless",
"options",
"[",
":name",
"]",
"if",
"options",
"[",
":feature",
"]",
"features",
... | Method add a route or method to be managed by safety cone | [
"Method",
"add",
"a",
"route",
"or",
"method",
"to",
"be",
"managed",
"by",
"safety",
"cone"
] | 45dfcb0a9f9702386f8f0af8254c72cb5162b0cb | https://github.com/boost/safety_cone/blob/45dfcb0a9f9702386f8f0af8254c72cb5162b0cb/lib/safety_cone/configuration.rb#L7-L18 |
7,844 | boost/safety_cone | lib/safety_cone/configuration.rb | SafetyCone.Configuration.make_key | def make_key
if options.key? :method
options[:method].to_sym
elsif options.include?(:controller) && options.include?(:action)
"#{options[:controller]}_#{options[:action]}".to_sym
else
raise(ArgumentError,
'Options should contain :controller and :action or :method.... | ruby | def make_key
if options.key? :method
options[:method].to_sym
elsif options.include?(:controller) && options.include?(:action)
"#{options[:controller]}_#{options[:action]}".to_sym
else
raise(ArgumentError,
'Options should contain :controller and :action or :method.... | [
"def",
"make_key",
"if",
"options",
".",
"key?",
":method",
"options",
"[",
":method",
"]",
".",
"to_sym",
"elsif",
"options",
".",
"include?",
"(",
":controller",
")",
"&&",
"options",
".",
"include?",
"(",
":action",
")",
"\"#{options[:controller]}_#{options[:... | Method to generate a key from the options | [
"Method",
"to",
"generate",
"a",
"key",
"from",
"the",
"options"
] | 45dfcb0a9f9702386f8f0af8254c72cb5162b0cb | https://github.com/boost/safety_cone/blob/45dfcb0a9f9702386f8f0af8254c72cb5162b0cb/lib/safety_cone/configuration.rb#L21-L30 |
7,845 | agoragames/oembedr | lib/oembedr/client.rb | Oembedr.Client.get | def get options = {}
additional_params = options.delete(:params) || {}
connection(options).get do |req|
req.url parsed_url.path
req.params = additional_params.merge({
:url => resource_url,
:format => "json"
})
end
end | ruby | def get options = {}
additional_params = options.delete(:params) || {}
connection(options).get do |req|
req.url parsed_url.path
req.params = additional_params.merge({
:url => resource_url,
:format => "json"
})
end
end | [
"def",
"get",
"options",
"=",
"{",
"}",
"additional_params",
"=",
"options",
".",
"delete",
"(",
":params",
")",
"||",
"{",
"}",
"connection",
"(",
"options",
")",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"parsed_url",
".",
"path",
"req"... | Requests the oembeddable resource
@return Faraday::Response | [
"Requests",
"the",
"oembeddable",
"resource"
] | 9e453adceaa01c5b07db466e6429a4ebb8bcda03 | https://github.com/agoragames/oembedr/blob/9e453adceaa01c5b07db466e6429a4ebb8bcda03/lib/oembedr/client.rb#L40-L49 |
7,846 | gnumarcelo/campaigning | lib/campaigning/list.rb | Campaigning.List.create_custom_field! | def create_custom_field!(params)
response = @@soap.createListCustomField(
:apiKey => @apiKey,
:listID => @listID,
:fieldName => params[:fieldName],
:dataType => params[:dataType],
:options => params.fetch(:options, "")
)
handle_response response.list_CreateCustomFi... | ruby | def create_custom_field!(params)
response = @@soap.createListCustomField(
:apiKey => @apiKey,
:listID => @listID,
:fieldName => params[:fieldName],
:dataType => params[:dataType],
:options => params.fetch(:options, "")
)
handle_response response.list_CreateCustomFi... | [
"def",
"create_custom_field!",
"(",
"params",
")",
"response",
"=",
"@@soap",
".",
"createListCustomField",
"(",
":apiKey",
"=>",
"@apiKey",
",",
":listID",
"=>",
"@listID",
",",
":fieldName",
"=>",
"params",
"[",
":fieldName",
"]",
",",
":dataType",
"=>",
"pa... | Creates a new custom field for a list
Available _params_ argument are:
* :fieldName - The Name for the new Custom Field. This will be used to generate the custom fields Key.
* :dataType - The Data Type for the new Custom Field. This must be one of Text, Number, MultiSelectOne, or MultiSelectMany
* :options - ... | [
"Creates",
"a",
"new",
"custom",
"field",
"for",
"a",
"list"
] | f3d7da053b65cfa376269533183919dc890964fd | https://github.com/gnumarcelo/campaigning/blob/f3d7da053b65cfa376269533183919dc890964fd/lib/campaigning/list.rb#L61-L70 |
7,847 | gnumarcelo/campaigning | lib/campaigning/list.rb | Campaigning.List.get_all_active_subscribers | def get_all_active_subscribers
find_active_subscribers(DateTime.new(y=1911,m=1,d=01, h=01,min=00,s=00))
end | ruby | def get_all_active_subscribers
find_active_subscribers(DateTime.new(y=1911,m=1,d=01, h=01,min=00,s=00))
end | [
"def",
"get_all_active_subscribers",
"find_active_subscribers",
"(",
"DateTime",
".",
"new",
"(",
"y",
"=",
"1911",
",",
"m",
"=",
"1",
",",
"d",
"=",
"01",
",",
"h",
"=",
"01",
",",
"min",
"=",
"00",
",",
"s",
"=",
"00",
")",
")",
"end"
] | Gets a list of all active subscribers for a list.
*Return*:
*Success*: Upon a successful call, this method will return a collection of Campaigning::Subscriber objects.
*Error*: An Exception containing the cause of the error will be raised. | [
"Gets",
"a",
"list",
"of",
"all",
"active",
"subscribers",
"for",
"a",
"list",
"."
] | f3d7da053b65cfa376269533183919dc890964fd | https://github.com/gnumarcelo/campaigning/blob/f3d7da053b65cfa376269533183919dc890964fd/lib/campaigning/list.rb#L180-L182 |
7,848 | r7kamura/plz | lib/plz/command_builder.rb | Plz.CommandBuilder.base_url_from_schema | def base_url_from_schema
json_schema.links.find do |link|
if link.href && link.rel == "self"
return link.href
end
end
end | ruby | def base_url_from_schema
json_schema.links.find do |link|
if link.href && link.rel == "self"
return link.href
end
end
end | [
"def",
"base_url_from_schema",
"json_schema",
".",
"links",
".",
"find",
"do",
"|",
"link",
"|",
"if",
"link",
".",
"href",
"&&",
"link",
".",
"rel",
"==",
"\"self\"",
"return",
"link",
".",
"href",
"end",
"end",
"end"
] | Extracts the base url of the API from JSON Schema
@return [String, nil]
@example
base_url_from_schema #=> "https://api.example.com/" | [
"Extracts",
"the",
"base",
"url",
"of",
"the",
"API",
"from",
"JSON",
"Schema"
] | 66aca9f864da21b561d558841ce4c17704eebbfc | https://github.com/r7kamura/plz/blob/66aca9f864da21b561d558841ce4c17704eebbfc/lib/plz/command_builder.rb#L206-L212 |
7,849 | ViaQ/Relp | lib/relp/relp_protocol.rb | Relp.RelpProtocol.frame_read | def frame_read(socket)
begin
socket_content = socket.read_nonblock(4096)
frame = Hash.new
if match = socket_content.match(/(^[0-9]+) ([\S]*) (\d+)([\s\S]*)/)
frame[:txnr], frame[:command], frame[:data_length], frame[:message] = match.captures
# check_message_length(fram... | ruby | def frame_read(socket)
begin
socket_content = socket.read_nonblock(4096)
frame = Hash.new
if match = socket_content.match(/(^[0-9]+) ([\S]*) (\d+)([\s\S]*)/)
frame[:txnr], frame[:command], frame[:data_length], frame[:message] = match.captures
# check_message_length(fram... | [
"def",
"frame_read",
"(",
"socket",
")",
"begin",
"socket_content",
"=",
"socket",
".",
"read_nonblock",
"(",
"4096",
")",
"frame",
"=",
"Hash",
".",
"new",
"if",
"match",
"=",
"socket_content",
".",
"match",
"(",
"/",
"\\S",
"\\d",
"\\s",
"\\S",
"/",
... | Read socket and return Relp frame information in hash | [
"Read",
"socket",
"and",
"return",
"Relp",
"frame",
"information",
"in",
"hash"
] | 979bbb757274d84f84c3d00bc459f2b30146c4fe | https://github.com/ViaQ/Relp/blob/979bbb757274d84f84c3d00bc459f2b30146c4fe/lib/relp/relp_protocol.rb#L33-L55 |
7,850 | ViaQ/Relp | lib/relp/relp_protocol.rb | Relp.RelpProtocol.is_valid_command | def is_valid_command(command)
valid_commands = ["open", "close", "rsp", "syslog"]
if !valid_commands.include?(command)
@logger.error 'Invalid RELP command'
raise Relp::InvalidCommand.new('Invalid command')
end
end | ruby | def is_valid_command(command)
valid_commands = ["open", "close", "rsp", "syslog"]
if !valid_commands.include?(command)
@logger.error 'Invalid RELP command'
raise Relp::InvalidCommand.new('Invalid command')
end
end | [
"def",
"is_valid_command",
"(",
"command",
")",
"valid_commands",
"=",
"[",
"\"open\"",
",",
"\"close\"",
",",
"\"rsp\"",
",",
"\"syslog\"",
"]",
"if",
"!",
"valid_commands",
".",
"include?",
"(",
"command",
")",
"@logger",
".",
"error",
"'Invalid RELP command'"... | Check if command is one of valid commands if not raise exception | [
"Check",
"if",
"command",
"is",
"one",
"of",
"valid",
"commands",
"if",
"not",
"raise",
"exception"
] | 979bbb757274d84f84c3d00bc459f2b30146c4fe | https://github.com/ViaQ/Relp/blob/979bbb757274d84f84c3d00bc459f2b30146c4fe/lib/relp/relp_protocol.rb#L59-L65 |
7,851 | benbalter/squad_goals | lib/squad_goals/helpers.rb | SquadGoals.Helpers.client_call | def client_call(method, *args)
key = cache_key(method, args)
cached = dalli.get(key)
return cached if cached
response = client.send(method, *args)
dalli.set(key, response)
response
end | ruby | def client_call(method, *args)
key = cache_key(method, args)
cached = dalli.get(key)
return cached if cached
response = client.send(method, *args)
dalli.set(key, response)
response
end | [
"def",
"client_call",
"(",
"method",
",",
"*",
"args",
")",
"key",
"=",
"cache_key",
"(",
"method",
",",
"args",
")",
"cached",
"=",
"dalli",
".",
"get",
"(",
"key",
")",
"return",
"cached",
"if",
"cached",
"response",
"=",
"client",
".",
"send",
"("... | Call octokit, using memcached response, when available | [
"Call",
"octokit",
"using",
"memcached",
"response",
"when",
"available"
] | f3c06e7e45980833ebccacd6b7aaca25c8a216cc | https://github.com/benbalter/squad_goals/blob/f3c06e7e45980833ebccacd6b7aaca25c8a216cc/lib/squad_goals/helpers.rb#L4-L11 |
7,852 | xijo/helmsman | lib/helmsman/view_helper.rb | Helmsman.ViewHelper.current_state_by_controller | def current_state_by_controller(*given_controller_names, actions: [])
if given_controller_names.any? { |name| name == controller_name.to_sym }
if actions.present?
Array(actions).include?(action_name.to_sym)
else
true
end
end
end | ruby | def current_state_by_controller(*given_controller_names, actions: [])
if given_controller_names.any? { |name| name == controller_name.to_sym }
if actions.present?
Array(actions).include?(action_name.to_sym)
else
true
end
end
end | [
"def",
"current_state_by_controller",
"(",
"*",
"given_controller_names",
",",
"actions",
":",
"[",
"]",
")",
"if",
"given_controller_names",
".",
"any?",
"{",
"|",
"name",
"|",
"name",
"==",
"controller_name",
".",
"to_sym",
"}",
"if",
"actions",
".",
"presen... | Returns true if one of the given controllers match the actual one.
If actions are set they are taken into account. | [
"Returns",
"true",
"if",
"one",
"of",
"the",
"given",
"controllers",
"match",
"the",
"actual",
"one",
".",
"If",
"actions",
"are",
"set",
"they",
"are",
"taken",
"into",
"account",
"."
] | 0cf50f298e8fc3c2d90344bf27c007ae2227fa9c | https://github.com/xijo/helmsman/blob/0cf50f298e8fc3c2d90344bf27c007ae2227fa9c/lib/helmsman/view_helper.rb#L5-L13 |
7,853 | mru2/salesforce_adapter | lib/salesforce_adapter.rb | SalesforceAdapter.Base.call_webservice | def call_webservice(method_name, arguments, schema_url, service_path)
# Perform the call to the webservice and returns the result
Operations::WebserviceCall.new(@rforce_binding, method_name, arguments, schema_url, service_path).run()
end | ruby | def call_webservice(method_name, arguments, schema_url, service_path)
# Perform the call to the webservice and returns the result
Operations::WebserviceCall.new(@rforce_binding, method_name, arguments, schema_url, service_path).run()
end | [
"def",
"call_webservice",
"(",
"method_name",
",",
"arguments",
",",
"schema_url",
",",
"service_path",
")",
"# Perform the call to the webservice and returns the result",
"Operations",
"::",
"WebserviceCall",
".",
"new",
"(",
"@rforce_binding",
",",
"method_name",
",",
"... | Queries a salesforce webservice | [
"Queries",
"a",
"salesforce",
"webservice"
] | 5f7ddd0cce6ee5bce5cd60482e5415a11d5593a4 | https://github.com/mru2/salesforce_adapter/blob/5f7ddd0cce6ee5bce5cd60482e5415a11d5593a4/lib/salesforce_adapter.rb#L66-L71 |
7,854 | michaelachrisco/nasa-api-client | lib/nasa/client.rb | NASA.Client.neo_feed | def neo_feed(start_date = Time.now.strftime('%Y-%m-%d'),
end_date = (Time.now + 604800).strftime('%Y-%m-%d'))
request
.neo
.rest
.v1('feed')
.get(:params => { :api_key => @application_id.dup,
:start_date => start_date,
... | ruby | def neo_feed(start_date = Time.now.strftime('%Y-%m-%d'),
end_date = (Time.now + 604800).strftime('%Y-%m-%d'))
request
.neo
.rest
.v1('feed')
.get(:params => { :api_key => @application_id.dup,
:start_date => start_date,
... | [
"def",
"neo_feed",
"(",
"start_date",
"=",
"Time",
".",
"now",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
",",
"end_date",
"=",
"(",
"Time",
".",
"now",
"+",
"604800",
")",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
")",
"request",
".",
"neo",
".",
"rest... | end_date is 1 week in seconds | [
"end_date",
"is",
"1",
"week",
"in",
"seconds"
] | 768be8a6006207050deca1bc9b039b7349fc969e | https://github.com/michaelachrisco/nasa-api-client/blob/768be8a6006207050deca1bc9b039b7349fc969e/lib/nasa/client.rb#L27-L37 |
7,855 | blackwinter/nuggets | lib/nuggets/ruby_mixin.rb | Nuggets.RubyMixin.ruby_executable | def ruby_executable
@ruby_executable ||= begin
dir, name, ext = CONFIG.values_at(*%w[bindir RUBY_INSTALL_NAME EXEEXT])
::File.join(dir, name + ext).sub(/.*\s.*/m, '"\&"')
end
end | ruby | def ruby_executable
@ruby_executable ||= begin
dir, name, ext = CONFIG.values_at(*%w[bindir RUBY_INSTALL_NAME EXEEXT])
::File.join(dir, name + ext).sub(/.*\s.*/m, '"\&"')
end
end | [
"def",
"ruby_executable",
"@ruby_executable",
"||=",
"begin",
"dir",
",",
"name",
",",
"ext",
"=",
"CONFIG",
".",
"values_at",
"(",
"%w[",
"bindir",
"RUBY_INSTALL_NAME",
"EXEEXT",
"]",
")",
"::",
"File",
".",
"join",
"(",
"dir",
",",
"name",
"+",
"ext",
... | Returns the full path to the current Ruby interpreter's executable file.
This might not be the actual correct command to use for invoking the Ruby
interpreter; use ruby_command instead. | [
"Returns",
"the",
"full",
"path",
"to",
"the",
"current",
"Ruby",
"interpreter",
"s",
"executable",
"file",
".",
"This",
"might",
"not",
"be",
"the",
"actual",
"correct",
"command",
"to",
"use",
"for",
"invoking",
"the",
"Ruby",
"interpreter",
";",
"use",
... | 2a1d0beb015077b2820851ab190e886d1ad588b8 | https://github.com/blackwinter/nuggets/blob/2a1d0beb015077b2820851ab190e886d1ad588b8/lib/nuggets/ruby_mixin.rb#L81-L86 |
7,856 | blackwinter/nuggets | lib/nuggets/ruby_mixin.rb | Nuggets.RubyMixin.command_for_ruby_tool | def command_for_ruby_tool(name)
filename = respond_to?(name) ? send(name) : locate_ruby_tool(name)
shebang_command(filename) =~ /ruby/ ? "#{ruby_command} #{filename}" : filename
end | ruby | def command_for_ruby_tool(name)
filename = respond_to?(name) ? send(name) : locate_ruby_tool(name)
shebang_command(filename) =~ /ruby/ ? "#{ruby_command} #{filename}" : filename
end | [
"def",
"command_for_ruby_tool",
"(",
"name",
")",
"filename",
"=",
"respond_to?",
"(",
"name",
")",
"?",
"send",
"(",
"name",
")",
":",
"locate_ruby_tool",
"(",
"name",
")",
"shebang_command",
"(",
"filename",
")",
"=~",
"/",
"/",
"?",
"\"#{ruby_command} #{f... | Returns the correct command string for invoking the +name+ executable
that belongs to the current Ruby interpreter. Returns +nil+ if the
command is not found.
If the command executable is a Ruby program, then we need to run it
in the correct Ruby interpreter just in case the command doesn't
have the correct sheba... | [
"Returns",
"the",
"correct",
"command",
"string",
"for",
"invoking",
"the",
"+",
"name",
"+",
"executable",
"that",
"belongs",
"to",
"the",
"current",
"Ruby",
"interpreter",
".",
"Returns",
"+",
"nil",
"+",
"if",
"the",
"command",
"is",
"not",
"found",
"."... | 2a1d0beb015077b2820851ab190e886d1ad588b8 | https://github.com/blackwinter/nuggets/blob/2a1d0beb015077b2820851ab190e886d1ad588b8/lib/nuggets/ruby_mixin.rb#L122-L125 |
7,857 | rightscale/right_develop | lib/right_develop/ci/util.rb | RightDevelop::CI.Util.pseudo_java_class_name | def pseudo_java_class_name(name)
result = ''
name.each_char do |chr|
if chr =~ JAVA_CLASS_NAME
result << chr
elsif chr == JAVA_PACKAGE_SEPARATOR
result << JAVE_PACKAGE_SEPARATOR_HOMOGLYPH
else
chr = chr.unpack('U')[0].to_s(16)
result << "&#x#{... | ruby | def pseudo_java_class_name(name)
result = ''
name.each_char do |chr|
if chr =~ JAVA_CLASS_NAME
result << chr
elsif chr == JAVA_PACKAGE_SEPARATOR
result << JAVE_PACKAGE_SEPARATOR_HOMOGLYPH
else
chr = chr.unpack('U')[0].to_s(16)
result << "&#x#{... | [
"def",
"pseudo_java_class_name",
"(",
"name",
")",
"result",
"=",
"''",
"name",
".",
"each_char",
"do",
"|",
"chr",
"|",
"if",
"chr",
"=~",
"JAVA_CLASS_NAME",
"result",
"<<",
"chr",
"elsif",
"chr",
"==",
"JAVA_PACKAGE_SEPARATOR",
"result",
"<<",
"JAVE_PACKAGE_... | Ruby 1.8-2.1 compatible
Make a string suitable for parsing by Jenkins JUnit display plugin by escaping any non-valid
Java class name characters as an XML entity. This prevents Jenkins from interpreting "hi1.2"
as a package-and-class name.
@param [String] name
@return [String] string with all non-alphanumerics rep... | [
"Ruby",
"1",
".",
"8",
"-",
"2",
".",
"1",
"compatible",
"Make",
"a",
"string",
"suitable",
"for",
"parsing",
"by",
"Jenkins",
"JUnit",
"display",
"plugin",
"by",
"escaping",
"any",
"non",
"-",
"valid",
"Java",
"class",
"name",
"characters",
"as",
"an",
... | 52527b3c32200b542ed590f6f9a275c76758df0e | https://github.com/rightscale/right_develop/blob/52527b3c32200b542ed590f6f9a275c76758df0e/lib/right_develop/ci/util.rb#L32-L47 |
7,858 | rightscale/right_develop | lib/right_develop/ci/util.rb | RightDevelop::CI.Util.purify | def purify(untrusted)
# First pass: strip bad UTF-8 characters
if RUBY_VERSION =~ /^1\.8/
iconv = Iconv.new('UTF-8//IGNORE', 'UTF-8')
result = iconv.iconv(untrusted)
else
result = untrusted.force_encoding(Encoding::BINARY).encode('UTF-8', :undef=>:replace, :replace=>'')
e... | ruby | def purify(untrusted)
# First pass: strip bad UTF-8 characters
if RUBY_VERSION =~ /^1\.8/
iconv = Iconv.new('UTF-8//IGNORE', 'UTF-8')
result = iconv.iconv(untrusted)
else
result = untrusted.force_encoding(Encoding::BINARY).encode('UTF-8', :undef=>:replace, :replace=>'')
e... | [
"def",
"purify",
"(",
"untrusted",
")",
"# First pass: strip bad UTF-8 characters",
"if",
"RUBY_VERSION",
"=~",
"/",
"\\.",
"/",
"iconv",
"=",
"Iconv",
".",
"new",
"(",
"'UTF-8//IGNORE'",
",",
"'UTF-8'",
")",
"result",
"=",
"iconv",
".",
"iconv",
"(",
"untrust... | Strip invalid UTF-8 sequences from a string and entity-escape any character that can't legally
appear inside XML CDATA. If test output contains weird data, we could end up generating
invalid JUnit XML which will choke Java. Preserve the purity of essence of our precious XML
fluids!
@return [String] the input with ... | [
"Strip",
"invalid",
"UTF",
"-",
"8",
"sequences",
"from",
"a",
"string",
"and",
"entity",
"-",
"escape",
"any",
"character",
"that",
"can",
"t",
"legally",
"appear",
"inside",
"XML",
"CDATA",
".",
"If",
"test",
"output",
"contains",
"weird",
"data",
"we",
... | 52527b3c32200b542ed590f6f9a275c76758df0e | https://github.com/rightscale/right_develop/blob/52527b3c32200b542ed590f6f9a275c76758df0e/lib/right_develop/ci/util.rb#L56-L69 |
7,859 | agoragames/oembedr | lib/oembedr/providers.rb | Oembedr.Providers.service_endpoint | def service_endpoint url
endpoint = LIST.find do |(pattern, endpoint)|
url =~ pattern
end
endpoint ? endpoint.last : false
end | ruby | def service_endpoint url
endpoint = LIST.find do |(pattern, endpoint)|
url =~ pattern
end
endpoint ? endpoint.last : false
end | [
"def",
"service_endpoint",
"url",
"endpoint",
"=",
"LIST",
".",
"find",
"do",
"|",
"(",
"pattern",
",",
"endpoint",
")",
"|",
"url",
"=~",
"pattern",
"end",
"endpoint",
"?",
"endpoint",
".",
"last",
":",
"false",
"end"
] | Locate the correct service endpoint for the given resource URL.
@param url [String] a fully-qualified URL to an oembeddable resource
@return the url, or false if no known endpoint. | [
"Locate",
"the",
"correct",
"service",
"endpoint",
"for",
"the",
"given",
"resource",
"URL",
"."
] | 9e453adceaa01c5b07db466e6429a4ebb8bcda03 | https://github.com/agoragames/oembedr/blob/9e453adceaa01c5b07db466e6429a4ebb8bcda03/lib/oembedr/providers.rb#L75-L80 |
7,860 | af83/desi | lib/desi/index_manager.rb | Desi.IndexManager.delete! | def delete!(pattern)
warn "You must provide a pattern" and exit if pattern.nil?
@outputter.puts "The following indices from host #{@host} are now deleted" if @verbose
indices(Regexp.new(pattern)).each do |index|
@client.delete("/#{index}")
@outputter.puts " * #{index.inspect}" if @ve... | ruby | def delete!(pattern)
warn "You must provide a pattern" and exit if pattern.nil?
@outputter.puts "The following indices from host #{@host} are now deleted" if @verbose
indices(Regexp.new(pattern)).each do |index|
@client.delete("/#{index}")
@outputter.puts " * #{index.inspect}" if @ve... | [
"def",
"delete!",
"(",
"pattern",
")",
"warn",
"\"You must provide a pattern\"",
"and",
"exit",
"if",
"pattern",
".",
"nil?",
"@outputter",
".",
"puts",
"\"The following indices from host #{@host} are now deleted\"",
"if",
"@verbose",
"indices",
"(",
"Regexp",
".",
"new... | Delete all indices matching the specified pattern
@param [#to_s] pattern Regexp pattern used to restrict the selection
@return [void]
@note No confirmation is needed, so beware!
@note This method will also output its result on STDOUT if +@verbose+ is
true
@example Delete all indices whose n... | [
"Delete",
"all",
"indices",
"matching",
"the",
"specified",
"pattern"
] | 30c51ce3b484765bd8911baf2fb83a85809cc81c | https://github.com/af83/desi/blob/30c51ce3b484765bd8911baf2fb83a85809cc81c/lib/desi/index_manager.rb#L124-L133 |
7,861 | af83/desi | lib/desi/index_manager.rb | Desi.IndexManager.close! | def close!(pattern)
warn "You must provide a pattern" and exit if pattern.nil?
@outputter.puts "The following indices from host #{@host} are now closed" if @verbose
indices(Regexp.new(pattern)).each do |index|
@client.post("/#{index}/_close")
@outputter.puts " * #{index.inspect}" if ... | ruby | def close!(pattern)
warn "You must provide a pattern" and exit if pattern.nil?
@outputter.puts "The following indices from host #{@host} are now closed" if @verbose
indices(Regexp.new(pattern)).each do |index|
@client.post("/#{index}/_close")
@outputter.puts " * #{index.inspect}" if ... | [
"def",
"close!",
"(",
"pattern",
")",
"warn",
"\"You must provide a pattern\"",
"and",
"exit",
"if",
"pattern",
".",
"nil?",
"@outputter",
".",
"puts",
"\"The following indices from host #{@host} are now closed\"",
"if",
"@verbose",
"indices",
"(",
"Regexp",
".",
"new",... | Close all indices matching the specified pattern
@param [#to_s] pattern Regexp pattern used to restrict the selection
@return [void]
@note No confirmation is needed, so beware!
@note This method will also output its result on STDOUT if +@verbose+ is
true
@example Close all indices whose nam... | [
"Close",
"all",
"indices",
"matching",
"the",
"specified",
"pattern"
] | 30c51ce3b484765bd8911baf2fb83a85809cc81c | https://github.com/af83/desi/blob/30c51ce3b484765bd8911baf2fb83a85809cc81c/lib/desi/index_manager.rb#L149-L158 |
7,862 | datacite/toccatore | lib/toccatore/usage_update.rb | Toccatore.UsageUpdate.push_data | def push_data(items, options={})
if items.empty?
puts "No works found in the Queue."
0
elsif options[:access_token].blank?
puts "An error occured: Access token missing."
options[:total]
else
error_total = 0
Array(items).each do |item|
puts item... | ruby | def push_data(items, options={})
if items.empty?
puts "No works found in the Queue."
0
elsif options[:access_token].blank?
puts "An error occured: Access token missing."
options[:total]
else
error_total = 0
Array(items).each do |item|
puts item... | [
"def",
"push_data",
"(",
"items",
",",
"options",
"=",
"{",
"}",
")",
"if",
"items",
".",
"empty?",
"puts",
"\"No works found in the Queue.\"",
"0",
"elsif",
"options",
"[",
":access_token",
"]",
".",
"blank?",
"puts",
"\"An error occured: Access token missing.\"",
... | method returns number of errors | [
"method",
"returns",
"number",
"of",
"errors"
] | 2fe36304776d599700c568544982d83c6ad44eac | https://github.com/datacite/toccatore/blob/2fe36304776d599700c568544982d83c6ad44eac/lib/toccatore/usage_update.rb#L70-L86 |
7,863 | rschultheis/hatt | lib/hatt/configuration.rb | Hatt.Configuration.init_config | def init_config
unless instance_variable_defined? :@hatt_configuration
@hatt_configuration = TCFG::Base.new
# build up some default configuration
@hatt_configuration.tcfg_set 'hatt_services', {}
@hatt_configuration.tcfg_set 'hatt_globs', DEFAULT_HATT_GLOBS
@hatt_configura... | ruby | def init_config
unless instance_variable_defined? :@hatt_configuration
@hatt_configuration = TCFG::Base.new
# build up some default configuration
@hatt_configuration.tcfg_set 'hatt_services', {}
@hatt_configuration.tcfg_set 'hatt_globs', DEFAULT_HATT_GLOBS
@hatt_configura... | [
"def",
"init_config",
"unless",
"instance_variable_defined?",
":@hatt_configuration",
"@hatt_configuration",
"=",
"TCFG",
"::",
"Base",
".",
"new",
"# build up some default configuration",
"@hatt_configuration",
".",
"tcfg_set",
"'hatt_services'",
",",
"{",
"}",
"@hatt_config... | ensure the configuration is resolved and ready to use | [
"ensure",
"the",
"configuration",
"is",
"resolved",
"and",
"ready",
"to",
"use"
] | b1b5cddf2b52d8952e5607a2987d2efb648babaf | https://github.com/rschultheis/hatt/blob/b1b5cddf2b52d8952e5607a2987d2efb648babaf/lib/hatt/configuration.rb#L35-L57 |
7,864 | birarda/logan | lib/logan/client.rb | Logan.Client.auth= | def auth=(auth_hash)
# symbolize the keys
new_auth_hash = {}
auth_hash.each {|k, v| new_auth_hash[k.to_sym] = v}
auth_hash = new_auth_hash
if auth_hash.has_key? :access_token
# clear the basic_auth, if it's set
self.class.default_options.reject!{ |k| k == :basic_auth }
... | ruby | def auth=(auth_hash)
# symbolize the keys
new_auth_hash = {}
auth_hash.each {|k, v| new_auth_hash[k.to_sym] = v}
auth_hash = new_auth_hash
if auth_hash.has_key? :access_token
# clear the basic_auth, if it's set
self.class.default_options.reject!{ |k| k == :basic_auth }
... | [
"def",
"auth",
"=",
"(",
"auth_hash",
")",
"# symbolize the keys",
"new_auth_hash",
"=",
"{",
"}",
"auth_hash",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"new_auth_hash",
"[",
"k",
".",
"to_sym",
"]",
"=",
"v",
"}",
"auth_hash",
"=",
"new_auth_hash",
... | Initializes the Logan shared client with information required to communicate with Basecamp
@param basecamp_id [String] the Basecamp company ID
@param auth_hash [Hash] authorization hash consisting of a username and password combination (:username, :password) or an access_token (:access_token)
@param user_agent [Str... | [
"Initializes",
"the",
"Logan",
"shared",
"client",
"with",
"information",
"required",
"to",
"communicate",
"with",
"Basecamp"
] | c007081c7dbb5b98ef5312db78f84867c6075ab0 | https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/client.rb#L22-L45 |
7,865 | birarda/logan | lib/logan/client.rb | Logan.Client.project_templates | def project_templates
response = self.class.get '/project_templates.json'
handle_response(response, Proc.new {|h| Logan::ProjectTemplate.new(h) })
end | ruby | def project_templates
response = self.class.get '/project_templates.json'
handle_response(response, Proc.new {|h| Logan::ProjectTemplate.new(h) })
end | [
"def",
"project_templates",
"response",
"=",
"self",
".",
"class",
".",
"get",
"'/project_templates.json'",
"handle_response",
"(",
"response",
",",
"Proc",
".",
"new",
"{",
"|",
"h",
"|",
"Logan",
"::",
"ProjectTemplate",
".",
"new",
"(",
"h",
")",
"}",
"... | get project templates from Basecamp API
@return [Array<Logan::ProjectTemplate>] array of {Logan::ProjectTemplate} instances | [
"get",
"project",
"templates",
"from",
"Basecamp",
"API"
] | c007081c7dbb5b98ef5312db78f84867c6075ab0 | https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/client.rb#L61-L64 |
7,866 | birarda/logan | lib/logan/client.rb | Logan.Client.todolists | def todolists
response = self.class.get '/todolists.json'
handle_response(response,
Proc.new { |h|
list = Logan::TodoList.new(h)
# grab the project ID for this list from the url
list.project_id = list.url.scan( /projects\/(\d+)/).last.first
# return the list... | ruby | def todolists
response = self.class.get '/todolists.json'
handle_response(response,
Proc.new { |h|
list = Logan::TodoList.new(h)
# grab the project ID for this list from the url
list.project_id = list.url.scan( /projects\/(\d+)/).last.first
# return the list... | [
"def",
"todolists",
"response",
"=",
"self",
".",
"class",
".",
"get",
"'/todolists.json'",
"handle_response",
"(",
"response",
",",
"Proc",
".",
"new",
"{",
"|",
"h",
"|",
"list",
"=",
"Logan",
"::",
"TodoList",
".",
"new",
"(",
"h",
")",
"# grab the pr... | get active Todo lists for all projects from Basecamp API
@return [Array<Logan::TodoList>] array of {Logan::TodoList} instances | [
"get",
"active",
"Todo",
"lists",
"for",
"all",
"projects",
"from",
"Basecamp",
"API"
] | c007081c7dbb5b98ef5312db78f84867c6075ab0 | https://github.com/birarda/logan/blob/c007081c7dbb5b98ef5312db78f84867c6075ab0/lib/logan/client.rb#L69-L82 |
7,867 | nyk/catflap | lib/catflap/netfilter/writer.rb | NetfilterWriter.Rules.chain | def chain(cmd, chain, p = {})
cmds = {
new: '-N', rename: '-E', delete: '-X', flush: '-F',
list_rules: '-S', list: '-L', zero: '-Z', policy: '-P'
}
@buffer << [
'iptables',
option('-t', @table), cmds[cmd], option('-n', p[:numeric]), chain,
option(false, p[:rule... | ruby | def chain(cmd, chain, p = {})
cmds = {
new: '-N', rename: '-E', delete: '-X', flush: '-F',
list_rules: '-S', list: '-L', zero: '-Z', policy: '-P'
}
@buffer << [
'iptables',
option('-t', @table), cmds[cmd], option('-n', p[:numeric]), chain,
option(false, p[:rule... | [
"def",
"chain",
"(",
"cmd",
",",
"chain",
",",
"p",
"=",
"{",
"}",
")",
"cmds",
"=",
"{",
"new",
":",
"'-N'",
",",
"rename",
":",
"'-E'",
",",
"delete",
":",
"'-X'",
",",
"flush",
":",
"'-F'",
",",
"list_rules",
":",
"'-S'",
",",
"list",
":",
... | Create, flush and delete chains and other iptable chain operations.
@param [Symbol] cmd the operation to perform (:new, :delete, :flush)
@param [String] chain name of the chain (e.g. INPUT, CATFLAP-DENY, etc.)
@param [Hash] p parameters for specific iptables features.
@return self
@example
Rules.new('nat').chai... | [
"Create",
"flush",
"and",
"delete",
"chains",
"and",
"other",
"iptable",
"chain",
"operations",
"."
] | e146e5df6d8d0085c127bf3ab77bfecfa9af78d9 | https://github.com/nyk/catflap/blob/e146e5df6d8d0085c127bf3ab77bfecfa9af78d9/lib/catflap/netfilter/writer.rb#L44-L57 |
7,868 | bilus/akasha | lib/akasha/changeset.rb | Akasha.Changeset.append | def append(event_name, **data)
id = SecureRandom.uuid
event = Akasha::Event.new(event_name, id, { aggregate_id: aggregate_id }, **data)
@aggregate.apply_events([event])
@events << event
end | ruby | def append(event_name, **data)
id = SecureRandom.uuid
event = Akasha::Event.new(event_name, id, { aggregate_id: aggregate_id }, **data)
@aggregate.apply_events([event])
@events << event
end | [
"def",
"append",
"(",
"event_name",
",",
"**",
"data",
")",
"id",
"=",
"SecureRandom",
".",
"uuid",
"event",
"=",
"Akasha",
"::",
"Event",
".",
"new",
"(",
"event_name",
",",
"id",
",",
"{",
"aggregate_id",
":",
"aggregate_id",
"}",
",",
"**",
"data",
... | Adds an event to the changeset. | [
"Adds",
"an",
"event",
"to",
"the",
"changeset",
"."
] | 5fadefc249f520ae909b762956ac23a6f916b021 | https://github.com/bilus/akasha/blob/5fadefc249f520ae909b762956ac23a6f916b021/lib/akasha/changeset.rb#L17-L22 |
7,869 | chetan/bixby-client | lib/bixby-client/client.rb | Bixby.Client.exec_api | def exec_api(json_req)
begin
req = sign_request(json_req)
return HttpChannel.new(api_uri).execute(req)
rescue Curl::Err::CurlError => ex
return JsonResponse.new("fail", ex.message)
end
end | ruby | def exec_api(json_req)
begin
req = sign_request(json_req)
return HttpChannel.new(api_uri).execute(req)
rescue Curl::Err::CurlError => ex
return JsonResponse.new("fail", ex.message)
end
end | [
"def",
"exec_api",
"(",
"json_req",
")",
"begin",
"req",
"=",
"sign_request",
"(",
"json_req",
")",
"return",
"HttpChannel",
".",
"new",
"(",
"api_uri",
")",
".",
"execute",
"(",
"req",
")",
"rescue",
"Curl",
"::",
"Err",
"::",
"CurlError",
"=>",
"ex",
... | Execute the given API request on the manager
@param [JsonRequest] json_req
@return [JsonResponse] | [
"Execute",
"the",
"given",
"API",
"request",
"on",
"the",
"manager"
] | 5444c2fb154fddef53459dd5cebe08b3f091d252 | https://github.com/chetan/bixby-client/blob/5444c2fb154fddef53459dd5cebe08b3f091d252/lib/bixby-client/client.rb#L46-L53 |
7,870 | asaaki/sjekksum | lib/sjekksum/luhn.rb | Sjekksum.Luhn.of | def of number
raise_on_type_mismatch number
digits = convert_number_to_digits(number)
sum = digits.reverse.map.with_index do |digit, idx|
idx.even? ? (digit * 2).divmod(10).reduce(&:+) : digit
end.reduce(&:+)
(10 - sum % 10) % 10
end | ruby | def of number
raise_on_type_mismatch number
digits = convert_number_to_digits(number)
sum = digits.reverse.map.with_index do |digit, idx|
idx.even? ? (digit * 2).divmod(10).reduce(&:+) : digit
end.reduce(&:+)
(10 - sum % 10) % 10
end | [
"def",
"of",
"number",
"raise_on_type_mismatch",
"number",
"digits",
"=",
"convert_number_to_digits",
"(",
"number",
")",
"sum",
"=",
"digits",
".",
"reverse",
".",
"map",
".",
"with_index",
"do",
"|",
"digit",
",",
"idx",
"|",
"idx",
".",
"even?",
"?",
"(... | Calculates Luhn checksum
@example
Sjekksum::Luhn.of(7992739871) #=> 3
@param number [Integer, String] number for which the checksum should be calculated
@return [Integer] calculated checksum | [
"Calculates",
"Luhn",
"checksum"
] | 47a21c19dcffc67a3bef11d4f2de7c167fd20087 | https://github.com/asaaki/sjekksum/blob/47a21c19dcffc67a3bef11d4f2de7c167fd20087/lib/sjekksum/luhn.rb#L20-L29 |
7,871 | sgillesp/taxonomite | lib/taxonomite/taxonomy.rb | Taxonomite.Taxonomy.valid_parent_types | def valid_parent_types(child)
# could be a node object, or maybe a string
str = child.respond_to?(:entity_type) ? child.entity_type : child
self.up_taxonomy[str]
end | ruby | def valid_parent_types(child)
# could be a node object, or maybe a string
str = child.respond_to?(:entity_type) ? child.entity_type : child
self.up_taxonomy[str]
end | [
"def",
"valid_parent_types",
"(",
"child",
")",
"# could be a node object, or maybe a string",
"str",
"=",
"child",
".",
"respond_to?",
"(",
":entity_type",
")",
"?",
"child",
".",
"entity_type",
":",
"child",
"self",
".",
"up_taxonomy",
"[",
"str",
"]",
"end"
] | access the appropriate parent entity_types for a particular child or child entity_type
@param [Taxonomy::Node, String] child the child object or entity_type string
@return [Array] an array of strings which are the valid parent types for the child | [
"access",
"the",
"appropriate",
"parent",
"entity_types",
"for",
"a",
"particular",
"child",
"or",
"child",
"entity_type"
] | 731b42d0dfa1f52b39d050026f49b2d205407ff8 | https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/taxonomy.rb#L56-L60 |
7,872 | sgillesp/taxonomite | lib/taxonomite/taxonomy.rb | Taxonomite.Taxonomy.valid_child_types | def valid_child_types(parent)
# could be a node object, or maybe a string
str = parent.respond_to?(:entity_type) ? parent.entity_type : child
self.down_taxonomy[str]
end | ruby | def valid_child_types(parent)
# could be a node object, or maybe a string
str = parent.respond_to?(:entity_type) ? parent.entity_type : child
self.down_taxonomy[str]
end | [
"def",
"valid_child_types",
"(",
"parent",
")",
"# could be a node object, or maybe a string",
"str",
"=",
"parent",
".",
"respond_to?",
"(",
":entity_type",
")",
"?",
"parent",
".",
"entity_type",
":",
"child",
"self",
".",
"down_taxonomy",
"[",
"str",
"]",
"end"... | access the appropriate child entity_types for a particular parent or parent entity_type
@param [Taxonomy::Node, String] parent the parent object or entity_type string
@return [Array] an array of strings which are the valid child types for the child | [
"access",
"the",
"appropriate",
"child",
"entity_types",
"for",
"a",
"particular",
"parent",
"or",
"parent",
"entity_type"
] | 731b42d0dfa1f52b39d050026f49b2d205407ff8 | https://github.com/sgillesp/taxonomite/blob/731b42d0dfa1f52b39d050026f49b2d205407ff8/lib/taxonomite/taxonomy.rb#L66-L70 |
7,873 | thumblemonks/riot-rails | lib/riot/action_controller/context_middleware.rb | RiotRails.ActionControllerMiddleware.nested_handle? | def nested_handle?(context)
(handle?(context.description) || nested_handle?(context.parent)) if context.respond_to?(:description)
end | ruby | def nested_handle?(context)
(handle?(context.description) || nested_handle?(context.parent)) if context.respond_to?(:description)
end | [
"def",
"nested_handle?",
"(",
"context",
")",
"(",
"handle?",
"(",
"context",
".",
"description",
")",
"||",
"nested_handle?",
"(",
"context",
".",
"parent",
")",
")",
"if",
"context",
".",
"respond_to?",
"(",
":description",
")",
"end"
] | Walking the description chain looking to see if any of them are serviceable
TODO: see if we can't define a method on the context to observe instead of calling
action_controller_description? each time | [
"Walking",
"the",
"description",
"chain",
"looking",
"to",
"see",
"if",
"any",
"of",
"them",
"are",
"serviceable"
] | 8bb2555d04f7fb67407f7224536e8b32349cede1 | https://github.com/thumblemonks/riot-rails/blob/8bb2555d04f7fb67407f7224536e8b32349cede1/lib/riot/action_controller/context_middleware.rb#L19-L21 |
7,874 | dlangevin/gxapi_rails | lib/gxapi/base.rb | Gxapi.Base.get_variant | def get_variant(identifier, override = nil)
# identifier object to handle finding and caching the
# experiment
identifier = GxApi::ExperimentIdentifier.new(identifier)
Celluloid::Future.new do
# allows us to override and get back a variant
# easily that conforms to the api
... | ruby | def get_variant(identifier, override = nil)
# identifier object to handle finding and caching the
# experiment
identifier = GxApi::ExperimentIdentifier.new(identifier)
Celluloid::Future.new do
# allows us to override and get back a variant
# easily that conforms to the api
... | [
"def",
"get_variant",
"(",
"identifier",
",",
"override",
"=",
"nil",
")",
"# identifier object to handle finding and caching the",
"# experiment",
"identifier",
"=",
"GxApi",
"::",
"ExperimentIdentifier",
".",
"new",
"(",
"identifier",
")",
"Celluloid",
"::",
"Future",... | return a variant value by name or id
@param identifier [String, Hash] The name of the experiment or a hash
with the id of the experiment
@param override [String] Override value returned from the experiment
@example
variant = @gxapi.get_variant("my_experiment")
variant.value =>
# Ostruct.new(experiment_... | [
"return",
"a",
"variant",
"value",
"by",
"name",
"or",
"id"
] | 21361227f0c70118b38f7fa372a18c0ae7aab810 | https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/base.rb#L55-L69 |
7,875 | dlangevin/gxapi_rails | lib/gxapi/base.rb | Gxapi.Base.get_variant_value | def get_variant_value(identifier)
data = Gxapi.with_error_handling do
Timeout::timeout(2.0) do
Gxapi.cache.fetch(self.cache_key(identifier)) do
@interface.get_variant(identifier).to_hash
end
end
end
Ostruct.new(
data.is_a?(Hash) ? data : self.def... | ruby | def get_variant_value(identifier)
data = Gxapi.with_error_handling do
Timeout::timeout(2.0) do
Gxapi.cache.fetch(self.cache_key(identifier)) do
@interface.get_variant(identifier).to_hash
end
end
end
Ostruct.new(
data.is_a?(Hash) ? data : self.def... | [
"def",
"get_variant_value",
"(",
"identifier",
")",
"data",
"=",
"Gxapi",
".",
"with_error_handling",
"do",
"Timeout",
"::",
"timeout",
"(",
"2.0",
")",
"do",
"Gxapi",
".",
"cache",
".",
"fetch",
"(",
"self",
".",
"cache_key",
"(",
"identifier",
")",
")",
... | protected method to make the actual calls to get values
from the cache or from Google
@param identifier [ExperimentIdentifier] Experiment to look for
@return [Gxapi::Ostruct] Experiment data | [
"protected",
"method",
"to",
"make",
"the",
"actual",
"calls",
"to",
"get",
"values",
"from",
"the",
"cache",
"or",
"from",
"Google"
] | 21361227f0c70118b38f7fa372a18c0ae7aab810 | https://github.com/dlangevin/gxapi_rails/blob/21361227f0c70118b38f7fa372a18c0ae7aab810/lib/gxapi/base.rb#L108-L119 |
7,876 | thumblemonks/riot-rails | lib/riot/active_record/transactional_middleware.rb | RiotRails.TransactionalMiddleware.hijack_local_run | def hijack_local_run(context)
(class << context; self; end).class_eval do
alias_method :transactionless_local_run, :local_run
def local_run(*args)
::ActiveRecord::Base.transaction do
transactionless_local_run(*args)
raise ::ActiveRecord::Rollback
end
... | ruby | def hijack_local_run(context)
(class << context; self; end).class_eval do
alias_method :transactionless_local_run, :local_run
def local_run(*args)
::ActiveRecord::Base.transaction do
transactionless_local_run(*args)
raise ::ActiveRecord::Rollback
end
... | [
"def",
"hijack_local_run",
"(",
"context",
")",
"(",
"class",
"<<",
"context",
";",
"self",
";",
"end",
")",
".",
"class_eval",
"do",
"alias_method",
":transactionless_local_run",
",",
":local_run",
"def",
"local_run",
"(",
"*",
"args",
")",
"::",
"ActiveRecor... | Don't you just love mr. metaclass? | [
"Don",
"t",
"you",
"just",
"love",
"mr",
".",
"metaclass?"
] | 8bb2555d04f7fb67407f7224536e8b32349cede1 | https://github.com/thumblemonks/riot-rails/blob/8bb2555d04f7fb67407f7224536e8b32349cede1/lib/riot/active_record/transactional_middleware.rb#L15-L25 |
7,877 | medcat/packed_struct | lib/packed_struct/directive.rb | PackedStruct.Directive.[] | def [](new_size)
if new_size.is_a? Directive
tags.merge! new_size.tags_for_sized_directive
else
tags[:size] = new_size
end
self
end | ruby | def [](new_size)
if new_size.is_a? Directive
tags.merge! new_size.tags_for_sized_directive
else
tags[:size] = new_size
end
self
end | [
"def",
"[]",
"(",
"new_size",
")",
"if",
"new_size",
".",
"is_a?",
"Directive",
"tags",
".",
"merge!",
"new_size",
".",
"tags_for_sized_directive",
"else",
"tags",
"[",
":size",
"]",
"=",
"new_size",
"end",
"self",
"end"
] | Changes the size of the directive to the given size. It is
possible for the given value to the a directive; if it is,
it just uses the name of the directive.
@param new_size [Numeric, Directive]
@return [self] | [
"Changes",
"the",
"size",
"of",
"the",
"directive",
"to",
"the",
"given",
"size",
".",
"It",
"is",
"possible",
"for",
"the",
"given",
"value",
"to",
"the",
"a",
"directive",
";",
"if",
"it",
"is",
"it",
"just",
"uses",
"the",
"name",
"of",
"the",
"di... | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/directive.rb#L69-L77 |
7,878 | medcat/packed_struct | lib/packed_struct/directive.rb | PackedStruct.Directive.finalize! | def finalize!
return if finalized?
modifiers.each do |modifier|
modifier.type.each_with_index do |type, i|
case type
when :endian, :signedness, :precision, :type, :string_type
tags[type] = modifier.value[i]
when :size
tags[:size] = modifier.valu... | ruby | def finalize!
return if finalized?
modifiers.each do |modifier|
modifier.type.each_with_index do |type, i|
case type
when :endian, :signedness, :precision, :type, :string_type
tags[type] = modifier.value[i]
when :size
tags[:size] = modifier.valu... | [
"def",
"finalize!",
"return",
"if",
"finalized?",
"modifiers",
".",
"each",
"do",
"|",
"modifier",
"|",
"modifier",
".",
"type",
".",
"each_with_index",
"do",
"|",
"type",
",",
"i",
"|",
"case",
"type",
"when",
":endian",
",",
":signedness",
",",
":precisi... | Finalizes the directive.
@return [void] | [
"Finalizes",
"the",
"directive",
"."
] | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/directive.rb#L144-L163 |
7,879 | medcat/packed_struct | lib/packed_struct/directive.rb | PackedStruct.Directive.bytesize | def bytesize(data = {})
case tags[:type]
when nil
(size(data) || 8) / 8
when :short, :int, :long
BYTES_IN_STRING.fetch tags[:type]
when :float
if tags[:precision] == :double
BYTES_IN_STRING[:float_double]
else
BYTES_IN_STRING[:float_single]
... | ruby | def bytesize(data = {})
case tags[:type]
when nil
(size(data) || 8) / 8
when :short, :int, :long
BYTES_IN_STRING.fetch tags[:type]
when :float
if tags[:precision] == :double
BYTES_IN_STRING[:float_double]
else
BYTES_IN_STRING[:float_single]
... | [
"def",
"bytesize",
"(",
"data",
"=",
"{",
"}",
")",
"case",
"tags",
"[",
":type",
"]",
"when",
"nil",
"(",
"size",
"(",
"data",
")",
"||",
"8",
")",
"/",
"8",
"when",
":short",
",",
":int",
",",
":long",
"BYTES_IN_STRING",
".",
"fetch",
"tags",
"... | The number of bytes this takes up in the resulting packed string.
@param (see #to_s)
@return [Numeric] | [
"The",
"number",
"of",
"bytes",
"this",
"takes",
"up",
"in",
"the",
"resulting",
"packed",
"string",
"."
] | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/directive.rb#L223-L242 |
7,880 | medcat/packed_struct | lib/packed_struct/directive.rb | PackedStruct.Directive.modify_if_needed | def modify_if_needed(str, include_endian = true)
base = if @tags[:signedness] == :signed
str.swapcase
else
str
end
if include_endian
modify_for_endianness(base)
else
base
end
end | ruby | def modify_if_needed(str, include_endian = true)
base = if @tags[:signedness] == :signed
str.swapcase
else
str
end
if include_endian
modify_for_endianness(base)
else
base
end
end | [
"def",
"modify_if_needed",
"(",
"str",
",",
"include_endian",
"=",
"true",
")",
"base",
"=",
"if",
"@tags",
"[",
":signedness",
"]",
"==",
":signed",
"str",
".",
"swapcase",
"else",
"str",
"end",
"if",
"include_endian",
"modify_for_endianness",
"(",
"base",
... | Modifies the given string if it's needed, according to
signness and endianness. This assumes that a signed
directive should be in lowercase.
@param str [String] the string to modify.
@param include_endian [Boolean] whether or not to include the
endianness.
@return [String] | [
"Modifies",
"the",
"given",
"string",
"if",
"it",
"s",
"needed",
"according",
"to",
"signness",
"and",
"endianness",
".",
"This",
"assumes",
"that",
"a",
"signed",
"directive",
"should",
"be",
"in",
"lowercase",
"."
] | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/directive.rb#L339-L350 |
7,881 | medcat/packed_struct | lib/packed_struct/directive.rb | PackedStruct.Directive.modify_for_endianness | def modify_for_endianness(str, use_case = false)
case [tags[:endian], use_case]
when [:little, true]
str.swapcase
when [:little, false]
str + "<"
when [:big, true]
str
when [:big, false]
str + ">"
else
str
end
end | ruby | def modify_for_endianness(str, use_case = false)
case [tags[:endian], use_case]
when [:little, true]
str.swapcase
when [:little, false]
str + "<"
when [:big, true]
str
when [:big, false]
str + ">"
else
str
end
end | [
"def",
"modify_for_endianness",
"(",
"str",
",",
"use_case",
"=",
"false",
")",
"case",
"[",
"tags",
"[",
":endian",
"]",
",",
"use_case",
"]",
"when",
"[",
":little",
",",
"true",
"]",
"str",
".",
"swapcase",
"when",
"[",
":little",
",",
"false",
"]",... | Modifies the given string to account for endianness. If
+use_case+ is true, it modifies the case of the given string to
represent endianness; otherwise, it appends data to the string
to represent endianness.
@param str [String] the string to modify.
@param use_case [Boolean]
@return [String] | [
"Modifies",
"the",
"given",
"string",
"to",
"account",
"for",
"endianness",
".",
"If",
"+",
"use_case",
"+",
"is",
"true",
"it",
"modifies",
"the",
"case",
"of",
"the",
"given",
"string",
"to",
"represent",
"endianness",
";",
"otherwise",
"it",
"appends",
... | 4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f | https://github.com/medcat/packed_struct/blob/4c32c17acbfbe8c1a1a27daafb04d2f6bee0347f/lib/packed_struct/directive.rb#L360-L373 |
7,882 | bdurand/acts_as_trashable | lib/acts_as_trashable/trash_record.rb | ActsAsTrashable.TrashRecord.restore | def restore
restore_class = self.trashable_type.constantize
sti_type = self.trashable_attributes[restore_class.inheritance_column]
if sti_type
begin
if !restore_class.store_full_sti_class && !sti_type.start_with?("::")
sti_type = "#{restore_class.parent.name}::#{sti_... | ruby | def restore
restore_class = self.trashable_type.constantize
sti_type = self.trashable_attributes[restore_class.inheritance_column]
if sti_type
begin
if !restore_class.store_full_sti_class && !sti_type.start_with?("::")
sti_type = "#{restore_class.parent.name}::#{sti_... | [
"def",
"restore",
"restore_class",
"=",
"self",
".",
"trashable_type",
".",
"constantize",
"sti_type",
"=",
"self",
".",
"trashable_attributes",
"[",
"restore_class",
".",
"inheritance_column",
"]",
"if",
"sti_type",
"begin",
"if",
"!",
"restore_class",
".",
"stor... | Create a new trash record for the provided record.
Restore a trashed record into an object. The record will not be saved. | [
"Create",
"a",
"new",
"trash",
"record",
"for",
"the",
"provided",
"record",
".",
"Restore",
"a",
"trashed",
"record",
"into",
"an",
"object",
".",
"The",
"record",
"will",
"not",
"be",
"saved",
"."
] | 8bb0e40d6b30dda9c5175a0deb28da1b067fff03 | https://github.com/bdurand/acts_as_trashable/blob/8bb0e40d6b30dda9c5175a0deb28da1b067fff03/lib/acts_as_trashable/trash_record.rb#L56-L84 |
7,883 | bdurand/acts_as_trashable | lib/acts_as_trashable/trash_record.rb | ActsAsTrashable.TrashRecord.trashable_attributes | def trashable_attributes
return nil unless self.data
uncompressed = Zlib::Inflate.inflate(self.data) rescue uncompressed = self.data # backward compatibility with uncompressed data
Marshal.load(uncompressed)
end | ruby | def trashable_attributes
return nil unless self.data
uncompressed = Zlib::Inflate.inflate(self.data) rescue uncompressed = self.data # backward compatibility with uncompressed data
Marshal.load(uncompressed)
end | [
"def",
"trashable_attributes",
"return",
"nil",
"unless",
"self",
".",
"data",
"uncompressed",
"=",
"Zlib",
"::",
"Inflate",
".",
"inflate",
"(",
"self",
".",
"data",
")",
"rescue",
"uncompressed",
"=",
"self",
".",
"data",
"# backward compatibility with uncompres... | Attributes of the trashed record as a hash. | [
"Attributes",
"of",
"the",
"trashed",
"record",
"as",
"a",
"hash",
"."
] | 8bb0e40d6b30dda9c5175a0deb28da1b067fff03 | https://github.com/bdurand/acts_as_trashable/blob/8bb0e40d6b30dda9c5175a0deb28da1b067fff03/lib/acts_as_trashable/trash_record.rb#L95-L99 |
7,884 | emancu/ork | lib/ork/model/document.rb | Ork.Document.save | def save
__robject.content_type = model.content_type
__robject.data = __persist_attributes
__check_unique_indices
__update_indices
__robject.store
@id = __robject.key
self
end | ruby | def save
__robject.content_type = model.content_type
__robject.data = __persist_attributes
__check_unique_indices
__update_indices
__robject.store
@id = __robject.key
self
end | [
"def",
"save",
"__robject",
".",
"content_type",
"=",
"model",
".",
"content_type",
"__robject",
".",
"data",
"=",
"__persist_attributes",
"__check_unique_indices",
"__update_indices",
"__robject",
".",
"store",
"@id",
"=",
"__robject",
".",
"key",
"self",
"end"
] | Persist the model attributes and update indices and unique
indices.
Example:
class User
include Ork::Document
attribute :name
end
u = User.new(:name => "John").save
# => #<User:6kS5VHNbaed9h7gFLnVg5lmO4U7 {:name=>"John"}> | [
"Persist",
"the",
"model",
"attributes",
"and",
"update",
"indices",
"and",
"unique",
"indices",
"."
] | 83b2deaef0e790d90f98c031f254b5f438b19edf | https://github.com/emancu/ork/blob/83b2deaef0e790d90f98c031f254b5f438b19edf/lib/ork/model/document.rb#L72-L83 |
7,885 | emancu/ork | lib/ork/model/document.rb | Ork.Document.load! | def load!(id)
self.__robject.key = id
__load_robject! id, @__robject.reload(force: true)
end | ruby | def load!(id)
self.__robject.key = id
__load_robject! id, @__robject.reload(force: true)
end | [
"def",
"load!",
"(",
"id",
")",
"self",
".",
"__robject",
".",
"key",
"=",
"id",
"__load_robject!",
"id",
",",
"@__robject",
".",
"reload",
"(",
"force",
":",
"true",
")",
"end"
] | Overwrite attributes with the persisted attributes in Riak. | [
"Overwrite",
"attributes",
"with",
"the",
"persisted",
"attributes",
"in",
"Riak",
"."
] | 83b2deaef0e790d90f98c031f254b5f438b19edf | https://github.com/emancu/ork/blob/83b2deaef0e790d90f98c031f254b5f438b19edf/lib/ork/model/document.rb#L102-L105 |
7,886 | emancu/ork | lib/ork/model/document.rb | Ork.Document.__update_indices | def __update_indices
model.indices.values.each do |index|
__robject.indexes[index.riak_name] = index.value_from(attributes)
end
end | ruby | def __update_indices
model.indices.values.each do |index|
__robject.indexes[index.riak_name] = index.value_from(attributes)
end
end | [
"def",
"__update_indices",
"model",
".",
"indices",
".",
"values",
".",
"each",
"do",
"|",
"index",
"|",
"__robject",
".",
"indexes",
"[",
"index",
".",
"riak_name",
"]",
"=",
"index",
".",
"value_from",
"(",
"attributes",
")",
"end",
"end"
] | Build the secondary indices of this object | [
"Build",
"the",
"secondary",
"indices",
"of",
"this",
"object"
] | 83b2deaef0e790d90f98c031f254b5f438b19edf | https://github.com/emancu/ork/blob/83b2deaef0e790d90f98c031f254b5f438b19edf/lib/ork/model/document.rb#L132-L136 |
7,887 | emancu/ork | lib/ork/model/document.rb | Ork.Document.__check_unique_indices | def __check_unique_indices
model.uniques.each do |uniq|
if value = attributes[uniq]
index = model.indices[uniq]
records = model.bucket.get_index(index.riak_name, value)
unless records.empty? || records == [self.id]
raise Ork::UniqueIndexViolation, "#{uniq} is not ... | ruby | def __check_unique_indices
model.uniques.each do |uniq|
if value = attributes[uniq]
index = model.indices[uniq]
records = model.bucket.get_index(index.riak_name, value)
unless records.empty? || records == [self.id]
raise Ork::UniqueIndexViolation, "#{uniq} is not ... | [
"def",
"__check_unique_indices",
"model",
".",
"uniques",
".",
"each",
"do",
"|",
"uniq",
"|",
"if",
"value",
"=",
"attributes",
"[",
"uniq",
"]",
"index",
"=",
"model",
".",
"indices",
"[",
"uniq",
"]",
"records",
"=",
"model",
".",
"bucket",
".",
"ge... | Look up into Riak for repeated values on unique attributes | [
"Look",
"up",
"into",
"Riak",
"for",
"repeated",
"values",
"on",
"unique",
"attributes"
] | 83b2deaef0e790d90f98c031f254b5f438b19edf | https://github.com/emancu/ork/blob/83b2deaef0e790d90f98c031f254b5f438b19edf/lib/ork/model/document.rb#L139-L149 |
7,888 | roja/words | lib/wordnet_connectors/tokyo_wordnet_connection.rb | Words.TokyoWordnetConnection.open! | def open!
unless connected?
if @data_path.exist?
@connection = Rufus::Tokyo::Table.new(@data_path.to_s, :mode => 'r')
@connected = true
else
@connected = false
raise BadWordnetDataset, "Failed to locate the tokyo words dataset at #{@data_path}. Please insure you have created it using t... | ruby | def open!
unless connected?
if @data_path.exist?
@connection = Rufus::Tokyo::Table.new(@data_path.to_s, :mode => 'r')
@connected = true
else
@connected = false
raise BadWordnetDataset, "Failed to locate the tokyo words dataset at #{@data_path}. Please insure you have created it using t... | [
"def",
"open!",
"unless",
"connected?",
"if",
"@data_path",
".",
"exist?",
"@connection",
"=",
"Rufus",
"::",
"Tokyo",
"::",
"Table",
".",
"new",
"(",
"@data_path",
".",
"to_s",
",",
":mode",
"=>",
"'r'",
")",
"@connected",
"=",
"true",
"else",
"@connected... | Constructs a new tokyo ruby connector for use with the words wordnet class.
@param [Pathname] data_path Specifies the directory within which constructed datasets can be found (tokyo index, evocations etc...)
@param [Pathname] wordnet_path Specifies the directory within which the wordnet dictionary can be found.
@re... | [
"Constructs",
"a",
"new",
"tokyo",
"ruby",
"connector",
"for",
"use",
"with",
"the",
"words",
"wordnet",
"class",
"."
] | 4d6302e7218533fcc2afb4cd993686dd56fe2cde | https://github.com/roja/words/blob/4d6302e7218533fcc2afb4cd993686dd56fe2cde/lib/wordnet_connectors/tokyo_wordnet_connection.rb#L57-L70 |
7,889 | locks/halibut | lib/halibut/core/resource.rb | Halibut::Core.Resource.set_property | def set_property(property, value)
if property == '_links' || property == '_embedded'
raise ArgumentError, "Argument #{property} is a reserved property"
end
tap { @properties[property] = value }
end | ruby | def set_property(property, value)
if property == '_links' || property == '_embedded'
raise ArgumentError, "Argument #{property} is a reserved property"
end
tap { @properties[property] = value }
end | [
"def",
"set_property",
"(",
"property",
",",
"value",
")",
"if",
"property",
"==",
"'_links'",
"||",
"property",
"==",
"'_embedded'",
"raise",
"ArgumentError",
",",
"\"Argument #{property} is a reserved property\"",
"end",
"tap",
"{",
"@properties",
"[",
"property",
... | Sets a property in the resource.
@example
resource = Halibut::Core::Resource.new
resource.set_property :name, 'FooBar'
resource.property :name
# => "FooBar"
@param [Object] property the key
@param [Object] value the value | [
"Sets",
"a",
"property",
"in",
"the",
"resource",
"."
] | b8da6aa0796c9db317b9cd3d377915499a52383c | https://github.com/locks/halibut/blob/b8da6aa0796c9db317b9cd3d377915499a52383c/lib/halibut/core/resource.rb#L84-L90 |
7,890 | locks/halibut | lib/halibut/core/resource.rb | Halibut::Core.Resource.add_link | def add_link(relation, href, opts={})
@links.add relation, Link.new(href, opts)
end | ruby | def add_link(relation, href, opts={})
@links.add relation, Link.new(href, opts)
end | [
"def",
"add_link",
"(",
"relation",
",",
"href",
",",
"opts",
"=",
"{",
"}",
")",
"@links",
".",
"add",
"relation",
",",
"Link",
".",
"new",
"(",
"href",
",",
"opts",
")",
"end"
] | Adds link to relation.
@example
resource = Halibut::Core::Resource.new
resource.add_link 'next', '/resource/2', name: 'Foo'
link = resource.links['next'].first
link.href
# => "/resource/2"
link.name
# => "Foo"
@param [String] relation relation
@param [String] href ... | [
"Adds",
"link",
"to",
"relation",
"."
] | b8da6aa0796c9db317b9cd3d377915499a52383c | https://github.com/locks/halibut/blob/b8da6aa0796c9db317b9cd3d377915499a52383c/lib/halibut/core/resource.rb#L132-L134 |
7,891 | locks/halibut | lib/halibut/core/resource.rb | Halibut::Core.Resource.to_hash | def to_hash
{}.merge(@properties).tap do |h|
h['_links'] = {}.merge @links unless @links.empty?
combined_embedded = {}
combined_embedded.merge! @embedded unless @embedded.empty?
combined_embedded.merge! @embedded_arrays unless @embedded_arrays.empty?
h['_embedded'] = co... | ruby | def to_hash
{}.merge(@properties).tap do |h|
h['_links'] = {}.merge @links unless @links.empty?
combined_embedded = {}
combined_embedded.merge! @embedded unless @embedded.empty?
combined_embedded.merge! @embedded_arrays unless @embedded_arrays.empty?
h['_embedded'] = co... | [
"def",
"to_hash",
"{",
"}",
".",
"merge",
"(",
"@properties",
")",
".",
"tap",
"do",
"|",
"h",
"|",
"h",
"[",
"'_links'",
"]",
"=",
"{",
"}",
".",
"merge",
"@links",
"unless",
"@links",
".",
"empty?",
"combined_embedded",
"=",
"{",
"}",
"combined_emb... | Hash representation of the resource.
Will ommit links and embedded keys if they're empty
@return [Hash] hash representation of the resource | [
"Hash",
"representation",
"of",
"the",
"resource",
".",
"Will",
"ommit",
"links",
"and",
"embedded",
"keys",
"if",
"they",
"re",
"empty"
] | b8da6aa0796c9db317b9cd3d377915499a52383c | https://github.com/locks/halibut/blob/b8da6aa0796c9db317b9cd3d377915499a52383c/lib/halibut/core/resource.rb#L161-L170 |
7,892 | ombulabs/bitpagos | lib/bitpagos/client.rb | Bitpagos.Client.get_transaction_type_from_symbol | def get_transaction_type_from_symbol(transaction_type)
begin
target_type = transaction_type.to_s.upcase
return if target_type.empty?
self.class.const_get(target_type)
rescue NameError => error
raise Bitpagos::Errors::InvalidTransactionType.new(error.message)
end
end | ruby | def get_transaction_type_from_symbol(transaction_type)
begin
target_type = transaction_type.to_s.upcase
return if target_type.empty?
self.class.const_get(target_type)
rescue NameError => error
raise Bitpagos::Errors::InvalidTransactionType.new(error.message)
end
end | [
"def",
"get_transaction_type_from_symbol",
"(",
"transaction_type",
")",
"begin",
"target_type",
"=",
"transaction_type",
".",
"to_s",
".",
"upcase",
"return",
"if",
"target_type",
".",
"empty?",
"self",
".",
"class",
".",
"const_get",
"(",
"target_type",
")",
"re... | Takes a symbol and returns the proper transaction type.
@param [Symbol] Can be :pending, :waiting, :completed or :partially_paid
@return [String,nil] Returns the corresponding "PE", "WA", "CO" or "PP" | [
"Takes",
"a",
"symbol",
"and",
"returns",
"the",
"proper",
"transaction",
"type",
"."
] | 007fca57437f1e3fc3eff72f3d84f56f49cf64fc | https://github.com/ombulabs/bitpagos/blob/007fca57437f1e3fc3eff72f3d84f56f49cf64fc/lib/bitpagos/client.rb#L69-L77 |
7,893 | ombulabs/bitpagos | lib/bitpagos/client.rb | Bitpagos.Client.retrieve_transactions | def retrieve_transactions(query = nil, transaction_id = nil)
headers.merge!(params: query) if query
url = "#{API_BASE}/transaction/#{transaction_id}"
begin
response = RestClient.get(url, headers)
JSON.parse(response)
rescue RestClient::Unauthorized => error
raise Bitpagos... | ruby | def retrieve_transactions(query = nil, transaction_id = nil)
headers.merge!(params: query) if query
url = "#{API_BASE}/transaction/#{transaction_id}"
begin
response = RestClient.get(url, headers)
JSON.parse(response)
rescue RestClient::Unauthorized => error
raise Bitpagos... | [
"def",
"retrieve_transactions",
"(",
"query",
"=",
"nil",
",",
"transaction_id",
"=",
"nil",
")",
"headers",
".",
"merge!",
"(",
"params",
":",
"query",
")",
"if",
"query",
"url",
"=",
"\"#{API_BASE}/transaction/#{transaction_id}\"",
"begin",
"response",
"=",
"R... | Hits the Bitpagos transaction API, returns a hash with results
@param [String] State (Pending, Waiting, Completed, Partially Paid)
@param [String] Transaction ID
@return [Hash] | [
"Hits",
"the",
"Bitpagos",
"transaction",
"API",
"returns",
"a",
"hash",
"with",
"results"
] | 007fca57437f1e3fc3eff72f3d84f56f49cf64fc | https://github.com/ombulabs/bitpagos/blob/007fca57437f1e3fc3eff72f3d84f56f49cf64fc/lib/bitpagos/client.rb#L84-L93 |
7,894 | nwops/retrospec | lib/retrospec/plugins.rb | Retrospec.Plugins.discover_plugin | def discover_plugin(module_path)
plugin = plugin_classes.find {|c| c.send(:valid_module_dir?, module_path) }
raise NoSuitablePluginFoundException unless plugin
plugin
end | ruby | def discover_plugin(module_path)
plugin = plugin_classes.find {|c| c.send(:valid_module_dir?, module_path) }
raise NoSuitablePluginFoundException unless plugin
plugin
end | [
"def",
"discover_plugin",
"(",
"module_path",
")",
"plugin",
"=",
"plugin_classes",
".",
"find",
"{",
"|",
"c",
"|",
"c",
".",
"send",
"(",
":valid_module_dir?",
",",
"module_path",
")",
"}",
"raise",
"NoSuitablePluginFoundException",
"unless",
"plugin",
"plugin... | returns the first plugin class that supports this module directory
not sure what to do when we find multiple plugins
would need additional criteria | [
"returns",
"the",
"first",
"plugin",
"class",
"that",
"supports",
"this",
"module",
"directory",
"not",
"sure",
"what",
"to",
"do",
"when",
"we",
"find",
"multiple",
"plugins",
"would",
"need",
"additional",
"criteria"
] | e61a8e8b86384c64a3ce9340d1342fa416740522 | https://github.com/nwops/retrospec/blob/e61a8e8b86384c64a3ce9340d1342fa416740522/lib/retrospec/plugins.rb#L38-L42 |
7,895 | wilson/revenant | lib/revenant/task.rb | Revenant.Task.run | def run(&block)
unless @work = block
raise ArgumentError, "Usage: run { while_we_have_the_lock }"
end
@shutdown = false
@restart = false
install_plugins
startup # typically daemonizes the process, can have various implementations
on_load.call(self) if on_load
run_... | ruby | def run(&block)
unless @work = block
raise ArgumentError, "Usage: run { while_we_have_the_lock }"
end
@shutdown = false
@restart = false
install_plugins
startup # typically daemonizes the process, can have various implementations
on_load.call(self) if on_load
run_... | [
"def",
"run",
"(",
"&",
"block",
")",
"unless",
"@work",
"=",
"block",
"raise",
"ArgumentError",
",",
"\"Usage: run { while_we_have_the_lock }\"",
"end",
"@shutdown",
"=",
"false",
"@restart",
"=",
"false",
"install_plugins",
"startup",
"# typically daemonizes the proce... | Takes actual block of code that is to be guarded by
the lock. The +run_loop+ method does the actual work.
If 'daemon?' is true, your code (including +on_load+)
will execute after a fork.
Make sure you don't open files and sockets in the exiting
parent process by mistake. Open them in code that is called
via +on... | [
"Takes",
"actual",
"block",
"of",
"code",
"that",
"is",
"to",
"be",
"guarded",
"by",
"the",
"lock",
".",
"The",
"+",
"run_loop",
"+",
"method",
"does",
"the",
"actual",
"work",
"."
] | 80fe65742de54ce0c5a8e6c56cea7003fe286746 | https://github.com/wilson/revenant/blob/80fe65742de54ce0c5a8e6c56cea7003fe286746/lib/revenant/task.rb#L48-L60 |
7,896 | cloudspace/ruby-fleetctl | lib/fleet/cluster.rb | Fleet.Cluster.build_from | def build_from(*ip_addrs)
ip_addrs = [*ip_addrs].flatten.compact
begin
Fleetctl.logger.info 'building from hosts: ' + ip_addrs.inspect
built_from = ip_addrs.detect { |ip_addr| fetch_machines(ip_addr) }
Fleetctl.logger.info 'built successfully from host: ' + built_from.inspect if buil... | ruby | def build_from(*ip_addrs)
ip_addrs = [*ip_addrs].flatten.compact
begin
Fleetctl.logger.info 'building from hosts: ' + ip_addrs.inspect
built_from = ip_addrs.detect { |ip_addr| fetch_machines(ip_addr) }
Fleetctl.logger.info 'built successfully from host: ' + built_from.inspect if buil... | [
"def",
"build_from",
"(",
"*",
"ip_addrs",
")",
"ip_addrs",
"=",
"[",
"ip_addrs",
"]",
".",
"flatten",
".",
"compact",
"begin",
"Fleetctl",
".",
"logger",
".",
"info",
"'building from hosts: '",
"+",
"ip_addrs",
".",
"inspect",
"built_from",
"=",
"ip_addrs",
... | attempts to rebuild the cluster from any of the hosts passed as arguments
returns the first ip that worked, else nil | [
"attempts",
"to",
"rebuild",
"the",
"cluster",
"from",
"any",
"of",
"the",
"hosts",
"passed",
"as",
"arguments",
"returns",
"the",
"first",
"ip",
"that",
"worked",
"else",
"nil"
] | 23c9a71f733d43275fbfaf35c568d4b284f715ab | https://github.com/cloudspace/ruby-fleetctl/blob/23c9a71f733d43275fbfaf35c568d4b284f715ab/lib/fleet/cluster.rb#L25-L38 |
7,897 | cloudspace/ruby-fleetctl | lib/fleet/cluster.rb | Fleet.Cluster.fetch_machines | def fetch_machines(host)
Fleetctl.logger.info 'Fetching machines from host: '+host.inspect
clear
Fleetctl::Command.new('list-machines', '-l') do |runner|
runner.run(host: host)
new_machines = parse_machines(runner.output)
if runner.exit_code == 0
return true
e... | ruby | def fetch_machines(host)
Fleetctl.logger.info 'Fetching machines from host: '+host.inspect
clear
Fleetctl::Command.new('list-machines', '-l') do |runner|
runner.run(host: host)
new_machines = parse_machines(runner.output)
if runner.exit_code == 0
return true
e... | [
"def",
"fetch_machines",
"(",
"host",
")",
"Fleetctl",
".",
"logger",
".",
"info",
"'Fetching machines from host: '",
"+",
"host",
".",
"inspect",
"clear",
"Fleetctl",
"::",
"Command",
".",
"new",
"(",
"'list-machines'",
",",
"'-l'",
")",
"do",
"|",
"runner",
... | attempts a list-machines action on the given host.
returns true if successful, else false | [
"attempts",
"a",
"list",
"-",
"machines",
"action",
"on",
"the",
"given",
"host",
".",
"returns",
"true",
"if",
"successful",
"else",
"false"
] | 23c9a71f733d43275fbfaf35c568d4b284f715ab | https://github.com/cloudspace/ruby-fleetctl/blob/23c9a71f733d43275fbfaf35c568d4b284f715ab/lib/fleet/cluster.rb#L42-L54 |
7,898 | cloudspace/ruby-fleetctl | lib/fleet/cluster.rb | Fleet.Cluster.discover! | def discover!
known_hosts = [Fleetctl.options.fleet_host] | fleet_hosts.to_a
clear
success_host = build_from(known_hosts) || build_from(Fleet::Discovery.hosts)
if success_host
Fleetctl.logger.info 'Successfully recovered from host: ' + success_host.inspect
else
Fleetctl.log... | ruby | def discover!
known_hosts = [Fleetctl.options.fleet_host] | fleet_hosts.to_a
clear
success_host = build_from(known_hosts) || build_from(Fleet::Discovery.hosts)
if success_host
Fleetctl.logger.info 'Successfully recovered from host: ' + success_host.inspect
else
Fleetctl.log... | [
"def",
"discover!",
"known_hosts",
"=",
"[",
"Fleetctl",
".",
"options",
".",
"fleet_host",
"]",
"|",
"fleet_hosts",
".",
"to_a",
"clear",
"success_host",
"=",
"build_from",
"(",
"known_hosts",
")",
"||",
"build_from",
"(",
"Fleet",
"::",
"Discovery",
".",
"... | attempts to rebuild the cluster by the specified fleet host, then hosts that it
has built previously, and finally by using the discovery url | [
"attempts",
"to",
"rebuild",
"the",
"cluster",
"by",
"the",
"specified",
"fleet",
"host",
"then",
"hosts",
"that",
"it",
"has",
"built",
"previously",
"and",
"finally",
"by",
"using",
"the",
"discovery",
"url"
] | 23c9a71f733d43275fbfaf35c568d4b284f715ab | https://github.com/cloudspace/ruby-fleetctl/blob/23c9a71f733d43275fbfaf35c568d4b284f715ab/lib/fleet/cluster.rb#L67-L76 |
7,899 | jarhart/rattler | lib/rattler/parsers/token.rb | Rattler::Parsers.Token.parse | def parse(scanner, rules, scope = ParserScope.empty)
p = scanner.pos
child.parse(scanner, rules, scope) && scanner.string[p...(scanner.pos)]
end | ruby | def parse(scanner, rules, scope = ParserScope.empty)
p = scanner.pos
child.parse(scanner, rules, scope) && scanner.string[p...(scanner.pos)]
end | [
"def",
"parse",
"(",
"scanner",
",",
"rules",
",",
"scope",
"=",
"ParserScope",
".",
"empty",
")",
"p",
"=",
"scanner",
".",
"pos",
"child",
".",
"parse",
"(",
"scanner",
",",
"rules",
",",
"scope",
")",
"&&",
"scanner",
".",
"string",
"[",
"p",
".... | If the decorated parser matches return the entire matched string,
otherwise return a false value.
@param (see Match#parse)
@return (see Match#parse) | [
"If",
"the",
"decorated",
"parser",
"matches",
"return",
"the",
"entire",
"matched",
"string",
"otherwise",
"return",
"a",
"false",
"value",
"."
] | 8b4efde2a05e9e790955bb635d4a1a9615893719 | https://github.com/jarhart/rattler/blob/8b4efde2a05e9e790955bb635d4a1a9615893719/lib/rattler/parsers/token.rb#L15-L18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.