repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
rightscale/right_chimp | lib/right_chimp/resources/server.rb | Chimp.Server.run_executable | def run_executable(exec, options)
script_href = "right_script_href="+exec.href
# Construct the parameters to pass for the inputs
params=options.collect { |k, v|
"&inputs[][name]=#{k}&inputs[][value]=#{v}" unless k == :ignore_lock
}.join('&')
if options[:ignore_lock]
para... | ruby | def run_executable(exec, options)
script_href = "right_script_href="+exec.href
# Construct the parameters to pass for the inputs
params=options.collect { |k, v|
"&inputs[][name]=#{k}&inputs[][value]=#{v}" unless k == :ignore_lock
}.join('&')
if options[:ignore_lock]
para... | [
"def",
"run_executable",
"(",
"exec",
",",
"options",
")",
"script_href",
"=",
"\"right_script_href=\"",
"+",
"exec",
".",
"href",
"params",
"=",
"options",
".",
"collect",
"{",
"|",
"k",
",",
"v",
"|",
"\"&inputs[][name]=#{k}&inputs[][value]=#{v}\"",
"unless",
... | In order to run the task, we need to call run_executable on ourselves | [
"In",
"order",
"to",
"run",
"the",
"task",
"we",
"need",
"to",
"call",
"run_executable",
"on",
"ourselves"
] | 290d3e01f7bf4b505722a080cb0abbb0314222f8 | https://github.com/rightscale/right_chimp/blob/290d3e01f7bf4b505722a080cb0abbb0314222f8/lib/right_chimp/resources/server.rb#L63-L77 | train |
rberger/phaserunner | lib/phaserunner/main.rb | Phaserunner.Cli.main | def main
program_desc 'Read values from the Grin PhaseRunner Controller primarily for logging'
version Phaserunner::VERSION
subcommand_option_handling :normal
arguments :strict
sort_help :manually
desc 'Serial (USB) device'
default_value '/dev/ttyUSB0'
arg 'tty'
... | ruby | def main
program_desc 'Read values from the Grin PhaseRunner Controller primarily for logging'
version Phaserunner::VERSION
subcommand_option_handling :normal
arguments :strict
sort_help :manually
desc 'Serial (USB) device'
default_value '/dev/ttyUSB0'
arg 'tty'
... | [
"def",
"main",
"program_desc",
"'Read values from the Grin PhaseRunner Controller primarily for logging'",
"version",
"Phaserunner",
"::",
"VERSION",
"subcommand_option_handling",
":normal",
"arguments",
":strict",
"sort_help",
":manually",
"desc",
"'Serial (USB) device'",
"default_v... | Does all the CLI work | [
"Does",
"all",
"the",
"CLI",
"work"
] | bc1d7c94381c1a3547f5badd581c2f40eefdd807 | https://github.com/rberger/phaserunner/blob/bc1d7c94381c1a3547f5badd581c2f40eefdd807/lib/phaserunner/main.rb#L22-L131 | train |
angelim/rails_redshift_replicator | lib/rails_redshift_replicator/deleter.rb | RailsRedshiftReplicator.Deleter.handle_delete_propagation | def handle_delete_propagation
if replicable.tracking_deleted && has_deleted_ids?
RailsRedshiftReplicator.logger.info propagation_message(:propagating_deletes)
delete_on_target ? purge_deleted : RailsRedshiftReplicator.logger.error(propagation_message(:delete_propagation_error))
end
end | ruby | def handle_delete_propagation
if replicable.tracking_deleted && has_deleted_ids?
RailsRedshiftReplicator.logger.info propagation_message(:propagating_deletes)
delete_on_target ? purge_deleted : RailsRedshiftReplicator.logger.error(propagation_message(:delete_propagation_error))
end
end | [
"def",
"handle_delete_propagation",
"if",
"replicable",
".",
"tracking_deleted",
"&&",
"has_deleted_ids?",
"RailsRedshiftReplicator",
".",
"logger",
".",
"info",
"propagation_message",
"(",
":propagating_deletes",
")",
"delete_on_target",
"?",
"purge_deleted",
":",
"RailsRe... | Deletes records flagged for deletion on target and then delete the queue from source | [
"Deletes",
"records",
"flagged",
"for",
"deletion",
"on",
"target",
"and",
"then",
"delete",
"the",
"queue",
"from",
"source"
] | 823f6da36f43a39f340a3ca7eb159df58a86766d | https://github.com/angelim/rails_redshift_replicator/blob/823f6da36f43a39f340a3ca7eb159df58a86766d/lib/rails_redshift_replicator/deleter.rb#L20-L25 | train |
rayyanqcri/rayyan-scrapers | lib/rayyan-scrapers/nih_fulltext_scraper.rb | RayyanScrapers.NihFulltextScraper.process_list_page | def process_list_page(page)
@logger.info("Processing list page with URL: #{page.uri}")
#page.save_as "html/result-list.html"
new_items_found = nil
items = page.links #[0..50] # TODO REMOVE [], getting sample only
items_len = items.length - 1
@total = @total + items_len
# pli... | ruby | def process_list_page(page)
@logger.info("Processing list page with URL: #{page.uri}")
#page.save_as "html/result-list.html"
new_items_found = nil
items = page.links #[0..50] # TODO REMOVE [], getting sample only
items_len = items.length - 1
@total = @total + items_len
# pli... | [
"def",
"process_list_page",
"(",
"page",
")",
"@logger",
".",
"info",
"(",
"\"Processing list page with URL: #{page.uri}\"",
")",
"new_items_found",
"=",
"nil",
"items",
"=",
"page",
".",
"links",
"items_len",
"=",
"items",
".",
"length",
"-",
"1",
"@total",
"="... | NOTUSED by islam | [
"NOTUSED",
"by",
"islam"
] | 63d8b02987790ca08c06121775f95c49ed52c1b4 | https://github.com/rayyanqcri/rayyan-scrapers/blob/63d8b02987790ca08c06121775f95c49ed52c1b4/lib/rayyan-scrapers/nih_fulltext_scraper.rb#L54-L94 | train |
emn178/sms_carrier | lib/sms_carrier/log_subscriber.rb | SmsCarrier.LogSubscriber.deliver | def deliver(event)
info do
recipients = Array(event.payload[:to]).join(', ')
"\nSent SMS to #{recipients} (#{event.duration.round(1)}ms)"
end
debug { event.payload[:sms] }
end | ruby | def deliver(event)
info do
recipients = Array(event.payload[:to]).join(', ')
"\nSent SMS to #{recipients} (#{event.duration.round(1)}ms)"
end
debug { event.payload[:sms] }
end | [
"def",
"deliver",
"(",
"event",
")",
"info",
"do",
"recipients",
"=",
"Array",
"(",
"event",
".",
"payload",
"[",
":to",
"]",
")",
".",
"join",
"(",
"', '",
")",
"\"\\nSent SMS to #{recipients} (#{event.duration.round(1)}ms)\"",
"end",
"debug",
"{",
"event",
"... | An SMS was delivered. | [
"An",
"SMS",
"was",
"delivered",
"."
] | 6aa97b46d8fa6e92db67a8cf5c81076d5ae1f9ad | https://github.com/emn178/sms_carrier/blob/6aa97b46d8fa6e92db67a8cf5c81076d5ae1f9ad/lib/sms_carrier/log_subscriber.rb#L8-L15 | train |
activenetwork/actv | lib/actv/base.rb | ACTV.Base.to_hash | def to_hash
hash = {}
hash["attrs"] = @attrs
self.instance_variables.keep_if { |key| key != :@attrs }.each do |var|
val = self.instance_variable_get(var)
hash["attrs"][var.to_s.delete("@").to_sym] = val.to_hash if val.is_a? ACTV::Base
end
hash["attrs"]
end | ruby | def to_hash
hash = {}
hash["attrs"] = @attrs
self.instance_variables.keep_if { |key| key != :@attrs }.each do |var|
val = self.instance_variable_get(var)
hash["attrs"][var.to_s.delete("@").to_sym] = val.to_hash if val.is_a? ACTV::Base
end
hash["attrs"]
end | [
"def",
"to_hash",
"hash",
"=",
"{",
"}",
"hash",
"[",
"\"attrs\"",
"]",
"=",
"@attrs",
"self",
".",
"instance_variables",
".",
"keep_if",
"{",
"|",
"key",
"|",
"key",
"!=",
":@attrs",
"}",
".",
"each",
"do",
"|",
"var",
"|",
"val",
"=",
"self",
"."... | Creation of object hash when sending request to soap | [
"Creation",
"of",
"object",
"hash",
"when",
"sending",
"request",
"to",
"soap"
] | 861222f5eccf81628221c71af8b8681789171402 | https://github.com/activenetwork/actv/blob/861222f5eccf81628221c71af8b8681789171402/lib/actv/base.rb#L125-L135 | train |
praxis/attributor | lib/attributor/attribute_resolver.rb | Attributor.AttributeResolver.check | def check(path_prefix, key_path, predicate = nil)
value = query(key_path, path_prefix)
# we have a value, any value, which is good enough given no predicate
return true if !value.nil? && predicate.nil?
case predicate
when ::String, ::Regexp, ::Integer, ::Float, ::DateTime, true, false
... | ruby | def check(path_prefix, key_path, predicate = nil)
value = query(key_path, path_prefix)
# we have a value, any value, which is good enough given no predicate
return true if !value.nil? && predicate.nil?
case predicate
when ::String, ::Regexp, ::Integer, ::Float, ::DateTime, true, false
... | [
"def",
"check",
"(",
"path_prefix",
",",
"key_path",
",",
"predicate",
"=",
"nil",
")",
"value",
"=",
"query",
"(",
"key_path",
",",
"path_prefix",
")",
"return",
"true",
"if",
"!",
"value",
".",
"nil?",
"&&",
"predicate",
".",
"nil?",
"case",
"predicate... | Checks that the the condition is met. This means the attribute identified
by path_prefix and key_path satisfies the optional predicate, which when
nil simply checks for existence.
@param path_prefix [String]
@param key_path [String]
@param predicate [String|Regexp|Proc|NilClass]
@returns [Boolean] True if :requ... | [
"Checks",
"that",
"the",
"the",
"condition",
"is",
"met",
".",
"This",
"means",
"the",
"attribute",
"identified",
"by",
"path_prefix",
"and",
"key_path",
"satisfies",
"the",
"optional",
"predicate",
"which",
"when",
"nil",
"simply",
"checks",
"for",
"existence",... | faebaa0176086e1421cefc54a352d13a5b08d985 | https://github.com/praxis/attributor/blob/faebaa0176086e1421cefc54a352d13a5b08d985/lib/attributor/attribute_resolver.rb#L82-L99 | train |
praxis/attributor | lib/attributor/attribute.rb | Attributor.Attribute.describe | def describe(shallow = true, example: nil)
description = {}
# Clone the common options
TOP_LEVEL_OPTIONS.each do |option_name|
description[option_name] = options[option_name] if options.key? option_name
end
# Make sure this option definition is not mistaken for the real generated ... | ruby | def describe(shallow = true, example: nil)
description = {}
# Clone the common options
TOP_LEVEL_OPTIONS.each do |option_name|
description[option_name] = options[option_name] if options.key? option_name
end
# Make sure this option definition is not mistaken for the real generated ... | [
"def",
"describe",
"(",
"shallow",
"=",
"true",
",",
"example",
":",
"nil",
")",
"description",
"=",
"{",
"}",
"TOP_LEVEL_OPTIONS",
".",
"each",
"do",
"|",
"option_name",
"|",
"description",
"[",
"option_name",
"]",
"=",
"options",
"[",
"option_name",
"]",... | Options we don't want to expose when describing attributes | [
"Options",
"we",
"don",
"t",
"want",
"to",
"expose",
"when",
"describing",
"attributes"
] | faebaa0176086e1421cefc54a352d13a5b08d985 | https://github.com/praxis/attributor/blob/faebaa0176086e1421cefc54a352d13a5b08d985/lib/attributor/attribute.rb#L97-L126 | train |
praxis/attributor | lib/attributor/attribute.rb | Attributor.Attribute.validate | def validate(object, context = Attributor::DEFAULT_ROOT_CONTEXT)
raise "INVALID CONTEXT!! #{context}" unless context
# Validate any requirements, absolute or conditional, and return.
if object.nil? # == Attributor::UNSET
# With no value, we can only validate whether that is acceptable or not ... | ruby | def validate(object, context = Attributor::DEFAULT_ROOT_CONTEXT)
raise "INVALID CONTEXT!! #{context}" unless context
# Validate any requirements, absolute or conditional, and return.
if object.nil? # == Attributor::UNSET
# With no value, we can only validate whether that is acceptable or not ... | [
"def",
"validate",
"(",
"object",
",",
"context",
"=",
"Attributor",
"::",
"DEFAULT_ROOT_CONTEXT",
")",
"raise",
"\"INVALID CONTEXT!! #{context}\"",
"unless",
"context",
"if",
"object",
".",
"nil?",
"return",
"validate_missing_value",
"(",
"context",
")",
"end",
"er... | Validates stuff and checks dependencies | [
"Validates",
"stuff",
"and",
"checks",
"dependencies"
] | faebaa0176086e1421cefc54a352d13a5b08d985 | https://github.com/praxis/attributor/blob/faebaa0176086e1421cefc54a352d13a5b08d985/lib/attributor/attribute.rb#L180-L202 | train |
cldwalker/boson-more | lib/boson/pipes.rb | Boson.Pipes.sort_pipe | def sort_pipe(object, sort)
sort_lambda = lambda {}
if object[0].is_a?(Hash)
if sort.to_s[/^\d+$/]
sort = sort.to_i
elsif object[0].keys.all? {|e| e.is_a?(Symbol) }
sort = sort.to_sym
end
sort_lambda = untouched_sort?(object.map {|e| e[sort] }) ? lambda {|... | ruby | def sort_pipe(object, sort)
sort_lambda = lambda {}
if object[0].is_a?(Hash)
if sort.to_s[/^\d+$/]
sort = sort.to_i
elsif object[0].keys.all? {|e| e.is_a?(Symbol) }
sort = sort.to_sym
end
sort_lambda = untouched_sort?(object.map {|e| e[sort] }) ? lambda {|... | [
"def",
"sort_pipe",
"(",
"object",
",",
"sort",
")",
"sort_lambda",
"=",
"lambda",
"{",
"}",
"if",
"object",
"[",
"0",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"if",
"sort",
".",
"to_s",
"[",
"/",
"\\d",
"/",
"]",
"sort",
"=",
"sort",
".",
"to_i",
... | Sorts an array of objects or hashes using a sort field. Sort is reversed with reverse_sort set to true. | [
"Sorts",
"an",
"array",
"of",
"objects",
"or",
"hashes",
"using",
"a",
"sort",
"field",
".",
"Sort",
"is",
"reversed",
"with",
"reverse_sort",
"set",
"to",
"true",
"."
] | f928ebc18d8641e038891f78896ae7251b97415c | https://github.com/cldwalker/boson-more/blob/f928ebc18d8641e038891f78896ae7251b97415c/lib/boson/pipes.rb#L43-L59 | train |
cldwalker/boson-more | lib/boson/pipes.rb | Boson.Pipes.pipes_pipe | def pipes_pipe(obj, arr)
arr.inject(obj) {|acc,e| Boson.full_invoke(e, [acc]) }
end | ruby | def pipes_pipe(obj, arr)
arr.inject(obj) {|acc,e| Boson.full_invoke(e, [acc]) }
end | [
"def",
"pipes_pipe",
"(",
"obj",
",",
"arr",
")",
"arr",
".",
"inject",
"(",
"obj",
")",
"{",
"|",
"acc",
",",
"e",
"|",
"Boson",
".",
"full_invoke",
"(",
"e",
",",
"[",
"acc",
"]",
")",
"}",
"end"
] | Pipes output of multiple commands recursively, given initial object | [
"Pipes",
"output",
"of",
"multiple",
"commands",
"recursively",
"given",
"initial",
"object"
] | f928ebc18d8641e038891f78896ae7251b97415c | https://github.com/cldwalker/boson-more/blob/f928ebc18d8641e038891f78896ae7251b97415c/lib/boson/pipes.rb#L71-L73 | train |
PeterCamilleri/mini_readline | lib/mini_readline/read_line.rb | MiniReadline.Readline.readline | def readline(options = {})
suppress_warnings
initialize_parms(options)
MiniTerm.raw { @edit.edit_process }
ensure
restore_warnings
puts
end | ruby | def readline(options = {})
suppress_warnings
initialize_parms(options)
MiniTerm.raw { @edit.edit_process }
ensure
restore_warnings
puts
end | [
"def",
"readline",
"(",
"options",
"=",
"{",
"}",
")",
"suppress_warnings",
"initialize_parms",
"(",
"options",
")",
"MiniTerm",
".",
"raw",
"{",
"@edit",
".",
"edit_process",
"}",
"ensure",
"restore_warnings",
"puts",
"end"
] | Read a line from the console with edit and history. | [
"Read",
"a",
"line",
"from",
"the",
"console",
"with",
"edit",
"and",
"history",
"."
] | 45175ee01653a184b8ba04b2e8691dce5b26a1b5 | https://github.com/PeterCamilleri/mini_readline/blob/45175ee01653a184b8ba04b2e8691dce5b26a1b5/lib/mini_readline/read_line.rb#L34-L41 | train |
PeterCamilleri/mini_readline | lib/mini_readline/read_line.rb | MiniReadline.Readline.set_options | def set_options(options)
@options = MiniReadline::BASE_OPTIONS
.merge(instance_options)
.merge(options)
@options[:window_width] = MiniTerm.width - 1
set_prompt(@options[:prompt])
verify_mask(@options[:secret_mask])
end | ruby | def set_options(options)
@options = MiniReadline::BASE_OPTIONS
.merge(instance_options)
.merge(options)
@options[:window_width] = MiniTerm.width - 1
set_prompt(@options[:prompt])
verify_mask(@options[:secret_mask])
end | [
"def",
"set_options",
"(",
"options",
")",
"@options",
"=",
"MiniReadline",
"::",
"BASE_OPTIONS",
".",
"merge",
"(",
"instance_options",
")",
".",
"merge",
"(",
"options",
")",
"@options",
"[",
":window_width",
"]",
"=",
"MiniTerm",
".",
"width",
"-",
"1",
... | Set up the options | [
"Set",
"up",
"the",
"options"
] | 45175ee01653a184b8ba04b2e8691dce5b26a1b5 | https://github.com/PeterCamilleri/mini_readline/blob/45175ee01653a184b8ba04b2e8691dce5b26a1b5/lib/mini_readline/read_line.rb#L55-L63 | train |
PeterCamilleri/mini_readline | lib/mini_readline/read_line.rb | MiniReadline.Readline.set_prompt | def set_prompt(prompt)
@options[:base_prompt] = Prompt.new(prompt)
@options[:scroll_prompt] = Prompt.new(@options[:alt_prompt] || prompt)
verify_prompt(@options[:base_prompt])
verify_prompt(@options[:scroll_prompt])
end | ruby | def set_prompt(prompt)
@options[:base_prompt] = Prompt.new(prompt)
@options[:scroll_prompt] = Prompt.new(@options[:alt_prompt] || prompt)
verify_prompt(@options[:base_prompt])
verify_prompt(@options[:scroll_prompt])
end | [
"def",
"set_prompt",
"(",
"prompt",
")",
"@options",
"[",
":base_prompt",
"]",
"=",
"Prompt",
".",
"new",
"(",
"prompt",
")",
"@options",
"[",
":scroll_prompt",
"]",
"=",
"Prompt",
".",
"new",
"(",
"@options",
"[",
":alt_prompt",
"]",
"||",
"prompt",
")"... | Set up the prompt. | [
"Set",
"up",
"the",
"prompt",
"."
] | 45175ee01653a184b8ba04b2e8691dce5b26a1b5 | https://github.com/PeterCamilleri/mini_readline/blob/45175ee01653a184b8ba04b2e8691dce5b26a1b5/lib/mini_readline/read_line.rb#L66-L72 | train |
jomalley2112/hot_date_rails | app/helpers/form_helper.rb | FormHelper.ActionView::Helpers::FormTagHelper.hd_picker_tag | def hd_picker_tag(field_name, value=nil, cls="datepicker", opts={}, locale_format=nil)
draw_ext_input_tag(field_name, value, cls, locale_format, opts)
end | ruby | def hd_picker_tag(field_name, value=nil, cls="datepicker", opts={}, locale_format=nil)
draw_ext_input_tag(field_name, value, cls, locale_format, opts)
end | [
"def",
"hd_picker_tag",
"(",
"field_name",
",",
"value",
"=",
"nil",
",",
"cls",
"=",
"\"datepicker\"",
",",
"opts",
"=",
"{",
"}",
",",
"locale_format",
"=",
"nil",
")",
"draw_ext_input_tag",
"(",
"field_name",
",",
"value",
",",
"cls",
",",
"locale_forma... | for when there's no rails form object and you really just need inputs | [
"for",
"when",
"there",
"s",
"no",
"rails",
"form",
"object",
"and",
"you",
"really",
"just",
"need",
"inputs"
] | 4580d2c2823ba472afca3d38f21b2f8acff954f2 | https://github.com/jomalley2112/hot_date_rails/blob/4580d2c2823ba472afca3d38f21b2f8acff954f2/app/helpers/form_helper.rb#L5-L7 | train |
ejlangev/citibike | lib/citibike/api.rb | Citibike.Api.distance_from | def distance_from(lat, long)
dLat = self.degrees_to_radians(lat - self.latitude)
dLon = self.degrees_to_radians(long - self.longitude)
lat1 = self.degrees_to_radians(lat)
lat2 = self.degrees_to_radians(self.latitude)
a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.sin(dLon /... | ruby | def distance_from(lat, long)
dLat = self.degrees_to_radians(lat - self.latitude)
dLon = self.degrees_to_radians(long - self.longitude)
lat1 = self.degrees_to_radians(lat)
lat2 = self.degrees_to_radians(self.latitude)
a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.sin(dLon /... | [
"def",
"distance_from",
"(",
"lat",
",",
"long",
")",
"dLat",
"=",
"self",
".",
"degrees_to_radians",
"(",
"lat",
"-",
"self",
".",
"latitude",
")",
"dLon",
"=",
"self",
".",
"degrees_to_radians",
"(",
"long",
"-",
"self",
".",
"longitude",
")",
"lat1",
... | Returns the distance this object is from the given
latitude and longitude. Distance is as the crow flies.
@param lat [Float] [A latitude position]
@param long [Float] [A longitude position]
@return [Float] [Distance from the input postion in miles] | [
"Returns",
"the",
"distance",
"this",
"object",
"is",
"from",
"the",
"given",
"latitude",
"and",
"longitude",
".",
"Distance",
"is",
"as",
"the",
"crow",
"flies",
"."
] | 40ae300dacb299468985fa9c2fdf5dba7a235c93 | https://github.com/ejlangev/citibike/blob/40ae300dacb299468985fa9c2fdf5dba7a235c93/lib/citibike/api.rb#L44-L58 | train |
ejlangev/citibike | lib/citibike/api.rb | Citibike.Api.method_missing | def method_missing(sym, *args, &block)
if self.internal_object.key?(sym.to_s)
return self.internal_object[sym.to_s]
end
super
end | ruby | def method_missing(sym, *args, &block)
if self.internal_object.key?(sym.to_s)
return self.internal_object[sym.to_s]
end
super
end | [
"def",
"method_missing",
"(",
"sym",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"self",
".",
"internal_object",
".",
"key?",
"(",
"sym",
".",
"to_s",
")",
"return",
"self",
".",
"internal_object",
"[",
"sym",
".",
"to_s",
"]",
"end",
"super",
"e... | Allow hash keys to be used as methods | [
"Allow",
"hash",
"keys",
"to",
"be",
"used",
"as",
"methods"
] | 40ae300dacb299468985fa9c2fdf5dba7a235c93 | https://github.com/ejlangev/citibike/blob/40ae300dacb299468985fa9c2fdf5dba7a235c93/lib/citibike/api.rb#L66-L72 | train |
3scale/xcflushd | lib/xcflushd/storage.rb | Xcflushd.Storage.reports_to_flush | def reports_to_flush
# The Redis rename command overwrites the key with the new name if it
# exists. This means that if the rename operation fails in a flush cycle,
# and succeeds in a next one, the data that the key had in the first
# flush cycle will be lost.
# For that reason, every tim... | ruby | def reports_to_flush
# The Redis rename command overwrites the key with the new name if it
# exists. This means that if the rename operation fails in a flush cycle,
# and succeeds in a next one, the data that the key had in the first
# flush cycle will be lost.
# For that reason, every tim... | [
"def",
"reports_to_flush",
"suffix",
"=",
"suffix_for_unique_naming",
"report_keys",
"=",
"report_keys_to_flush",
"(",
"suffix",
")",
"if",
"report_keys",
".",
"empty?",
"logger",
".",
"warn",
"\"No reports available to flush\"",
"report_keys",
"else",
"reports",
"(",
"... | This performs a cleanup of the reports to be flushed.
We can decide later whether it is better to leave this responsibility
to the caller of the method.
Returns an array of hashes where each of them has a service_id,
credentials, and a usage. The usage is another hash where the keys are
the metrics and the values... | [
"This",
"performs",
"a",
"cleanup",
"of",
"the",
"reports",
"to",
"be",
"flushed",
".",
"We",
"can",
"decide",
"later",
"whether",
"it",
"is",
"better",
"to",
"leave",
"this",
"responsibility",
"to",
"the",
"caller",
"of",
"the",
"method",
"."
] | ca29b7674c3cd952a2a50c0604a99f04662bf27d | https://github.com/3scale/xcflushd/blob/ca29b7674c3cd952a2a50c0604a99f04662bf27d/lib/xcflushd/storage.rb#L53-L71 | train |
pdobb/object_inspector | lib/object_inspector/scope.rb | ObjectInspector.Scope.join_name | def join_name(parts,
separator: ObjectInspector.configuration.name_separator)
the_parts = Array(parts).tap(&:compact!)
the_parts.join(separator) if the_parts.any?
end | ruby | def join_name(parts,
separator: ObjectInspector.configuration.name_separator)
the_parts = Array(parts).tap(&:compact!)
the_parts.join(separator) if the_parts.any?
end | [
"def",
"join_name",
"(",
"parts",
",",
"separator",
":",
"ObjectInspector",
".",
"configuration",
".",
"name_separator",
")",
"the_parts",
"=",
"Array",
"(",
"parts",
")",
".",
"tap",
"(",
"&",
":compact!",
")",
"the_parts",
".",
"join",
"(",
"separator",
... | Join the passed-in name parts with the passed in separator.
@param parts [Array<#to_s>]
@param separator [#to_s] (ObjectInspector.configuration.flags_separator) | [
"Join",
"the",
"passed",
"-",
"in",
"name",
"parts",
"with",
"the",
"passed",
"in",
"separator",
"."
] | ce89add5055b195e3a024f3cc98c8fe5cc1d4d94 | https://github.com/pdobb/object_inspector/blob/ce89add5055b195e3a024f3cc98c8fe5cc1d4d94/lib/object_inspector/scope.rb#L28-L32 | train |
pdobb/object_inspector | lib/object_inspector/scope.rb | ObjectInspector.Scope.join_flags | def join_flags(flags,
separator: ObjectInspector.configuration.flags_separator)
the_flags = Array(flags).tap(&:compact!)
the_flags.join(separator) if the_flags.any?
end | ruby | def join_flags(flags,
separator: ObjectInspector.configuration.flags_separator)
the_flags = Array(flags).tap(&:compact!)
the_flags.join(separator) if the_flags.any?
end | [
"def",
"join_flags",
"(",
"flags",
",",
"separator",
":",
"ObjectInspector",
".",
"configuration",
".",
"flags_separator",
")",
"the_flags",
"=",
"Array",
"(",
"flags",
")",
".",
"tap",
"(",
"&",
":compact!",
")",
"the_flags",
".",
"join",
"(",
"separator",
... | Join the passed-in flags with the passed in separator.
@param flags [Array<#to_s>]
@param separator [#to_s] (ObjectInspector.configuration.flags_separator) | [
"Join",
"the",
"passed",
"-",
"in",
"flags",
"with",
"the",
"passed",
"in",
"separator",
"."
] | ce89add5055b195e3a024f3cc98c8fe5cc1d4d94 | https://github.com/pdobb/object_inspector/blob/ce89add5055b195e3a024f3cc98c8fe5cc1d4d94/lib/object_inspector/scope.rb#L38-L42 | train |
pdobb/object_inspector | lib/object_inspector/scope.rb | ObjectInspector.Scope.join_issues | def join_issues(issues,
separator: ObjectInspector.configuration.issues_separator)
the_issues = Array(issues).tap(&:compact!)
the_issues.join(separator) if the_issues.any?
end | ruby | def join_issues(issues,
separator: ObjectInspector.configuration.issues_separator)
the_issues = Array(issues).tap(&:compact!)
the_issues.join(separator) if the_issues.any?
end | [
"def",
"join_issues",
"(",
"issues",
",",
"separator",
":",
"ObjectInspector",
".",
"configuration",
".",
"issues_separator",
")",
"the_issues",
"=",
"Array",
"(",
"issues",
")",
".",
"tap",
"(",
"&",
":compact!",
")",
"the_issues",
".",
"join",
"(",
"separa... | Join the passed-in issues with the passed in separator.
@param issues [Array<#to_s>]
@param separator [#to_s] (ObjectInspector.configuration.issues_separator) | [
"Join",
"the",
"passed",
"-",
"in",
"issues",
"with",
"the",
"passed",
"in",
"separator",
"."
] | ce89add5055b195e3a024f3cc98c8fe5cc1d4d94 | https://github.com/pdobb/object_inspector/blob/ce89add5055b195e3a024f3cc98c8fe5cc1d4d94/lib/object_inspector/scope.rb#L48-L52 | train |
pdobb/object_inspector | lib/object_inspector/scope.rb | ObjectInspector.Scope.join_info | def join_info(items,
separator: ObjectInspector.configuration.info_separator)
the_items = Array(items).tap(&:compact!)
the_items.join(separator) if the_items.any?
end | ruby | def join_info(items,
separator: ObjectInspector.configuration.info_separator)
the_items = Array(items).tap(&:compact!)
the_items.join(separator) if the_items.any?
end | [
"def",
"join_info",
"(",
"items",
",",
"separator",
":",
"ObjectInspector",
".",
"configuration",
".",
"info_separator",
")",
"the_items",
"=",
"Array",
"(",
"items",
")",
".",
"tap",
"(",
"&",
":compact!",
")",
"the_items",
".",
"join",
"(",
"separator",
... | Join the passed-in items with the passed in separator.
@param items [Array<#to_s>]
@param separator [#to_s] (ObjectInspector.configuration.info_separator) | [
"Join",
"the",
"passed",
"-",
"in",
"items",
"with",
"the",
"passed",
"in",
"separator",
"."
] | ce89add5055b195e3a024f3cc98c8fe5cc1d4d94 | https://github.com/pdobb/object_inspector/blob/ce89add5055b195e3a024f3cc98c8fe5cc1d4d94/lib/object_inspector/scope.rb#L58-L62 | train |
alexandre025/cdx | lib/friendly_id/json_translate.rb | FriendlyId.JsonTranslate.execute_with_locale | def execute_with_locale(locale = ::I18n.locale, &block)
actual_locale = ::I18n.locale
::I18n.locale = locale
block.call
::I18n.locale = actual_locale
end | ruby | def execute_with_locale(locale = ::I18n.locale, &block)
actual_locale = ::I18n.locale
::I18n.locale = locale
block.call
::I18n.locale = actual_locale
end | [
"def",
"execute_with_locale",
"(",
"locale",
"=",
"::",
"I18n",
".",
"locale",
",",
"&",
"block",
")",
"actual_locale",
"=",
"::",
"I18n",
".",
"locale",
"::",
"I18n",
".",
"locale",
"=",
"locale",
"block",
".",
"call",
"::",
"I18n",
".",
"locale",
"="... | Auxiliar function to execute a block with other locale set | [
"Auxiliar",
"function",
"to",
"execute",
"a",
"block",
"with",
"other",
"locale",
"set"
] | a689edac06736978956a3d7b952eadab62c8691b | https://github.com/alexandre025/cdx/blob/a689edac06736978956a3d7b952eadab62c8691b/lib/friendly_id/json_translate.rb#L66-L73 | train |
brightbox/brightbox-cli | lib/brightbox-cli/database_server.rb | Brightbox.DatabaseServer.maintenance_window | def maintenance_window
return nil if maintenance_weekday.nil?
weekday = Date::DAYNAMES[maintenance_weekday]
sprintf("%s %02d:00 UTC", weekday, maintenance_hour)
end | ruby | def maintenance_window
return nil if maintenance_weekday.nil?
weekday = Date::DAYNAMES[maintenance_weekday]
sprintf("%s %02d:00 UTC", weekday, maintenance_hour)
end | [
"def",
"maintenance_window",
"return",
"nil",
"if",
"maintenance_weekday",
".",
"nil?",
"weekday",
"=",
"Date",
"::",
"DAYNAMES",
"[",
"maintenance_weekday",
"]",
"sprintf",
"(",
"\"%s %02d:00 UTC\"",
",",
"weekday",
",",
"maintenance_hour",
")",
"end"
] | A more humanised version of the maintenance window | [
"A",
"more",
"humanised",
"version",
"of",
"the",
"maintenance",
"window"
] | aba751383197e0484f75c504420ca0f355a57dc1 | https://github.com/brightbox/brightbox-cli/blob/aba751383197e0484f75c504420ca0f355a57dc1/lib/brightbox-cli/database_server.rb#L100-L104 | train |
sferik/mtgox | lib/mtgox/client.rb | MtGox.Client.ticker | def ticker
ticker = get('/api/1/BTCUSD/ticker')
Ticker.instance.buy = value_currency ticker['buy']
Ticker.instance.high = value_currency ticker['high']
Ticker.instance.price = value_currency ticker['last_all']
Ticker.instance.low = value_currency ticker['low']
... | ruby | def ticker
ticker = get('/api/1/BTCUSD/ticker')
Ticker.instance.buy = value_currency ticker['buy']
Ticker.instance.high = value_currency ticker['high']
Ticker.instance.price = value_currency ticker['last_all']
Ticker.instance.low = value_currency ticker['low']
... | [
"def",
"ticker",
"ticker",
"=",
"get",
"(",
"'/api/1/BTCUSD/ticker'",
")",
"Ticker",
".",
"instance",
".",
"buy",
"=",
"value_currency",
"ticker",
"[",
"'buy'",
"]",
"Ticker",
".",
"instance",
".",
"high",
"=",
"value_currency",
"ticker",
"[",
"'high'",
"]",... | Fetch the latest ticker data
@authenticated false
@return [MtGox::Ticker]
@example
MtGox.ticker | [
"Fetch",
"the",
"latest",
"ticker",
"data"
] | 031308d64fabbcdb0a745a866818fa9235830c51 | https://github.com/sferik/mtgox/blob/031308d64fabbcdb0a745a866818fa9235830c51/lib/mtgox/client.rb#L55-L67 | train |
sferik/mtgox | lib/mtgox/client.rb | MtGox.Client.offers | def offers
offers = get('/api/1/BTCUSD/depth/fetch')
asks = offers['asks'].sort_by { |ask| ask['price_int'].to_i }.collect { |ask| Ask.new(self, ask) }
bids = offers['bids'].sort_by { |bid| -bid['price_int'].to_i }.collect { |bid| Bid.new(self, bid) }
{:asks => asks, :bids => bids}
end | ruby | def offers
offers = get('/api/1/BTCUSD/depth/fetch')
asks = offers['asks'].sort_by { |ask| ask['price_int'].to_i }.collect { |ask| Ask.new(self, ask) }
bids = offers['bids'].sort_by { |bid| -bid['price_int'].to_i }.collect { |bid| Bid.new(self, bid) }
{:asks => asks, :bids => bids}
end | [
"def",
"offers",
"offers",
"=",
"get",
"(",
"'/api/1/BTCUSD/depth/fetch'",
")",
"asks",
"=",
"offers",
"[",
"'asks'",
"]",
".",
"sort_by",
"{",
"|",
"ask",
"|",
"ask",
"[",
"'price_int'",
"]",
".",
"to_i",
"}",
".",
"collect",
"{",
"|",
"ask",
"|",
"... | Fetch both bids and asks in one call, for network efficiency
@authenticated false
@return [Hash] with keys :asks and :bids, which contain arrays as described in {MtGox::Client#asks} and {MtGox::Clients#bids}
@example
MtGox.offers | [
"Fetch",
"both",
"bids",
"and",
"asks",
"in",
"one",
"call",
"for",
"network",
"efficiency"
] | 031308d64fabbcdb0a745a866818fa9235830c51 | https://github.com/sferik/mtgox/blob/031308d64fabbcdb0a745a866818fa9235830c51/lib/mtgox/client.rb#L88-L93 | train |
sferik/mtgox | lib/mtgox/client.rb | MtGox.Client.trades | def trades(opts = {})
get('/api/1/BTCUSD/trades/fetch', opts).
sort_by { |trade| trade['date'] }.collect do |trade|
Trade.new(trade)
end
end | ruby | def trades(opts = {})
get('/api/1/BTCUSD/trades/fetch', opts).
sort_by { |trade| trade['date'] }.collect do |trade|
Trade.new(trade)
end
end | [
"def",
"trades",
"(",
"opts",
"=",
"{",
"}",
")",
"get",
"(",
"'/api/1/BTCUSD/trades/fetch'",
",",
"opts",
")",
".",
"sort_by",
"{",
"|",
"trade",
"|",
"trade",
"[",
"'date'",
"]",
"}",
".",
"collect",
"do",
"|",
"trade",
"|",
"Trade",
".",
"new",
... | Fetch recent trades
@authenticated false
@return [Array<MtGox::Trade>] an array of trades, sorted in chronological order
@example
MtGox.trades
MtGox.trades :since => 12341234 | [
"Fetch",
"recent",
"trades"
] | 031308d64fabbcdb0a745a866818fa9235830c51 | https://github.com/sferik/mtgox/blob/031308d64fabbcdb0a745a866818fa9235830c51/lib/mtgox/client.rb#L142-L147 | train |
sferik/mtgox | lib/mtgox/client.rb | MtGox.Client.order! | def order!(type, amount, price)
order = {:type => order_type(type), :amount_int => intify(amount, :btc)}
order[:price_int] = intify(price, :usd) if price != :market
post('/api/1/BTCUSD/order/add', order)
end | ruby | def order!(type, amount, price)
order = {:type => order_type(type), :amount_int => intify(amount, :btc)}
order[:price_int] = intify(price, :usd) if price != :market
post('/api/1/BTCUSD/order/add', order)
end | [
"def",
"order!",
"(",
"type",
",",
"amount",
",",
"price",
")",
"order",
"=",
"{",
":type",
"=>",
"order_type",
"(",
"type",
")",
",",
":amount_int",
"=>",
"intify",
"(",
"amount",
",",
":btc",
")",
"}",
"order",
"[",
":price_int",
"]",
"=",
"intify"... | Create a new order
@authenticated true
@param type [String] the type of order to create, either "buy" or "sell"
@param amount [Numberic] the number of bitcoins to buy/sell
@param price [Numeric or Symbol] the bid/ask price in USD, or :market if placing a market order
@return [String] order ID for the order, can b... | [
"Create",
"a",
"new",
"order"
] | 031308d64fabbcdb0a745a866818fa9235830c51 | https://github.com/sferik/mtgox/blob/031308d64fabbcdb0a745a866818fa9235830c51/lib/mtgox/client.rb#L235-L239 | train |
sferik/mtgox | lib/mtgox/client.rb | MtGox.Client.withdraw! | def withdraw!(amount, address)
if amount >= 1000
fail(FilthyRichError.new("#withdraw! take bitcoin amount as parameter (you are trying to withdraw #{amount} BTC"))
else
post('/api/1/generic/bitcoin/send_simple', :amount_int => intify(amount, :btc), :address => address)['trx']
end
e... | ruby | def withdraw!(amount, address)
if amount >= 1000
fail(FilthyRichError.new("#withdraw! take bitcoin amount as parameter (you are trying to withdraw #{amount} BTC"))
else
post('/api/1/generic/bitcoin/send_simple', :amount_int => intify(amount, :btc), :address => address)['trx']
end
e... | [
"def",
"withdraw!",
"(",
"amount",
",",
"address",
")",
"if",
"amount",
">=",
"1000",
"fail",
"(",
"FilthyRichError",
".",
"new",
"(",
"\"#withdraw! take bitcoin amount as parameter (you are trying to withdraw #{amount} BTC\"",
")",
")",
"else",
"post",
"(",
"'/api/1/ge... | Transfer bitcoins from your Mt. Gox account into another account
@authenticated true
@param amount [Numeric] the number of bitcoins to withdraw
@param address [String] the bitcoin address to send to
@return [String] Completed Transaction ID
@example
# Withdraw 1 BTC from your account
MtGox.withdraw! 1.0, '1... | [
"Transfer",
"bitcoins",
"from",
"your",
"Mt",
".",
"Gox",
"account",
"into",
"another",
"account"
] | 031308d64fabbcdb0a745a866818fa9235830c51 | https://github.com/sferik/mtgox/blob/031308d64fabbcdb0a745a866818fa9235830c51/lib/mtgox/client.rb#L284-L290 | train |
cldwalker/boson-more | lib/boson/pipe.rb | Boson.Pipe.scientist_process | def scientist_process(object, global_opt, env={})
@env = env
[:query, :sort, :reverse_sort].each {|e| global_opt.delete(e) } unless object.is_a?(Array)
process_pipes(object, global_opt)
end | ruby | def scientist_process(object, global_opt, env={})
@env = env
[:query, :sort, :reverse_sort].each {|e| global_opt.delete(e) } unless object.is_a?(Array)
process_pipes(object, global_opt)
end | [
"def",
"scientist_process",
"(",
"object",
",",
"global_opt",
",",
"env",
"=",
"{",
"}",
")",
"@env",
"=",
"env",
"[",
":query",
",",
":sort",
",",
":reverse_sort",
"]",
".",
"each",
"{",
"|",
"e",
"|",
"global_opt",
".",
"delete",
"(",
"e",
")",
"... | Process pipes for Scientist | [
"Process",
"pipes",
"for",
"Scientist"
] | f928ebc18d8641e038891f78896ae7251b97415c | https://github.com/cldwalker/boson-more/blob/f928ebc18d8641e038891f78896ae7251b97415c/lib/boson/pipe.rb#L77-L81 | train |
cldwalker/boson-more | lib/boson/pipe.rb | Boson.Pipe.process_pipes | def process_pipes(obj, options)
internal_pipes(options).each {|pipe|
obj = Pipes.send("#{pipe}_pipe", obj, options[pipe]) if options[pipe]
}
process_user_pipes(obj, options)
end | ruby | def process_pipes(obj, options)
internal_pipes(options).each {|pipe|
obj = Pipes.send("#{pipe}_pipe", obj, options[pipe]) if options[pipe]
}
process_user_pipes(obj, options)
end | [
"def",
"process_pipes",
"(",
"obj",
",",
"options",
")",
"internal_pipes",
"(",
"options",
")",
".",
"each",
"{",
"|",
"pipe",
"|",
"obj",
"=",
"Pipes",
".",
"send",
"(",
"\"#{pipe}_pipe\"",
",",
"obj",
",",
"options",
"[",
"pipe",
"]",
")",
"if",
"o... | Main method which processes all pipe commands, both default and user-defined ones. | [
"Main",
"method",
"which",
"processes",
"all",
"pipe",
"commands",
"both",
"default",
"and",
"user",
"-",
"defined",
"ones",
"."
] | f928ebc18d8641e038891f78896ae7251b97415c | https://github.com/cldwalker/boson-more/blob/f928ebc18d8641e038891f78896ae7251b97415c/lib/boson/pipe.rb#L84-L89 | train |
cldwalker/boson-more | lib/boson/pipe.rb | Boson.Pipe.process_user_pipes | def process_user_pipes(result, global_opt)
pipes_to_process(global_opt).each {|e|
args = [pipe(e)[:pipe], result]
args << global_opt[e] unless pipe(e)[:type] == :boolean
args << get_env(e, global_opt) if pipe(e)[:env]
pipe_result = Boson.invoke(*args)
result = pipe_result i... | ruby | def process_user_pipes(result, global_opt)
pipes_to_process(global_opt).each {|e|
args = [pipe(e)[:pipe], result]
args << global_opt[e] unless pipe(e)[:type] == :boolean
args << get_env(e, global_opt) if pipe(e)[:env]
pipe_result = Boson.invoke(*args)
result = pipe_result i... | [
"def",
"process_user_pipes",
"(",
"result",
",",
"global_opt",
")",
"pipes_to_process",
"(",
"global_opt",
")",
".",
"each",
"{",
"|",
"e",
"|",
"args",
"=",
"[",
"pipe",
"(",
"e",
")",
"[",
":pipe",
"]",
",",
"result",
"]",
"args",
"<<",
"global_opt",... | global_opt can come from Hirb callback or Scientist | [
"global_opt",
"can",
"come",
"from",
"Hirb",
"callback",
"or",
"Scientist"
] | f928ebc18d8641e038891f78896ae7251b97415c | https://github.com/cldwalker/boson-more/blob/f928ebc18d8641e038891f78896ae7251b97415c/lib/boson/pipe.rb#L117-L126 | train |
svoop/aixm | lib/aixm/document.rb | AIXM.Document.errors | def errors
xsd = Nokogiri::XML::Schema(File.open(AIXM.schema(:xsd)))
xsd.validate(Nokogiri::XML(to_xml)).reject do |error|
AIXM.config.ignored_errors && error.message.match?(AIXM.config.ignored_errors)
end
end | ruby | def errors
xsd = Nokogiri::XML::Schema(File.open(AIXM.schema(:xsd)))
xsd.validate(Nokogiri::XML(to_xml)).reject do |error|
AIXM.config.ignored_errors && error.message.match?(AIXM.config.ignored_errors)
end
end | [
"def",
"errors",
"xsd",
"=",
"Nokogiri",
"::",
"XML",
"::",
"Schema",
"(",
"File",
".",
"open",
"(",
"AIXM",
".",
"schema",
"(",
":xsd",
")",
")",
")",
"xsd",
".",
"validate",
"(",
"Nokogiri",
"::",
"XML",
"(",
"to_xml",
")",
")",
".",
"reject",
... | Validate the generated AIXM or OFMX atainst it's XSD and return the
errors found.
@return [Array<String>] validation errors | [
"Validate",
"the",
"generated",
"AIXM",
"or",
"OFMX",
"atainst",
"it",
"s",
"XSD",
"and",
"return",
"the",
"errors",
"found",
"."
] | 4541e6543d4b6fcd023ef3cd2768946a29ec0b9e | https://github.com/svoop/aixm/blob/4541e6543d4b6fcd023ef3cd2768946a29ec0b9e/lib/aixm/document.rb#L74-L79 | train |
cldwalker/boson-more | lib/boson/namespacer.rb | Boson.Namespacer.full_invoke | def full_invoke(cmd, args) #:nodoc:
command, subcommand = cmd.include?(NAMESPACE) ? cmd.split(NAMESPACE, 2) : [cmd, nil]
dispatcher = subcommand ? Boson.invoke(command) : Boson.main_object
dispatcher.send(subcommand || command, *args)
end | ruby | def full_invoke(cmd, args) #:nodoc:
command, subcommand = cmd.include?(NAMESPACE) ? cmd.split(NAMESPACE, 2) : [cmd, nil]
dispatcher = subcommand ? Boson.invoke(command) : Boson.main_object
dispatcher.send(subcommand || command, *args)
end | [
"def",
"full_invoke",
"(",
"cmd",
",",
"args",
")",
"command",
",",
"subcommand",
"=",
"cmd",
".",
"include?",
"(",
"NAMESPACE",
")",
"?",
"cmd",
".",
"split",
"(",
"NAMESPACE",
",",
"2",
")",
":",
"[",
"cmd",
",",
"nil",
"]",
"dispatcher",
"=",
"s... | Invoke command string even with namespaces | [
"Invoke",
"command",
"string",
"even",
"with",
"namespaces"
] | f928ebc18d8641e038891f78896ae7251b97415c | https://github.com/cldwalker/boson-more/blob/f928ebc18d8641e038891f78896ae7251b97415c/lib/boson/namespacer.rb#L13-L17 | train |
soffes/unmarkdown | lib/unmarkdown/parser.rb | Unmarkdown.Parser.parse_nodes | def parse_nodes(nodes)
output = ''
# Short-circuit if it's empty
return output if !nodes || nodes.empty?
# Loop through nodes
nodes.each do |node|
case node.name
when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
level = node.name.match(/\Ah(\d)\Z/)[1].to_i
if @o... | ruby | def parse_nodes(nodes)
output = ''
# Short-circuit if it's empty
return output if !nodes || nodes.empty?
# Loop through nodes
nodes.each do |node|
case node.name
when 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
level = node.name.match(/\Ah(\d)\Z/)[1].to_i
if @o... | [
"def",
"parse_nodes",
"(",
"nodes",
")",
"output",
"=",
"''",
"return",
"output",
"if",
"!",
"nodes",
"||",
"nodes",
".",
"empty?",
"nodes",
".",
"each",
"do",
"|",
"node",
"|",
"case",
"node",
".",
"name",
"when",
"'h1'",
",",
"'h2'",
",",
"'h3'",
... | Parse the children of a node | [
"Parse",
"the",
"children",
"of",
"a",
"node"
] | 5dac78bc785918e36568b23b087cccb90e288b53 | https://github.com/soffes/unmarkdown/blob/5dac78bc785918e36568b23b087cccb90e288b53/lib/unmarkdown/parser.rb#L36-L130 | train |
soffes/unmarkdown | lib/unmarkdown/parser.rb | Unmarkdown.Parser.parse_content | def parse_content(node)
content = if node.children.empty?
node.content
else
parse_nodes(node.children)
end
end | ruby | def parse_content(node)
content = if node.children.empty?
node.content
else
parse_nodes(node.children)
end
end | [
"def",
"parse_content",
"(",
"node",
")",
"content",
"=",
"if",
"node",
".",
"children",
".",
"empty?",
"node",
".",
"content",
"else",
"parse_nodes",
"(",
"node",
".",
"children",
")",
"end",
"end"
] | Get the content from a node | [
"Get",
"the",
"content",
"from",
"a",
"node"
] | 5dac78bc785918e36568b23b087cccb90e288b53 | https://github.com/soffes/unmarkdown/blob/5dac78bc785918e36568b23b087cccb90e288b53/lib/unmarkdown/parser.rb#L133-L139 | train |
svoop/aixm | lib/aixm/a.rb | AIXM.A.invert | def invert
build(precision: precision, deg: (deg + 180) % 360, suffix: SUFFIX_INVERSIONS.fetch(suffix, suffix))
end | ruby | def invert
build(precision: precision, deg: (deg + 180) % 360, suffix: SUFFIX_INVERSIONS.fetch(suffix, suffix))
end | [
"def",
"invert",
"build",
"(",
"precision",
":",
"precision",
",",
"deg",
":",
"(",
"deg",
"+",
"180",
")",
"%",
"360",
",",
"suffix",
":",
"SUFFIX_INVERSIONS",
".",
"fetch",
"(",
"suffix",
",",
"suffix",
")",
")",
"end"
] | Invert an angle by 180 degrees
@example
AIXM.a(120).invert # => AIXM.a(300)
AIXM.a("34L").invert # => AIXM.a("16R")
AIXM.a("33X").invert # => AIXM.a("33X")
@return [AIXM::A] inverted angle | [
"Invert",
"an",
"angle",
"by",
"180",
"degrees"
] | 4541e6543d4b6fcd023ef3cd2768946a29ec0b9e | https://github.com/svoop/aixm/blob/4541e6543d4b6fcd023ef3cd2768946a29ec0b9e/lib/aixm/a.rb#L90-L92 | train |
3scale/xcflushd | lib/xcflushd/flusher.rb | Xcflushd.Flusher.async_authorization_tasks | def async_authorization_tasks(reports)
# Each call to authorizer.authorizations might need to contact 3scale
# several times. The number of calls equals 1 + number of reported
# metrics without limits.
# This is probably good enough for now, but in the future we might want
# to make sure t... | ruby | def async_authorization_tasks(reports)
# Each call to authorizer.authorizations might need to contact 3scale
# several times. The number of calls equals 1 + number of reported
# metrics without limits.
# This is probably good enough for now, but in the future we might want
# to make sure t... | [
"def",
"async_authorization_tasks",
"(",
"reports",
")",
"reports",
".",
"map",
"do",
"|",
"report",
"|",
"task",
"=",
"Concurrent",
"::",
"Future",
".",
"new",
"(",
"executor",
":",
"thread_pool",
")",
"do",
"authorizer",
".",
"authorizations",
"(",
"report... | Returns a Hash. The keys are the reports and the values their associated
async authorization tasks. | [
"Returns",
"a",
"Hash",
".",
"The",
"keys",
"are",
"the",
"reports",
"and",
"the",
"values",
"their",
"associated",
"async",
"authorization",
"tasks",
"."
] | ca29b7674c3cd952a2a50c0604a99f04662bf27d | https://github.com/3scale/xcflushd/blob/ca29b7674c3cd952a2a50c0604a99f04662bf27d/lib/xcflushd/flusher.rb#L129-L144 | train |
leandog/gametel | lib/gametel/navigation.rb | Gametel.Navigation.on | def on(cls, &block)
@current_screen = @current_page = cls.new
waiting_for = "#{cls} to be active"
wait_until(10, waiting_for) { @current_screen.active? } if @current_screen.respond_to?(:active?)
block.call @current_screen if block
@current_screen
end | ruby | def on(cls, &block)
@current_screen = @current_page = cls.new
waiting_for = "#{cls} to be active"
wait_until(10, waiting_for) { @current_screen.active? } if @current_screen.respond_to?(:active?)
block.call @current_screen if block
@current_screen
end | [
"def",
"on",
"(",
"cls",
",",
"&",
"block",
")",
"@current_screen",
"=",
"@current_page",
"=",
"cls",
".",
"new",
"waiting_for",
"=",
"\"#{cls} to be active\"",
"wait_until",
"(",
"10",
",",
"waiting_for",
")",
"{",
"@current_screen",
".",
"active?",
"}",
"i... | create a new screen given a class name | [
"create",
"a",
"new",
"screen",
"given",
"a",
"class",
"name"
] | fc9468da9a443b5e6ac553b3e445333a0eabfc18 | https://github.com/leandog/gametel/blob/fc9468da9a443b5e6ac553b3e445333a0eabfc18/lib/gametel/navigation.rb#L15-L21 | train |
kaspermeyer/prawndown | lib/prawndown.rb | Prawndown.Interface.markdown | def markdown(string, options = {})
text Prawndown::Parser.new(string).to_prawn, options.merge(inline_format: true)
end | ruby | def markdown(string, options = {})
text Prawndown::Parser.new(string).to_prawn, options.merge(inline_format: true)
end | [
"def",
"markdown",
"(",
"string",
",",
"options",
"=",
"{",
"}",
")",
"text",
"Prawndown",
"::",
"Parser",
".",
"new",
"(",
"string",
")",
".",
"to_prawn",
",",
"options",
".",
"merge",
"(",
"inline_format",
":",
"true",
")",
"end"
] | Renders Markdown in the current document
It supports header 1-6, bold text, italic text, strikethrough and links
It supports the same options as +Prawn::Document#text+
Prawn::Document.generate('markdown.pdf') do
markdown '# Welcome to Prawndown!'
markdown '**Important:** We _hope_ you enjoy your stay!... | [
"Renders",
"Markdown",
"in",
"the",
"current",
"document"
] | 9d9f86f0a2c799a1dedd32a214427d06e1cf3488 | https://github.com/kaspermeyer/prawndown/blob/9d9f86f0a2c799a1dedd32a214427d06e1cf3488/lib/prawndown.rb#L17-L19 | train |
PeterCamilleri/mini_readline | lib/mini_readline/read_line/edit.rb | MiniReadline.Edit.edit_loop | def edit_loop
while @working
@edit_window.sync_window(edit_buffer, edit_posn)
@edit_window.sync_cursor(edit_posn)
process_keystroke(MiniTerm.get_mapped_char)
end
edit_buffer
end | ruby | def edit_loop
while @working
@edit_window.sync_window(edit_buffer, edit_posn)
@edit_window.sync_cursor(edit_posn)
process_keystroke(MiniTerm.get_mapped_char)
end
edit_buffer
end | [
"def",
"edit_loop",
"while",
"@working",
"@edit_window",
".",
"sync_window",
"(",
"edit_buffer",
",",
"edit_posn",
")",
"@edit_window",
".",
"sync_cursor",
"(",
"edit_posn",
")",
"process_keystroke",
"(",
"MiniTerm",
".",
"get_mapped_char",
")",
"end",
"edit_buffer"... | The line editor processing loop. | [
"The",
"line",
"editor",
"processing",
"loop",
"."
] | 45175ee01653a184b8ba04b2e8691dce5b26a1b5 | https://github.com/PeterCamilleri/mini_readline/blob/45175ee01653a184b8ba04b2e8691dce5b26a1b5/lib/mini_readline/read_line/edit.rb#L68-L76 | train |
PeterCamilleri/mini_readline | lib/mini_readline/read_line/edit/word_right.rb | MiniReadline.Edit.word_right | def word_right(_keyboard_args)
if @edit_posn < length
right = @edit_buffer[(@edit_posn+1)..-1]
@edit_posn = (posn = right.index(/\s\S/)) ? @edit_posn+posn+2 : length
else
MiniTerm.beep
end
end | ruby | def word_right(_keyboard_args)
if @edit_posn < length
right = @edit_buffer[(@edit_posn+1)..-1]
@edit_posn = (posn = right.index(/\s\S/)) ? @edit_posn+posn+2 : length
else
MiniTerm.beep
end
end | [
"def",
"word_right",
"(",
"_keyboard_args",
")",
"if",
"@edit_posn",
"<",
"length",
"right",
"=",
"@edit_buffer",
"[",
"(",
"@edit_posn",
"+",
"1",
")",
"..",
"-",
"1",
"]",
"@edit_posn",
"=",
"(",
"posn",
"=",
"right",
".",
"index",
"(",
"/",
"\\s",
... | A little more to the right please! | [
"A",
"little",
"more",
"to",
"the",
"right",
"please!"
] | 45175ee01653a184b8ba04b2e8691dce5b26a1b5 | https://github.com/PeterCamilleri/mini_readline/blob/45175ee01653a184b8ba04b2e8691dce5b26a1b5/lib/mini_readline/read_line/edit/word_right.rb#L10-L17 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/request_reporter/view_rendering.rb | UnionStationHooks.RequestReporter.log_view_rendering | def log_view_rendering(options)
return do_nothing_on_null(:log_view_rendering) if null?
Utils.require_key(options, :name)
Utils.require_key(options, :begin_time)
Utils.require_key(options, :end_time)
@transaction.log_activity(next_view_rendering_name,
options[:begin_time], options... | ruby | def log_view_rendering(options)
return do_nothing_on_null(:log_view_rendering) if null?
Utils.require_key(options, :name)
Utils.require_key(options, :begin_time)
Utils.require_key(options, :end_time)
@transaction.log_activity(next_view_rendering_name,
options[:begin_time], options... | [
"def",
"log_view_rendering",
"(",
"options",
")",
"return",
"do_nothing_on_null",
"(",
":log_view_rendering",
")",
"if",
"null?",
"Utils",
".",
"require_key",
"(",
"options",
",",
":name",
")",
"Utils",
".",
"require_key",
"(",
"options",
",",
":begin_time",
")"... | Logs timing information about the rendering of a single view, template or
partial.
Unlike {#log_view_rendering_block}, this form does not expect a block.
However, you are expected to pass timing information to the options
hash.
The `union_station_hooks_rails` gem automatically calls
{#log_view_rendering_block} ... | [
"Logs",
"timing",
"information",
"about",
"the",
"rendering",
"of",
"a",
"single",
"view",
"template",
"or",
"partial",
"."
] | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/request_reporter/view_rendering.rb#L72-L81 | train |
pdobb/version_compare | lib/version_compare/conversions.rb | VersionCompare.Conversions.ComparableVersion | def ComparableVersion(value)
case value
when String,
Integer,
Float,
->(val) { val.respond_to?(:to_ary) }
ComparableVersion.new(value)
when ->(val) { val.respond_to?(:to_comparable_version) }
value.to_comparable_version
else
raise TypeErro... | ruby | def ComparableVersion(value)
case value
when String,
Integer,
Float,
->(val) { val.respond_to?(:to_ary) }
ComparableVersion.new(value)
when ->(val) { val.respond_to?(:to_comparable_version) }
value.to_comparable_version
else
raise TypeErro... | [
"def",
"ComparableVersion",
"(",
"value",
")",
"case",
"value",
"when",
"String",
",",
"Integer",
",",
"Float",
",",
"->",
"(",
"val",
")",
"{",
"val",
".",
"respond_to?",
"(",
":to_ary",
")",
"}",
"ComparableVersion",
".",
"new",
"(",
"value",
")",
"w... | Strict conversion method for creating a `ComparableVersion` object out of
anything that can be interpreted is a ComparableVersion.
@param [Object] value the object to be converted
@example
ComparableVersion(1)
# => #<ComparableVersion @major=1, @minor=nil, @tiny=nil, @patch=nil>
ComparableVersion(1.2)
... | [
"Strict",
"conversion",
"method",
"for",
"creating",
"a",
"ComparableVersion",
"object",
"out",
"of",
"anything",
"that",
"can",
"be",
"interpreted",
"is",
"a",
"ComparableVersion",
"."
] | 3da53adbd2cf639c3bb248bb87f33c4bea83d704 | https://github.com/pdobb/version_compare/blob/3da53adbd2cf639c3bb248bb87f33c4bea83d704/lib/version_compare/conversions.rb#L25-L37 | train |
epuber-io/epuber | lib/epuber/compiler.rb | Epuber.Compiler.archive | def archive(path = nil, configuration_suffix: nil)
path ||= epub_name(configuration_suffix)
epub_path = File.expand_path(path)
Dir.chdir(@file_resolver.destination_path) do
new_paths = @file_resolver.package_files.map(&:pkg_destination_path)
if ::File.exists?(epub_path)
Zi... | ruby | def archive(path = nil, configuration_suffix: nil)
path ||= epub_name(configuration_suffix)
epub_path = File.expand_path(path)
Dir.chdir(@file_resolver.destination_path) do
new_paths = @file_resolver.package_files.map(&:pkg_destination_path)
if ::File.exists?(epub_path)
Zi... | [
"def",
"archive",
"(",
"path",
"=",
"nil",
",",
"configuration_suffix",
":",
"nil",
")",
"path",
"||=",
"epub_name",
"(",
"configuration_suffix",
")",
"epub_path",
"=",
"File",
".",
"expand_path",
"(",
"path",
")",
"Dir",
".",
"chdir",
"(",
"@file_resolver",... | Archives current target files to epub
@param path [String] path to created archive
@return [String] path | [
"Archives",
"current",
"target",
"files",
"to",
"epub"
] | 4d736deb3f18c034fc93fcb95cfb9bf03b63c252 | https://github.com/epuber-io/epuber/blob/4d736deb3f18c034fc93fcb95cfb9bf03b63c252/lib/epuber/compiler.rb#L112-L136 | train |
epuber-io/epuber | lib/epuber/compiler.rb | Epuber.Compiler.epub_name | def epub_name(configuration_suffix = nil)
epub_name = if !@book.output_base_name.nil?
@book.output_base_name
elsif @book.from_file?
::File.basename(@book.file_path, ::File.extname(@book.file_path))
else
@book.title
... | ruby | def epub_name(configuration_suffix = nil)
epub_name = if !@book.output_base_name.nil?
@book.output_base_name
elsif @book.from_file?
::File.basename(@book.file_path, ::File.extname(@book.file_path))
else
@book.title
... | [
"def",
"epub_name",
"(",
"configuration_suffix",
"=",
"nil",
")",
"epub_name",
"=",
"if",
"!",
"@book",
".",
"output_base_name",
".",
"nil?",
"@book",
".",
"output_base_name",
"elsif",
"@book",
".",
"from_file?",
"::",
"File",
".",
"basename",
"(",
"@book",
... | Creates name of epub file for current book and current target
@return [String] name of result epub file | [
"Creates",
"name",
"of",
"epub",
"file",
"for",
"current",
"book",
"and",
"current",
"target"
] | 4d736deb3f18c034fc93fcb95cfb9bf03b63c252 | https://github.com/epuber-io/epuber/blob/4d736deb3f18c034fc93fcb95cfb9bf03b63c252/lib/epuber/compiler.rb#L142-L155 | train |
JonnieCache/tinyci | lib/tinyci/scheduler.rb | TinyCI.Scheduler.run_all_commits | def run_all_commits
commits = get_commits
until commits.empty? do
commits.each {|c| run_commit(c)}
commits = get_commits
end
end | ruby | def run_all_commits
commits = get_commits
until commits.empty? do
commits.each {|c| run_commit(c)}
commits = get_commits
end
end | [
"def",
"run_all_commits",
"commits",
"=",
"get_commits",
"until",
"commits",
".",
"empty?",
"do",
"commits",
".",
"each",
"{",
"|",
"c",
"|",
"run_commit",
"(",
"c",
")",
"}",
"commits",
"=",
"get_commits",
"end",
"end"
] | Repeatedly gets the list of eligable commits and runs TinyCI against them until there are no more remaining | [
"Repeatedly",
"gets",
"the",
"list",
"of",
"eligable",
"commits",
"and",
"runs",
"TinyCI",
"against",
"them",
"until",
"there",
"are",
"no",
"more",
"remaining"
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/scheduler.rb#L96-L104 | train |
appoxy/simple_record | lib/simple_record/results_array.rb | SimpleRecord.ResultsArray.as_json | def as_json(options = nil) #:nodoc:
# use encoder as a proxy to call as_json on all elements, to protect from circular references
encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options)
map { |v| encoder.as_json(v) }
end | ruby | def as_json(options = nil) #:nodoc:
# use encoder as a proxy to call as_json on all elements, to protect from circular references
encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options)
map { |v| encoder.as_json(v) }
end | [
"def",
"as_json",
"(",
"options",
"=",
"nil",
")",
"encoder",
"=",
"options",
"&&",
"options",
"[",
":encoder",
"]",
"||",
"ActiveSupport",
"::",
"JSON",
"::",
"Encoding",
"::",
"Encoder",
".",
"new",
"(",
"options",
")",
"map",
"{",
"|",
"v",
"|",
"... | A couple json serialization methods copied from active_support | [
"A",
"couple",
"json",
"serialization",
"methods",
"copied",
"from",
"active_support"
] | 0252a022a938f368d6853ab1ae31f77f80b9f044 | https://github.com/appoxy/simple_record/blob/0252a022a938f368d6853ab1ae31f77f80b9f044/lib/simple_record/results_array.rb#L219-L223 | train |
talis/blueprint_rb | lib/blueprint_ruby_client/api/assets_api.rb | BlueprintClient.AssetsApi.add_asset_to_node | def add_asset_to_node(namespace, type, id, asset_type, asset_id, opts = {})
data, _status_code, _headers = add_asset_to_node_with_http_info(namespace, type, id, asset_type, asset_id, opts)
return data
end | ruby | def add_asset_to_node(namespace, type, id, asset_type, asset_id, opts = {})
data, _status_code, _headers = add_asset_to_node_with_http_info(namespace, type, id, asset_type, asset_id, opts)
return data
end | [
"def",
"add_asset_to_node",
"(",
"namespace",
",",
"type",
",",
"id",
",",
"asset_type",
",",
"asset_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"add_asset_to_node_with_http_info",
"(",
"namespace",
",",
"type",
"... | Add an asset to the node. Body must be empty. Will upsert the asset if it doesn't exist
@param namespace identifier namespacing the blueprint. It must start with a letter or underscore and can only be followed by letters, numbers and underscores.
@param type subtype of Node, e.g. 'modules', 'departments... | [
"Add",
"an",
"asset",
"to",
"the",
"node",
".",
"Body",
"must",
"be",
"empty",
".",
"Will",
"upsert",
"the",
"asset",
"if",
"it",
"doesn",
"t",
"exist"
] | 0ded0734161d288ba2d81485b3d3ec82a4063e1e | https://github.com/talis/blueprint_rb/blob/0ded0734161d288ba2d81485b3d3ec82a4063e1e/lib/blueprint_ruby_client/api/assets_api.rb#L32-L35 | train |
talis/blueprint_rb | lib/blueprint_ruby_client/api/assets_api.rb | BlueprintClient.AssetsApi.delete_asset | def delete_asset(namespace, asset_id, asset_type, opts = {})
delete_asset_with_http_info(namespace, asset_id, asset_type, opts)
return nil
end | ruby | def delete_asset(namespace, asset_id, asset_type, opts = {})
delete_asset_with_http_info(namespace, asset_id, asset_type, opts)
return nil
end | [
"def",
"delete_asset",
"(",
"namespace",
",",
"asset_id",
",",
"asset_type",
",",
"opts",
"=",
"{",
"}",
")",
"delete_asset_with_http_info",
"(",
"namespace",
",",
"asset_id",
",",
"asset_type",
",",
"opts",
")",
"return",
"nil",
"end"
] | Delete an Asset
@param namespace identifier namespacing the blueprint. It must start with a letter or underscore and can only be followed by letters, numbers and underscores.
@param asset_id id of an asset
@param asset_type subtype of Asset, e.g. 'textbooks', 'digitisations', etc.
@param [Hash] opts... | [
"Delete",
"an",
"Asset"
] | 0ded0734161d288ba2d81485b3d3ec82a4063e1e | https://github.com/talis/blueprint_rb/blob/0ded0734161d288ba2d81485b3d3ec82a4063e1e/lib/blueprint_ruby_client/api/assets_api.rb#L135-L138 | train |
talis/blueprint_rb | lib/blueprint_ruby_client/api/assets_api.rb | BlueprintClient.AssetsApi.get_asset | def get_asset(namespace, asset_type, asset_id, opts = {})
data, _status_code, _headers = get_asset_with_http_info(namespace, asset_type, asset_id, opts)
return data
end | ruby | def get_asset(namespace, asset_type, asset_id, opts = {})
data, _status_code, _headers = get_asset_with_http_info(namespace, asset_type, asset_id, opts)
return data
end | [
"def",
"get_asset",
"(",
"namespace",
",",
"asset_type",
",",
"asset_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"get_asset_with_http_info",
"(",
"namespace",
",",
"asset_type",
",",
"asset_id",
",",
"opts",
")",
... | Get details of a given asset
@param namespace identifier namespacing the blueprint. It must start with a letter or underscore and can only be followed by letters, numbers and underscores.
@param asset_type subtype of Asset, e.g. 'textbooks', 'digitisations', etc.
@param asset_id id of an asset
@para... | [
"Get",
"details",
"of",
"a",
"given",
"asset"
] | 0ded0734161d288ba2d81485b3d3ec82a4063e1e | https://github.com/talis/blueprint_rb/blob/0ded0734161d288ba2d81485b3d3ec82a4063e1e/lib/blueprint_ruby_client/api/assets_api.rb#L283-L286 | train |
talis/blueprint_rb | lib/blueprint_ruby_client/api/assets_api.rb | BlueprintClient.AssetsApi.get_assets_in_node | def get_assets_in_node(namespace, type, id, opts = {})
data, _status_code, _headers = get_assets_in_node_with_http_info(namespace, type, id, opts)
return data
end | ruby | def get_assets_in_node(namespace, type, id, opts = {})
data, _status_code, _headers = get_assets_in_node_with_http_info(namespace, type, id, opts)
return data
end | [
"def",
"get_assets_in_node",
"(",
"namespace",
",",
"type",
",",
"id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"get_assets_in_node_with_http_info",
"(",
"namespace",
",",
"type",
",",
"id",
",",
"opts",
")",
"ret... | Get for assets in the relevant node
@param namespace identifier namespacing the blueprint. It must start with a letter or underscore and can only be followed by letters, numbers and underscores.
@param type subtype of Node, e.g. 'modules', 'departments', etc.
@param id id identifying a domain model
... | [
"Get",
"for",
"assets",
"in",
"the",
"relevant",
"node"
] | 0ded0734161d288ba2d81485b3d3ec82a4063e1e | https://github.com/talis/blueprint_rb/blob/0ded0734161d288ba2d81485b3d3ec82a4063e1e/lib/blueprint_ruby_client/api/assets_api.rb#L371-L374 | train |
talis/blueprint_rb | lib/blueprint_ruby_client/api/assets_api.rb | BlueprintClient.AssetsApi.remove_asset_from_node | def remove_asset_from_node(namespace, type, id, asset_type, asset_id, opts = {})
remove_asset_from_node_with_http_info(namespace, type, id, asset_type, asset_id, opts)
return nil
end | ruby | def remove_asset_from_node(namespace, type, id, asset_type, asset_id, opts = {})
remove_asset_from_node_with_http_info(namespace, type, id, asset_type, asset_id, opts)
return nil
end | [
"def",
"remove_asset_from_node",
"(",
"namespace",
",",
"type",
",",
"id",
",",
"asset_type",
",",
"asset_id",
",",
"opts",
"=",
"{",
"}",
")",
"remove_asset_from_node_with_http_info",
"(",
"namespace",
",",
"type",
",",
"id",
",",
"asset_type",
",",
"asset_id... | Remove an asset from the relevant node
@param namespace identifier namespacing the blueprint. It must start with a letter or underscore and can only be followed by letters, numbers and underscores.
@param type subtype of Node, e.g. 'modules', 'departments', etc.
@param id id identifying a domain mode... | [
"Remove",
"an",
"asset",
"from",
"the",
"relevant",
"node"
] | 0ded0734161d288ba2d81485b3d3ec82a4063e1e | https://github.com/talis/blueprint_rb/blob/0ded0734161d288ba2d81485b3d3ec82a4063e1e/lib/blueprint_ruby_client/api/assets_api.rb#L482-L485 | train |
feduxorg/filegen | lib/filegen/erb_generator.rb | Filegen.ErbGenerator.compile | def compile(source, destination)
erb = ERB.new(source.read, nil, '-')
begin
destination.puts erb.result(data.instance_binding)
rescue SyntaxError => e
raise Exceptions::ErbTemplateHasSyntaxErrors, e.message
end
end | ruby | def compile(source, destination)
erb = ERB.new(source.read, nil, '-')
begin
destination.puts erb.result(data.instance_binding)
rescue SyntaxError => e
raise Exceptions::ErbTemplateHasSyntaxErrors, e.message
end
end | [
"def",
"compile",
"(",
"source",
",",
"destination",
")",
"erb",
"=",
"ERB",
".",
"new",
"(",
"source",
".",
"read",
",",
"nil",
",",
"'-'",
")",
"begin",
"destination",
".",
"puts",
"erb",
".",
"result",
"(",
"data",
".",
"instance_binding",
")",
"r... | Create erb generator
@param [Data] data
The data class to be used within the template
Compile the template
@param [IO] source
The source template to be used
@param [IO] destination
The output io handle | [
"Create",
"erb",
"generator"
] | 08c31d3caa7fb7ac61a6544154714b9d79b88985 | https://github.com/feduxorg/filegen/blob/08c31d3caa7fb7ac61a6544154714b9d79b88985/lib/filegen/erb_generator.rb#L25-L32 | train |
dcrec1/acts_as_solr_reloaded | lib/acts_as_solr/instance_methods.rb | ActsAsSolr.InstanceMethods.solr_save | def solr_save
return true if indexing_disabled?
if evaluate_condition(:if, self)
debug "solr_save: #{self.class.name} : #{record_id(self)}"
solr_add to_solr_doc
solr_commit if configuration[:auto_commit]
true
else
solr_destroy
end
end | ruby | def solr_save
return true if indexing_disabled?
if evaluate_condition(:if, self)
debug "solr_save: #{self.class.name} : #{record_id(self)}"
solr_add to_solr_doc
solr_commit if configuration[:auto_commit]
true
else
solr_destroy
end
end | [
"def",
"solr_save",
"return",
"true",
"if",
"indexing_disabled?",
"if",
"evaluate_condition",
"(",
":if",
",",
"self",
")",
"debug",
"\"solr_save: #{self.class.name} : #{record_id(self)}\"",
"solr_add",
"to_solr_doc",
"solr_commit",
"if",
"configuration",
"[",
":auto_commit... | saves to the Solr index | [
"saves",
"to",
"the",
"Solr",
"index"
] | 20900d1339daa1f805c74c0d2203afb37edde3db | https://github.com/dcrec1/acts_as_solr_reloaded/blob/20900d1339daa1f805c74c0d2203afb37edde3db/lib/acts_as_solr/instance_methods.rb#L11-L21 | train |
dcrec1/acts_as_solr_reloaded | lib/acts_as_solr/instance_methods.rb | ActsAsSolr.InstanceMethods.to_solr_doc | def to_solr_doc
debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}"
doc = Solr::Document.new
doc.boost = validate_boost(configuration[:boost]) if configuration[:boost]
doc << {:id => solr_id,
solr_configuration[:type_field] => self.class.n... | ruby | def to_solr_doc
debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}"
doc = Solr::Document.new
doc.boost = validate_boost(configuration[:boost]) if configuration[:boost]
doc << {:id => solr_id,
solr_configuration[:type_field] => self.class.n... | [
"def",
"to_solr_doc",
"debug",
"\"to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}\"",
"doc",
"=",
"Solr",
"::",
"Document",
".",
"new",
"doc",
".",
"boost",
"=",
"validate_boost",
"(",
"configuration",
"[",
":boost",
"]",
")",
"if",
"conf... | convert instance to Solr document | [
"convert",
"instance",
"to",
"Solr",
"document"
] | 20900d1339daa1f805c74c0d2203afb37edde3db | https://github.com/dcrec1/acts_as_solr_reloaded/blob/20900d1339daa1f805c74c0d2203afb37edde3db/lib/acts_as_solr/instance_methods.rb#L37-L74 | train |
stereobooster/typograf | lib/typograf/client.rb | Typograf.Client.send_request | def send_request(text)
params = {
'text' => text.encode("cp1251"),
}
params['xml'] = @xml if @xml
request = Net::HTTP::Post.new(@url.path)
request.set_form_data(params)
begin
response = Net::HTTP.new(@url.host, @url.port).start do |http|
http.request(reques... | ruby | def send_request(text)
params = {
'text' => text.encode("cp1251"),
}
params['xml'] = @xml if @xml
request = Net::HTTP::Post.new(@url.path)
request.set_form_data(params)
begin
response = Net::HTTP.new(@url.host, @url.port).start do |http|
http.request(reques... | [
"def",
"send_request",
"(",
"text",
")",
"params",
"=",
"{",
"'text'",
"=>",
"text",
".",
"encode",
"(",
"\"cp1251\"",
")",
",",
"}",
"params",
"[",
"'xml'",
"]",
"=",
"@xml",
"if",
"@xml",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Post",
".",
"n... | Process text with remote web-service | [
"Process",
"text",
"with",
"remote",
"web",
"-",
"service"
] | c2f89dac63361e58a856801e474db55f2fb8a472 | https://github.com/stereobooster/typograf/blob/c2f89dac63361e58a856801e474db55f2fb8a472/lib/typograf/client.rb#L118-L151 | train |
dcrec1/acts_as_solr_reloaded | lib/acts_as_solr/acts_methods.rb | ActsAsSolr.ActsMethods.acts_as_solr | def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration)
$solr_indexed_models << self
extend ClassMethods
include InstanceMethods
include CommonMethods
include ParserMethods
define_solr_configuration_methods
acts_as_taggable_on :tags if options[:taggable]... | ruby | def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration)
$solr_indexed_models << self
extend ClassMethods
include InstanceMethods
include CommonMethods
include ParserMethods
define_solr_configuration_methods
acts_as_taggable_on :tags if options[:taggable]... | [
"def",
"acts_as_solr",
"(",
"options",
"=",
"{",
"}",
",",
"solr_options",
"=",
"{",
"}",
",",
"&",
"deferred_solr_configuration",
")",
"$solr_indexed_models",
"<<",
"self",
"extend",
"ClassMethods",
"include",
"InstanceMethods",
"include",
"CommonMethods",
"include... | declares a class as solr-searchable
==== options:
fields:: This option can be used to specify only the fields you'd
like to index. If not given, all the attributes from the
class will be indexed. You can also use this option to
include methods that should be indexed as fields
... | [
"declares",
"a",
"class",
"as",
"solr",
"-",
"searchable"
] | 20900d1339daa1f805c74c0d2203afb37edde3db | https://github.com/dcrec1/acts_as_solr_reloaded/blob/20900d1339daa1f805c74c0d2203afb37edde3db/lib/acts_as_solr/acts_methods.rb#L172-L195 | train |
alphasights/json-api-client | lib/json_api_client/mapper.rb | JsonApiClient.Mapper.build_linked_resources_map | def build_linked_resources_map(data)
data["linked"].each_with_object({}) do |(type, resources), obj|
obj[type] ||= {}
resources.each do |linked_resource|
obj[type][linked_resource["id"]] = linked_resource
end
end
end | ruby | def build_linked_resources_map(data)
data["linked"].each_with_object({}) do |(type, resources), obj|
obj[type] ||= {}
resources.each do |linked_resource|
obj[type][linked_resource["id"]] = linked_resource
end
end
end | [
"def",
"build_linked_resources_map",
"(",
"data",
")",
"data",
"[",
"\"linked\"",
"]",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"type",
",",
"resources",
")",
",",
"obj",
"|",
"obj",
"[",
"type",
"]",
"||=",
"{",
"}",
"resources",
... | Builds a map to enable getting references by type and id
eg.
{
"users" => {
"1" => { "id" => "1", "name" => "John" },
"5" => { "id" => "5", "name" => "Walter" },
}
} | [
"Builds",
"a",
"map",
"to",
"enable",
"getting",
"references",
"by",
"type",
"and",
"id"
] | 00598445ea200f5db352fd50ce3a7e5ae3a37b9e | https://github.com/alphasights/json-api-client/blob/00598445ea200f5db352fd50ce3a7e5ae3a37b9e/lib/json_api_client/mapper.rb#L72-L79 | train |
alphasights/json-api-client | lib/json_api_client/mapper.rb | JsonApiClient.Mapper.build_link_type_map | def build_link_type_map(data)
data["links"].each_with_object({}) do |(key, value), obj|
association = key.split(".").last
obj[association] = value["type"].pluralize
end
end | ruby | def build_link_type_map(data)
data["links"].each_with_object({}) do |(key, value), obj|
association = key.split(".").last
obj[association] = value["type"].pluralize
end
end | [
"def",
"build_link_type_map",
"(",
"data",
")",
"data",
"[",
"\"links\"",
"]",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"obj",
"|",
"association",
"=",
"key",
".",
"split",
"(",
"\".\"",
")",
".",
... | Builds a map to translate references to types
eg.
{ "author" => "users", "comments" => "comments" } | [
"Builds",
"a",
"map",
"to",
"translate",
"references",
"to",
"types"
] | 00598445ea200f5db352fd50ce3a7e5ae3a37b9e | https://github.com/alphasights/json-api-client/blob/00598445ea200f5db352fd50ce3a7e5ae3a37b9e/lib/json_api_client/mapper.rb#L85-L90 | train |
redding/dk | lib/dk/tree_runner.rb | Dk.TreeRunner.build_and_run_task | def build_and_run_task(task_class, params = nil)
task_run = TaskRun.new(task_class, params)
@task_run_stack.last.runs << task_run
@task_run_stack.push(task_run)
task = super(task_class, params)
@task_run_stack.pop
task
end | ruby | def build_and_run_task(task_class, params = nil)
task_run = TaskRun.new(task_class, params)
@task_run_stack.last.runs << task_run
@task_run_stack.push(task_run)
task = super(task_class, params)
@task_run_stack.pop
task
end | [
"def",
"build_and_run_task",
"(",
"task_class",
",",
"params",
"=",
"nil",
")",
"task_run",
"=",
"TaskRun",
".",
"new",
"(",
"task_class",
",",
"params",
")",
"@task_run_stack",
".",
"last",
".",
"runs",
"<<",
"task_run",
"@task_run_stack",
".",
"push",
"(",... | track all task runs | [
"track",
"all",
"task",
"runs"
] | 9b6122ce815467c698811014c01518cca539946e | https://github.com/redding/dk/blob/9b6122ce815467c698811014c01518cca539946e/lib/dk/tree_runner.rb#L41-L49 | train |
JonnieCache/tinyci | lib/tinyci/runner.rb | TinyCI.Runner.run! | def run!
begin
ensure_path target_path
setup_log
log_info "Commit: #{@commit}"
log_info "Cleaning..."
clean
log_info "Exporting..."
ensure_path export_path
export
begin
load_config
rescue ... | ruby | def run!
begin
ensure_path target_path
setup_log
log_info "Commit: #{@commit}"
log_info "Cleaning..."
clean
log_info "Exporting..."
ensure_path export_path
export
begin
load_config
rescue ... | [
"def",
"run!",
"begin",
"ensure_path",
"target_path",
"setup_log",
"log_info",
"\"Commit: #{@commit}\"",
"log_info",
"\"Cleaning...\"",
"clean",
"log_info",
"\"Exporting...\"",
"ensure_path",
"export_path",
"export",
"begin",
"load_config",
"rescue",
"ConfigMissingError",
"=>... | Constructor, allows injection of generic configuration params.
@param working_dir [String] The working directory to execute against.
@param commit [String] SHA1 of git object to run against
@param logger [Logger] Logger object
@param time [Time] Override time of object creation. Used solely for testing at this tim... | [
"Constructor",
"allows",
"injection",
"of",
"generic",
"configuration",
"params",
"."
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/runner.rb#L48-L126 | train |
JonnieCache/tinyci | lib/tinyci/runner.rb | TinyCI.Runner.instantiate_builder | def instantiate_builder
klass = TinyCI::Builders.const_get(@config[:builder][:class])
klass.new(@config[:builder][:config].merge(target: export_path), logger: @logger)
end | ruby | def instantiate_builder
klass = TinyCI::Builders.const_get(@config[:builder][:class])
klass.new(@config[:builder][:config].merge(target: export_path), logger: @logger)
end | [
"def",
"instantiate_builder",
"klass",
"=",
"TinyCI",
"::",
"Builders",
".",
"const_get",
"(",
"@config",
"[",
":builder",
"]",
"[",
":class",
"]",
")",
"klass",
".",
"new",
"(",
"@config",
"[",
":builder",
"]",
"[",
":config",
"]",
".",
"merge",
"(",
... | Instantiate the Builder object according to the class named in the config | [
"Instantiate",
"the",
"Builder",
"object",
"according",
"to",
"the",
"class",
"named",
"in",
"the",
"config"
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/runner.rb#L158-L161 | train |
JonnieCache/tinyci | lib/tinyci/runner.rb | TinyCI.Runner.instantiate_hooker | def instantiate_hooker
return nil unless @config[:hooker].is_a? Hash
klass = TinyCI::Hookers.const_get(@config[:hooker][:class])
klass.new(@config[:hooker][:config].merge(target: export_path), logger: @logger)
end | ruby | def instantiate_hooker
return nil unless @config[:hooker].is_a? Hash
klass = TinyCI::Hookers.const_get(@config[:hooker][:class])
klass.new(@config[:hooker][:config].merge(target: export_path), logger: @logger)
end | [
"def",
"instantiate_hooker",
"return",
"nil",
"unless",
"@config",
"[",
":hooker",
"]",
".",
"is_a?",
"Hash",
"klass",
"=",
"TinyCI",
"::",
"Hookers",
".",
"const_get",
"(",
"@config",
"[",
":hooker",
"]",
"[",
":class",
"]",
")",
"klass",
".",
"new",
"(... | Instantiate the Hooker object according to the class named in the config | [
"Instantiate",
"the",
"Hooker",
"object",
"according",
"to",
"the",
"class",
"named",
"in",
"the",
"config"
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/runner.rb#L170-L175 | train |
sosedoff/grooveshark | lib/grooveshark/playlist.rb | Grooveshark.Playlist.load_songs | def load_songs
@songs = []
playlist = @client.request('getPlaylistByID', playlistID: @id)
@songs = playlist['songs'].map! do |s|
Song.new(s)
end if playlist.key?('songs')
@songs
end | ruby | def load_songs
@songs = []
playlist = @client.request('getPlaylistByID', playlistID: @id)
@songs = playlist['songs'].map! do |s|
Song.new(s)
end if playlist.key?('songs')
@songs
end | [
"def",
"load_songs",
"@songs",
"=",
"[",
"]",
"playlist",
"=",
"@client",
".",
"request",
"(",
"'getPlaylistByID'",
",",
"playlistID",
":",
"@id",
")",
"@songs",
"=",
"playlist",
"[",
"'songs'",
"]",
".",
"map!",
"do",
"|",
"s",
"|",
"Song",
".",
"new"... | Fetch playlist songs | [
"Fetch",
"playlist",
"songs"
] | e55686c620c13848fa6d918cc2980fd44cf40e35 | https://github.com/sosedoff/grooveshark/blob/e55686c620c13848fa6d918cc2980fd44cf40e35/lib/grooveshark/playlist.rb#L24-L31 | train |
PRX/audio_monster | lib/audio_monster/monster.rb | AudioMonster.Monster.create_wav_wrapped_mpeg | def create_wav_wrapped_mpeg(mpeg_path, result_path, options={})
options.to_options!
start_at = get_datetime_for_option(options[:start_at])
end_at = get_datetime_for_option(options[:end_at])
wav_wrapped_mpeg = NuWav::WaveFile.from_mpeg(mpeg_path)
cart = wav_wrapped_mpeg.chunks[:cart]
... | ruby | def create_wav_wrapped_mpeg(mpeg_path, result_path, options={})
options.to_options!
start_at = get_datetime_for_option(options[:start_at])
end_at = get_datetime_for_option(options[:end_at])
wav_wrapped_mpeg = NuWav::WaveFile.from_mpeg(mpeg_path)
cart = wav_wrapped_mpeg.chunks[:cart]
... | [
"def",
"create_wav_wrapped_mpeg",
"(",
"mpeg_path",
",",
"result_path",
",",
"options",
"=",
"{",
"}",
")",
"options",
".",
"to_options!",
"start_at",
"=",
"get_datetime_for_option",
"(",
"options",
"[",
":start_at",
"]",
")",
"end_at",
"=",
"get_datetime_for_opti... | need start_at, ends_on | [
"need",
"start_at",
"ends_on"
] | 51654ec0937258902c0c7af1f7d230c5cd2c932b | https://github.com/PRX/audio_monster/blob/51654ec0937258902c0c7af1f7d230c5cd2c932b/lib/audio_monster/monster.rb#L566-L591 | train |
PRX/audio_monster | lib/audio_monster/monster.rb | AudioMonster.Monster.run_command | def run_command(command, options={})
timeout = options[:timeout] || 7200
# default to adding a nice 13 if nothing specified
nice = if options.key?(:nice)
(options[:nice] == 'n') ? '' : "nice -n #{options[:nice]} "
else
'nice -n 19 '
end
echo_return = (options.key?(:... | ruby | def run_command(command, options={})
timeout = options[:timeout] || 7200
# default to adding a nice 13 if nothing specified
nice = if options.key?(:nice)
(options[:nice] == 'n') ? '' : "nice -n #{options[:nice]} "
else
'nice -n 19 '
end
echo_return = (options.key?(:... | [
"def",
"run_command",
"(",
"command",
",",
"options",
"=",
"{",
"}",
")",
"timeout",
"=",
"options",
"[",
":timeout",
"]",
"||",
"7200",
"nice",
"=",
"if",
"options",
".",
"key?",
"(",
":nice",
")",
"(",
"options",
"[",
":nice",
"]",
"==",
"'n'",
"... | Pass the command to run, and a timeout | [
"Pass",
"the",
"command",
"to",
"run",
"and",
"a",
"timeout"
] | 51654ec0937258902c0c7af1f7d230c5cd2c932b | https://github.com/PRX/audio_monster/blob/51654ec0937258902c0c7af1f7d230c5cd2c932b/lib/audio_monster/monster.rb#L903-L943 | train |
GetEmerson/emerson-rb | lib/emerson/responder.rb | Emerson.Responder.key_for_primary | def key_for_primary
@_key_for_primary ||= if options[:as]
options[:as]
else
controller_name = controller.controller_name
(resource.respond_to?(:each) ? controller_name : controller_name.singularize).intern
end
end | ruby | def key_for_primary
@_key_for_primary ||= if options[:as]
options[:as]
else
controller_name = controller.controller_name
(resource.respond_to?(:each) ? controller_name : controller_name.singularize).intern
end
end | [
"def",
"key_for_primary",
"@_key_for_primary",
"||=",
"if",
"options",
"[",
":as",
"]",
"options",
"[",
":as",
"]",
"else",
"controller_name",
"=",
"controller",
".",
"controller_name",
"(",
"resource",
".",
"respond_to?",
"(",
":each",
")",
"?",
"controller_nam... | The primary resource is keyed per the request. | [
"The",
"primary",
"resource",
"is",
"keyed",
"per",
"the",
"request",
"."
] | 184facb853e69fdf79c977fb7573f350844603b5 | https://github.com/GetEmerson/emerson-rb/blob/184facb853e69fdf79c977fb7573f350844603b5/lib/emerson/responder.rb#L150-L157 | train |
juandebravo/quora-client | lib/quora/client.rb | Quora.Client.get | def get(field, filter = true)
if field.nil? or !field.instance_of?(String)
raise ArgumentError, "Field value must be a string"
end
resp = http.get("#{BASEPATH}?fields=#{field}", headers)
data = resp.body[RESP_PREFIX.length..-1]
data = JSON.parse(data)
if filter && data.has_ke... | ruby | def get(field, filter = true)
if field.nil? or !field.instance_of?(String)
raise ArgumentError, "Field value must be a string"
end
resp = http.get("#{BASEPATH}?fields=#{field}", headers)
data = resp.body[RESP_PREFIX.length..-1]
data = JSON.parse(data)
if filter && data.has_ke... | [
"def",
"get",
"(",
"field",
",",
"filter",
"=",
"true",
")",
"if",
"field",
".",
"nil?",
"or",
"!",
"field",
".",
"instance_of?",
"(",
"String",
")",
"raise",
"ArgumentError",
",",
"\"Field value must be a string\"",
"end",
"resp",
"=",
"http",
".",
"get",... | Base method to send a request to Quora API.
@param [required, string] supported field (or multiple fields CSV) to retrieve
@param [optional, bool] filter if field is a key in result hash, only this
value is returned | [
"Base",
"method",
"to",
"send",
"a",
"request",
"to",
"Quora",
"API",
"."
] | eb09bbb70aef5c5c77887dc0b689ccb422fba49f | https://github.com/juandebravo/quora-client/blob/eb09bbb70aef5c5c77887dc0b689ccb422fba49f/lib/quora/client.rb#L83-L95 | train |
juandebravo/quora-client | lib/quora/client.rb | Quora.Client.method_missing | def method_missing(method_id, *arguments, &block)
if method_id.to_s =~ /^get_[\w]+/
self.class.send :define_method, method_id do
field = method_id.to_s[4..-1]
get(field)
end
self.send(method_id)
else
super
end
end | ruby | def method_missing(method_id, *arguments, &block)
if method_id.to_s =~ /^get_[\w]+/
self.class.send :define_method, method_id do
field = method_id.to_s[4..-1]
get(field)
end
self.send(method_id)
else
super
end
end | [
"def",
"method_missing",
"(",
"method_id",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"if",
"method_id",
".",
"to_s",
"=~",
"/",
"\\w",
"/",
"self",
".",
"class",
".",
"send",
":define_method",
",",
"method_id",
"do",
"field",
"=",
"method_id",
".",
... | Override method_missing so any method that starts with "get_" will be
defined.
i.e.
client.get_profile
will generate =>
def get_profile
get("profile")
end | [
"Override",
"method_missing",
"so",
"any",
"method",
"that",
"starts",
"with",
"get_",
"will",
"be",
"defined",
"."
] | eb09bbb70aef5c5c77887dc0b689ccb422fba49f | https://github.com/juandebravo/quora-client/blob/eb09bbb70aef5c5c77887dc0b689ccb422fba49f/lib/quora/client.rb#L131-L141 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/request_reporter/controllers.rb | UnionStationHooks.RequestReporter.log_controller_action_block | def log_controller_action_block(options = {})
if null?
do_nothing_on_null(:log_controller_action_block)
yield
else
build_full_controller_action_string(options)
has_error = true
begin_time = UnionStationHooks.now
begin
result = yield
has_err... | ruby | def log_controller_action_block(options = {})
if null?
do_nothing_on_null(:log_controller_action_block)
yield
else
build_full_controller_action_string(options)
has_error = true
begin_time = UnionStationHooks.now
begin
result = yield
has_err... | [
"def",
"log_controller_action_block",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"null?",
"do_nothing_on_null",
"(",
":log_controller_action_block",
")",
"yield",
"else",
"build_full_controller_action_string",
"(",
"options",
")",
"has_error",
"=",
"true",
"begin_time",
... | Logging controller-related information
Logs that you are calling a web framework controller action. Of course,
you should only call this if your web framework has the concept of
controller actions. For example Rails does, but Sinatra and Grape
don't.
This form takes an options hash as well as a block. You can pa... | [
"Logging",
"controller",
"-",
"related",
"information",
"Logs",
"that",
"you",
"are",
"calling",
"a",
"web",
"framework",
"controller",
"action",
".",
"Of",
"course",
"you",
"should",
"only",
"call",
"this",
"if",
"your",
"web",
"framework",
"has",
"the",
"c... | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/request_reporter/controllers.rb#L75-L97 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/request_reporter/controllers.rb | UnionStationHooks.RequestReporter.log_controller_action | def log_controller_action(options)
return do_nothing_on_null(:log_controller_action) if null?
Utils.require_key(options, :begin_time)
Utils.require_key(options, :end_time)
if options[:controller_name]
build_full_controller_action_string(options)
@transaction.message("Controller ... | ruby | def log_controller_action(options)
return do_nothing_on_null(:log_controller_action) if null?
Utils.require_key(options, :begin_time)
Utils.require_key(options, :end_time)
if options[:controller_name]
build_full_controller_action_string(options)
@transaction.message("Controller ... | [
"def",
"log_controller_action",
"(",
"options",
")",
"return",
"do_nothing_on_null",
"(",
":log_controller_action",
")",
"if",
"null?",
"Utils",
".",
"require_key",
"(",
"options",
",",
":begin_time",
")",
"Utils",
".",
"require_key",
"(",
"options",
",",
":end_ti... | Logs that you are calling a web framework controller action. Of course,
you should only call this if your web framework has the concept of
controller actions. For example Rails does, but Sinatra and Grape
don't.
You can pass additional information about the web framework controller
action, which will be logged.
... | [
"Logs",
"that",
"you",
"are",
"calling",
"a",
"web",
"framework",
"controller",
"action",
".",
"Of",
"course",
"you",
"should",
"only",
"call",
"this",
"if",
"your",
"web",
"framework",
"has",
"the",
"concept",
"of",
"controller",
"actions",
".",
"For",
"e... | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/request_reporter/controllers.rb#L153-L167 | train |
MrMicrowaveOven/zadt | lib/zadt/AbstractDataTypes/Graph/graph.rb | Zadt.Graph.remove_vertex | def remove_vertex(vertex)
# The vertex must exist
raise "not a vertex" unless vertex.is_a?(Vertex)
if !vertex
raise "Vertex does not exist"
# The vertex must not be connected to anything
elsif !vertex.connections.empty?
raise "Vertex has edges. Break them first."
# I... | ruby | def remove_vertex(vertex)
# The vertex must exist
raise "not a vertex" unless vertex.is_a?(Vertex)
if !vertex
raise "Vertex does not exist"
# The vertex must not be connected to anything
elsif !vertex.connections.empty?
raise "Vertex has edges. Break them first."
# I... | [
"def",
"remove_vertex",
"(",
"vertex",
")",
"raise",
"\"not a vertex\"",
"unless",
"vertex",
".",
"is_a?",
"(",
"Vertex",
")",
"if",
"!",
"vertex",
"raise",
"\"Vertex does not exist\"",
"elsif",
"!",
"vertex",
".",
"connections",
".",
"empty?",
"raise",
"\"Verte... | Remove a vertex | [
"Remove",
"a",
"vertex"
] | 789420b1e05f7545f886309c07b235dd560f6696 | https://github.com/MrMicrowaveOven/zadt/blob/789420b1e05f7545f886309c07b235dd560f6696/lib/zadt/AbstractDataTypes/Graph/graph.rb#L31-L43 | train |
MrMicrowaveOven/zadt | lib/zadt/AbstractDataTypes/Graph/graph.rb | Zadt.Graph.make_connection | def make_connection(v1, v2)
raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
raise "already connected" if is_connected?(v1, v2)
# Make new edge
edge = Edge.new(v1, v2)
# Connect the two using the vertex method "connect"
v1.connect(v2, edge)
v2.connect(v1, edge)
... | ruby | def make_connection(v1, v2)
raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
raise "already connected" if is_connected?(v1, v2)
# Make new edge
edge = Edge.new(v1, v2)
# Connect the two using the vertex method "connect"
v1.connect(v2, edge)
v2.connect(v1, edge)
... | [
"def",
"make_connection",
"(",
"v1",
",",
"v2",
")",
"raise",
"\"not a vertex\"",
"unless",
"v1",
".",
"is_a?",
"(",
"Vertex",
")",
"&&",
"v2",
".",
"is_a?",
"(",
"Vertex",
")",
"raise",
"\"already connected\"",
"if",
"is_connected?",
"(",
"v1",
",",
"v2",... | Make an edge between two vertices | [
"Make",
"an",
"edge",
"between",
"two",
"vertices"
] | 789420b1e05f7545f886309c07b235dd560f6696 | https://github.com/MrMicrowaveOven/zadt/blob/789420b1e05f7545f886309c07b235dd560f6696/lib/zadt/AbstractDataTypes/Graph/graph.rb#L46-L58 | train |
MrMicrowaveOven/zadt | lib/zadt/AbstractDataTypes/Graph/graph.rb | Zadt.Graph.find_connection | def find_connection(v1, v2)
raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
raise "Vertices not connected" if !is_connected?(v1, v2)
connection = v1.edges.select {|edge| edge.connection.include?(v2)}
raise "Error finding connection" if connection.length > 1
connection.firs... | ruby | def find_connection(v1, v2)
raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
raise "Vertices not connected" if !is_connected?(v1, v2)
connection = v1.edges.select {|edge| edge.connection.include?(v2)}
raise "Error finding connection" if connection.length > 1
connection.firs... | [
"def",
"find_connection",
"(",
"v1",
",",
"v2",
")",
"raise",
"\"not a vertex\"",
"unless",
"v1",
".",
"is_a?",
"(",
"Vertex",
")",
"&&",
"v2",
".",
"is_a?",
"(",
"Vertex",
")",
"raise",
"\"Vertices not connected\"",
"if",
"!",
"is_connected?",
"(",
"v1",
... | Find the edge connecting two vertices | [
"Find",
"the",
"edge",
"connecting",
"two",
"vertices"
] | 789420b1e05f7545f886309c07b235dd560f6696 | https://github.com/MrMicrowaveOven/zadt/blob/789420b1e05f7545f886309c07b235dd560f6696/lib/zadt/AbstractDataTypes/Graph/graph.rb#L61-L67 | train |
MrMicrowaveOven/zadt | lib/zadt/AbstractDataTypes/Graph/graph.rb | Zadt.Graph.is_connected? | def is_connected?(v1, v2)
raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
v1.connections.include?(v2)
end | ruby | def is_connected?(v1, v2)
raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
v1.connections.include?(v2)
end | [
"def",
"is_connected?",
"(",
"v1",
",",
"v2",
")",
"raise",
"\"not a vertex\"",
"unless",
"v1",
".",
"is_a?",
"(",
"Vertex",
")",
"&&",
"v2",
".",
"is_a?",
"(",
"Vertex",
")",
"v1",
".",
"connections",
".",
"include?",
"(",
"v2",
")",
"end"
] | Returns whether two vertices are connected | [
"Returns",
"whether",
"two",
"vertices",
"are",
"connected"
] | 789420b1e05f7545f886309c07b235dd560f6696 | https://github.com/MrMicrowaveOven/zadt/blob/789420b1e05f7545f886309c07b235dd560f6696/lib/zadt/AbstractDataTypes/Graph/graph.rb#L70-L73 | train |
dcrec1/acts_as_solr_reloaded | lib/acts_as_solr/class_methods.rb | ActsAsSolr.ClassMethods.find_by_solr | def find_by_solr(query, options={})
data = parse_query(query, options)
return parse_results(data, options)
end | ruby | def find_by_solr(query, options={})
data = parse_query(query, options)
return parse_results(data, options)
end | [
"def",
"find_by_solr",
"(",
"query",
",",
"options",
"=",
"{",
"}",
")",
"data",
"=",
"parse_query",
"(",
"query",
",",
"options",
")",
"return",
"parse_results",
"(",
"data",
",",
"options",
")",
"end"
] | Finds instances of a model. Terms are ANDed by default, can be overwritten
by using OR between terms
Here's a sample (untested) code for your controller:
def search
results = Book.find_by_solr params[:query]
end
For specific fields searching use :filter_queries options
====options:
offset:: - The first... | [
"Finds",
"instances",
"of",
"a",
"model",
".",
"Terms",
"are",
"ANDed",
"by",
"default",
"can",
"be",
"overwritten",
"by",
"using",
"OR",
"between",
"terms"
] | 20900d1339daa1f805c74c0d2203afb37edde3db | https://github.com/dcrec1/acts_as_solr_reloaded/blob/20900d1339daa1f805c74c0d2203afb37edde3db/lib/acts_as_solr/class_methods.rb#L121-L124 | train |
dcrec1/acts_as_solr_reloaded | lib/acts_as_solr/class_methods.rb | ActsAsSolr.ClassMethods.rebuild_solr_index | def rebuild_solr_index(batch_size=300, options = {}, &finder)
finder ||= lambda do |ar, sql_options|
ar.all sql_options.merge!({:order => self.primary_key, :include => configuration[:solr_includes].keys})
end
start_time = Time.now
options[:offset] ||= 0
options[:threads] ||= 2
... | ruby | def rebuild_solr_index(batch_size=300, options = {}, &finder)
finder ||= lambda do |ar, sql_options|
ar.all sql_options.merge!({:order => self.primary_key, :include => configuration[:solr_includes].keys})
end
start_time = Time.now
options[:offset] ||= 0
options[:threads] ||= 2
... | [
"def",
"rebuild_solr_index",
"(",
"batch_size",
"=",
"300",
",",
"options",
"=",
"{",
"}",
",",
"&",
"finder",
")",
"finder",
"||=",
"lambda",
"do",
"|",
"ar",
",",
"sql_options",
"|",
"ar",
".",
"all",
"sql_options",
".",
"merge!",
"(",
"{",
":order",... | It's used to rebuild the Solr index for a specific model.
Book.rebuild_solr_index
If batch_size is greater than 0, adds will be done in batches.
NOTE: If using sqlserver, be sure to use a finder with an explicit order.
Non-edge versions of rails do not handle pagination correctly for sqlserver
without an order c... | [
"It",
"s",
"used",
"to",
"rebuild",
"the",
"Solr",
"index",
"for",
"a",
"specific",
"model",
".",
"Book",
".",
"rebuild_solr_index"
] | 20900d1339daa1f805c74c0d2203afb37edde3db | https://github.com/dcrec1/acts_as_solr_reloaded/blob/20900d1339daa1f805c74c0d2203afb37edde3db/lib/acts_as_solr/class_methods.rb#L205-L274 | train |
grosser/s3_meta_sync | lib/s3_meta_sync/syncer.rb | S3MetaSync.Syncer.delete_old_temp_folders | def delete_old_temp_folders
path = File.join(Dir.tmpdir, STAGING_AREA_PREFIX + '*')
day = 24 * 60 * 60
dirs = Dir.glob(path)
dirs.select! { |dir| Time.now.utc - File.ctime(dir).utc > day } # only stale ones
removed = dirs.each { |dir| FileUtils.rm_rf(dir) }
log "Removed #{removed} ... | ruby | def delete_old_temp_folders
path = File.join(Dir.tmpdir, STAGING_AREA_PREFIX + '*')
day = 24 * 60 * 60
dirs = Dir.glob(path)
dirs.select! { |dir| Time.now.utc - File.ctime(dir).utc > day } # only stale ones
removed = dirs.each { |dir| FileUtils.rm_rf(dir) }
log "Removed #{removed} ... | [
"def",
"delete_old_temp_folders",
"path",
"=",
"File",
".",
"join",
"(",
"Dir",
".",
"tmpdir",
",",
"STAGING_AREA_PREFIX",
"+",
"'*'",
")",
"day",
"=",
"24",
"*",
"60",
"*",
"60",
"dirs",
"=",
"Dir",
".",
"glob",
"(",
"path",
")",
"dirs",
".",
"selec... | Sometimes SIGTERM causes Dir.mktmpdir to not properly delete the temp folder
Remove 1 day old folders | [
"Sometimes",
"SIGTERM",
"causes",
"Dir",
".",
"mktmpdir",
"to",
"not",
"properly",
"delete",
"the",
"temp",
"folder",
"Remove",
"1",
"day",
"old",
"folders"
] | 52178496c15aa9b1d868064cbf72e452193d757e | https://github.com/grosser/s3_meta_sync/blob/52178496c15aa9b1d868064cbf72e452193d757e/lib/s3_meta_sync/syncer.rb#L97-L106 | train |
coupler/linkage | lib/linkage/field_set.rb | Linkage.FieldSet.fetch_key | def fetch_key(key)
string_key = key.to_s
keys.detect { |k| k.to_s.casecmp(string_key) == 0 }
end | ruby | def fetch_key(key)
string_key = key.to_s
keys.detect { |k| k.to_s.casecmp(string_key) == 0 }
end | [
"def",
"fetch_key",
"(",
"key",
")",
"string_key",
"=",
"key",
".",
"to_s",
"keys",
".",
"detect",
"{",
"|",
"k",
"|",
"k",
".",
"to_s",
".",
"casecmp",
"(",
"string_key",
")",
"==",
"0",
"}",
"end"
] | Returns a key that matches the parameter in a case-insensitive manner.
@param key [String, Symbol]
@return [Symbol] | [
"Returns",
"a",
"key",
"that",
"matches",
"the",
"parameter",
"in",
"a",
"case",
"-",
"insensitive",
"manner",
"."
] | 2f208ae0709a141a6a8e5ba3bc6914677e986cb0 | https://github.com/coupler/linkage/blob/2f208ae0709a141a6a8e5ba3bc6914677e986cb0/lib/linkage/field_set.rb#L38-L41 | train |
appoxy/simple_record | lib/simple_record/translations.rb | SimpleRecord.Translations.ruby_to_sdb | def ruby_to_sdb(name, value)
return nil if value.nil?
name = name.to_s
# puts "Converting #{name} to sdb value=#{value}"
# puts "atts_local=" + defined_attributes_local.inspect
att_meta = get_att_meta(name)
if value.is_a? Array
ret = value.collect { |x| ruby_t... | ruby | def ruby_to_sdb(name, value)
return nil if value.nil?
name = name.to_s
# puts "Converting #{name} to sdb value=#{value}"
# puts "atts_local=" + defined_attributes_local.inspect
att_meta = get_att_meta(name)
if value.is_a? Array
ret = value.collect { |x| ruby_t... | [
"def",
"ruby_to_sdb",
"(",
"name",
",",
"value",
")",
"return",
"nil",
"if",
"value",
".",
"nil?",
"name",
"=",
"name",
".",
"to_s",
"att_meta",
"=",
"get_att_meta",
"(",
"name",
")",
"if",
"value",
".",
"is_a?",
"Array",
"ret",
"=",
"value",
".",
"c... | Time to second precision | [
"Time",
"to",
"second",
"precision"
] | 0252a022a938f368d6853ab1ae31f77f80b9f044 | https://github.com/appoxy/simple_record/blob/0252a022a938f368d6853ab1ae31f77f80b9f044/lib/simple_record/translations.rb#L22-L53 | train |
appoxy/simple_record | lib/simple_record/translations.rb | SimpleRecord.Translations.sdb_to_ruby | def sdb_to_ruby(name, value)
# puts 'sdb_to_ruby arg=' + name.inspect + ' - ' + name.class.name + ' - value=' + value.to_s
return nil if value.nil?
att_meta = get_att_meta(name)
if att_meta.options
if att_meta.options[:encrypted]
value = Translations.decrypt(value, att_me... | ruby | def sdb_to_ruby(name, value)
# puts 'sdb_to_ruby arg=' + name.inspect + ' - ' + name.class.name + ' - value=' + value.to_s
return nil if value.nil?
att_meta = get_att_meta(name)
if att_meta.options
if att_meta.options[:encrypted]
value = Translations.decrypt(value, att_me... | [
"def",
"sdb_to_ruby",
"(",
"name",
",",
"value",
")",
"return",
"nil",
"if",
"value",
".",
"nil?",
"att_meta",
"=",
"get_att_meta",
"(",
"name",
")",
"if",
"att_meta",
".",
"options",
"if",
"att_meta",
".",
"options",
"[",
":encrypted",
"]",
"value",
"="... | Convert value from SimpleDB String version to real ruby value. | [
"Convert",
"value",
"from",
"SimpleDB",
"String",
"version",
"to",
"real",
"ruby",
"value",
"."
] | 0252a022a938f368d6853ab1ae31f77f80b9f044 | https://github.com/appoxy/simple_record/blob/0252a022a938f368d6853ab1ae31f77f80b9f044/lib/simple_record/translations.rb#L57-L113 | train |
jimmyz/familysearch-rb | lib/familysearch/url_template.rb | FamilySearch.URLTemplate.head | def head(template_values)
raise FamilySearch::Error::MethodNotAllowed unless allow.include?('head')
template_values = validate_values(template_values)
t = Addressable::Template.new(@template)
url = t.expand(template_values).to_s
@client.head url
end | ruby | def head(template_values)
raise FamilySearch::Error::MethodNotAllowed unless allow.include?('head')
template_values = validate_values(template_values)
t = Addressable::Template.new(@template)
url = t.expand(template_values).to_s
@client.head url
end | [
"def",
"head",
"(",
"template_values",
")",
"raise",
"FamilySearch",
"::",
"Error",
"::",
"MethodNotAllowed",
"unless",
"allow",
".",
"include?",
"(",
"'head'",
")",
"template_values",
"=",
"validate_values",
"(",
"template_values",
")",
"t",
"=",
"Addressable",
... | Calls HTTP HEAD on the URL template. It takes the +template_values+ hash and merges the values into the template.
A template will contain a URL like this:
https://sandbox.familysearch.org/platform/tree/persons-with-relationships{?access_token,person}
or
https://sandbox.familysearch.org/platform/tree/persons/{p... | [
"Calls",
"HTTP",
"HEAD",
"on",
"the",
"URL",
"template",
".",
"It",
"takes",
"the",
"+",
"template_values",
"+",
"hash",
"and",
"merges",
"the",
"values",
"into",
"the",
"template",
"."
] | be6ae2ea6f4ad4734a3355fa5f8fdf8d33f0c7a1 | https://github.com/jimmyz/familysearch-rb/blob/be6ae2ea6f4ad4734a3355fa5f8fdf8d33f0c7a1/lib/familysearch/url_template.rb#L122-L128 | train |
LAS-IT/ps_utilities | lib/ps_utilities/pre_built_get.rb | PsUtilities.PreBuiltGet.get_one_student | def get_one_student(params)
# api_path = "/ws/v1/district/student/{dcid}?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
ps_dcid = params[:dcid] || params[:dc_id] || params[:id]
api_path = "/ws/v1/student/#{ps_dcid.to_i}"
options = { query:
{ "ex... | ruby | def get_one_student(params)
# api_path = "/ws/v1/district/student/{dcid}?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
ps_dcid = params[:dcid] || params[:dc_id] || params[:id]
api_path = "/ws/v1/student/#{ps_dcid.to_i}"
options = { query:
{ "ex... | [
"def",
"get_one_student",
"(",
"params",
")",
"ps_dcid",
"=",
"params",
"[",
":dcid",
"]",
"||",
"params",
"[",
":dc_id",
"]",
"||",
"params",
"[",
":id",
"]",
"api_path",
"=",
"\"/ws/v1/student/#{ps_dcid.to_i}\"",
"options",
"=",
"{",
"query",
":",
"{",
"... | retrieves all individual student's details - you must use the DCID !!!
@param params [Hash] - use either: {dcid: "12345"} or {id: "12345"}
@return [Hash] - in the format of:
{ :student=>
{ "@expansions"=> "demographics, addresses, alerts, phones, school_enrollment, ethnicity_race, contact, contact_info, initial_e... | [
"retrieves",
"all",
"individual",
"student",
"s",
"details",
"-",
"you",
"must",
"use",
"the",
"DCID",
"!!!"
] | 85fbb528d982b66ca706de5fdb70b4410f21e637 | https://github.com/LAS-IT/ps_utilities/blob/85fbb528d982b66ca706de5fdb70b4410f21e637/lib/ps_utilities/pre_built_get.rb#L108-L123 | train |
LAS-IT/ps_utilities | lib/ps_utilities/pre_built_get.rb | PsUtilities.PreBuiltGet.build_query | def build_query(params)
query = []
query << "school_enrollment.enroll_status_code==#{params[:status_code]}" if params.has_key?(:status_code)
query << "school_enrollment.enroll_status==#{params[:enroll_status]}" if params.has_key?(:enroll_status)
query << "student_username==#{params[:username... | ruby | def build_query(params)
query = []
query << "school_enrollment.enroll_status_code==#{params[:status_code]}" if params.has_key?(:status_code)
query << "school_enrollment.enroll_status==#{params[:enroll_status]}" if params.has_key?(:enroll_status)
query << "student_username==#{params[:username... | [
"def",
"build_query",
"(",
"params",
")",
"query",
"=",
"[",
"]",
"query",
"<<",
"\"school_enrollment.enroll_status_code==#{params[:status_code]}\"",
"if",
"params",
".",
"has_key?",
"(",
":status_code",
")",
"query",
"<<",
"\"school_enrollment.enroll_status==#{params[:enro... | build the api query - you can use splats to match any character
@param params [Hash] - valid keys include: :status_code (or :enroll_status), :username, :last_name, :first_name, :student_id (or :local_id), :id (or :dcid)
@return [String] - "id==345;name.last_name==BA*" | [
"build",
"the",
"api",
"query",
"-",
"you",
"can",
"use",
"splats",
"to",
"match",
"any",
"character"
] | 85fbb528d982b66ca706de5fdb70b4410f21e637 | https://github.com/LAS-IT/ps_utilities/blob/85fbb528d982b66ca706de5fdb70b4410f21e637/lib/ps_utilities/pre_built_get.rb#L131-L144 | train |
JonnieCache/tinyci | lib/tinyci/compactor.rb | TinyCI.Compactor.directories_to_compact | def directories_to_compact
builds = Dir.entries builds_dir
builds.select! {|e| File.directory? builds_dir(e) }
builds.reject! {|e| %w{. ..}.include? e }
builds.sort!
builds = builds[0..-(@num_builds_to_leave+1)]
builds.reject! {|e| @builds_to_leave.include?(e) || @builds_to_le... | ruby | def directories_to_compact
builds = Dir.entries builds_dir
builds.select! {|e| File.directory? builds_dir(e) }
builds.reject! {|e| %w{. ..}.include? e }
builds.sort!
builds = builds[0..-(@num_builds_to_leave+1)]
builds.reject! {|e| @builds_to_leave.include?(e) || @builds_to_le... | [
"def",
"directories_to_compact",
"builds",
"=",
"Dir",
".",
"entries",
"builds_dir",
"builds",
".",
"select!",
"{",
"|",
"e",
"|",
"File",
".",
"directory?",
"builds_dir",
"(",
"e",
")",
"}",
"builds",
".",
"reject!",
"{",
"|",
"e",
"|",
"%w{",
".",
".... | Build the list of directories to compact according to the options | [
"Build",
"the",
"list",
"of",
"directories",
"to",
"compact",
"according",
"to",
"the",
"options"
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/compactor.rb#L47-L57 | train |
JonnieCache/tinyci | lib/tinyci/compactor.rb | TinyCI.Compactor.compress_directory | def compress_directory(dir)
File.open archive_path(dir), 'wb' do |oarchive_path|
Zlib::GzipWriter.wrap oarchive_path do |gz|
Gem::Package::TarWriter.new gz do |tar|
Find.find "#{builds_dir}/"+dir do |f|
relative_path = f.sub "#{builds_dir}/", ""
mode = Fil... | ruby | def compress_directory(dir)
File.open archive_path(dir), 'wb' do |oarchive_path|
Zlib::GzipWriter.wrap oarchive_path do |gz|
Gem::Package::TarWriter.new gz do |tar|
Find.find "#{builds_dir}/"+dir do |f|
relative_path = f.sub "#{builds_dir}/", ""
mode = Fil... | [
"def",
"compress_directory",
"(",
"dir",
")",
"File",
".",
"open",
"archive_path",
"(",
"dir",
")",
",",
"'wb'",
"do",
"|",
"oarchive_path",
"|",
"Zlib",
"::",
"GzipWriter",
".",
"wrap",
"oarchive_path",
"do",
"|",
"gz",
"|",
"Gem",
"::",
"Package",
"::"... | Create a .tar.gz file from a directory
Done in pure ruby to ensure portability | [
"Create",
"a",
".",
"tar",
".",
"gz",
"file",
"from",
"a",
"directory",
"Done",
"in",
"pure",
"ruby",
"to",
"ensure",
"portability"
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/compactor.rb#L71-L97 | train |
JonnieCache/tinyci | lib/tinyci/subprocesses.rb | TinyCI.Subprocesses.execute | def execute(*command, label: nil)
output, status = Open3.capture2(*command.flatten)
log_debug caller[0]
log_debug "CMD: #{command.join(' ')}"
log_debug "OUT: #{output}"
unless status.success?
log_error output
raise SubprocessError.new(label, command.join(' '),... | ruby | def execute(*command, label: nil)
output, status = Open3.capture2(*command.flatten)
log_debug caller[0]
log_debug "CMD: #{command.join(' ')}"
log_debug "OUT: #{output}"
unless status.success?
log_error output
raise SubprocessError.new(label, command.join(' '),... | [
"def",
"execute",
"(",
"*",
"command",
",",
"label",
":",
"nil",
")",
"output",
",",
"status",
"=",
"Open3",
".",
"capture2",
"(",
"*",
"command",
".",
"flatten",
")",
"log_debug",
"caller",
"[",
"0",
"]",
"log_debug",
"\"CMD: #{command.join(' ')}\"",
"log... | Synchronously execute a command as a subprocess and return the output.
@param [Array<String>] command The command line
@param [String] label A label for debug and logging purposes
@return [String] The output of the command
@raise [SubprocessError] if the subprocess returns status > 0 | [
"Synchronously",
"execute",
"a",
"command",
"as",
"a",
"subprocess",
"and",
"return",
"the",
"output",
"."
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/subprocesses.rb#L15-L28 | train |
JonnieCache/tinyci | lib/tinyci/subprocesses.rb | TinyCI.Subprocesses.execute_pipe | def execute_pipe(*commands, label: nil)
stdout, waiters = Open3.pipeline_r(*commands)
output = stdout.read
waiters.each_with_index do |waiter, i|
status = waiter.value
unless status.success?
log_error output
raise SubprocessError.new(label, commands[i].join('... | ruby | def execute_pipe(*commands, label: nil)
stdout, waiters = Open3.pipeline_r(*commands)
output = stdout.read
waiters.each_with_index do |waiter, i|
status = waiter.value
unless status.success?
log_error output
raise SubprocessError.new(label, commands[i].join('... | [
"def",
"execute_pipe",
"(",
"*",
"commands",
",",
"label",
":",
"nil",
")",
"stdout",
",",
"waiters",
"=",
"Open3",
".",
"pipeline_r",
"(",
"*",
"commands",
")",
"output",
"=",
"stdout",
".",
"read",
"waiters",
".",
"each_with_index",
"do",
"|",
"waiter"... | Synchronously execute a chain multiple commands piped into each other as a
subprocess and return the output.
@param [Array<Array<String>>] commands The command lines
@param [String] label A label for debug and logging purposes
@return [String] The output of the command
@raise [SubprocessError] if the subprocess ... | [
"Synchronously",
"execute",
"a",
"chain",
"multiple",
"commands",
"piped",
"into",
"each",
"other",
"as",
"a",
"subprocess",
"and",
"return",
"the",
"output",
"."
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/subprocesses.rb#L38-L51 | train |
JonnieCache/tinyci | lib/tinyci/subprocesses.rb | TinyCI.Subprocesses.execute_stream | def execute_stream(*command, label: nil, pwd: nil)
opts = {}
opts[:chdir] = pwd unless pwd.nil?
Open3.popen2e(command.join(' '), opts) do |stdin, stdout_and_stderr, wait_thr|
stdin.close
until stdout_and_stderr.closed? || stdout_and_stderr.eof?
line = stdout_a... | ruby | def execute_stream(*command, label: nil, pwd: nil)
opts = {}
opts[:chdir] = pwd unless pwd.nil?
Open3.popen2e(command.join(' '), opts) do |stdin, stdout_and_stderr, wait_thr|
stdin.close
until stdout_and_stderr.closed? || stdout_and_stderr.eof?
line = stdout_a... | [
"def",
"execute_stream",
"(",
"*",
"command",
",",
"label",
":",
"nil",
",",
"pwd",
":",
"nil",
")",
"opts",
"=",
"{",
"}",
"opts",
"[",
":chdir",
"]",
"=",
"pwd",
"unless",
"pwd",
".",
"nil?",
"Open3",
".",
"popen2e",
"(",
"command",
".",
"join",
... | Synchronously execute a command as a subprocess and and stream the output
to `STDOUT`
@param [Array<String>] command The command line
@param [String] label A label for debug and logging purposes
@param [String] pwd Optionally specify a different working directory in which to execute the command
@return [TrueClas... | [
"Synchronously",
"execute",
"a",
"command",
"as",
"a",
"subprocess",
"and",
"and",
"stream",
"the",
"output",
"to",
"STDOUT"
] | 6dc23fc201f3527718afd814223eee0238ef8b06 | https://github.com/JonnieCache/tinyci/blob/6dc23fc201f3527718afd814223eee0238ef8b06/lib/tinyci/subprocesses.rb#L62-L82 | train |
fairfaxmedia/borderlands | lib/borderlands/propertymanager.rb | Borderlands.PropertyManager.property | def property(contractid, groupid, propertyid)
begin
property_hash = @client.get_json_body(
"/papi/v0/properties/#{propertyid}",
{ 'contractId' => contractid, 'groupId' => groupid, },
)
rescue
puts "# unable to retrieve property for (group=#{groupid},contract=#{con... | ruby | def property(contractid, groupid, propertyid)
begin
property_hash = @client.get_json_body(
"/papi/v0/properties/#{propertyid}",
{ 'contractId' => contractid, 'groupId' => groupid, },
)
rescue
puts "# unable to retrieve property for (group=#{groupid},contract=#{con... | [
"def",
"property",
"(",
"contractid",
",",
"groupid",
",",
"propertyid",
")",
"begin",
"property_hash",
"=",
"@client",
".",
"get_json_body",
"(",
"\"/papi/v0/properties/#{propertyid}\"",
",",
"{",
"'contractId'",
"=>",
"contractid",
",",
"'groupId'",
"=>",
"groupid... | fetch a single property | [
"fetch",
"a",
"single",
"property"
] | 7285467ef0dca520a692ebfeae3b1fc53295b7d5 | https://github.com/fairfaxmedia/borderlands/blob/7285467ef0dca520a692ebfeae3b1fc53295b7d5/lib/borderlands/propertymanager.rb#L40-L50 | train |
fairfaxmedia/borderlands | lib/borderlands/propertymanager.rb | Borderlands.PropertyManager.properties | def properties
properties = []
contract_group_pairs.each do |cg|
begin
properties_hash = @client.get_json_body(
"/papi/v0/properties/",
{ 'contractId' => cg[:contract], 'groupId' => cg[:group], }
)
if properties_hash && properties_hash['propertie... | ruby | def properties
properties = []
contract_group_pairs.each do |cg|
begin
properties_hash = @client.get_json_body(
"/papi/v0/properties/",
{ 'contractId' => cg[:contract], 'groupId' => cg[:group], }
)
if properties_hash && properties_hash['propertie... | [
"def",
"properties",
"properties",
"=",
"[",
"]",
"contract_group_pairs",
".",
"each",
"do",
"|",
"cg",
"|",
"begin",
"properties_hash",
"=",
"@client",
".",
"get_json_body",
"(",
"\"/papi/v0/properties/\"",
",",
"{",
"'contractId'",
"=>",
"cg",
"[",
":contract"... | takes a long time to complete! | [
"takes",
"a",
"long",
"time",
"to",
"complete!"
] | 7285467ef0dca520a692ebfeae3b1fc53295b7d5 | https://github.com/fairfaxmedia/borderlands/blob/7285467ef0dca520a692ebfeae3b1fc53295b7d5/lib/borderlands/propertymanager.rb#L53-L72 | train |
fairfaxmedia/borderlands | lib/borderlands/propertymanager.rb | Borderlands.PropertyManager.hostnames | def hostnames(property, skip_update_dns_status = false, version = nil)
raise 'property must be a Borderlands::Property object' unless property.is_a? Property
version ||= property.productionversion
begin
hostnames_hash = @client.get_json_body(
"/papi/v0/properties/#{property.id}/versi... | ruby | def hostnames(property, skip_update_dns_status = false, version = nil)
raise 'property must be a Borderlands::Property object' unless property.is_a? Property
version ||= property.productionversion
begin
hostnames_hash = @client.get_json_body(
"/papi/v0/properties/#{property.id}/versi... | [
"def",
"hostnames",
"(",
"property",
",",
"skip_update_dns_status",
"=",
"false",
",",
"version",
"=",
"nil",
")",
"raise",
"'property must be a Borderlands::Property object'",
"unless",
"property",
".",
"is_a?",
"Property",
"version",
"||=",
"property",
".",
"product... | version defaults to the current production version, which is pretty
much always going to be the most meaningful thing to look at | [
"version",
"defaults",
"to",
"the",
"current",
"production",
"version",
"which",
"is",
"pretty",
"much",
"always",
"going",
"to",
"be",
"the",
"most",
"meaningful",
"thing",
"to",
"look",
"at"
] | 7285467ef0dca520a692ebfeae3b1fc53295b7d5 | https://github.com/fairfaxmedia/borderlands/blob/7285467ef0dca520a692ebfeae3b1fc53295b7d5/lib/borderlands/propertymanager.rb#L76-L98 | train |
fairfaxmedia/borderlands | lib/borderlands/propertymanager.rb | Borderlands.PropertyManager.ruletree | def ruletree(property,version = nil)
raise 'property must be a Borderlands::Property object' unless property.is_a? Property
version ||= property.productionversion
tree = nil
begin
rt = @client.get_json_body(
"/papi/v0/properties/#{property.id}/versions/#{version}/rules/",
... | ruby | def ruletree(property,version = nil)
raise 'property must be a Borderlands::Property object' unless property.is_a? Property
version ||= property.productionversion
tree = nil
begin
rt = @client.get_json_body(
"/papi/v0/properties/#{property.id}/versions/#{version}/rules/",
... | [
"def",
"ruletree",
"(",
"property",
",",
"version",
"=",
"nil",
")",
"raise",
"'property must be a Borderlands::Property object'",
"unless",
"property",
".",
"is_a?",
"Property",
"version",
"||=",
"property",
".",
"productionversion",
"tree",
"=",
"nil",
"begin",
"r... | version defaults to current production version here too | [
"version",
"defaults",
"to",
"current",
"production",
"version",
"here",
"too"
] | 7285467ef0dca520a692ebfeae3b1fc53295b7d5 | https://github.com/fairfaxmedia/borderlands/blob/7285467ef0dca520a692ebfeae3b1fc53295b7d5/lib/borderlands/propertymanager.rb#L101-L115 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/spec_helper.rb | UnionStationHooks.SpecHelper.find_passenger_config | def find_passenger_config
passenger_config = ENV['PASSENGER_CONFIG']
if passenger_config.nil? || passenger_config.empty?
passenger_config = find_passenger_config_vendor ||
find_passenger_config_in_path
end
if passenger_config.nil? || passenger_config.empty?
abort 'ERROR... | ruby | def find_passenger_config
passenger_config = ENV['PASSENGER_CONFIG']
if passenger_config.nil? || passenger_config.empty?
passenger_config = find_passenger_config_vendor ||
find_passenger_config_in_path
end
if passenger_config.nil? || passenger_config.empty?
abort 'ERROR... | [
"def",
"find_passenger_config",
"passenger_config",
"=",
"ENV",
"[",
"'PASSENGER_CONFIG'",
"]",
"if",
"passenger_config",
".",
"nil?",
"||",
"passenger_config",
".",
"empty?",
"passenger_config",
"=",
"find_passenger_config_vendor",
"||",
"find_passenger_config_in_path",
"e... | Lookup the `passenger-config` command, either by respecting the
`PASSENGER_CONFIG` environment variable, or by looking it up in `PATH`.
If the command cannot be found, the current process aborts with an
error message. | [
"Lookup",
"the",
"passenger",
"-",
"config",
"command",
"either",
"by",
"respecting",
"the",
"PASSENGER_CONFIG",
"environment",
"variable",
"or",
"by",
"looking",
"it",
"up",
"in",
"PATH",
".",
"If",
"the",
"command",
"cannot",
"be",
"found",
"the",
"current",... | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/spec_helper.rb#L56-L70 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/spec_helper.rb | UnionStationHooks.SpecHelper.undo_bundler | def undo_bundler
clean_env = nil
Bundler.with_clean_env do
clean_env = ENV.to_hash
end
ENV.replace(clean_env)
end | ruby | def undo_bundler
clean_env = nil
Bundler.with_clean_env do
clean_env = ENV.to_hash
end
ENV.replace(clean_env)
end | [
"def",
"undo_bundler",
"clean_env",
"=",
"nil",
"Bundler",
".",
"with_clean_env",
"do",
"clean_env",
"=",
"ENV",
".",
"to_hash",
"end",
"ENV",
".",
"replace",
"(",
"clean_env",
")",
"end"
] | Unit tests must undo the Bundler environment so that the gem's
own Gemfile doesn't affect subprocesses that may have their
own Gemfile. | [
"Unit",
"tests",
"must",
"undo",
"the",
"Bundler",
"environment",
"so",
"that",
"the",
"gem",
"s",
"own",
"Gemfile",
"doesn",
"t",
"affect",
"subprocesses",
"that",
"may",
"have",
"their",
"own",
"Gemfile",
"."
] | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/spec_helper.rb#L134-L140 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/spec_helper.rb | UnionStationHooks.SpecHelper.write_file | def write_file(path, content)
dir = File.dirname(path)
if !File.exist?(dir)
FileUtils.mkdir_p(dir)
end
File.open(path, 'wb') do |f|
f.write(content)
end
end | ruby | def write_file(path, content)
dir = File.dirname(path)
if !File.exist?(dir)
FileUtils.mkdir_p(dir)
end
File.open(path, 'wb') do |f|
f.write(content)
end
end | [
"def",
"write_file",
"(",
"path",
",",
"content",
")",
"dir",
"=",
"File",
".",
"dirname",
"(",
"path",
")",
"if",
"!",
"File",
".",
"exist?",
"(",
"dir",
")",
"FileUtils",
".",
"mkdir_p",
"(",
"dir",
")",
"end",
"File",
".",
"open",
"(",
"path",
... | Writes the given content to the file at the given path. If or or more
parent directories don't exist, then they are created. | [
"Writes",
"the",
"given",
"content",
"to",
"the",
"file",
"at",
"the",
"given",
"path",
".",
"If",
"or",
"or",
"more",
"parent",
"directories",
"don",
"t",
"exist",
"then",
"they",
"are",
"created",
"."
] | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/spec_helper.rb#L149-L157 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/spec_helper.rb | UnionStationHooks.SpecHelper.debug_shell | def debug_shell
puts '------ Opening debug shell -----'
@orig_dir = Dir.pwd
begin
if respond_to?(:prepare_debug_shell)
prepare_debug_shell
end
system('bash')
ensure
Dir.chdir(@orig_dir)
end
puts '------ Exiting debug shell -----'
end | ruby | def debug_shell
puts '------ Opening debug shell -----'
@orig_dir = Dir.pwd
begin
if respond_to?(:prepare_debug_shell)
prepare_debug_shell
end
system('bash')
ensure
Dir.chdir(@orig_dir)
end
puts '------ Exiting debug shell -----'
end | [
"def",
"debug_shell",
"puts",
"'------ Opening debug shell -----'",
"@orig_dir",
"=",
"Dir",
".",
"pwd",
"begin",
"if",
"respond_to?",
"(",
":prepare_debug_shell",
")",
"prepare_debug_shell",
"end",
"system",
"(",
"'bash'",
")",
"ensure",
"Dir",
".",
"chdir",
"(",
... | Opens a debug shell. By default, the debug shell is opened in the current
working directory. If the current module has the `prepare_debug_shell`
method, that method is called before opening the debug shell. The method
could, for example, change the working directory.
This method does *not* raise an exception if th... | [
"Opens",
"a",
"debug",
"shell",
".",
"By",
"default",
"the",
"debug",
"shell",
"is",
"opened",
"in",
"the",
"current",
"working",
"directory",
".",
"If",
"the",
"current",
"module",
"has",
"the",
"prepare_debug_shell",
"method",
"that",
"method",
"is",
"call... | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/spec_helper.rb#L187-L199 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/spec_helper.rb | UnionStationHooks.SpecHelper.eventually | def eventually(deadline_duration = 3, check_interval = 0.05)
deadline = Time.now + deadline_duration
while Time.now < deadline
if yield
return
else
sleep(check_interval)
end
end
raise 'Time limit exceeded'
end | ruby | def eventually(deadline_duration = 3, check_interval = 0.05)
deadline = Time.now + deadline_duration
while Time.now < deadline
if yield
return
else
sleep(check_interval)
end
end
raise 'Time limit exceeded'
end | [
"def",
"eventually",
"(",
"deadline_duration",
"=",
"3",
",",
"check_interval",
"=",
"0.05",
")",
"deadline",
"=",
"Time",
".",
"now",
"+",
"deadline_duration",
"while",
"Time",
".",
"now",
"<",
"deadline",
"if",
"yield",
"return",
"else",
"sleep",
"(",
"c... | Asserts that something should eventually happen. This is done by checking
that the given block eventually returns true. The block is called
once every `check_interval` msec. If the block does not return true
within `deadline_duration` secs, then an exception is raised. | [
"Asserts",
"that",
"something",
"should",
"eventually",
"happen",
".",
"This",
"is",
"done",
"by",
"checking",
"that",
"the",
"given",
"block",
"eventually",
"returns",
"true",
".",
"The",
"block",
"is",
"called",
"once",
"every",
"check_interval",
"msec",
"."... | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/spec_helper.rb#L252-L262 | train |
phusion/union_station_hooks_core | lib/union_station_hooks_core/spec_helper.rb | UnionStationHooks.SpecHelper.should_never_happen | def should_never_happen(deadline_duration = 0.5, check_interval = 0.05)
deadline = Time.now + deadline_duration
while Time.now < deadline
if yield
raise "That which shouldn't happen happened anyway"
else
sleep(check_interval)
end
end
end | ruby | def should_never_happen(deadline_duration = 0.5, check_interval = 0.05)
deadline = Time.now + deadline_duration
while Time.now < deadline
if yield
raise "That which shouldn't happen happened anyway"
else
sleep(check_interval)
end
end
end | [
"def",
"should_never_happen",
"(",
"deadline_duration",
"=",
"0.5",
",",
"check_interval",
"=",
"0.05",
")",
"deadline",
"=",
"Time",
".",
"now",
"+",
"deadline_duration",
"while",
"Time",
".",
"now",
"<",
"deadline",
"if",
"yield",
"raise",
"\"That which should... | Asserts that something should never happen. This is done by checking that
the given block never returns true. The block is called once every
`check_interval` msec, until `deadline_duration` seconds have passed.
If the block ever returns true, then an exception is raised. | [
"Asserts",
"that",
"something",
"should",
"never",
"happen",
".",
"This",
"is",
"done",
"by",
"checking",
"that",
"the",
"given",
"block",
"never",
"returns",
"true",
".",
"The",
"block",
"is",
"called",
"once",
"every",
"check_interval",
"msec",
"until",
"d... | e4b1797736a9b72a348db8e6d4ceebb62b30d478 | https://github.com/phusion/union_station_hooks_core/blob/e4b1797736a9b72a348db8e6d4ceebb62b30d478/lib/union_station_hooks_core/spec_helper.rb#L268-L277 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.