id int32 0 24.9k | repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 |
|---|---|---|---|---|---|---|---|---|---|---|---|
17,000 | untra/polyglot | lib/jekyll/polyglot/patches/jekyll/site.rb | Jekyll.Site.coordinate_documents | def coordinate_documents(docs)
regex = document_url_regex
approved = {}
docs.each do |doc|
lang = doc.data['lang'] || @default_lang
url = doc.url.gsub(regex, '/')
doc.data['permalink'] = url
next if @file_langs[url] == @active_lang
next if @file_langs[url] == @d... | ruby | def coordinate_documents(docs)
regex = document_url_regex
approved = {}
docs.each do |doc|
lang = doc.data['lang'] || @default_lang
url = doc.url.gsub(regex, '/')
doc.data['permalink'] = url
next if @file_langs[url] == @active_lang
next if @file_langs[url] == @d... | [
"def",
"coordinate_documents",
"(",
"docs",
")",
"regex",
"=",
"document_url_regex",
"approved",
"=",
"{",
"}",
"docs",
".",
"each",
"do",
"|",
"doc",
"|",
"lang",
"=",
"doc",
".",
"data",
"[",
"'lang'",
"]",
"||",
"@default_lang",
"url",
"=",
"doc",
"... | assigns natural permalinks to documents and prioritizes documents with
active_lang languages over others | [
"assigns",
"natural",
"permalinks",
"to",
"documents",
"and",
"prioritizes",
"documents",
"with",
"active_lang",
"languages",
"over",
"others"
] | 23163148ba91daef1ce536b37a62c1ca67c05e84 | https://github.com/untra/polyglot/blob/23163148ba91daef1ce536b37a62c1ca67c05e84/lib/jekyll/polyglot/patches/jekyll/site.rb#L93-L106 |
17,001 | untra/polyglot | lib/jekyll/polyglot/patches/jekyll/site.rb | Jekyll.Site.process_documents | def process_documents(docs)
return if @active_lang == @default_lang
url = config.fetch('url', false)
rel_regex = relative_url_regex
abs_regex = absolute_url_regex(url)
docs.each do |doc|
relativize_urls(doc, rel_regex)
if url
then relativize_absolute_urls(doc, abs_r... | ruby | def process_documents(docs)
return if @active_lang == @default_lang
url = config.fetch('url', false)
rel_regex = relative_url_regex
abs_regex = absolute_url_regex(url)
docs.each do |doc|
relativize_urls(doc, rel_regex)
if url
then relativize_absolute_urls(doc, abs_r... | [
"def",
"process_documents",
"(",
"docs",
")",
"return",
"if",
"@active_lang",
"==",
"@default_lang",
"url",
"=",
"config",
".",
"fetch",
"(",
"'url'",
",",
"false",
")",
"rel_regex",
"=",
"relative_url_regex",
"abs_regex",
"=",
"absolute_url_regex",
"(",
"url",
... | performs any necesarry operations on the documents before rendering them | [
"performs",
"any",
"necesarry",
"operations",
"on",
"the",
"documents",
"before",
"rendering",
"them"
] | 23163148ba91daef1ce536b37a62c1ca67c05e84 | https://github.com/untra/polyglot/blob/23163148ba91daef1ce536b37a62c1ca67c05e84/lib/jekyll/polyglot/patches/jekyll/site.rb#L109-L120 |
17,002 | schneems/maildown | lib/maildown/ext/action_view.rb | ActionView.OptimizedFileSystemResolver.extract_handler_and_format_and_variant | def extract_handler_and_format_and_variant(*args)
if args.first.end_with?('md.erb')
path = args.shift
path = path.gsub(/\.md\.erb\z/, '.md+erb')
args.unshift(path)
end
return original_extract_handler_and_format_and_variant(*args)
end | ruby | def extract_handler_and_format_and_variant(*args)
if args.first.end_with?('md.erb')
path = args.shift
path = path.gsub(/\.md\.erb\z/, '.md+erb')
args.unshift(path)
end
return original_extract_handler_and_format_and_variant(*args)
end | [
"def",
"extract_handler_and_format_and_variant",
"(",
"*",
"args",
")",
"if",
"args",
".",
"first",
".",
"end_with?",
"(",
"'md.erb'",
")",
"path",
"=",
"args",
".",
"shift",
"path",
"=",
"path",
".",
"gsub",
"(",
"/",
"\\.",
"\\.",
"\\z",
"/",
",",
"'... | Different versions of rails have different
method signatures here, path is always first | [
"Different",
"versions",
"of",
"rails",
"have",
"different",
"method",
"signatures",
"here",
"path",
"is",
"always",
"first"
] | fc2220194dc2d32ef8313981503723a9657824ff | https://github.com/schneems/maildown/blob/fc2220194dc2d32ef8313981503723a9657824ff/lib/maildown/ext/action_view.rb#L13-L20 |
17,003 | gocardless/gocardless-pro-ruby | lib/gocardless_pro/api_service.rb | GoCardlessPro.ApiService.make_request | def make_request(method, path, options = {})
raise ArgumentError, 'options must be a hash' unless options.is_a?(Hash)
options[:headers] ||= {}
options[:headers] = @headers.merge(options[:headers])
Request.new(@connection, method, @path_prefix + path, options).request
end | ruby | def make_request(method, path, options = {})
raise ArgumentError, 'options must be a hash' unless options.is_a?(Hash)
options[:headers] ||= {}
options[:headers] = @headers.merge(options[:headers])
Request.new(@connection, method, @path_prefix + path, options).request
end | [
"def",
"make_request",
"(",
"method",
",",
"path",
",",
"options",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'options must be a hash'",
"unless",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"[",
":headers",
"]",
"||=",
"{",
"}",
"option... | Initialize an APIService
@param url [String] the URL to make requests to
@param key [String] the API Key ID to use
@param secret [String] the API key secret to use
@param options [Hash] additional options to use when creating the service
Make a request to the API
@param method [Symbol] the method to use to make... | [
"Initialize",
"an",
"APIService"
] | 9473ecfa64eef2de6d5a404357c0db90de57efb1 | https://github.com/gocardless/gocardless-pro-ruby/blob/9473ecfa64eef2de6d5a404357c0db90de57efb1/lib/gocardless_pro/api_service.rb#L44-L49 |
17,004 | gocardless/gocardless-pro-ruby | lib/gocardless_pro/paginator.rb | GoCardlessPro.Paginator.enumerator | def enumerator
response = get_initial_response
Enumerator.new do |yielder|
loop do
response.records.each { |item| yielder << item }
after_cursor = response.after
break if after_cursor.nil?
@options[:params] ||= {}
@options[:params] = @options[:para... | ruby | def enumerator
response = get_initial_response
Enumerator.new do |yielder|
loop do
response.records.each { |item| yielder << item }
after_cursor = response.after
break if after_cursor.nil?
@options[:params] ||= {}
@options[:params] = @options[:para... | [
"def",
"enumerator",
"response",
"=",
"get_initial_response",
"Enumerator",
".",
"new",
"do",
"|",
"yielder",
"|",
"loop",
"do",
"response",
".",
"records",
".",
"each",
"{",
"|",
"item",
"|",
"yielder",
"<<",
"item",
"}",
"after_cursor",
"=",
"response",
... | initialize a paginator
@param options [Hash]
@option options :service the service class to use to make requests to
@option options :options additional options to send with the requests
Get a lazy enumerable for listing data from the API | [
"initialize",
"a",
"paginator"
] | 9473ecfa64eef2de6d5a404357c0db90de57efb1 | https://github.com/gocardless/gocardless-pro-ruby/blob/9473ecfa64eef2de6d5a404357c0db90de57efb1/lib/gocardless_pro/paginator.rb#L14-L28 |
17,005 | gocardless/gocardless-pro-ruby | lib/gocardless_pro/client.rb | GoCardlessPro.Client.custom_options | def custom_options(options)
return default_options if options.nil?
return default_options.merge(options) unless options[:default_headers]
opts = default_options.merge(options)
opts[:default_headers] = default_options[:default_headers].merge(options[:default_headers])
opts
end | ruby | def custom_options(options)
return default_options if options.nil?
return default_options.merge(options) unless options[:default_headers]
opts = default_options.merge(options)
opts[:default_headers] = default_options[:default_headers].merge(options[:default_headers])
opts
end | [
"def",
"custom_options",
"(",
"options",
")",
"return",
"default_options",
"if",
"options",
".",
"nil?",
"return",
"default_options",
".",
"merge",
"(",
"options",
")",
"unless",
"options",
"[",
":default_headers",
"]",
"opts",
"=",
"default_options",
".",
"merg... | Get customized options. | [
"Get",
"customized",
"options",
"."
] | 9473ecfa64eef2de6d5a404357c0db90de57efb1 | https://github.com/gocardless/gocardless-pro-ruby/blob/9473ecfa64eef2de6d5a404357c0db90de57efb1/lib/gocardless_pro/client.rb#L122-L131 |
17,006 | ericqweinstein/ruumba | lib/ruumba/parser.rb | Ruumba.Parser.extract | def extract(contents)
file_text, matches = parse(contents)
extracted_ruby = +''
last_match = [0, 0]
matches.each do |start_index, end_index|
handle_region_before(start_index, last_match.last, file_text, extracted_ruby)
extracted_ruby << extract_match(file_text, start_index, en... | ruby | def extract(contents)
file_text, matches = parse(contents)
extracted_ruby = +''
last_match = [0, 0]
matches.each do |start_index, end_index|
handle_region_before(start_index, last_match.last, file_text, extracted_ruby)
extracted_ruby << extract_match(file_text, start_index, en... | [
"def",
"extract",
"(",
"contents",
")",
"file_text",
",",
"matches",
"=",
"parse",
"(",
"contents",
")",
"extracted_ruby",
"=",
"+",
"''",
"last_match",
"=",
"[",
"0",
",",
"0",
"]",
"matches",
".",
"each",
"do",
"|",
"start_index",
",",
"end_index",
"... | Extracts Ruby code from an ERB template.
@return [String] The extracted ruby code | [
"Extracts",
"Ruby",
"code",
"from",
"an",
"ERB",
"template",
"."
] | 9093819d011a2d9f6824d8f4c3789e34f4ff9b98 | https://github.com/ericqweinstein/ruumba/blob/9093819d011a2d9f6824d8f4c3789e34f4ff9b98/lib/ruumba/parser.rb#L13-L35 |
17,007 | ericqweinstein/ruumba | lib/ruumba/rake_task.rb | Ruumba.RakeTask.run | def run
# Like RuboCop itself, we'll lazy load so the task
# doesn't substantially impact Rakefile load time.
require 'ruumba'
analyzer = Ruumba::Analyzer.new(@options)
puts 'Running Ruumba...'
exit(analyzer.run(@dir))
end | ruby | def run
# Like RuboCop itself, we'll lazy load so the task
# doesn't substantially impact Rakefile load time.
require 'ruumba'
analyzer = Ruumba::Analyzer.new(@options)
puts 'Running Ruumba...'
exit(analyzer.run(@dir))
end | [
"def",
"run",
"# Like RuboCop itself, we'll lazy load so the task",
"# doesn't substantially impact Rakefile load time.",
"require",
"'ruumba'",
"analyzer",
"=",
"Ruumba",
"::",
"Analyzer",
".",
"new",
"(",
"@options",
")",
"puts",
"'Running Ruumba...'",
"exit",
"(",
"analyze... | Executes the custom Rake task.
@private | [
"Executes",
"the",
"custom",
"Rake",
"task",
"."
] | 9093819d011a2d9f6824d8f4c3789e34f4ff9b98 | https://github.com/ericqweinstein/ruumba/blob/9093819d011a2d9f6824d8f4c3789e34f4ff9b98/lib/ruumba/rake_task.rb#L31-L40 |
17,008 | ericqweinstein/ruumba | lib/ruumba/analyzer.rb | Ruumba.Analyzer.run | def run(files_or_dirs = ARGV)
if options[:tmp_folder]
analyze(File.expand_path(options[:tmp_folder]), files_or_dirs)
else
Dir.mktmpdir do |dir|
analyze(dir, files_or_dirs)
end
end
end | ruby | def run(files_or_dirs = ARGV)
if options[:tmp_folder]
analyze(File.expand_path(options[:tmp_folder]), files_or_dirs)
else
Dir.mktmpdir do |dir|
analyze(dir, files_or_dirs)
end
end
end | [
"def",
"run",
"(",
"files_or_dirs",
"=",
"ARGV",
")",
"if",
"options",
"[",
":tmp_folder",
"]",
"analyze",
"(",
"File",
".",
"expand_path",
"(",
"options",
"[",
":tmp_folder",
"]",
")",
",",
"files_or_dirs",
")",
"else",
"Dir",
".",
"mktmpdir",
"do",
"|"... | Performs static analysis on the provided directory.
@param [Array<String>] dir The directories / files to analyze. | [
"Performs",
"static",
"analysis",
"on",
"the",
"provided",
"directory",
"."
] | 9093819d011a2d9f6824d8f4c3789e34f4ff9b98 | https://github.com/ericqweinstein/ruumba/blob/9093819d011a2d9f6824d8f4c3789e34f4ff9b98/lib/ruumba/analyzer.rb#L24-L32 |
17,009 | mattbrictson/chandler | lib/chandler/logger.rb | Chandler.Logger.error | def error(message)
message = message.red unless message.color?
puts(stderr, message)
end | ruby | def error(message)
message = message.red unless message.color?
puts(stderr, message)
end | [
"def",
"error",
"(",
"message",
")",
"message",
"=",
"message",
".",
"red",
"unless",
"message",
".",
"color?",
"puts",
"(",
"stderr",
",",
"message",
")",
"end"
] | Logs a message to stderr. Unless otherwise specified, the message will
be printed in red. | [
"Logs",
"a",
"message",
"to",
"stderr",
".",
"Unless",
"otherwise",
"specified",
"the",
"message",
"will",
"be",
"printed",
"in",
"red",
"."
] | bb6d38ea19aa8d7a8f175384ac53f2dd1ffc620a | https://github.com/mattbrictson/chandler/blob/bb6d38ea19aa8d7a8f175384ac53f2dd1ffc620a/lib/chandler/logger.rb#L19-L22 |
17,010 | Vantiv/litle-sdk-for-ruby | lib/LitleTransaction.rb | LitleOnline.LitleTransaction.giftCardAuth_reversal | def giftCardAuth_reversal(options)
transaction = GiftCardAuthReversal.new
transaction.litleTxnId = options['litleTxnId']
transaction.card = GiftCardCardType.from_hash(options,'card')
transaction.originalRefCode = options['originalRefCode']
transaction.originalAmount = options['originalAmou... | ruby | def giftCardAuth_reversal(options)
transaction = GiftCardAuthReversal.new
transaction.litleTxnId = options['litleTxnId']
transaction.card = GiftCardCardType.from_hash(options,'card')
transaction.originalRefCode = options['originalRefCode']
transaction.originalAmount = options['originalAmou... | [
"def",
"giftCardAuth_reversal",
"(",
"options",
")",
"transaction",
"=",
"GiftCardAuthReversal",
".",
"new",
"transaction",
".",
"litleTxnId",
"=",
"options",
"[",
"'litleTxnId'",
"]",
"transaction",
".",
"card",
"=",
"GiftCardCardType",
".",
"from_hash",
"(",
"op... | XML 11.0 | [
"XML",
"11",
".",
"0"
] | a05590c5cbab688e6ae29cf38fea0eb44aa487e2 | https://github.com/Vantiv/litle-sdk-for-ruby/blob/a05590c5cbab688e6ae29cf38fea0eb44aa487e2/lib/LitleTransaction.rb#L185-L195 |
17,011 | Vantiv/litle-sdk-for-ruby | lib/LitleTransaction.rb | LitleOnline.LitleTransaction.fast_access_funding | def fast_access_funding(options)
transaction = FastAccessFunding.new
transaction.reportGroup = get_report_group(options)
transaction.transactionId = options['id']
transaction.customerId = options['customerId']
transaction.fundingSubmerchantId = options['fundingSubmerchantId']
tra... | ruby | def fast_access_funding(options)
transaction = FastAccessFunding.new
transaction.reportGroup = get_report_group(options)
transaction.transactionId = options['id']
transaction.customerId = options['customerId']
transaction.fundingSubmerchantId = options['fundingSubmerchantId']
tra... | [
"def",
"fast_access_funding",
"(",
"options",
")",
"transaction",
"=",
"FastAccessFunding",
".",
"new",
"transaction",
".",
"reportGroup",
"=",
"get_report_group",
"(",
"options",
")",
"transaction",
".",
"transactionId",
"=",
"options",
"[",
"'id'",
"]",
"transac... | 11.4 Begin | [
"11",
".",
"4",
"Begin"
] | a05590c5cbab688e6ae29cf38fea0eb44aa487e2 | https://github.com/Vantiv/litle-sdk-for-ruby/blob/a05590c5cbab688e6ae29cf38fea0eb44aa487e2/lib/LitleTransaction.rb#L659-L675 |
17,012 | Vantiv/litle-sdk-for-ruby | lib/LitleRequest.rb | LitleOnline.LitleRequest.finish_request | def finish_request
File.open(@path_to_request, 'w') do |f|
#jam dat header in there
f.puts(build_request_header())
#read into the request file from the batches file
File.foreach(@path_to_batches) do |li|
f.puts li
end
#finally, let's poot in a header, for... | ruby | def finish_request
File.open(@path_to_request, 'w') do |f|
#jam dat header in there
f.puts(build_request_header())
#read into the request file from the batches file
File.foreach(@path_to_batches) do |li|
f.puts li
end
#finally, let's poot in a header, for... | [
"def",
"finish_request",
"File",
".",
"open",
"(",
"@path_to_request",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"#jam dat header in there",
"f",
".",
"puts",
"(",
"build_request_header",
"(",
")",
")",
"#read into the request file from the batches file",
"File",
".",
... | Called when you wish to finish adding batches to your request, this method rewrites the aggregate
batch file to the final LitleRequest xml doc with the appropos LitleRequest tags. | [
"Called",
"when",
"you",
"wish",
"to",
"finish",
"adding",
"batches",
"to",
"your",
"request",
"this",
"method",
"rewrites",
"the",
"aggregate",
"batch",
"file",
"to",
"the",
"final",
"LitleRequest",
"xml",
"doc",
"with",
"the",
"appropos",
"LitleRequest",
"ta... | a05590c5cbab688e6ae29cf38fea0eb44aa487e2 | https://github.com/Vantiv/litle-sdk-for-ruby/blob/a05590c5cbab688e6ae29cf38fea0eb44aa487e2/lib/LitleRequest.rb#L440-L457 |
17,013 | duckinator/inq | lib/inq/cli.rb | Inq.CLI.parse | def parse(argv)
parser, options = parse_main(argv)
# Options that are mutually-exclusive with everything else.
options = {:help => true} if options[:help]
options = {:version => true} if options[:version]
validate_options!(options)
@options = options
@help_text = parser.t... | ruby | def parse(argv)
parser, options = parse_main(argv)
# Options that are mutually-exclusive with everything else.
options = {:help => true} if options[:help]
options = {:version => true} if options[:version]
validate_options!(options)
@options = options
@help_text = parser.t... | [
"def",
"parse",
"(",
"argv",
")",
"parser",
",",
"options",
"=",
"parse_main",
"(",
"argv",
")",
"# Options that are mutually-exclusive with everything else.",
"options",
"=",
"{",
":help",
"=>",
"true",
"}",
"if",
"options",
"[",
":help",
"]",
"options",
"=",
... | Parses an Array of command-line arguments into an equivalent Hash.
The results of this can be used to control the behavior of the rest
of the library.
@params argv [Array] An array of command-line arguments, e.g. +ARGV+.
@return [Hash] A Hash containing data used to control Inq's behavior. | [
"Parses",
"an",
"Array",
"of",
"command",
"-",
"line",
"arguments",
"into",
"an",
"equivalent",
"Hash",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/cli.rb#L34-L47 |
17,014 | duckinator/inq | lib/inq/config.rb | Inq.Config.load_site_configs | def load_site_configs(*files)
# Allows both:
# load_site_configs('foo', 'bar')
# load_site_configs(['foo', bar'])
# but not:
# load_site_configs(['foo'], 'bar')
files = files[0] if files.length == 1 && files[0].is_a?(Array)
load_files(*files)
end | ruby | def load_site_configs(*files)
# Allows both:
# load_site_configs('foo', 'bar')
# load_site_configs(['foo', bar'])
# but not:
# load_site_configs(['foo'], 'bar')
files = files[0] if files.length == 1 && files[0].is_a?(Array)
load_files(*files)
end | [
"def",
"load_site_configs",
"(",
"*",
"files",
")",
"# Allows both:",
"# load_site_configs('foo', 'bar')",
"# load_site_configs(['foo', bar'])",
"# but not:",
"# load_site_configs(['foo'], 'bar')",
"files",
"=",
"files",
"[",
"0",
"]",
"if",
"files",
".",
"length",
"=... | Load the config files as specified via +files+.
@param files [Array<String>] The path(s) for config files.
@return [Config] The config hash. (+self+) | [
"Load",
"the",
"config",
"files",
"as",
"specified",
"via",
"+",
"files",
"+",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/config.rb#L47-L56 |
17,015 | duckinator/inq | lib/inq/config.rb | Inq.Config.load | def load(*configs)
configs.each do |config|
config.each do |k, v|
if self[k] && self[k].is_a?(Array)
self[k] += v
else
self[k] = v
end
end
end
self
end | ruby | def load(*configs)
configs.each do |config|
config.each do |k, v|
if self[k] && self[k].is_a?(Array)
self[k] += v
else
self[k] = v
end
end
end
self
end | [
"def",
"load",
"(",
"*",
"configs",
")",
"configs",
".",
"each",
"do",
"|",
"config",
"|",
"config",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"if",
"self",
"[",
"k",
"]",
"&&",
"self",
"[",
"k",
"]",
".",
"is_a?",
"(",
"Array",
")",
"self"... | Take a collection of config hashes and cascade them, meaning values
in later ones override values in earlier ones.
E.g., this results in +{'a'=>'x', 'c'=>'d'}+:
load({'a'=>'b'}, {'c'=>'d'}, {'a'=>'x'})
And this results in +{'a'=>['b', 'c']}+:
load({'a'=>['b']}, {'a'=>['c']})
@param [Array<Hash>] The co... | [
"Take",
"a",
"collection",
"of",
"config",
"hashes",
"and",
"cascade",
"them",
"meaning",
"values",
"in",
"later",
"ones",
"override",
"values",
"in",
"earlier",
"ones",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/config.rb#L83-L95 |
17,016 | duckinator/inq | lib/inq/config.rb | Inq.Config.load_env | def load_env
Inq::Text.puts "Using configuration from environment variables."
gh_token = ENV["INQ_GITHUB_TOKEN"] || ENV["HOWIS_GITHUB_TOKEN"]
gh_username = ENV["INQ_GITHUB_USERNAME"] || ENV["HOWIS_GITHUB_USERNAME"]
raise "INQ_GITHUB_TOKEN environment variable is not set" \
unless gh_to... | ruby | def load_env
Inq::Text.puts "Using configuration from environment variables."
gh_token = ENV["INQ_GITHUB_TOKEN"] || ENV["HOWIS_GITHUB_TOKEN"]
gh_username = ENV["INQ_GITHUB_USERNAME"] || ENV["HOWIS_GITHUB_USERNAME"]
raise "INQ_GITHUB_TOKEN environment variable is not set" \
unless gh_to... | [
"def",
"load_env",
"Inq",
"::",
"Text",
".",
"puts",
"\"Using configuration from environment variables.\"",
"gh_token",
"=",
"ENV",
"[",
"\"INQ_GITHUB_TOKEN\"",
"]",
"||",
"ENV",
"[",
"\"HOWIS_GITHUB_TOKEN\"",
"]",
"gh_username",
"=",
"ENV",
"[",
"\"INQ_GITHUB_USERNAME\... | Load config info from environment variables.
Supported environment variables:
- INQ_GITHUB_TOKEN: a GitHub authentication token.
- INQ_GITHUB_USERNAME: the GitHub username corresponding to the token.
@return [Config] The resulting configuration. | [
"Load",
"config",
"info",
"from",
"environment",
"variables",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/config.rb#L104-L121 |
17,017 | duckinator/inq | lib/inq/date_time_helpers.rb | Inq.DateTimeHelpers.date_le | def date_le(left, right)
left = str_to_dt(left)
right = str_to_dt(right)
left <= right
end | ruby | def date_le(left, right)
left = str_to_dt(left)
right = str_to_dt(right)
left <= right
end | [
"def",
"date_le",
"(",
"left",
",",
"right",
")",
"left",
"=",
"str_to_dt",
"(",
"left",
")",
"right",
"=",
"str_to_dt",
"(",
"right",
")",
"left",
"<=",
"right",
"end"
] | Check if +left+ is less than or equal to +right+, where both are string
representations of a date.
@param left [String] A string representation of a date.
@param right [String] A string representation of a date.
@return [Boolean] True if +left+ is less-than-or-equal to +right+,
otherwise false. | [
"Check",
"if",
"+",
"left",
"+",
"is",
"less",
"than",
"or",
"equal",
"to",
"+",
"right",
"+",
"where",
"both",
"are",
"string",
"representations",
"of",
"a",
"date",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/date_time_helpers.rb#L17-L22 |
17,018 | duckinator/inq | lib/inq/date_time_helpers.rb | Inq.DateTimeHelpers.date_ge | def date_ge(left, right)
left = str_to_dt(left)
right = str_to_dt(right)
left >= right
end | ruby | def date_ge(left, right)
left = str_to_dt(left)
right = str_to_dt(right)
left >= right
end | [
"def",
"date_ge",
"(",
"left",
",",
"right",
")",
"left",
"=",
"str_to_dt",
"(",
"left",
")",
"right",
"=",
"str_to_dt",
"(",
"right",
")",
"left",
">=",
"right",
"end"
] | Check if +left+ is greater than or equal to +right+, where both are string
representations of a date.
@param left [String] A string representation of a date.
@param right [String] A string representation of a date.
@return [Boolean] True if +left+ is greater-than-or-equal to +right+,
otherwise false. | [
"Check",
"if",
"+",
"left",
"+",
"is",
"greater",
"than",
"or",
"equal",
"to",
"+",
"right",
"+",
"where",
"both",
"are",
"string",
"representations",
"of",
"a",
"date",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/date_time_helpers.rb#L31-L36 |
17,019 | duckinator/inq | lib/inq/report_collection.rb | Inq.ReportCollection.metadata | def metadata(repository)
end_date = DateTime.strptime(@date, "%Y-%m-%d")
friendly_end_date = end_date.strftime("%B %d, %y")
{
sanitized_repository: repository.tr("/", "-"),
repository: repository,
date: end_date,
friendly_date: friendly_end_date,
}
end | ruby | def metadata(repository)
end_date = DateTime.strptime(@date, "%Y-%m-%d")
friendly_end_date = end_date.strftime("%B %d, %y")
{
sanitized_repository: repository.tr("/", "-"),
repository: repository,
date: end_date,
friendly_date: friendly_end_date,
}
end | [
"def",
"metadata",
"(",
"repository",
")",
"end_date",
"=",
"DateTime",
".",
"strptime",
"(",
"@date",
",",
"\"%Y-%m-%d\"",
")",
"friendly_end_date",
"=",
"end_date",
".",
"strftime",
"(",
"\"%B %d, %y\"",
")",
"{",
"sanitized_repository",
":",
"repository",
"."... | Generates the metadata for the collection of Reports. | [
"Generates",
"the",
"metadata",
"for",
"the",
"collection",
"of",
"Reports",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/report_collection.rb#L28-L38 |
17,020 | duckinator/inq | lib/inq/report_collection.rb | Inq.ReportCollection.to_h | def to_h
results = {}
defaults = @config["default_reports"] || {}
@config["repositories"].map { |repo_config|
repo = repo_config["repository"]
config = config_for(repo)
config["reports"].map { |format, report_config|
# Sometimes report_data has unused keys, which ge... | ruby | def to_h
results = {}
defaults = @config["default_reports"] || {}
@config["repositories"].map { |repo_config|
repo = repo_config["repository"]
config = config_for(repo)
config["reports"].map { |format, report_config|
# Sometimes report_data has unused keys, which ge... | [
"def",
"to_h",
"results",
"=",
"{",
"}",
"defaults",
"=",
"@config",
"[",
"\"default_reports\"",
"]",
"||",
"{",
"}",
"@config",
"[",
"\"repositories\"",
"]",
".",
"map",
"{",
"|",
"repo_config",
"|",
"repo",
"=",
"repo_config",
"[",
"\"repository\"",
"]",... | Converts a ReportCollection to a Hash.
Also good for giving programmers nightmares, I suspect. | [
"Converts",
"a",
"ReportCollection",
"to",
"a",
"Hash",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/report_collection.rb#L66-L99 |
17,021 | duckinator/inq | lib/inq/report_collection.rb | Inq.ReportCollection.save_all | def save_all
reports = to_h
reports.each do |file, report|
File.write(file, report)
end
reports.keys
end | ruby | def save_all
reports = to_h
reports.each do |file, report|
File.write(file, report)
end
reports.keys
end | [
"def",
"save_all",
"reports",
"=",
"to_h",
"reports",
".",
"each",
"do",
"|",
"file",
",",
"report",
"|",
"File",
".",
"write",
"(",
"file",
",",
"report",
")",
"end",
"reports",
".",
"keys",
"end"
] | Save all of the reports to the corresponding files.
@return [Array<String>] An array of file paths. | [
"Save",
"all",
"of",
"the",
"reports",
"to",
"the",
"corresponding",
"files",
"."
] | e23a250aca4a62702cb5f3ee87cf26012e5a8344 | https://github.com/duckinator/inq/blob/e23a250aca4a62702cb5f3ee87cf26012e5a8344/lib/inq/report_collection.rb#L104-L111 |
17,022 | rails/sprockets-rails | lib/sprockets/railtie.rb | Rails.Application.asset_precompiled? | def asset_precompiled?(logical_path)
if precompiled_assets.include?(logical_path)
true
elsif !config.cache_classes
# Check to see if precompile list has been updated
precompiled_assets(true).include?(logical_path)
else
false
end
end | ruby | def asset_precompiled?(logical_path)
if precompiled_assets.include?(logical_path)
true
elsif !config.cache_classes
# Check to see if precompile list has been updated
precompiled_assets(true).include?(logical_path)
else
false
end
end | [
"def",
"asset_precompiled?",
"(",
"logical_path",
")",
"if",
"precompiled_assets",
".",
"include?",
"(",
"logical_path",
")",
"true",
"elsif",
"!",
"config",
".",
"cache_classes",
"# Check to see if precompile list has been updated",
"precompiled_assets",
"(",
"true",
")"... | Called from asset helpers to alert you if you reference an asset URL that
isn't precompiled and hence won't be available in production. | [
"Called",
"from",
"asset",
"helpers",
"to",
"alert",
"you",
"if",
"you",
"reference",
"an",
"asset",
"URL",
"that",
"isn",
"t",
"precompiled",
"and",
"hence",
"won",
"t",
"be",
"available",
"in",
"production",
"."
] | bbfcefda3240d924260e3530f896be94cdf23034 | https://github.com/rails/sprockets-rails/blob/bbfcefda3240d924260e3530f896be94cdf23034/lib/sprockets/railtie.rb#L34-L43 |
17,023 | rails/sprockets-rails | lib/sprockets/railtie.rb | Rails.Application.precompiled_assets | def precompiled_assets(clear_cache = false)
@precompiled_assets = nil if clear_cache
@precompiled_assets ||= assets_manifest.find(config.assets.precompile).map(&:logical_path).to_set
end | ruby | def precompiled_assets(clear_cache = false)
@precompiled_assets = nil if clear_cache
@precompiled_assets ||= assets_manifest.find(config.assets.precompile).map(&:logical_path).to_set
end | [
"def",
"precompiled_assets",
"(",
"clear_cache",
"=",
"false",
")",
"@precompiled_assets",
"=",
"nil",
"if",
"clear_cache",
"@precompiled_assets",
"||=",
"assets_manifest",
".",
"find",
"(",
"config",
".",
"assets",
".",
"precompile",
")",
".",
"map",
"(",
":log... | Lazy-load the precompile list so we don't cause asset compilation at app
boot time, but ensure we cache the list so we don't recompute it for each
request or test case. | [
"Lazy",
"-",
"load",
"the",
"precompile",
"list",
"so",
"we",
"don",
"t",
"cause",
"asset",
"compilation",
"at",
"app",
"boot",
"time",
"but",
"ensure",
"we",
"cache",
"the",
"list",
"so",
"we",
"don",
"t",
"recompute",
"it",
"for",
"each",
"request",
... | bbfcefda3240d924260e3530f896be94cdf23034 | https://github.com/rails/sprockets-rails/blob/bbfcefda3240d924260e3530f896be94cdf23034/lib/sprockets/railtie.rb#L48-L51 |
17,024 | guilleiguaran/fakeredis | lib/fakeredis/sorted_set_argument_handler.rb | FakeRedis.SortedSetArgumentHandler.handle | def handle(item)
case item
when "WEIGHTS"
self.type = :weights
self.weights = []
when "AGGREGATE"
self.type = :aggregate
when nil
# This should never be called, raise a syntax error if we manage to hit it
raise(Redis::CommandError, "ERR syntax error")
... | ruby | def handle(item)
case item
when "WEIGHTS"
self.type = :weights
self.weights = []
when "AGGREGATE"
self.type = :aggregate
when nil
# This should never be called, raise a syntax error if we manage to hit it
raise(Redis::CommandError, "ERR syntax error")
... | [
"def",
"handle",
"(",
"item",
")",
"case",
"item",
"when",
"\"WEIGHTS\"",
"self",
".",
"type",
"=",
":weights",
"self",
".",
"weights",
"=",
"[",
"]",
"when",
"\"AGGREGATE\"",
"self",
".",
"type",
"=",
":aggregate",
"when",
"nil",
"# This should never be cal... | Decides how to handle an item, depending on where we are in the arguments | [
"Decides",
"how",
"to",
"handle",
"an",
"item",
"depending",
"on",
"where",
"we",
"are",
"in",
"the",
"arguments"
] | df7b07f55e3b194ccb7208ed143711b2426d78c4 | https://github.com/guilleiguaran/fakeredis/blob/df7b07f55e3b194ccb7208ed143711b2426d78c4/lib/fakeredis/sorted_set_argument_handler.rb#L46-L60 |
17,025 | guilleiguaran/fakeredis | lib/fakeredis/sorted_set_store.rb | FakeRedis.SortedSetStore.computed_values | def computed_values
unless defined?(@computed_values) && @computed_values
# Do nothing if all weights are 1, as n * 1 is n
@computed_values = hashes if weights.all? {|weight| weight == 1 }
# Otherwise, multiply the values in each hash by that hash's weighting
@computed_values ||= h... | ruby | def computed_values
unless defined?(@computed_values) && @computed_values
# Do nothing if all weights are 1, as n * 1 is n
@computed_values = hashes if weights.all? {|weight| weight == 1 }
# Otherwise, multiply the values in each hash by that hash's weighting
@computed_values ||= h... | [
"def",
"computed_values",
"unless",
"defined?",
"(",
"@computed_values",
")",
"&&",
"@computed_values",
"# Do nothing if all weights are 1, as n * 1 is n",
"@computed_values",
"=",
"hashes",
"if",
"weights",
".",
"all?",
"{",
"|",
"weight",
"|",
"weight",
"==",
"1",
"... | Apply the weightings to the hashes | [
"Apply",
"the",
"weightings",
"to",
"the",
"hashes"
] | df7b07f55e3b194ccb7208ed143711b2426d78c4 | https://github.com/guilleiguaran/fakeredis/blob/df7b07f55e3b194ccb7208ed143711b2426d78c4/lib/fakeredis/sorted_set_store.rb#L27-L38 |
17,026 | guilleiguaran/fakeredis | lib/fakeredis/zset.rb | FakeRedis.ZSet._floatify | def _floatify(str, increment = true)
if (( inf = str.to_s.match(/^([+-])?inf/i) ))
(inf[1] == "-" ? -1.0 : 1.0) / 0.0
elsif (( number = str.to_s.match(/^\((\d+)/i) ))
number[1].to_i + (increment ? 1 : -1)
else
Float str.to_s
end
rescue ArgumentError
raise Redis:... | ruby | def _floatify(str, increment = true)
if (( inf = str.to_s.match(/^([+-])?inf/i) ))
(inf[1] == "-" ? -1.0 : 1.0) / 0.0
elsif (( number = str.to_s.match(/^\((\d+)/i) ))
number[1].to_i + (increment ? 1 : -1)
else
Float str.to_s
end
rescue ArgumentError
raise Redis:... | [
"def",
"_floatify",
"(",
"str",
",",
"increment",
"=",
"true",
")",
"if",
"(",
"(",
"inf",
"=",
"str",
".",
"to_s",
".",
"match",
"(",
"/",
"/i",
")",
")",
")",
"(",
"inf",
"[",
"1",
"]",
"==",
"\"-\"",
"?",
"-",
"1.0",
":",
"1.0",
")",
"/"... | Originally lifted from redis-rb | [
"Originally",
"lifted",
"from",
"redis",
"-",
"rb"
] | df7b07f55e3b194ccb7208ed143711b2426d78c4 | https://github.com/guilleiguaran/fakeredis/blob/df7b07f55e3b194ccb7208ed143711b2426d78c4/lib/fakeredis/zset.rb#L26-L36 |
17,027 | cequel/cequel | lib/cequel/uuids.rb | Cequel.Uuids.uuid | def uuid(value = nil)
if value.nil?
timeuuid_generator.now
elsif value.is_a?(Time)
timeuuid_generator.at(value)
elsif value.is_a?(DateTime)
timeuuid_generator.at(Time.at(value.to_f))
else
Type::Timeuuid.instance.cast(value)
end
end | ruby | def uuid(value = nil)
if value.nil?
timeuuid_generator.now
elsif value.is_a?(Time)
timeuuid_generator.at(value)
elsif value.is_a?(DateTime)
timeuuid_generator.at(Time.at(value.to_f))
else
Type::Timeuuid.instance.cast(value)
end
end | [
"def",
"uuid",
"(",
"value",
"=",
"nil",
")",
"if",
"value",
".",
"nil?",
"timeuuid_generator",
".",
"now",
"elsif",
"value",
".",
"is_a?",
"(",
"Time",
")",
"timeuuid_generator",
".",
"at",
"(",
"value",
")",
"elsif",
"value",
".",
"is_a?",
"(",
"Date... | Create a UUID
@param value [Time,String,Integer] timestamp to assign to the UUID, or
numeric or string representation of the UUID
@return a UUID appropriate for use with Cequel | [
"Create",
"a",
"UUID"
] | 35e90199470481795f0a6e1604767d65a0f2c604 | https://github.com/cequel/cequel/blob/35e90199470481795f0a6e1604767d65a0f2c604/lib/cequel/uuids.rb#L18-L28 |
17,028 | infused/dbf | lib/dbf/table.rb | DBF.Table.find | def find(command, options = {}, &block)
case command
when Integer
record(command)
when Array
command.map { |i| record(i) }
when :all
find_all(options, &block)
when :first
find_first(options)
end
end | ruby | def find(command, options = {}, &block)
case command
when Integer
record(command)
when Array
command.map { |i| record(i) }
when :all
find_all(options, &block)
when :first
find_first(options)
end
end | [
"def",
"find",
"(",
"command",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"case",
"command",
"when",
"Integer",
"record",
"(",
"command",
")",
"when",
"Array",
"command",
".",
"map",
"{",
"|",
"i",
"|",
"record",
"(",
"i",
")",
"}",
"... | Find records using a simple ActiveRecord-like syntax.
Examples:
table = DBF::Table.new 'mydata.dbf'
# Find record number 5
table.find(5)
# Find all records for Keith Morrison
table.find :all, first_name: "Keith", last_name: "Morrison"
# Find first record
table.find :first, first_name: "Keith"
... | [
"Find",
"records",
"using",
"a",
"simple",
"ActiveRecord",
"-",
"like",
"syntax",
"."
] | 6f60cfe100e854057f112e84fd32656f0ed7f84b | https://github.com/infused/dbf/blob/6f60cfe100e854057f112e84fd32656f0ed7f84b/lib/dbf/table.rb#L148-L159 |
17,029 | infused/dbf | lib/dbf/table.rb | DBF.Table.record | def record(index)
seek_to_record(index)
return nil if deleted_record?
DBF::Record.new(@data.read(record_length), columns, version, @memo)
end | ruby | def record(index)
seek_to_record(index)
return nil if deleted_record?
DBF::Record.new(@data.read(record_length), columns, version, @memo)
end | [
"def",
"record",
"(",
"index",
")",
"seek_to_record",
"(",
"index",
")",
"return",
"nil",
"if",
"deleted_record?",
"DBF",
"::",
"Record",
".",
"new",
"(",
"@data",
".",
"read",
"(",
"record_length",
")",
",",
"columns",
",",
"version",
",",
"@memo",
")",... | Retrieve a record by index number.
The record will be nil if it has been deleted, but not yet pruned from
the database.
@param [Integer] index
@return [DBF::Record, NilClass] | [
"Retrieve",
"a",
"record",
"by",
"index",
"number",
".",
"The",
"record",
"will",
"be",
"nil",
"if",
"it",
"has",
"been",
"deleted",
"but",
"not",
"yet",
"pruned",
"from",
"the",
"database",
"."
] | 6f60cfe100e854057f112e84fd32656f0ed7f84b | https://github.com/infused/dbf/blob/6f60cfe100e854057f112e84fd32656f0ed7f84b/lib/dbf/table.rb#L177-L182 |
17,030 | infused/dbf | lib/dbf/table.rb | DBF.Table.to_csv | def to_csv(path = nil)
out_io = path ? File.open(path, 'w') : $stdout
csv = CSV.new(out_io, force_quotes: true)
csv << column_names
each { |record| csv << record.to_a }
end | ruby | def to_csv(path = nil)
out_io = path ? File.open(path, 'w') : $stdout
csv = CSV.new(out_io, force_quotes: true)
csv << column_names
each { |record| csv << record.to_a }
end | [
"def",
"to_csv",
"(",
"path",
"=",
"nil",
")",
"out_io",
"=",
"path",
"?",
"File",
".",
"open",
"(",
"path",
",",
"'w'",
")",
":",
"$stdout",
"csv",
"=",
"CSV",
".",
"new",
"(",
"out_io",
",",
"force_quotes",
":",
"true",
")",
"csv",
"<<",
"colum... | Dumps all records to a CSV file. If no filename is given then CSV is
output to STDOUT.
@param [optional String] path Defaults to STDOUT | [
"Dumps",
"all",
"records",
"to",
"a",
"CSV",
"file",
".",
"If",
"no",
"filename",
"is",
"given",
"then",
"CSV",
"is",
"output",
"to",
"STDOUT",
"."
] | 6f60cfe100e854057f112e84fd32656f0ed7f84b | https://github.com/infused/dbf/blob/6f60cfe100e854057f112e84fd32656f0ed7f84b/lib/dbf/table.rb#L190-L195 |
17,031 | deliveroo/routemaster-drain | lib/routemaster/cache.rb | Routemaster.Cache.get | def get(url, version: nil, locale: nil)
@client.get(url, headers: headers(version: version, locale: locale))
end | ruby | def get(url, version: nil, locale: nil)
@client.get(url, headers: headers(version: version, locale: locale))
end | [
"def",
"get",
"(",
"url",
",",
"version",
":",
"nil",
",",
"locale",
":",
"nil",
")",
"@client",
".",
"get",
"(",
"url",
",",
"headers",
":",
"headers",
"(",
"version",
":",
"version",
",",
"locale",
":",
"locale",
")",
")",
"end"
] | Get the response from a URL, from the cache if possible.
Stores to the cache on misses.
Different versions and locales are stored separately in the cache.
@param version [Integer] The version to pass in headers, as `Accept: application/json;v=2`
@param locale [String] The language to request in the `Accept-Langua... | [
"Get",
"the",
"response",
"from",
"a",
"URL",
"from",
"the",
"cache",
"if",
"possible",
".",
"Stores",
"to",
"the",
"cache",
"on",
"misses",
"."
] | e854e15538d672c06ea5e82d3fde8e243b8d54d5 | https://github.com/deliveroo/routemaster-drain/blob/e854e15538d672c06ea5e82d3fde8e243b8d54d5/lib/routemaster/cache.rb#L51-L53 |
17,032 | deliveroo/routemaster-drain | lib/routemaster/redis_broker.rb | Routemaster.RedisBroker.inject | def inject(clients={})
@_injected_clients = true
clients.each_pair do |name, client|
_close_if_present(@_connections[name])
@_connections[name] = Redis::Namespace.new(DEFAULT_NAMESPACE, redis: client)
end
end | ruby | def inject(clients={})
@_injected_clients = true
clients.each_pair do |name, client|
_close_if_present(@_connections[name])
@_connections[name] = Redis::Namespace.new(DEFAULT_NAMESPACE, redis: client)
end
end | [
"def",
"inject",
"(",
"clients",
"=",
"{",
"}",
")",
"@_injected_clients",
"=",
"true",
"clients",
".",
"each_pair",
"do",
"|",
"name",
",",
"client",
"|",
"_close_if_present",
"(",
"@_connections",
"[",
"name",
"]",
")",
"@_connections",
"[",
"name",
"]",... | Allow to inject pre-built Redis clients
Before storing a new connection, ensures that any previously
set client is properly closed. | [
"Allow",
"to",
"inject",
"pre",
"-",
"built",
"Redis",
"clients"
] | e854e15538d672c06ea5e82d3fde8e243b8d54d5 | https://github.com/deliveroo/routemaster-drain/blob/e854e15538d672c06ea5e82d3fde8e243b8d54d5/lib/routemaster/redis_broker.rb#L35-L41 |
17,033 | nevans/resque-pool | features/support/aruba_daemon_support.rb | Aruba.Api.keep_trying | def keep_trying(timeout=10, tries=0)
puts "Try: #{tries}" if @announce_env
yield
rescue RSpec::Expectations::ExpectationNotMetError
if tries < timeout
sleep 1
tries += 1
retry
else
raise
end
end | ruby | def keep_trying(timeout=10, tries=0)
puts "Try: #{tries}" if @announce_env
yield
rescue RSpec::Expectations::ExpectationNotMetError
if tries < timeout
sleep 1
tries += 1
retry
else
raise
end
end | [
"def",
"keep_trying",
"(",
"timeout",
"=",
"10",
",",
"tries",
"=",
"0",
")",
"puts",
"\"Try: #{tries}\"",
"if",
"@announce_env",
"yield",
"rescue",
"RSpec",
"::",
"Expectations",
"::",
"ExpectationNotMetError",
"if",
"tries",
"<",
"timeout",
"sleep",
"1",
"tr... | this is a horrible hack, to make sure that it's done what it needs to do
before we do our next step | [
"this",
"is",
"a",
"horrible",
"hack",
"to",
"make",
"sure",
"that",
"it",
"s",
"done",
"what",
"it",
"needs",
"to",
"do",
"before",
"we",
"do",
"our",
"next",
"step"
] | 62293e48eb75852aa3e0f5f726d158a8614e9259 | https://github.com/nevans/resque-pool/blob/62293e48eb75852aa3e0f5f726d158a8614e9259/features/support/aruba_daemon_support.rb#L11-L22 |
17,034 | rharriso/bower-rails | lib/bower-rails/performer.rb | BowerRails.Performer.perform_command | def perform_command(remove_components = true, &block)
# Load in bower json file
txt = File.read(File.join(root_path, "bower.json"))
json = JSON.parse(txt)
# Load and merge root .bowerrc
dot_bowerrc = JSON.parse(File.read(File.join(root_path, '.bowerrc'))) rescue {}
dot_bowerrc["di... | ruby | def perform_command(remove_components = true, &block)
# Load in bower json file
txt = File.read(File.join(root_path, "bower.json"))
json = JSON.parse(txt)
# Load and merge root .bowerrc
dot_bowerrc = JSON.parse(File.read(File.join(root_path, '.bowerrc'))) rescue {}
dot_bowerrc["di... | [
"def",
"perform_command",
"(",
"remove_components",
"=",
"true",
",",
"&",
"block",
")",
"# Load in bower json file",
"txt",
"=",
"File",
".",
"read",
"(",
"File",
".",
"join",
"(",
"root_path",
",",
"\"bower.json\"",
")",
")",
"json",
"=",
"JSON",
".",
"p... | run the passed bower block in appropriate folders | [
"run",
"the",
"passed",
"bower",
"block",
"in",
"appropriate",
"folders"
] | 30c6697614149b996f8fb158290bb554990b247d | https://github.com/rharriso/bower-rails/blob/30c6697614149b996f8fb158290bb554990b247d/lib/bower-rails/performer.rb#L62-L114 |
17,035 | drecom/activerecord-turntable | lib/active_record/turntable/connection_proxy.rb | ActiveRecord::Turntable.ConnectionProxy.with_shard | def with_shard(shard)
shard = cluster.to_shard(shard)
old_shard = current_shard
old_fixed = fixed_shard
self.current_shard = shard
self.fixed_shard = shard
yield
ensure
self.fixed_shard = old_fixed
self.current_shard = old_shard
end | ruby | def with_shard(shard)
shard = cluster.to_shard(shard)
old_shard = current_shard
old_fixed = fixed_shard
self.current_shard = shard
self.fixed_shard = shard
yield
ensure
self.fixed_shard = old_fixed
self.current_shard = old_shard
end | [
"def",
"with_shard",
"(",
"shard",
")",
"shard",
"=",
"cluster",
".",
"to_shard",
"(",
"shard",
")",
"old_shard",
"=",
"current_shard",
"old_fixed",
"=",
"fixed_shard",
"self",
".",
"current_shard",
"=",
"shard",
"self",
".",
"fixed_shard",
"=",
"shard",
"yi... | Fix connection to given shard in block
@param [ActiveRecord::Base, Symbol, ActiveRecord::Turntable::Shard, Numeric, String] shard which you want to fix
@param shard [ActiveRecord::Base] AR Object
@param shard [Symbol] shard name symbol that defined in turntable.yml
@param shard [ActiveRecord::Turntable::Shard] Shar... | [
"Fix",
"connection",
"to",
"given",
"shard",
"in",
"block"
] | 7db85be222f8345c6ed14b97a242a1e1c392992e | https://github.com/drecom/activerecord-turntable/blob/7db85be222f8345c6ed14b97a242a1e1c392992e/lib/active_record/turntable/connection_proxy.rb#L159-L170 |
17,036 | drecom/activerecord-turntable | lib/active_record/turntable/connection_proxy.rb | ActiveRecord::Turntable.ConnectionProxy.with_all | def with_all(continue_on_error = false)
cluster.shards.map do |shard|
begin
with_shard(shard) {
yield
}
rescue Exception => err
unless continue_on_error
raise err
end
err
end
end
end | ruby | def with_all(continue_on_error = false)
cluster.shards.map do |shard|
begin
with_shard(shard) {
yield
}
rescue Exception => err
unless continue_on_error
raise err
end
err
end
end
end | [
"def",
"with_all",
"(",
"continue_on_error",
"=",
"false",
")",
"cluster",
".",
"shards",
".",
"map",
"do",
"|",
"shard",
"|",
"begin",
"with_shard",
"(",
"shard",
")",
"{",
"yield",
"}",
"rescue",
"Exception",
"=>",
"err",
"unless",
"continue_on_error",
"... | Send queries to all shards in this cluster
@param [Boolean] continue_on_error when a shard raises error, ignore exception and continue | [
"Send",
"queries",
"to",
"all",
"shards",
"in",
"this",
"cluster"
] | 7db85be222f8345c6ed14b97a242a1e1c392992e | https://github.com/drecom/activerecord-turntable/blob/7db85be222f8345c6ed14b97a242a1e1c392992e/lib/active_record/turntable/connection_proxy.rb#L201-L214 |
17,037 | drecom/activerecord-turntable | lib/active_record/turntable/connection_proxy.rb | ActiveRecord::Turntable.ConnectionProxy.with_default_and_all | def with_default_and_all(continue_on_error = false)
([default_shard] + cluster.shards).map do |shard|
begin
with_shard(shard) {
yield
}
rescue Exception => err
unless continue_on_error
raise err
end
err
end
end... | ruby | def with_default_and_all(continue_on_error = false)
([default_shard] + cluster.shards).map do |shard|
begin
with_shard(shard) {
yield
}
rescue Exception => err
unless continue_on_error
raise err
end
err
end
end... | [
"def",
"with_default_and_all",
"(",
"continue_on_error",
"=",
"false",
")",
"(",
"[",
"default_shard",
"]",
"+",
"cluster",
".",
"shards",
")",
".",
"map",
"do",
"|",
"shard",
"|",
"begin",
"with_shard",
"(",
"shard",
")",
"{",
"yield",
"}",
"rescue",
"E... | Send queries to default connection and all shards in this cluster
@param [Boolean] continue_on_error when a shard raises error, ignore exception and continue | [
"Send",
"queries",
"to",
"default",
"connection",
"and",
"all",
"shards",
"in",
"this",
"cluster"
] | 7db85be222f8345c6ed14b97a242a1e1c392992e | https://github.com/drecom/activerecord-turntable/blob/7db85be222f8345c6ed14b97a242a1e1c392992e/lib/active_record/turntable/connection_proxy.rb#L218-L231 |
17,038 | toland/patron | lib/patron/response.rb | Patron.Response.parse_headers | def parse_headers(header_data_for_multiple_responses)
@headers = {}
responses = Patron::HeaderParser.parse(header_data_for_multiple_responses)
last_response = responses[-1] # Only use the last response (for proxies and redirects)
@status_line = last_response.status_line
last_response.hea... | ruby | def parse_headers(header_data_for_multiple_responses)
@headers = {}
responses = Patron::HeaderParser.parse(header_data_for_multiple_responses)
last_response = responses[-1] # Only use the last response (for proxies and redirects)
@status_line = last_response.status_line
last_response.hea... | [
"def",
"parse_headers",
"(",
"header_data_for_multiple_responses",
")",
"@headers",
"=",
"{",
"}",
"responses",
"=",
"Patron",
"::",
"HeaderParser",
".",
"parse",
"(",
"header_data_for_multiple_responses",
")",
"last_response",
"=",
"responses",
"[",
"-",
"1",
"]",
... | Called by the C code to parse and set the headers | [
"Called",
"by",
"the",
"C",
"code",
"to",
"parse",
"and",
"set",
"the",
"headers"
] | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/response.rb#L116-L135 |
17,039 | toland/patron | lib/patron/request.rb | Patron.Request.auth_type= | def auth_type=(type=:basic)
@auth_type = case type
when :basic, "basic"
Request::AuthBasic
when :digest, "digest"
Request::AuthDigest
when :any, "any"
Request::AuthAny
else
raise "#{type.inspect} is an unknown authentication type"
end
end | ruby | def auth_type=(type=:basic)
@auth_type = case type
when :basic, "basic"
Request::AuthBasic
when :digest, "digest"
Request::AuthDigest
when :any, "any"
Request::AuthAny
else
raise "#{type.inspect} is an unknown authentication type"
end
end | [
"def",
"auth_type",
"=",
"(",
"type",
"=",
":basic",
")",
"@auth_type",
"=",
"case",
"type",
"when",
":basic",
",",
"\"basic\"",
"Request",
"::",
"AuthBasic",
"when",
":digest",
",",
"\"digest\"",
"Request",
"::",
"AuthDigest",
"when",
":any",
",",
"\"any\""... | Set the type of authentication to use for this request.
@param [String, Symbol]type The type of authentication to use for this request, can be one of
:basic, :digest, or :any
@example
sess.username = "foo"
sess.password = "sekrit"
sess.auth_type = :digest | [
"Set",
"the",
"type",
"of",
"authentication",
"to",
"use",
"for",
"this",
"request",
"."
] | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/request.rb#L49-L60 |
17,040 | toland/patron | lib/patron/request.rb | Patron.Request.action= | def action=(action)
if !VALID_ACTIONS.include?(action.to_s.upcase)
raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}"
end
@action = action.downcase.to_sym
end | ruby | def action=(action)
if !VALID_ACTIONS.include?(action.to_s.upcase)
raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}"
end
@action = action.downcase.to_sym
end | [
"def",
"action",
"=",
"(",
"action",
")",
"if",
"!",
"VALID_ACTIONS",
".",
"include?",
"(",
"action",
".",
"to_s",
".",
"upcase",
")",
"raise",
"ArgumentError",
",",
"\"Action must be one of #{VALID_ACTIONS.join(', ')}\"",
"end",
"@action",
"=",
"action",
".",
"... | Sets the HTTP verb for the request
@param action[String] the name of the HTTP verb | [
"Sets",
"the",
"HTTP",
"verb",
"for",
"the",
"request"
] | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/request.rb#L84-L89 |
17,041 | toland/patron | lib/patron/session.rb | Patron.Session.handle_cookies | def handle_cookies(file_path = nil)
if file_path
path = Pathname(file_path).expand_path
if !File.exists?(file_path) && !File.writable?(path.dirname)
raise ArgumentError, "Can't create file #{path} (permission error)"
elsif File.exists?(file_path) && !File.writable?(file_... | ruby | def handle_cookies(file_path = nil)
if file_path
path = Pathname(file_path).expand_path
if !File.exists?(file_path) && !File.writable?(path.dirname)
raise ArgumentError, "Can't create file #{path} (permission error)"
elsif File.exists?(file_path) && !File.writable?(file_... | [
"def",
"handle_cookies",
"(",
"file_path",
"=",
"nil",
")",
"if",
"file_path",
"path",
"=",
"Pathname",
"(",
"file_path",
")",
".",
"expand_path",
"if",
"!",
"File",
".",
"exists?",
"(",
"file_path",
")",
"&&",
"!",
"File",
".",
"writable?",
"(",
"path",... | Create a new Session object for performing requests.
@param args[Hash] options for the Session (same names as the writable attributes of the Session)
@yield self
Turn on cookie handling for this session, storing them in memory by
default or in +file+ if specified. The `file` must be readable and
writable. Calling... | [
"Create",
"a",
"new",
"Session",
"object",
"for",
"performing",
"requests",
"."
] | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/session.rb#L145-L164 |
17,042 | toland/patron | lib/patron/session.rb | Patron.Session.post | def post(url, data, headers = {})
if data.is_a?(Hash)
data = data.map {|k,v| urlencode(k.to_s) + '=' + urlencode(v.to_s) }.join('&')
headers['Content-Type'] = 'application/x-www-form-urlencoded'
end
request(:post, url, headers, :data => data)
end | ruby | def post(url, data, headers = {})
if data.is_a?(Hash)
data = data.map {|k,v| urlencode(k.to_s) + '=' + urlencode(v.to_s) }.join('&')
headers['Content-Type'] = 'application/x-www-form-urlencoded'
end
request(:post, url, headers, :data => data)
end | [
"def",
"post",
"(",
"url",
",",
"data",
",",
"headers",
"=",
"{",
"}",
")",
"if",
"data",
".",
"is_a?",
"(",
"Hash",
")",
"data",
"=",
"data",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"urlencode",
"(",
"k",
".",
"to_s",
")",
"+",
"'='",
"+... | Uploads the passed `data` to the specified `url` using an HTTP POST.
@param url[String] the URL to fetch
@param data[Hash, #to_s, #to_path] a Hash of form fields/values,
or an object that can be converted to a String
to create the request body, or an object that responds to #to_path to upload the
entire req... | [
"Uploads",
"the",
"passed",
"data",
"to",
"the",
"specified",
"url",
"using",
"an",
"HTTP",
"POST",
"."
] | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/session.rb#L275-L281 |
17,043 | toland/patron | lib/patron/session.rb | Patron.Session.post_multipart | def post_multipart(url, data, filename, headers = {})
request(:post, url, headers, {:data => data, :file => filename, :multipart => true})
end | ruby | def post_multipart(url, data, filename, headers = {})
request(:post, url, headers, {:data => data, :file => filename, :multipart => true})
end | [
"def",
"post_multipart",
"(",
"url",
",",
"data",
",",
"filename",
",",
"headers",
"=",
"{",
"}",
")",
"request",
"(",
":post",
",",
"url",
",",
"headers",
",",
"{",
":data",
"=>",
"data",
",",
":file",
"=>",
"filename",
",",
":multipart",
"=>",
"tru... | Uploads the contents of `filename` to the specified `url` using an HTTP POST,
in combination with given form fields passed in `data`.
@param url[String] the URL to fetch
@param data[Hash] hash of the form fields
@param filename[String] path to the file to be uploaded
@param headers[Hash] the hash of header keys t... | [
"Uploads",
"the",
"contents",
"of",
"filename",
"to",
"the",
"specified",
"url",
"using",
"an",
"HTTP",
"POST",
"in",
"combination",
"with",
"given",
"form",
"fields",
"passed",
"in",
"data",
"."
] | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/session.rb#L302-L304 |
17,044 | toland/patron | lib/patron/session.rb | Patron.Session.build_request | def build_request(action, url, headers, options = {})
# If the Expect header isn't set uploads are really slow
headers['Expect'] ||= ''
Request.new.tap do |req|
req.action = action
req.headers = self.headers.merge headers
req.automatic_content_en... | ruby | def build_request(action, url, headers, options = {})
# If the Expect header isn't set uploads are really slow
headers['Expect'] ||= ''
Request.new.tap do |req|
req.action = action
req.headers = self.headers.merge headers
req.automatic_content_en... | [
"def",
"build_request",
"(",
"action",
",",
"url",
",",
"headers",
",",
"options",
"=",
"{",
"}",
")",
"# If the Expect header isn't set uploads are really slow",
"headers",
"[",
"'Expect'",
"]",
"||=",
"''",
"Request",
".",
"new",
".",
"tap",
"do",
"|",
"req"... | Builds a request object that can be used by ++handle_request++
Note that internally, ++handle_request++ uses instance variables of
the Request object, and not it's public methods.
@param action[String] the HTTP verb
@param url[#to_s] the addition to the base url component, or a complete URL
@param headers[Hash] a... | [
"Builds",
"a",
"request",
"object",
"that",
"can",
"be",
"used",
"by",
"++",
"handle_request",
"++",
"Note",
"that",
"internally",
"++",
"handle_request",
"++",
"uses",
"instance",
"variables",
"of",
"the",
"Request",
"object",
"and",
"not",
"it",
"s",
"publ... | c48e31cfb93d8359c8c81a9d3fb14269f24b6aac | https://github.com/toland/patron/blob/c48e31cfb93d8359c8c81a9d3fb14269f24b6aac/lib/patron/session.rb#L357-L400 |
17,045 | xijo/reverse_markdown | lib/reverse_markdown/cleaner.rb | ReverseMarkdown.Cleaner.clean_tag_borders | def clean_tag_borders(string)
result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
preserve_border_whitespaces(match, default_border: ReverseMarkdown.config.tag_border) do
match.strip.sub('** ', '**').sub(' **', '**')
end
end
result = result.gsub(/\s?\_{2,}.*?\_{2,}\s?/)... | ruby | def clean_tag_borders(string)
result = string.gsub(/\s?\*{2,}.*?\*{2,}\s?/) do |match|
preserve_border_whitespaces(match, default_border: ReverseMarkdown.config.tag_border) do
match.strip.sub('** ', '**').sub(' **', '**')
end
end
result = result.gsub(/\s?\_{2,}.*?\_{2,}\s?/)... | [
"def",
"clean_tag_borders",
"(",
"string",
")",
"result",
"=",
"string",
".",
"gsub",
"(",
"/",
"\\s",
"\\*",
"\\*",
"\\s",
"/",
")",
"do",
"|",
"match",
"|",
"preserve_border_whitespaces",
"(",
"match",
",",
"default_border",
":",
"ReverseMarkdown",
".",
... | Find non-asterisk content that is enclosed by two or
more asterisks. Ensure that only one whitespace occurs
in the border area.
Same for underscores and brackets. | [
"Find",
"non",
"-",
"asterisk",
"content",
"that",
"is",
"enclosed",
"by",
"two",
"or",
"more",
"asterisks",
".",
"Ensure",
"that",
"only",
"one",
"whitespace",
"occurs",
"in",
"the",
"border",
"area",
".",
"Same",
"for",
"underscores",
"and",
"brackets",
... | 4a893bc6534ade98171ed4acfc8777e0f0ab7d6c | https://github.com/xijo/reverse_markdown/blob/4a893bc6534ade98171ed4acfc8777e0f0ab7d6c/lib/reverse_markdown/cleaner.rb#L32-L56 |
17,046 | sinatra/mustermann | mustermann-contrib/lib/mustermann/file_utils.rb | Mustermann.FileUtils.glob_map | def glob_map(map = {}, **options, &block)
map = Mapper === map ? map : Mapper.new(map, **options)
mapped = glob(*map.to_h.keys).map { |f| [f, unescape(map[f])] }
block ? mapped.map(&block) : Hash[mapped]
end | ruby | def glob_map(map = {}, **options, &block)
map = Mapper === map ? map : Mapper.new(map, **options)
mapped = glob(*map.to_h.keys).map { |f| [f, unescape(map[f])] }
block ? mapped.map(&block) : Hash[mapped]
end | [
"def",
"glob_map",
"(",
"map",
"=",
"{",
"}",
",",
"**",
"options",
",",
"&",
"block",
")",
"map",
"=",
"Mapper",
"===",
"map",
"?",
"map",
":",
"Mapper",
".",
"new",
"(",
"map",
",",
"**",
"options",
")",
"mapped",
"=",
"glob",
"(",
"map",
"."... | Allows to search for files an map these onto other strings.
@example
require 'mustermann/file_utils'
Mustermann::FileUtils.glob_map(':base.:ext' => ':base.bak.:ext') # => {'example.txt' => 'example.bak.txt'}
Mustermann::FileUtils.glob_map(':base.:ext' => :base) { |file, mapped| mapped } # => ['example']
@... | [
"Allows",
"to",
"search",
"for",
"files",
"an",
"map",
"these",
"onto",
"other",
"strings",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/file_utils.rb#L60-L64 |
17,047 | sinatra/mustermann | mustermann-contrib/lib/mustermann/file_utils.rb | Mustermann.FileUtils.cp | def cp(map = {}, recursive: false, **options)
utils_opts, opts = split_options(:preserve, :dereference_root, :remove_destination, **options)
cp_method = recursive ? :cp_r : :cp
glob_map(map, **opts) { |o,n| f.send(cp_method, o, n, **utils_opts) }
end | ruby | def cp(map = {}, recursive: false, **options)
utils_opts, opts = split_options(:preserve, :dereference_root, :remove_destination, **options)
cp_method = recursive ? :cp_r : :cp
glob_map(map, **opts) { |o,n| f.send(cp_method, o, n, **utils_opts) }
end | [
"def",
"cp",
"(",
"map",
"=",
"{",
"}",
",",
"recursive",
":",
"false",
",",
"**",
"options",
")",
"utils_opts",
",",
"opts",
"=",
"split_options",
"(",
":preserve",
",",
":dereference_root",
",",
":remove_destination",
",",
"**",
"options",
")",
"cp_metho... | Copies files based on a pattern mapping.
@example
require 'mustermann/file_utils'
# copies example.txt to example.bak.txt
Mustermann::FileUtils.cp(':base.:ext' => ':base.bak.:ext')
@see #glob_map | [
"Copies",
"files",
"based",
"on",
"a",
"pattern",
"mapping",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/file_utils.rb#L75-L79 |
17,048 | sinatra/mustermann | mustermann-contrib/lib/mustermann/file_utils.rb | Mustermann.FileUtils.mv | def mv(map = {}, **options)
utils_opts, opts = split_options(**options)
glob_map(map, **opts) { |o,n| f.mv(o, n, **utils_opts) }
end | ruby | def mv(map = {}, **options)
utils_opts, opts = split_options(**options)
glob_map(map, **opts) { |o,n| f.mv(o, n, **utils_opts) }
end | [
"def",
"mv",
"(",
"map",
"=",
"{",
"}",
",",
"**",
"options",
")",
"utils_opts",
",",
"opts",
"=",
"split_options",
"(",
"**",
"options",
")",
"glob_map",
"(",
"map",
",",
"**",
"opts",
")",
"{",
"|",
"o",
",",
"n",
"|",
"f",
".",
"mv",
"(",
... | Moves files based on a pattern mapping.
@example
require 'mustermann/file_utils'
# moves example.txt to example.bak.txt
Mustermann::FileUtils.mv(':base.:ext' => ':base.bak.:ext')
@see #glob_map | [
"Moves",
"files",
"based",
"on",
"a",
"pattern",
"mapping",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/file_utils.rb#L104-L107 |
17,049 | sinatra/mustermann | mustermann-contrib/lib/mustermann/file_utils.rb | Mustermann.FileUtils.ln | def ln(map = {}, symbolic: false, **options)
utils_opts, opts = split_options(**options)
link_method = symbolic ? :ln_s : :ln
glob_map(map, **opts) { |o,n| f.send(link_method, o, n, **utils_opts) }
end | ruby | def ln(map = {}, symbolic: false, **options)
utils_opts, opts = split_options(**options)
link_method = symbolic ? :ln_s : :ln
glob_map(map, **opts) { |o,n| f.send(link_method, o, n, **utils_opts) }
end | [
"def",
"ln",
"(",
"map",
"=",
"{",
"}",
",",
"symbolic",
":",
"false",
",",
"**",
"options",
")",
"utils_opts",
",",
"opts",
"=",
"split_options",
"(",
"**",
"options",
")",
"link_method",
"=",
"symbolic",
"?",
":ln_s",
":",
":ln",
"glob_map",
"(",
"... | Creates links based on a pattern mapping.
@example
require 'mustermann/file_utils'
# creates a link from bin/example to lib/example.rb
Mustermann::FileUtils.ln('lib/:name.rb' => 'bin/:name')
@see #glob_map | [
"Creates",
"links",
"based",
"on",
"a",
"pattern",
"mapping",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/file_utils.rb#L119-L123 |
17,050 | sinatra/mustermann | mustermann-contrib/lib/mustermann/file_utils.rb | Mustermann.FileUtils.ln_sf | def ln_sf(map = {}, **options)
ln(map, symbolic: true, force: true, **options)
end | ruby | def ln_sf(map = {}, **options)
ln(map, symbolic: true, force: true, **options)
end | [
"def",
"ln_sf",
"(",
"map",
"=",
"{",
"}",
",",
"**",
"options",
")",
"ln",
"(",
"map",
",",
"symbolic",
":",
"true",
",",
"force",
":",
"true",
",",
"**",
"options",
")",
"end"
] | Creates symbolic links based on a pattern mapping.
Overrides potentailly existing files.
@example
require 'mustermann/file_utils'
# creates a symbolic link from bin/example to lib/example.rb
Mustermann::FileUtils.ln_sf('lib/:name.rb' => 'bin/:name')
@see #glob_map | [
"Creates",
"symbolic",
"links",
"based",
"on",
"a",
"pattern",
"mapping",
".",
"Overrides",
"potentailly",
"existing",
"files",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/file_utils.rb#L148-L150 |
17,051 | sinatra/mustermann | mustermann-contrib/lib/mustermann/file_utils.rb | Mustermann.FileUtils.pattern_with_glob_pattern | def pattern_with_glob_pattern(*pattern, **options)
options[:uri_decode] ||= false
pattern = Mustermann.new(*pattern.flatten, **options)
@glob_patterns ||= {}
@glob_patterns[pattern] ||= GlobPattern.generate(pattern)
[pattern, @glob_patterns[pattern]]
end | ruby | def pattern_with_glob_pattern(*pattern, **options)
options[:uri_decode] ||= false
pattern = Mustermann.new(*pattern.flatten, **options)
@glob_patterns ||= {}
@glob_patterns[pattern] ||= GlobPattern.generate(pattern)
[pattern, @glob_patterns[pattern]]
end | [
"def",
"pattern_with_glob_pattern",
"(",
"*",
"pattern",
",",
"**",
"options",
")",
"options",
"[",
":uri_decode",
"]",
"||=",
"false",
"pattern",
"=",
"Mustermann",
".",
"new",
"(",
"pattern",
".",
"flatten",
",",
"**",
"options",
")",
"@glob_patterns",
"||... | Create a Mustermann pattern from whatever the input is and turn it into
a glob pattern.
@!visibility private | [
"Create",
"a",
"Mustermann",
"pattern",
"from",
"whatever",
"the",
"input",
"is",
"and",
"turn",
"it",
"into",
"a",
"glob",
"pattern",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/file_utils.rb#L173-L179 |
17,052 | sinatra/mustermann | mustermann/lib/mustermann/concat.rb | Mustermann.Concat.pump | def pump(string, inject_with: :+, initial: nil, with_size: false)
substring = string
results = Array(initial)
patterns.each do |pattern|
result, size = yield(pattern, substring)
return unless result
results << result
size ||= result
substring = substring[s... | ruby | def pump(string, inject_with: :+, initial: nil, with_size: false)
substring = string
results = Array(initial)
patterns.each do |pattern|
result, size = yield(pattern, substring)
return unless result
results << result
size ||= result
substring = substring[s... | [
"def",
"pump",
"(",
"string",
",",
"inject_with",
":",
":+",
",",
"initial",
":",
"nil",
",",
"with_size",
":",
"false",
")",
"substring",
"=",
"string",
"results",
"=",
"Array",
"(",
"initial",
")",
"patterns",
".",
"each",
"do",
"|",
"pattern",
"|",
... | used to generate results for various methods by scanning through an input string
@!visibility private | [
"used",
"to",
"generate",
"results",
"for",
"various",
"methods",
"by",
"scanning",
"through",
"an",
"input",
"string"
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/concat.rb#L110-L124 |
17,053 | sinatra/mustermann | mustermann/lib/mustermann/concat.rb | Mustermann.Concat.combined_ast | def combined_ast
payload = patterns.map { |p| AST::Node[:group].new(p.to_ast.payload) }
AST::Node[:root].new(payload)
end | ruby | def combined_ast
payload = patterns.map { |p| AST::Node[:group].new(p.to_ast.payload) }
AST::Node[:root].new(payload)
end | [
"def",
"combined_ast",
"payload",
"=",
"patterns",
".",
"map",
"{",
"|",
"p",
"|",
"AST",
"::",
"Node",
"[",
":group",
"]",
".",
"new",
"(",
"p",
".",
"to_ast",
".",
"payload",
")",
"}",
"AST",
"::",
"Node",
"[",
":root",
"]",
".",
"new",
"(",
... | generates one big AST from all patterns
will not check if patterns support AST generation
@!visibility private | [
"generates",
"one",
"big",
"AST",
"from",
"all",
"patterns",
"will",
"not",
"check",
"if",
"patterns",
"support",
"AST",
"generation"
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/concat.rb#L129-L132 |
17,054 | sinatra/mustermann | mustermann/lib/mustermann/sinatra.rb | Mustermann.Sinatra.| | def |(other)
return super unless converted = self.class.try_convert(other, **options)
return super unless converted.names.empty? or names.empty?
self.class.new(safe_string + "|" + converted.safe_string, **options)
end | ruby | def |(other)
return super unless converted = self.class.try_convert(other, **options)
return super unless converted.names.empty? or names.empty?
self.class.new(safe_string + "|" + converted.safe_string, **options)
end | [
"def",
"|",
"(",
"other",
")",
"return",
"super",
"unless",
"converted",
"=",
"self",
".",
"class",
".",
"try_convert",
"(",
"other",
",",
"**",
"options",
")",
"return",
"super",
"unless",
"converted",
".",
"names",
".",
"empty?",
"or",
"names",
".",
... | Creates a pattern that matches any string matching either one of the patterns.
If a string is supplied, it is treated as a fully escaped Sinatra pattern.
If the other pattern is also a Sintara pattern, it might join the two to a third
sinatra pattern instead of generating a composite for efficiency reasons.
This ... | [
"Creates",
"a",
"pattern",
"that",
"matches",
"any",
"string",
"matching",
"either",
"one",
"of",
"the",
"patterns",
".",
"If",
"a",
"string",
"is",
"supplied",
"it",
"is",
"treated",
"as",
"a",
"fully",
"escaped",
"Sinatra",
"pattern",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/sinatra.rb#L59-L63 |
17,055 | sinatra/mustermann | mustermann-contrib/lib/mustermann/string_scanner.rb | Mustermann.StringScanner.scan_until | def scan_until(pattern, **options)
result, prefix = check_until_with_prefix(pattern, **options)
track_result(prefix, result)
end | ruby | def scan_until(pattern, **options)
result, prefix = check_until_with_prefix(pattern, **options)
track_result(prefix, result)
end | [
"def",
"scan_until",
"(",
"pattern",
",",
"**",
"options",
")",
"result",
",",
"prefix",
"=",
"check_until_with_prefix",
"(",
"pattern",
",",
"**",
"options",
")",
"track_result",
"(",
"prefix",
",",
"result",
")",
"end"
] | Checks if the given pattern matches any substring starting at any position after the current position.
If it does, it will advance the current {#position} to the end of the substring and merges any params parsed
from the substring into {#params}.
@param (see Mustermann.new)
@return [Mustermann::StringScanner::Sca... | [
"Checks",
"if",
"the",
"given",
"pattern",
"matches",
"any",
"substring",
"starting",
"at",
"any",
"position",
"after",
"the",
"current",
"position",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/string_scanner.rb#L173-L176 |
17,056 | sinatra/mustermann | mustermann-contrib/lib/mustermann/string_scanner.rb | Mustermann.StringScanner.unscan | def unscan
raise ScanError, 'unscan failed: previous match record not exist' if @history.empty?
previous = @history[0..-2]
reset
previous.each { |r| track_result(*r) }
self
end | ruby | def unscan
raise ScanError, 'unscan failed: previous match record not exist' if @history.empty?
previous = @history[0..-2]
reset
previous.each { |r| track_result(*r) }
self
end | [
"def",
"unscan",
"raise",
"ScanError",
",",
"'unscan failed: previous match record not exist'",
"if",
"@history",
".",
"empty?",
"previous",
"=",
"@history",
"[",
"0",
"..",
"-",
"2",
"]",
"reset",
"previous",
".",
"each",
"{",
"|",
"r",
"|",
"track_result",
"... | Reverts the last operation that advanced the position.
Operations advancing the position: {#terminate}, {#scan}, {#scan_until}, {#getch}.
@return [Mustermann::StringScanner] the scanner itself | [
"Reverts",
"the",
"last",
"operation",
"that",
"advanced",
"the",
"position",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/string_scanner.rb#L182-L188 |
17,057 | sinatra/mustermann | mustermann-contrib/lib/mustermann/string_scanner.rb | Mustermann.StringScanner.check | def check(pattern, **options)
params, length = create_pattern(pattern, **options).peek_params(rest)
ScanResult.new(self, @position, length, params) if params
end | ruby | def check(pattern, **options)
params, length = create_pattern(pattern, **options).peek_params(rest)
ScanResult.new(self, @position, length, params) if params
end | [
"def",
"check",
"(",
"pattern",
",",
"**",
"options",
")",
"params",
",",
"length",
"=",
"create_pattern",
"(",
"pattern",
",",
"**",
"options",
")",
".",
"peek_params",
"(",
"rest",
")",
"ScanResult",
".",
"new",
"(",
"self",
",",
"@position",
",",
"l... | Checks if the given pattern matches any substring starting at the current position.
Does not affect {#position} or {#params}.
@param (see Mustermann.new)
@return [Mustermann::StringScanner::ScanResult, nil] the matched substring, nil if it didn't match | [
"Checks",
"if",
"the",
"given",
"pattern",
"matches",
"any",
"substring",
"starting",
"at",
"the",
"current",
"position",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/string_scanner.rb#L196-L199 |
17,058 | sinatra/mustermann | mustermann/lib/mustermann/identity.rb | Mustermann.Identity.expand | def expand(behavior = nil, values = {})
return to_s if values.empty? or behavior == :ignore
raise ExpandError, "cannot expand with keys %p" % values.keys.sort if behavior == :raise
raise ArgumentError, "unknown behavior %p" % behavior if behavior != :append
params = values.... | ruby | def expand(behavior = nil, values = {})
return to_s if values.empty? or behavior == :ignore
raise ExpandError, "cannot expand with keys %p" % values.keys.sort if behavior == :raise
raise ArgumentError, "unknown behavior %p" % behavior if behavior != :append
params = values.... | [
"def",
"expand",
"(",
"behavior",
"=",
"nil",
",",
"values",
"=",
"{",
"}",
")",
"return",
"to_s",
"if",
"values",
".",
"empty?",
"or",
"behavior",
"==",
":ignore",
"raise",
"ExpandError",
",",
"\"cannot expand with keys %p\"",
"%",
"values",
".",
"keys",
... | Identity patterns support expanding.
This implementation does not use {Mustermann::Expander} internally to save memory and
compilation time.
@example (see Mustermann::Pattern#expand)
@param (see Mustermann::Pattern#expand)
@return (see Mustermann::Pattern#expand)
@raise (see Mustermann::Pattern#expand)
@see Mu... | [
"Identity",
"patterns",
"support",
"expanding",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/identity.rb#L68-L75 |
17,059 | sinatra/mustermann | mustermann-contrib/lib/mustermann/versions.rb | Mustermann.Versions.new | def new(*args, version: nil, **options)
return super(*args, **options) unless versions.any?
self[version].new(*args, **options)
end | ruby | def new(*args, version: nil, **options)
return super(*args, **options) unless versions.any?
self[version].new(*args, **options)
end | [
"def",
"new",
"(",
"*",
"args",
",",
"version",
":",
"nil",
",",
"**",
"options",
")",
"return",
"super",
"(",
"args",
",",
"**",
"options",
")",
"unless",
"versions",
".",
"any?",
"self",
"[",
"version",
"]",
".",
"new",
"(",
"args",
",",
"**",
... | Checks if class has mulitple versions available and picks one that matches the version option.
@!visibility private | [
"Checks",
"if",
"class",
"has",
"mulitple",
"versions",
"available",
"and",
"picks",
"one",
"that",
"matches",
"the",
"version",
"option",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/versions.rb#L9-L12 |
17,060 | sinatra/mustermann | mustermann-contrib/lib/mustermann/versions.rb | Mustermann.Versions.version | def version(*list, inherit_from: nil, &block)
superclass = self[inherit_from] || self
subclass = Class.new(superclass, &block)
list.each { |v| versions[v] = subclass }
end | ruby | def version(*list, inherit_from: nil, &block)
superclass = self[inherit_from] || self
subclass = Class.new(superclass, &block)
list.each { |v| versions[v] = subclass }
end | [
"def",
"version",
"(",
"*",
"list",
",",
"inherit_from",
":",
"nil",
",",
"&",
"block",
")",
"superclass",
"=",
"self",
"[",
"inherit_from",
"]",
"||",
"self",
"subclass",
"=",
"Class",
".",
"new",
"(",
"superclass",
",",
"block",
")",
"list",
".",
"... | Defines a new version.
@!visibility private | [
"Defines",
"a",
"new",
"version",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/versions.rb#L22-L26 |
17,061 | sinatra/mustermann | mustermann-contrib/lib/mustermann/versions.rb | Mustermann.Versions.[] | def [](version)
return versions.values.last unless version
detected = versions.detect { |v,_| version.start_with?(v) }
raise ArgumentError, 'unsupported version %p' % version unless detected
detected.last
end | ruby | def [](version)
return versions.values.last unless version
detected = versions.detect { |v,_| version.start_with?(v) }
raise ArgumentError, 'unsupported version %p' % version unless detected
detected.last
end | [
"def",
"[]",
"(",
"version",
")",
"return",
"versions",
".",
"values",
".",
"last",
"unless",
"version",
"detected",
"=",
"versions",
".",
"detect",
"{",
"|",
"v",
",",
"_",
"|",
"version",
".",
"start_with?",
"(",
"v",
")",
"}",
"raise",
"ArgumentErro... | Resolve a subclass for a given version string.
@!visibility private | [
"Resolve",
"a",
"subclass",
"for",
"a",
"given",
"version",
"string",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann-contrib/lib/mustermann/versions.rb#L30-L35 |
17,062 | sinatra/mustermann | mustermann/lib/mustermann/caster.rb | Mustermann.Caster.cast | def cast(hash)
return hash if empty?
merge = {}
hash.delete_if do |key, value|
next unless casted = lazy.map { |e| e.cast(key, value) }.detect { |e| e }
casted = { key => casted } unless casted.respond_to? :to_hash
merge.update(casted.to_hash)
end
hash.update(merge)... | ruby | def cast(hash)
return hash if empty?
merge = {}
hash.delete_if do |key, value|
next unless casted = lazy.map { |e| e.cast(key, value) }.detect { |e| e }
casted = { key => casted } unless casted.respond_to? :to_hash
merge.update(casted.to_hash)
end
hash.update(merge)... | [
"def",
"cast",
"(",
"hash",
")",
"return",
"hash",
"if",
"empty?",
"merge",
"=",
"{",
"}",
"hash",
".",
"delete_if",
"do",
"|",
"key",
",",
"value",
"|",
"next",
"unless",
"casted",
"=",
"lazy",
".",
"map",
"{",
"|",
"e",
"|",
"e",
".",
"cast",
... | Transforms a Hash.
@param [Hash] hash pre-transform Hash
@return [Hash] post-transform Hash
@!visibility private | [
"Transforms",
"a",
"Hash",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/caster.rb#L45-L54 |
17,063 | sinatra/mustermann | mustermann/lib/mustermann/mapper.rb | Mustermann.Mapper.update | def update(map)
map.to_h.each_pair do |input, output|
input = Mustermann.new(input, **@options)
output = Expander.new(*output, additional_values: @additional_values, **@options) unless output.is_a? Expander
@map << [input, output]
end
end | ruby | def update(map)
map.to_h.each_pair do |input, output|
input = Mustermann.new(input, **@options)
output = Expander.new(*output, additional_values: @additional_values, **@options) unless output.is_a? Expander
@map << [input, output]
end
end | [
"def",
"update",
"(",
"map",
")",
"map",
".",
"to_h",
".",
"each_pair",
"do",
"|",
"input",
",",
"output",
"|",
"input",
"=",
"Mustermann",
".",
"new",
"(",
"input",
",",
"**",
"@options",
")",
"output",
"=",
"Expander",
".",
"new",
"(",
"output",
... | Creates a new mapper.
@overload initialize(**options)
@param options [Hash] options The options hash
@yield block for generating mappings as a hash
@yieldreturn [Hash] see {#update}
@example
require 'mustermann/mapper'
Mustermann::Mapper.new(type: :rails) {{
"/:foo" => ["/:foo.html", "/:... | [
"Creates",
"a",
"new",
"mapper",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/mapper.rb#L59-L65 |
17,064 | sinatra/mustermann | mustermann/lib/mustermann/mapper.rb | Mustermann.Mapper.convert | def convert(input, values = {})
@map.inject(input) do |current, (pattern, expander)|
params = pattern.params(current)
params &&= Hash[values.merge(params).map { |k,v| [k.to_s, v] }]
expander.expandable?(params) ? expander.expand(params) : current
end
end | ruby | def convert(input, values = {})
@map.inject(input) do |current, (pattern, expander)|
params = pattern.params(current)
params &&= Hash[values.merge(params).map { |k,v| [k.to_s, v] }]
expander.expandable?(params) ? expander.expand(params) : current
end
end | [
"def",
"convert",
"(",
"input",
",",
"values",
"=",
"{",
"}",
")",
"@map",
".",
"inject",
"(",
"input",
")",
"do",
"|",
"current",
",",
"(",
"pattern",
",",
"expander",
")",
"|",
"params",
"=",
"pattern",
".",
"params",
"(",
"current",
")",
"params... | Convert a string according to mappings. You can pass in additional params.
@example mapping with and without additional parameters
mapper = Mustermann::Mapper.new("/:example" => "(/:prefix)?/:example.html") | [
"Convert",
"a",
"string",
"according",
"to",
"mappings",
".",
"You",
"can",
"pass",
"in",
"additional",
"params",
"."
] | 5625972edfddb3d254acd949a1a312cca5167de3 | https://github.com/sinatra/mustermann/blob/5625972edfddb3d254acd949a1a312cca5167de3/mustermann/lib/mustermann/mapper.rb#L77-L83 |
17,065 | typhoeus/ethon | lib/ethon/easy.rb | Ethon.Easy.escape | def escape(value)
string_pointer = Curl.easy_escape(handle, value, value.bytesize)
returned_string = string_pointer.read_string
Curl.free(string_pointer)
returned_string
end | ruby | def escape(value)
string_pointer = Curl.easy_escape(handle, value, value.bytesize)
returned_string = string_pointer.read_string
Curl.free(string_pointer)
returned_string
end | [
"def",
"escape",
"(",
"value",
")",
"string_pointer",
"=",
"Curl",
".",
"easy_escape",
"(",
"handle",
",",
"value",
",",
"value",
".",
"bytesize",
")",
"returned_string",
"=",
"string_pointer",
".",
"read_string",
"Curl",
".",
"free",
"(",
"string_pointer",
... | Clones libcurl session handle. This means that all options that is set in
the current handle will be set on duplicated handle.
Url escapes the value.
@example Url escape.
easy.escape(value)
@param [ String ] value The value to escape.
@return [ String ] The escaped value.
@api private | [
"Clones",
"libcurl",
"session",
"handle",
".",
"This",
"means",
"that",
"all",
"options",
"that",
"is",
"set",
"in",
"the",
"current",
"handle",
"will",
"be",
"set",
"on",
"duplicated",
"handle",
".",
"Url",
"escapes",
"the",
"value",
"."
] | c5c9c6e10114c9939642be522ab05432ca7ec5d2 | https://github.com/typhoeus/ethon/blob/c5c9c6e10114c9939642be522ab05432ca7ec5d2/lib/ethon/easy.rb#L285-L290 |
17,066 | abitdodgy/words_counted | lib/words_counted/counter.rb | WordsCounted.Counter.token_frequency | def token_frequency
tokens.each_with_object(Hash.new(0)) { |token, hash| hash[token] += 1 }.sort_by_value_desc
end | ruby | def token_frequency
tokens.each_with_object(Hash.new(0)) { |token, hash| hash[token] += 1 }.sort_by_value_desc
end | [
"def",
"token_frequency",
"tokens",
".",
"each_with_object",
"(",
"Hash",
".",
"new",
"(",
"0",
")",
")",
"{",
"|",
"token",
",",
"hash",
"|",
"hash",
"[",
"token",
"]",
"+=",
"1",
"}",
".",
"sort_by_value_desc",
"end"
] | Returns a sorted two-dimensional array where each member array is a token and its frequency.
The array is sorted by frequency in descending order.
@example
Counter.new(%w[one two two three three three]).token_frequency
# => [ ['three', 3], ['two', 2], ['one', 1] ]
@return [Array<Array<String, Integer>>] An arr... | [
"Returns",
"a",
"sorted",
"two",
"-",
"dimensional",
"array",
"where",
"each",
"member",
"array",
"is",
"a",
"token",
"and",
"its",
"frequency",
".",
"The",
"array",
"is",
"sorted",
"by",
"frequency",
"in",
"descending",
"order",
"."
] | 5f3ea74249e05f22e16e097ce7cf9b940887e0ae | https://github.com/abitdodgy/words_counted/blob/5f3ea74249e05f22e16e097ce7cf9b940887e0ae/lib/words_counted/counter.rb#L66-L68 |
17,067 | abitdodgy/words_counted | lib/words_counted/counter.rb | WordsCounted.Counter.token_lengths | def token_lengths
tokens.uniq.each_with_object({}) { |token, hash| hash[token] = token.length }.sort_by_value_desc
end | ruby | def token_lengths
tokens.uniq.each_with_object({}) { |token, hash| hash[token] = token.length }.sort_by_value_desc
end | [
"def",
"token_lengths",
"tokens",
".",
"uniq",
".",
"each_with_object",
"(",
"{",
"}",
")",
"{",
"|",
"token",
",",
"hash",
"|",
"hash",
"[",
"token",
"]",
"=",
"token",
".",
"length",
"}",
".",
"sort_by_value_desc",
"end"
] | Returns a sorted two-dimensional array where each member array is a token and its length.
The array is sorted by length in descending order.
@example
Counter.new(%w[one two three four five]).token_lenghts
# => [ ['three', 5], ['four', 4], ['five', 4], ['one', 3], ['two', 3] ]
@return [Array<Array<String, Integ... | [
"Returns",
"a",
"sorted",
"two",
"-",
"dimensional",
"array",
"where",
"each",
"member",
"array",
"is",
"a",
"token",
"and",
"its",
"length",
".",
"The",
"array",
"is",
"sorted",
"by",
"length",
"in",
"descending",
"order",
"."
] | 5f3ea74249e05f22e16e097ce7cf9b940887e0ae | https://github.com/abitdodgy/words_counted/blob/5f3ea74249e05f22e16e097ce7cf9b940887e0ae/lib/words_counted/counter.rb#L78-L80 |
17,068 | abitdodgy/words_counted | lib/words_counted/counter.rb | WordsCounted.Counter.token_density | def token_density(precision: 2)
token_frequency.each_with_object({}) { |(token, freq), hash|
hash[token] = (freq / token_count.to_f).round(precision)
}.sort_by_value_desc
end | ruby | def token_density(precision: 2)
token_frequency.each_with_object({}) { |(token, freq), hash|
hash[token] = (freq / token_count.to_f).round(precision)
}.sort_by_value_desc
end | [
"def",
"token_density",
"(",
"precision",
":",
"2",
")",
"token_frequency",
".",
"each_with_object",
"(",
"{",
"}",
")",
"{",
"|",
"(",
"token",
",",
"freq",
")",
",",
"hash",
"|",
"hash",
"[",
"token",
"]",
"=",
"(",
"freq",
"/",
"token_count",
".",... | Returns a sorted two-dimensional array where each member array is a token and its density
as a float, rounded to a precision of two decimal places. It accepts a precision argument
which defaults to `2`.
@example
Counter.new(%w[Maj. Major Major Major]).token_density
# => [ ['major', .75], ['maj', .25] ]
@examp... | [
"Returns",
"a",
"sorted",
"two",
"-",
"dimensional",
"array",
"where",
"each",
"member",
"array",
"is",
"a",
"token",
"and",
"its",
"density",
"as",
"a",
"float",
"rounded",
"to",
"a",
"precision",
"of",
"two",
"decimal",
"places",
".",
"It",
"accepts",
... | 5f3ea74249e05f22e16e097ce7cf9b940887e0ae | https://github.com/abitdodgy/words_counted/blob/5f3ea74249e05f22e16e097ce7cf9b940887e0ae/lib/words_counted/counter.rb#L96-L100 |
17,069 | abitdodgy/words_counted | lib/words_counted/tokeniser.rb | WordsCounted.Tokeniser.tokenise | def tokenise(pattern: TOKEN_REGEXP, exclude: nil)
filter_proc = filter_to_proc(exclude)
@input.scan(pattern).map(&:downcase).reject { |token| filter_proc.call(token) }
end | ruby | def tokenise(pattern: TOKEN_REGEXP, exclude: nil)
filter_proc = filter_to_proc(exclude)
@input.scan(pattern).map(&:downcase).reject { |token| filter_proc.call(token) }
end | [
"def",
"tokenise",
"(",
"pattern",
":",
"TOKEN_REGEXP",
",",
"exclude",
":",
"nil",
")",
"filter_proc",
"=",
"filter_to_proc",
"(",
"exclude",
")",
"@input",
".",
"scan",
"(",
"pattern",
")",
".",
"map",
"(",
":downcase",
")",
".",
"reject",
"{",
"|",
... | Initialises state with the string to be tokenised.
@param [String] input The string to tokenise
Converts a string into an array of tokens using a regular expression.
If a regexp is not provided a default one is used. See `Tokenizer.TOKEN_REGEXP`.
Use `exclude` to remove tokens from the final list. `exclude` can... | [
"Initialises",
"state",
"with",
"the",
"string",
"to",
"be",
"tokenised",
"."
] | 5f3ea74249e05f22e16e097ce7cf9b940887e0ae | https://github.com/abitdodgy/words_counted/blob/5f3ea74249e05f22e16e097ce7cf9b940887e0ae/lib/words_counted/tokeniser.rb#L97-L100 |
17,070 | abitdodgy/words_counted | lib/words_counted/tokeniser.rb | WordsCounted.Tokeniser.filter_to_proc | def filter_to_proc(filter)
if filter.respond_to?(:to_a)
filter_procs_from_array(filter)
elsif filter.respond_to?(:to_str)
filter_proc_from_string(filter)
elsif regexp_filter = Regexp.try_convert(filter)
->(token) {
token =~ regexp_filter
}
elsif filter.r... | ruby | def filter_to_proc(filter)
if filter.respond_to?(:to_a)
filter_procs_from_array(filter)
elsif filter.respond_to?(:to_str)
filter_proc_from_string(filter)
elsif regexp_filter = Regexp.try_convert(filter)
->(token) {
token =~ regexp_filter
}
elsif filter.r... | [
"def",
"filter_to_proc",
"(",
"filter",
")",
"if",
"filter",
".",
"respond_to?",
"(",
":to_a",
")",
"filter_procs_from_array",
"(",
"filter",
")",
"elsif",
"filter",
".",
"respond_to?",
"(",
":to_str",
")",
"filter_proc_from_string",
"(",
"filter",
")",
"elsif",... | The following methods convert any arguments into a callable object. The return value of this
lambda is then used to determine whether a token should be excluded from the final list.
`filter` can be a string, a regular expression, a lambda, a symbol, or an array
of any combination of those types.
If `filter` is a ... | [
"The",
"following",
"methods",
"convert",
"any",
"arguments",
"into",
"a",
"callable",
"object",
".",
"The",
"return",
"value",
"of",
"this",
"lambda",
"is",
"then",
"used",
"to",
"determine",
"whether",
"a",
"token",
"should",
"be",
"excluded",
"from",
"the... | 5f3ea74249e05f22e16e097ce7cf9b940887e0ae | https://github.com/abitdodgy/words_counted/blob/5f3ea74249e05f22e16e097ce7cf9b940887e0ae/lib/words_counted/tokeniser.rb#L130-L145 |
17,071 | contentful/contentful_model | lib/contentful_model.rb | ContentfulModel.Configuration.to_hash | def to_hash
Hash[instance_variables.map { |name| [name.to_s.delete('@').to_sym, instance_variable_get(name)] }]
end | ruby | def to_hash
Hash[instance_variables.map { |name| [name.to_s.delete('@').to_sym, instance_variable_get(name)] }]
end | [
"def",
"to_hash",
"Hash",
"[",
"instance_variables",
".",
"map",
"{",
"|",
"name",
"|",
"[",
"name",
".",
"to_s",
".",
"delete",
"(",
"'@'",
")",
".",
"to_sym",
",",
"instance_variable_get",
"(",
"name",
")",
"]",
"}",
"]",
"end"
] | Return the Configuration object as a hash, with symbols as keys.
@return [Hash] | [
"Return",
"the",
"Configuration",
"object",
"as",
"a",
"hash",
"with",
"symbols",
"as",
"keys",
"."
] | b286afd939daae87fdeb1f320f43753dcaae3144 | https://github.com/contentful/contentful_model/blob/b286afd939daae87fdeb1f320f43753dcaae3144/lib/contentful_model.rb#L51-L53 |
17,072 | jkraemer/pdf-forms | lib/pdf_forms/pdftk_wrapper.rb | PdfForms.PdftkWrapper.cat | def cat(*args)
in_files = []
page_ranges = []
file_handle = "A"
output = normalize_path args.pop
args.flatten.compact.each do |in_file|
if in_file.is_a? Hash
path = in_file.keys.first
page_ranges.push *in_file.values.first.map {|range| "#{file_handle}#{range}"}... | ruby | def cat(*args)
in_files = []
page_ranges = []
file_handle = "A"
output = normalize_path args.pop
args.flatten.compact.each do |in_file|
if in_file.is_a? Hash
path = in_file.keys.first
page_ranges.push *in_file.values.first.map {|range| "#{file_handle}#{range}"}... | [
"def",
"cat",
"(",
"*",
"args",
")",
"in_files",
"=",
"[",
"]",
"page_ranges",
"=",
"[",
"]",
"file_handle",
"=",
"\"A\"",
"output",
"=",
"normalize_path",
"args",
".",
"pop",
"args",
".",
"flatten",
".",
"compact",
".",
"each",
"do",
"|",
"in_file",
... | concatenate documents, can optionally specify page ranges
args: in_file1, {in_file2 => ["1-2", "4-10"]}, ... , in_file_n, output | [
"concatenate",
"documents",
"can",
"optionally",
"specify",
"page",
"ranges"
] | 34518c762a52494893125dad9dc504eac2f88af3 | https://github.com/jkraemer/pdf-forms/blob/34518c762a52494893125dad9dc504eac2f88af3/lib/pdf_forms/pdftk_wrapper.rb#L94-L113 |
17,073 | jkraemer/pdf-forms | lib/pdf_forms/data_format.rb | PdfForms.DataFormat.to_pdf_data | def to_pdf_data
pdf_data = header
@data.each do |key, value|
if Hash === value
value.each do |sub_key, sub_value|
pdf_data << field("#{key}_#{sub_key}", sub_value)
end
else
pdf_data << field(key, value)
end
end
pdf_data << foote... | ruby | def to_pdf_data
pdf_data = header
@data.each do |key, value|
if Hash === value
value.each do |sub_key, sub_value|
pdf_data << field("#{key}_#{sub_key}", sub_value)
end
else
pdf_data << field(key, value)
end
end
pdf_data << foote... | [
"def",
"to_pdf_data",
"pdf_data",
"=",
"header",
"@data",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"Hash",
"===",
"value",
"value",
".",
"each",
"do",
"|",
"sub_key",
",",
"sub_value",
"|",
"pdf_data",
"<<",
"field",
"(",
"\"#{key}_#{sub_k... | generate PDF content in this data format | [
"generate",
"PDF",
"content",
"in",
"this",
"data",
"format"
] | 34518c762a52494893125dad9dc504eac2f88af3 | https://github.com/jkraemer/pdf-forms/blob/34518c762a52494893125dad9dc504eac2f88af3/lib/pdf_forms/data_format.rb#L17-L32 |
17,074 | piotrmurach/tty-spinner | lib/tty/spinner.rb | TTY.Spinner.auto_spin | def auto_spin
CURSOR_LOCK.synchronize do
start
sleep_time = 1.0 / @interval
spin
@thread = Thread.new do
sleep(sleep_time)
while @started_at
if Thread.current['pause']
Thread.stop
Thread.current['pause'] = false
... | ruby | def auto_spin
CURSOR_LOCK.synchronize do
start
sleep_time = 1.0 / @interval
spin
@thread = Thread.new do
sleep(sleep_time)
while @started_at
if Thread.current['pause']
Thread.stop
Thread.current['pause'] = false
... | [
"def",
"auto_spin",
"CURSOR_LOCK",
".",
"synchronize",
"do",
"start",
"sleep_time",
"=",
"1.0",
"/",
"@interval",
"spin",
"@thread",
"=",
"Thread",
".",
"new",
"do",
"sleep",
"(",
"sleep_time",
")",
"while",
"@started_at",
"if",
"Thread",
".",
"current",
"["... | Start automatic spinning animation
@api public | [
"Start",
"automatic",
"spinning",
"animation"
] | 876449a4a10831b38aedd92004592efe417c6377 | https://github.com/piotrmurach/tty-spinner/blob/876449a4a10831b38aedd92004592efe417c6377/lib/tty/spinner.rb#L240-L262 |
17,075 | piotrmurach/tty-spinner | lib/tty/spinner.rb | TTY.Spinner.run | def run(stop_message = '', &block)
job(&block)
auto_spin
@work = Thread.new { execute_job }
@work.join
ensure
stop(stop_message)
end | ruby | def run(stop_message = '', &block)
job(&block)
auto_spin
@work = Thread.new { execute_job }
@work.join
ensure
stop(stop_message)
end | [
"def",
"run",
"(",
"stop_message",
"=",
"''",
",",
"&",
"block",
")",
"job",
"(",
"block",
")",
"auto_spin",
"@work",
"=",
"Thread",
".",
"new",
"{",
"execute_job",
"}",
"@work",
".",
"join",
"ensure",
"stop",
"(",
"stop_message",
")",
"end"
] | Run spinner while executing job
@param [String] stop_message
the message displayed when block is finished
@yield automatically animate and finish spinner
@example
spinner.run('Migrated DB') { ... }
@api public | [
"Run",
"spinner",
"while",
"executing",
"job"
] | 876449a4a10831b38aedd92004592efe417c6377 | https://github.com/piotrmurach/tty-spinner/blob/876449a4a10831b38aedd92004592efe417c6377/lib/tty/spinner.rb#L304-L312 |
17,076 | piotrmurach/tty-spinner | lib/tty/spinner.rb | TTY.Spinner.spin | def spin
synchronize do
return if @done
emit(:spin)
if @hide_cursor && !spinning?
write(TTY::Cursor.hide)
end
data = message.gsub(MATCHER, @frames[@current])
data = replace_tokens(data)
write(data, true)
@current = (@current + 1) % @lengt... | ruby | def spin
synchronize do
return if @done
emit(:spin)
if @hide_cursor && !spinning?
write(TTY::Cursor.hide)
end
data = message.gsub(MATCHER, @frames[@current])
data = replace_tokens(data)
write(data, true)
@current = (@current + 1) % @lengt... | [
"def",
"spin",
"synchronize",
"do",
"return",
"if",
"@done",
"emit",
"(",
":spin",
")",
"if",
"@hide_cursor",
"&&",
"!",
"spinning?",
"write",
"(",
"TTY",
"::",
"Cursor",
".",
"hide",
")",
"end",
"data",
"=",
"message",
".",
"gsub",
"(",
"MATCHER",
","... | Perform a spin
@return [String]
the printed data
@api public | [
"Perform",
"a",
"spin"
] | 876449a4a10831b38aedd92004592efe417c6377 | https://github.com/piotrmurach/tty-spinner/blob/876449a4a10831b38aedd92004592efe417c6377/lib/tty/spinner.rb#L352-L368 |
17,077 | piotrmurach/tty-spinner | lib/tty/spinner.rb | TTY.Spinner.fetch_format | def fetch_format(token, property)
if FORMATS.key?(token)
FORMATS[token][property]
else
raise ArgumentError, "Unknown format token `:#{token}`"
end
end | ruby | def fetch_format(token, property)
if FORMATS.key?(token)
FORMATS[token][property]
else
raise ArgumentError, "Unknown format token `:#{token}`"
end
end | [
"def",
"fetch_format",
"(",
"token",
",",
"property",
")",
"if",
"FORMATS",
".",
"key?",
"(",
"token",
")",
"FORMATS",
"[",
"token",
"]",
"[",
"property",
"]",
"else",
"raise",
"ArgumentError",
",",
"\"Unknown format token `:#{token}`\"",
"end",
"end"
] | Find frames by token name
@param [Symbol] token
the name for the frames
@return [Array, String]
@api private | [
"Find",
"frames",
"by",
"token",
"name"
] | 876449a4a10831b38aedd92004592efe417c6377 | https://github.com/piotrmurach/tty-spinner/blob/876449a4a10831b38aedd92004592efe417c6377/lib/tty/spinner.rb#L547-L553 |
17,078 | felixbuenemann/xlsxtream | lib/xlsxtream/row.rb | Xlsxtream.Row.auto_format | def auto_format(value)
case value
when TRUE_STRING
true
when FALSE_STRING
false
when NUMBER_PATTERN
value.include?('.') ? value.to_f : value.to_i
when DATE_PATTERN
Date.parse(value) rescue value
when TIME_PATTERN
DateTime.parse(value) rescue va... | ruby | def auto_format(value)
case value
when TRUE_STRING
true
when FALSE_STRING
false
when NUMBER_PATTERN
value.include?('.') ? value.to_f : value.to_i
when DATE_PATTERN
Date.parse(value) rescue value
when TIME_PATTERN
DateTime.parse(value) rescue va... | [
"def",
"auto_format",
"(",
"value",
")",
"case",
"value",
"when",
"TRUE_STRING",
"true",
"when",
"FALSE_STRING",
"false",
"when",
"NUMBER_PATTERN",
"value",
".",
"include?",
"(",
"'.'",
")",
"?",
"value",
".",
"to_f",
":",
"value",
".",
"to_i",
"when",
"DA... | Detects and casts numbers, date, time in text | [
"Detects",
"and",
"casts",
"numbers",
"date",
"time",
"in",
"text"
] | b2e14c9eac716b154f00280041b08a6535abacd1 | https://github.com/felixbuenemann/xlsxtream/blob/b2e14c9eac716b154f00280041b08a6535abacd1/lib/xlsxtream/row.rb#L71-L86 |
17,079 | felixbuenemann/xlsxtream | lib/xlsxtream/row.rb | Xlsxtream.Row.time_to_oa_date | def time_to_oa_date(time)
time = time.to_time if time.respond_to?(:to_time)
# Local dates are stored as UTC by truncating the offset:
# 1970-01-01 00:00:00 +0200 => 1970-01-01 00:00:00 UTC
# This is done because SpreadsheetML is not timezone aware.
(time + time.utc_offset).utc.to_f / 24 /... | ruby | def time_to_oa_date(time)
time = time.to_time if time.respond_to?(:to_time)
# Local dates are stored as UTC by truncating the offset:
# 1970-01-01 00:00:00 +0200 => 1970-01-01 00:00:00 UTC
# This is done because SpreadsheetML is not timezone aware.
(time + time.utc_offset).utc.to_f / 24 /... | [
"def",
"time_to_oa_date",
"(",
"time",
")",
"time",
"=",
"time",
".",
"to_time",
"if",
"time",
".",
"respond_to?",
"(",
":to_time",
")",
"# Local dates are stored as UTC by truncating the offset:",
"# 1970-01-01 00:00:00 +0200 => 1970-01-01 00:00:00 UTC",
"# This is done becaus... | Converts Time objects to OLE Automation Date | [
"Converts",
"Time",
"objects",
"to",
"OLE",
"Automation",
"Date"
] | b2e14c9eac716b154f00280041b08a6535abacd1 | https://github.com/felixbuenemann/xlsxtream/blob/b2e14c9eac716b154f00280041b08a6535abacd1/lib/xlsxtream/row.rb#L89-L96 |
17,080 | chef/ffi-yajl | lib/ffi_yajl/map_library_name.rb | FFI_Yajl.MapLibraryName.expanded_library_names | def expanded_library_names
library_names.map do |libname|
pathname = File.expand_path(File.join(Libyajl2.opt_path, libname))
pathname if File.file?(pathname)
end.compact
end | ruby | def expanded_library_names
library_names.map do |libname|
pathname = File.expand_path(File.join(Libyajl2.opt_path, libname))
pathname if File.file?(pathname)
end.compact
end | [
"def",
"expanded_library_names",
"library_names",
".",
"map",
"do",
"|",
"libname",
"|",
"pathname",
"=",
"File",
".",
"expand_path",
"(",
"File",
".",
"join",
"(",
"Libyajl2",
".",
"opt_path",
",",
"libname",
")",
")",
"pathname",
"if",
"File",
".",
"file... | Array of yajl library names prepended with the libyajl2 path to use to
load those directly and bypass the system libyajl by default. Since
these are full paths, this API checks to ensure that the file exists on
the filesystem. May return an empty array.
@api private
@return [Array<String>] Array of full paths t... | [
"Array",
"of",
"yajl",
"library",
"names",
"prepended",
"with",
"the",
"libyajl2",
"path",
"to",
"use",
"to",
"load",
"those",
"directly",
"and",
"bypass",
"the",
"system",
"libyajl",
"by",
"default",
".",
"Since",
"these",
"are",
"full",
"paths",
"this",
... | 4b001a89c8c63ef7b39c7fb30a63061add9a44d5 | https://github.com/chef/ffi-yajl/blob/4b001a89c8c63ef7b39c7fb30a63061add9a44d5/lib/ffi_yajl/map_library_name.rb#L67-L72 |
17,081 | chef/ffi-yajl | lib/ffi_yajl/map_library_name.rb | FFI_Yajl.MapLibraryName.dlopen_yajl_library | def dlopen_yajl_library
found = false
( expanded_library_names + library_names ).each do |libname|
begin
dlopen(libname)
found = true
break
rescue ArgumentError
end
end
raise "cannot find yajl library for platform" unless found
end | ruby | def dlopen_yajl_library
found = false
( expanded_library_names + library_names ).each do |libname|
begin
dlopen(libname)
found = true
break
rescue ArgumentError
end
end
raise "cannot find yajl library for platform" unless found
end | [
"def",
"dlopen_yajl_library",
"found",
"=",
"false",
"(",
"expanded_library_names",
"+",
"library_names",
")",
".",
"each",
"do",
"|",
"libname",
"|",
"begin",
"dlopen",
"(",
"libname",
")",
"found",
"=",
"true",
"break",
"rescue",
"ArgumentError",
"end",
"end... | Iterate across the expanded library names in the libyajl2-gem and then
attempt to load the system libraries. Uses the native dlopen extension
that ships in this gem.
@api private | [
"Iterate",
"across",
"the",
"expanded",
"library",
"names",
"in",
"the",
"libyajl2",
"-",
"gem",
"and",
"then",
"attempt",
"to",
"load",
"the",
"system",
"libraries",
".",
"Uses",
"the",
"native",
"dlopen",
"extension",
"that",
"ships",
"in",
"this",
"gem",
... | 4b001a89c8c63ef7b39c7fb30a63061add9a44d5 | https://github.com/chef/ffi-yajl/blob/4b001a89c8c63ef7b39c7fb30a63061add9a44d5/lib/ffi_yajl/map_library_name.rb#L79-L90 |
17,082 | chef/ffi-yajl | lib/ffi_yajl/map_library_name.rb | FFI_Yajl.MapLibraryName.ffi_open_yajl_library | def ffi_open_yajl_library
found = false
expanded_library_names.each do |libname|
begin
ffi_lib libname
found = true
rescue LoadError
end
end
ffi_lib "yajl" unless found
end | ruby | def ffi_open_yajl_library
found = false
expanded_library_names.each do |libname|
begin
ffi_lib libname
found = true
rescue LoadError
end
end
ffi_lib "yajl" unless found
end | [
"def",
"ffi_open_yajl_library",
"found",
"=",
"false",
"expanded_library_names",
".",
"each",
"do",
"|",
"libname",
"|",
"begin",
"ffi_lib",
"libname",
"found",
"=",
"true",
"rescue",
"LoadError",
"end",
"end",
"ffi_lib",
"\"yajl\"",
"unless",
"found",
"end"
] | Iterate across the expanded library names in the libyajl2-gem and attempt
to load them. If they are missing just use `ffi_lib 'yajl'` to accept
the FFI default algorithm to find the library.
@api private | [
"Iterate",
"across",
"the",
"expanded",
"library",
"names",
"in",
"the",
"libyajl2",
"-",
"gem",
"and",
"attempt",
"to",
"load",
"them",
".",
"If",
"they",
"are",
"missing",
"just",
"use",
"ffi_lib",
"yajl",
"to",
"accept",
"the",
"FFI",
"default",
"algori... | 4b001a89c8c63ef7b39c7fb30a63061add9a44d5 | https://github.com/chef/ffi-yajl/blob/4b001a89c8c63ef7b39c7fb30a63061add9a44d5/lib/ffi_yajl/map_library_name.rb#L97-L107 |
17,083 | cookpad/grpc_kit | lib/grpc_kit/server.rb | GrpcKit.Server.graceful_shutdown | def graceful_shutdown(timeout: true)
@stopping = true
Thread.new do
GrpcKit.logger.debug('graceful shutdown')
@mutex.synchronize { @sessions.each(&:drain) }
begin
sec = timeout ? @shutdown_timeout : 0
Timeout.timeout(sec) do
sleep 1 until @sessions.e... | ruby | def graceful_shutdown(timeout: true)
@stopping = true
Thread.new do
GrpcKit.logger.debug('graceful shutdown')
@mutex.synchronize { @sessions.each(&:drain) }
begin
sec = timeout ? @shutdown_timeout : 0
Timeout.timeout(sec) do
sleep 1 until @sessions.e... | [
"def",
"graceful_shutdown",
"(",
"timeout",
":",
"true",
")",
"@stopping",
"=",
"true",
"Thread",
".",
"new",
"do",
"GrpcKit",
".",
"logger",
".",
"debug",
"(",
"'graceful shutdown'",
")",
"@mutex",
".",
"synchronize",
"{",
"@sessions",
".",
"each",
"(",
"... | This method is expected to be called in trap context
@params timeout [Boolean] timeout error could be raised or not
@return [void] | [
"This",
"method",
"is",
"expected",
"to",
"be",
"called",
"in",
"trap",
"context"
] | bc5180e4d05c68c3f85a823418951ef2e22bbb0c | https://github.com/cookpad/grpc_kit/blob/bc5180e4d05c68c3f85a823418951ef2e22bbb0c/lib/grpc_kit/server.rb#L69-L86 |
17,084 | whitequark/ast | lib/ast/node.rb | AST.Node.updated | def updated(type=nil, children=nil, properties=nil)
new_type = type || @type
new_children = children || @children
new_properties = properties || {}
if @type == new_type &&
@children == new_children &&
properties.nil?
self
else
original_d... | ruby | def updated(type=nil, children=nil, properties=nil)
new_type = type || @type
new_children = children || @children
new_properties = properties || {}
if @type == new_type &&
@children == new_children &&
properties.nil?
self
else
original_d... | [
"def",
"updated",
"(",
"type",
"=",
"nil",
",",
"children",
"=",
"nil",
",",
"properties",
"=",
"nil",
")",
"new_type",
"=",
"type",
"||",
"@type",
"new_children",
"=",
"children",
"||",
"@children",
"new_properties",
"=",
"properties",
"||",
"{",
"}",
"... | Returns a new instance of Node where non-nil arguments replace the
corresponding fields of `self`.
For example, `Node.new(:foo, [ 1, 2 ]).updated(:bar)` would yield
`(bar 1 2)`, and `Node.new(:foo, [ 1, 2 ]).updated(nil, [])` would
yield `(foo)`.
If the resulting node would be identical to `self`, does nothing.
... | [
"Returns",
"a",
"new",
"instance",
"of",
"Node",
"where",
"non",
"-",
"nil",
"arguments",
"replace",
"the",
"corresponding",
"fields",
"of",
"self",
"."
] | 50ff345ab7152bf513865b88e03664570942318b | https://github.com/whitequark/ast/blob/50ff345ab7152bf513865b88e03664570942318b/lib/ast/node.rb#L133-L145 |
17,085 | whitequark/ast | lib/ast/node.rb | AST.Node.to_sexp | def to_sexp(indent=0)
indented = " " * indent
sexp = "#{indented}(#{fancy_type}"
children.each do |child|
if child.is_a?(Node)
sexp += "\n#{child.to_sexp(indent + 1)}"
else
sexp += " #{child.inspect}"
end
end
sexp += ")"
sexp
end | ruby | def to_sexp(indent=0)
indented = " " * indent
sexp = "#{indented}(#{fancy_type}"
children.each do |child|
if child.is_a?(Node)
sexp += "\n#{child.to_sexp(indent + 1)}"
else
sexp += " #{child.inspect}"
end
end
sexp += ")"
sexp
end | [
"def",
"to_sexp",
"(",
"indent",
"=",
"0",
")",
"indented",
"=",
"\" \"",
"*",
"indent",
"sexp",
"=",
"\"#{indented}(#{fancy_type}\"",
"children",
".",
"each",
"do",
"|",
"child",
"|",
"if",
"child",
".",
"is_a?",
"(",
"Node",
")",
"sexp",
"+=",
"\"\\n#... | Converts `self` to a pretty-printed s-expression.
@param [Integer] indent Base indentation level.
@return [String] | [
"Converts",
"self",
"to",
"a",
"pretty",
"-",
"printed",
"s",
"-",
"expression",
"."
] | 50ff345ab7152bf513865b88e03664570942318b | https://github.com/whitequark/ast/blob/50ff345ab7152bf513865b88e03664570942318b/lib/ast/node.rb#L185-L200 |
17,086 | whitequark/ast | lib/ast/node.rb | AST.Node.to_sexp_array | def to_sexp_array
children_sexp_arrs = children.map do |child|
if child.is_a?(Node)
child.to_sexp_array
else
child
end
end
[type, *children_sexp_arrs]
end | ruby | def to_sexp_array
children_sexp_arrs = children.map do |child|
if child.is_a?(Node)
child.to_sexp_array
else
child
end
end
[type, *children_sexp_arrs]
end | [
"def",
"to_sexp_array",
"children_sexp_arrs",
"=",
"children",
".",
"map",
"do",
"|",
"child",
"|",
"if",
"child",
".",
"is_a?",
"(",
"Node",
")",
"child",
".",
"to_sexp_array",
"else",
"child",
"end",
"end",
"[",
"type",
",",
"children_sexp_arrs",
"]",
"e... | Converts `self` to an Array where the first element is the type as a Symbol,
and subsequent elements are the same representation of its children.
@return [Array<Symbol, [...Array]>] | [
"Converts",
"self",
"to",
"an",
"Array",
"where",
"the",
"first",
"element",
"is",
"the",
"type",
"as",
"a",
"Symbol",
"and",
"subsequent",
"elements",
"are",
"the",
"same",
"representation",
"of",
"its",
"children",
"."
] | 50ff345ab7152bf513865b88e03664570942318b | https://github.com/whitequark/ast/blob/50ff345ab7152bf513865b88e03664570942318b/lib/ast/node.rb#L235-L245 |
17,087 | stitchfix/pwwka | lib/pwwka/configuration.rb | Pwwka.Configuration.payload_parser | def payload_parser
@payload_parser ||= if @receive_raw_payload
->(payload) { payload }
else
->(payload) {
ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(payload))
}
... | ruby | def payload_parser
@payload_parser ||= if @receive_raw_payload
->(payload) { payload }
else
->(payload) {
ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(payload))
}
... | [
"def",
"payload_parser",
"@payload_parser",
"||=",
"if",
"@receive_raw_payload",
"->",
"(",
"payload",
")",
"{",
"payload",
"}",
"else",
"->",
"(",
"payload",
")",
"{",
"ActiveSupport",
"::",
"HashWithIndifferentAccess",
".",
"new",
"(",
"JSON",
".",
"parse",
... | Returns a proc that, when called with the payload, parses it according to the configuration.
By default, this will assume the payload is JSON, parse it, and return a HashWithIndifferentAccess. | [
"Returns",
"a",
"proc",
"that",
"when",
"called",
"with",
"the",
"payload",
"parses",
"it",
"according",
"to",
"the",
"configuration",
"."
] | 581a5261cabaa3e97cfe286da33ce80ffa2d750a | https://github.com/stitchfix/pwwka/blob/581a5261cabaa3e97cfe286da33ce80ffa2d750a/lib/pwwka/configuration.rb#L131-L139 |
17,088 | stitchfix/pwwka | lib/pwwka/configuration.rb | Pwwka.Configuration.omit_payload_from_log? | def omit_payload_from_log?(level_of_message_with_payload)
return true if @receive_raw_payload
Pwwka::Logging::LEVELS[Pwwka.configuration.payload_logging.to_sym] > Pwwka::Logging::LEVELS[level_of_message_with_payload.to_sym]
end | ruby | def omit_payload_from_log?(level_of_message_with_payload)
return true if @receive_raw_payload
Pwwka::Logging::LEVELS[Pwwka.configuration.payload_logging.to_sym] > Pwwka::Logging::LEVELS[level_of_message_with_payload.to_sym]
end | [
"def",
"omit_payload_from_log?",
"(",
"level_of_message_with_payload",
")",
"return",
"true",
"if",
"@receive_raw_payload",
"Pwwka",
"::",
"Logging",
"::",
"LEVELS",
"[",
"Pwwka",
".",
"configuration",
".",
"payload_logging",
".",
"to_sym",
"]",
">",
"Pwwka",
"::",
... | True if we should omit the payload from the log
::level_of_message_with_payload the level of the message about to be logged | [
"True",
"if",
"we",
"should",
"omit",
"the",
"payload",
"from",
"the",
"log"
] | 581a5261cabaa3e97cfe286da33ce80ffa2d750a | https://github.com/stitchfix/pwwka/blob/581a5261cabaa3e97cfe286da33ce80ffa2d750a/lib/pwwka/configuration.rb#L144-L147 |
17,089 | AirHelp/danger-duplicate_localizable_strings | lib/duplicate_localizable_strings/plugin.rb | Danger.DangerDuplicateLocalizableStrings.localizable_duplicate_entries | def localizable_duplicate_entries
localizable_files = (git.modified_files + git.added_files) - git.deleted_files
localizable_files.select! { |line| line.end_with?('.strings') }
duplicate_entries = []
localizable_files.each do |file|
lines = File.readlines(file)
# Grab just the... | ruby | def localizable_duplicate_entries
localizable_files = (git.modified_files + git.added_files) - git.deleted_files
localizable_files.select! { |line| line.end_with?('.strings') }
duplicate_entries = []
localizable_files.each do |file|
lines = File.readlines(file)
# Grab just the... | [
"def",
"localizable_duplicate_entries",
"localizable_files",
"=",
"(",
"git",
".",
"modified_files",
"+",
"git",
".",
"added_files",
")",
"-",
"git",
".",
"deleted_files",
"localizable_files",
".",
"select!",
"{",
"|",
"line",
"|",
"line",
".",
"end_with?",
"(",... | Returns an array of all detected duplicate entries. An entry is
represented by a has with file path under 'file' key and the
Localizable.strings key under 'key' key.
@return [Array of duplicate Localizable.strings entries] | [
"Returns",
"an",
"array",
"of",
"all",
"detected",
"duplicate",
"entries",
".",
"An",
"entry",
"is",
"represented",
"by",
"a",
"has",
"with",
"file",
"path",
"under",
"file",
"key",
"and",
"the",
"Localizable",
".",
"strings",
"key",
"under",
"key",
"key",... | 155d82a64bb280d277d9656d2afa2541b0883006 | https://github.com/AirHelp/danger-duplicate_localizable_strings/blob/155d82a64bb280d277d9656d2afa2541b0883006/lib/duplicate_localizable_strings/plugin.rb#L20-L47 |
17,090 | nbulaj/proxy_fetcher | lib/proxy_fetcher/document.rb | ProxyFetcher.Document.xpath | def xpath(*args)
backend.xpath(*args).map { |node| backend.proxy_node.new(node) }
end | ruby | def xpath(*args)
backend.xpath(*args).map { |node| backend.proxy_node.new(node) }
end | [
"def",
"xpath",
"(",
"*",
"args",
")",
"backend",
".",
"xpath",
"(",
"args",
")",
".",
"map",
"{",
"|",
"node",
"|",
"backend",
".",
"proxy_node",
".",
"new",
"(",
"node",
")",
"}",
"end"
] | Initialize abstract ProxyFetcher HTML Document
@return [Document]
Searches elements by XPath selector.
@return [Array<ProxyFetcher::Document::Node>]
collection of nodes | [
"Initialize",
"abstract",
"ProxyFetcher",
"HTML",
"Document"
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/document.rb#L36-L38 |
17,091 | nbulaj/proxy_fetcher | lib/proxy_fetcher/document.rb | ProxyFetcher.Document.css | def css(*args)
backend.css(*args).map { |node| backend.proxy_node.new(node) }
end | ruby | def css(*args)
backend.css(*args).map { |node| backend.proxy_node.new(node) }
end | [
"def",
"css",
"(",
"*",
"args",
")",
"backend",
".",
"css",
"(",
"args",
")",
".",
"map",
"{",
"|",
"node",
"|",
"backend",
".",
"proxy_node",
".",
"new",
"(",
"node",
")",
"}",
"end"
] | Searches elements by CSS selector.
@return [Array<ProxyFetcher::Document::Node>]
collection of nodes | [
"Searches",
"elements",
"by",
"CSS",
"selector",
"."
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/document.rb#L45-L47 |
17,092 | nbulaj/proxy_fetcher | lib/proxy_fetcher/utils/proxy_validator.rb | ProxyFetcher.ProxyValidator.connectable? | def connectable?
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
@http.head(URL_TO_CHECK, ssl_context: ssl_context).status.success?
rescue StandardError
false
end | ruby | def connectable?
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
@http.head(URL_TO_CHECK, ssl_context: ssl_context).status.success?
rescue StandardError
false
end | [
"def",
"connectable?",
"ssl_context",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"SSLContext",
".",
"new",
"ssl_context",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"@http",
".",
"head",
"(",
"URL_TO_CHECK",
",",
"ssl_context",
":",
"ssl_con... | Initialize new ProxyValidator instance
@param proxy_addr [String] proxy address or IP
@param proxy_port [String, Integer] proxy port
@return [ProxyValidator]
Checks if proxy is connectable (can be used to connect
resources via proxy server).
@return [Boolean]
true if connection to the server using proxy es... | [
"Initialize",
"new",
"ProxyValidator",
"instance"
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/utils/proxy_validator.rb#L42-L49 |
17,093 | nbulaj/proxy_fetcher | lib/proxy_fetcher/configuration/providers_registry.rb | ProxyFetcher.ProvidersRegistry.class_for | def class_for(provider_name)
provider_name = provider_name.to_sym
providers.fetch(provider_name)
rescue KeyError
raise ProxyFetcher::Exceptions::UnknownProvider, provider_name
end | ruby | def class_for(provider_name)
provider_name = provider_name.to_sym
providers.fetch(provider_name)
rescue KeyError
raise ProxyFetcher::Exceptions::UnknownProvider, provider_name
end | [
"def",
"class_for",
"(",
"provider_name",
")",
"provider_name",
"=",
"provider_name",
".",
"to_sym",
"providers",
".",
"fetch",
"(",
"provider_name",
")",
"rescue",
"KeyError",
"raise",
"ProxyFetcher",
"::",
"Exceptions",
"::",
"UnknownProvider",
",",
"provider_name... | Returns a class for specific provider if it is registered
in the registry. Otherwise throws an exception.
@param provider_name [String, Symbol]
provider name
@return [Class]
provider class
@raise [ProxyFetcher::Exceptions::UnknownProvider]
provider is unknown | [
"Returns",
"a",
"class",
"for",
"specific",
"provider",
"if",
"it",
"is",
"registered",
"in",
"the",
"registry",
".",
"Otherwise",
"throws",
"an",
"exception",
"."
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/configuration/providers_registry.rb#L47-L53 |
17,094 | nbulaj/proxy_fetcher | lib/proxy_fetcher/configuration.rb | ProxyFetcher.Configuration.setup_custom_class | def setup_custom_class(klass, required_methods: [])
unless klass.respond_to?(*required_methods)
raise ProxyFetcher::Exceptions::WrongCustomClass.new(klass, required_methods)
end
klass
end | ruby | def setup_custom_class(klass, required_methods: [])
unless klass.respond_to?(*required_methods)
raise ProxyFetcher::Exceptions::WrongCustomClass.new(klass, required_methods)
end
klass
end | [
"def",
"setup_custom_class",
"(",
"klass",
",",
"required_methods",
":",
"[",
"]",
")",
"unless",
"klass",
".",
"respond_to?",
"(",
"required_methods",
")",
"raise",
"ProxyFetcher",
"::",
"Exceptions",
"::",
"WrongCustomClass",
".",
"new",
"(",
"klass",
",",
"... | Checks if custom class has some required class methods | [
"Checks",
"if",
"custom",
"class",
"has",
"some",
"required",
"class",
"methods"
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/configuration.rb#L175-L181 |
17,095 | nbulaj/proxy_fetcher | lib/proxy_fetcher/utils/http_client.rb | ProxyFetcher.HTTPClient.fetch | def fetch
response = process_http_request
response.body.to_s
rescue StandardError => error
ProxyFetcher.logger.warn("Failed to process request to #{url} (#{error.message})")
''
end | ruby | def fetch
response = process_http_request
response.body.to_s
rescue StandardError => error
ProxyFetcher.logger.warn("Failed to process request to #{url} (#{error.message})")
''
end | [
"def",
"fetch",
"response",
"=",
"process_http_request",
"response",
".",
"body",
".",
"to_s",
"rescue",
"StandardError",
"=>",
"error",
"ProxyFetcher",
".",
"logger",
".",
"warn",
"(",
"\"Failed to process request to #{url} (#{error.message})\"",
")",
"''",
"end"
] | Initialize HTTP client instance
@return [HTTPClient]
Fetches resource content by sending HTTP request to it.
@return [String]
response body | [
"Initialize",
"HTTP",
"client",
"instance"
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/utils/http_client.rb#L70-L76 |
17,096 | nbulaj/proxy_fetcher | lib/proxy_fetcher/manager.rb | ProxyFetcher.Manager.refresh_list! | def refresh_list!(filters = nil)
@proxies = []
threads = []
lock = Mutex.new
ProxyFetcher.config.providers.each do |provider_name|
threads << Thread.new do
provider = ProxyFetcher::Configuration.providers_registry.class_for(provider_name)
provider_filters = filters ... | ruby | def refresh_list!(filters = nil)
@proxies = []
threads = []
lock = Mutex.new
ProxyFetcher.config.providers.each do |provider_name|
threads << Thread.new do
provider = ProxyFetcher::Configuration.providers_registry.class_for(provider_name)
provider_filters = filters ... | [
"def",
"refresh_list!",
"(",
"filters",
"=",
"nil",
")",
"@proxies",
"=",
"[",
"]",
"threads",
"=",
"[",
"]",
"lock",
"=",
"Mutex",
".",
"new",
"ProxyFetcher",
".",
"config",
".",
"providers",
".",
"each",
"do",
"|",
"provider_name",
"|",
"threads",
"<... | Initialize ProxyFetcher Manager instance for managing proxies
refresh: true - load proxy list from the remote server on initialization
refresh: false - just initialize the class, proxy list will be empty ([])
@return [Manager]
Update current proxy list using configured providers.
@param filters [Hash] provider... | [
"Initialize",
"ProxyFetcher",
"Manager",
"instance",
"for",
"managing",
"proxies"
] | da2e067acd930886d894490e229ba094f7f5ea53 | https://github.com/nbulaj/proxy_fetcher/blob/da2e067acd930886d894490e229ba094f7f5ea53/lib/proxy_fetcher/manager.rb#L31-L52 |
17,097 | zeisler/active_mocker | lib/active_mocker/mock/queries.rb | ActiveMocker.Queries.delete_all | def delete_all(conditions = nil)
check_for_limit_scope!
collection = conditions.nil? ? to_a.each(&:delete).clear : where(conditions)
collection.map(&:delete).count
end | ruby | def delete_all(conditions = nil)
check_for_limit_scope!
collection = conditions.nil? ? to_a.each(&:delete).clear : where(conditions)
collection.map(&:delete).count
end | [
"def",
"delete_all",
"(",
"conditions",
"=",
"nil",
")",
"check_for_limit_scope!",
"collection",
"=",
"conditions",
".",
"nil?",
"?",
"to_a",
".",
"each",
"(",
":delete",
")",
".",
"clear",
":",
"where",
"(",
"conditions",
")",
"collection",
".",
"map",
"(... | Deletes the records matching +conditions+ by instantiating each
record and calling its +delete+ method.
==== Parameters
* +conditions+ - A string, array, or hash that specifies which records
to destroy. If omitted, all records are destroyed.
==== Examples
PersonMock.destroy_all(status: "inactive")
Pers... | [
"Deletes",
"the",
"records",
"matching",
"+",
"conditions",
"+",
"by",
"instantiating",
"each",
"record",
"and",
"calling",
"its",
"+",
"delete",
"+",
"method",
"."
] | bb03387df80708817de2f4d7fc9ca2d3f4b161c3 | https://github.com/zeisler/active_mocker/blob/bb03387df80708817de2f4d7fc9ca2d3f4b161c3/lib/active_mocker/mock/queries.rb#L62-L67 |
17,098 | zeisler/active_mocker | lib/active_mocker/mock/queries.rb | ActiveMocker.Queries.find_by | def find_by(conditions = {})
to_a.detect do |record|
Find.new(record).is_of(conditions)
end
end | ruby | def find_by(conditions = {})
to_a.detect do |record|
Find.new(record).is_of(conditions)
end
end | [
"def",
"find_by",
"(",
"conditions",
"=",
"{",
"}",
")",
"to_a",
".",
"detect",
"do",
"|",
"record",
"|",
"Find",
".",
"new",
"(",
"record",
")",
".",
"is_of",
"(",
"conditions",
")",
"end",
"end"
] | Finds the first record matching the specified conditions. There
is no implied ordering so if order matters, you should specify it
yourself.
If no record is found, returns <tt>nil</tt>.
Post.find_by name: 'Spartacus', rating: 4 | [
"Finds",
"the",
"first",
"record",
"matching",
"the",
"specified",
"conditions",
".",
"There",
"is",
"no",
"implied",
"ordering",
"so",
"if",
"order",
"matters",
"you",
"should",
"specify",
"it",
"yourself",
"."
] | bb03387df80708817de2f4d7fc9ca2d3f4b161c3 | https://github.com/zeisler/active_mocker/blob/bb03387df80708817de2f4d7fc9ca2d3f4b161c3/lib/active_mocker/mock/queries.rb#L192-L196 |
17,099 | zeisler/active_mocker | lib/active_mocker/mock/queries.rb | ActiveMocker.Queries.limit | def limit(num)
relation = __new_relation__(all.take(num))
relation.send(:set_from_limit)
relation
end | ruby | def limit(num)
relation = __new_relation__(all.take(num))
relation.send(:set_from_limit)
relation
end | [
"def",
"limit",
"(",
"num",
")",
"relation",
"=",
"__new_relation__",
"(",
"all",
".",
"take",
"(",
"num",
")",
")",
"relation",
".",
"send",
"(",
":set_from_limit",
")",
"relation",
"end"
] | Specifies a limit for the number of records to retrieve.
User.limit(10) | [
"Specifies",
"a",
"limit",
"for",
"the",
"number",
"of",
"records",
"to",
"retrieve",
"."
] | bb03387df80708817de2f4d7fc9ca2d3f4b161c3 | https://github.com/zeisler/active_mocker/blob/bb03387df80708817de2f4d7fc9ca2d3f4b161c3/lib/active_mocker/mock/queries.rb#L268-L272 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.