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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
9,500
|
ithouse/lolita-paypal
|
app/controllers/lolita_paypal/transactions_controller.rb
|
LolitaPaypal.TransactionsController.set_active_payment
|
def set_active_payment
@payment ||= session[:payment_data][:billing_class].constantize.find(session[:payment_data][:billing_id])
rescue
render text: I18n.t('lolita_paypal.wrong_request'), status: 400
end
|
ruby
|
def set_active_payment
@payment ||= session[:payment_data][:billing_class].constantize.find(session[:payment_data][:billing_id])
rescue
render text: I18n.t('lolita_paypal.wrong_request'), status: 400
end
|
[
"def",
"set_active_payment",
"@payment",
"||=",
"session",
"[",
":payment_data",
"]",
"[",
":billing_class",
"]",
".",
"constantize",
".",
"find",
"(",
"session",
"[",
":payment_data",
"]",
"[",
":billing_id",
"]",
")",
"rescue",
"render",
"text",
":",
"I18n",
".",
"t",
"(",
"'lolita_paypal.wrong_request'",
")",
",",
"status",
":",
"400",
"end"
] |
returns current payment instance from session
|
[
"returns",
"current",
"payment",
"instance",
"from",
"session"
] |
f18d0995aaec58a144e39d073bf32bdd2c1cb4b1
|
https://github.com/ithouse/lolita-paypal/blob/f18d0995aaec58a144e39d073bf32bdd2c1cb4b1/app/controllers/lolita_paypal/transactions_controller.rb#L51-L55
|
9,501
|
loveablelobster/DwCR
|
lib/dwca_content_analyzer/file_contents.rb
|
DwCAContentAnalyzer.FileContents.headers
|
def headers(file)
Array.new(CSV.open(file, &:readline).size) { |i| i.to_s }
end
|
ruby
|
def headers(file)
Array.new(CSV.open(file, &:readline).size) { |i| i.to_s }
end
|
[
"def",
"headers",
"(",
"file",
")",
"Array",
".",
"new",
"(",
"CSV",
".",
"open",
"(",
"file",
",",
":readline",
")",
".",
"size",
")",
"{",
"|",
"i",
"|",
"i",
".",
"to_s",
"}",
"end"
] |
reads the first line of the CSV file
returns the columns indices as an array
|
[
"reads",
"the",
"first",
"line",
"of",
"the",
"CSV",
"file",
"returns",
"the",
"columns",
"indices",
"as",
"an",
"array"
] |
093e112337bfb664630a0f164c9d9d7552b1e54c
|
https://github.com/loveablelobster/DwCR/blob/093e112337bfb664630a0f164c9d9d7552b1e54c/lib/dwca_content_analyzer/file_contents.rb#L33-L35
|
9,502
|
petebrowne/machined
|
lib/machined/sprocket.rb
|
Machined.Sprocket.use_all_templates
|
def use_all_templates
Utils.available_templates.each do |ext, template|
next if engines(ext)
register_engine ext, template
end
end
|
ruby
|
def use_all_templates
Utils.available_templates.each do |ext, template|
next if engines(ext)
register_engine ext, template
end
end
|
[
"def",
"use_all_templates",
"Utils",
".",
"available_templates",
".",
"each",
"do",
"|",
"ext",
",",
"template",
"|",
"next",
"if",
"engines",
"(",
"ext",
")",
"register_engine",
"ext",
",",
"template",
"end",
"end"
] |
Loops through the available Tilt templates
and registers them as processor engines for
Sprockets. By default, Sprockets cherry picks
templates that work for web assets. We need to
allow use of Haml, Markdown, etc.
|
[
"Loops",
"through",
"the",
"available",
"Tilt",
"templates",
"and",
"registers",
"them",
"as",
"processor",
"engines",
"for",
"Sprockets",
".",
"By",
"default",
"Sprockets",
"cherry",
"picks",
"templates",
"that",
"work",
"for",
"web",
"assets",
".",
"We",
"need",
"to",
"allow",
"use",
"of",
"Haml",
"Markdown",
"etc",
"."
] |
4f3921bc5098104096474300e933f009f1b4f7dd
|
https://github.com/petebrowne/machined/blob/4f3921bc5098104096474300e933f009f1b4f7dd/lib/machined/sprocket.rb#L53-L58
|
9,503
|
bogrobotten/fetch
|
lib/fetch/callbacks.rb
|
Fetch.Callbacks.run_callbacks_for
|
def run_callbacks_for(name, args, reverse)
callbacks_for(name, reverse).map do |block|
run_callback(block, args)
end
end
|
ruby
|
def run_callbacks_for(name, args, reverse)
callbacks_for(name, reverse).map do |block|
run_callback(block, args)
end
end
|
[
"def",
"run_callbacks_for",
"(",
"name",
",",
"args",
",",
"reverse",
")",
"callbacks_for",
"(",
"name",
",",
"reverse",
")",
".",
"map",
"do",
"|",
"block",
"|",
"run_callback",
"(",
"block",
",",
"args",
")",
"end",
"end"
] |
Run specific callbacks.
run_callbacks_for(:before_fetch)
run_callbacks_for(:progress, 12) # 12 percent done
|
[
"Run",
"specific",
"callbacks",
"."
] |
8a9e1fb42ed0719dd7b4d1a965d11b0f5decca4f
|
https://github.com/bogrobotten/fetch/blob/8a9e1fb42ed0719dd7b4d1a965d11b0f5decca4f/lib/fetch/callbacks.rb#L18-L22
|
9,504
|
payout/announcer
|
lib/announcer/subscription.rb
|
Announcer.Subscription._determine_path
|
def _determine_path
path = File.expand_path('../..', __FILE__)
# Will be something like:
# "/path/to/file.rb:47:in `method_name'"
non_announcer_caller = caller.find { |c| !c.start_with?(path) }
unless non_announcer_caller
# This is not expected to occur.
raise Errors::SubscriptionError, "Could not find non-Announcer caller"
end
non_announcer_caller
end
|
ruby
|
def _determine_path
path = File.expand_path('../..', __FILE__)
# Will be something like:
# "/path/to/file.rb:47:in `method_name'"
non_announcer_caller = caller.find { |c| !c.start_with?(path) }
unless non_announcer_caller
# This is not expected to occur.
raise Errors::SubscriptionError, "Could not find non-Announcer caller"
end
non_announcer_caller
end
|
[
"def",
"_determine_path",
"path",
"=",
"File",
".",
"expand_path",
"(",
"'../..'",
",",
"__FILE__",
")",
"# Will be something like:",
"# \"/path/to/file.rb:47:in `method_name'\"",
"non_announcer_caller",
"=",
"caller",
".",
"find",
"{",
"|",
"c",
"|",
"!",
"c",
".",
"start_with?",
"(",
"path",
")",
"}",
"unless",
"non_announcer_caller",
"# This is not expected to occur.",
"raise",
"Errors",
"::",
"SubscriptionError",
",",
"\"Could not find non-Announcer caller\"",
"end",
"non_announcer_caller",
"end"
] |
Determines the file path of the ruby code defining the subscription.
It's important that this is called from within the initializer to get the
desired effect.
|
[
"Determines",
"the",
"file",
"path",
"of",
"the",
"ruby",
"code",
"defining",
"the",
"subscription",
".",
"It",
"s",
"important",
"that",
"this",
"is",
"called",
"from",
"within",
"the",
"initializer",
"to",
"get",
"the",
"desired",
"effect",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/subscription.rb#L59-L72
|
9,505
|
payout/announcer
|
lib/announcer/subscription.rb
|
Announcer.Subscription._generate_identifier
|
def _generate_identifier
# Cut off everything from the line number onward. That way, the identifier
# does not change when the subscription block moves to a different line.
index = _path.rindex(/:\d+:/) - 1
path = _path[0..index]
raise Errors::SubscriptionError, "Invalid path: #{path}" unless File.exists?(path)
Digest::MD5.hexdigest("#{path}:#{event_name}:#{name}").to_sym
end
|
ruby
|
def _generate_identifier
# Cut off everything from the line number onward. That way, the identifier
# does not change when the subscription block moves to a different line.
index = _path.rindex(/:\d+:/) - 1
path = _path[0..index]
raise Errors::SubscriptionError, "Invalid path: #{path}" unless File.exists?(path)
Digest::MD5.hexdigest("#{path}:#{event_name}:#{name}").to_sym
end
|
[
"def",
"_generate_identifier",
"# Cut off everything from the line number onward. That way, the identifier",
"# does not change when the subscription block moves to a different line.",
"index",
"=",
"_path",
".",
"rindex",
"(",
"/",
"\\d",
"/",
")",
"-",
"1",
"path",
"=",
"_path",
"[",
"0",
"..",
"index",
"]",
"raise",
"Errors",
"::",
"SubscriptionError",
",",
"\"Invalid path: #{path}\"",
"unless",
"File",
".",
"exists?",
"(",
"path",
")",
"Digest",
"::",
"MD5",
".",
"hexdigest",
"(",
"\"#{path}:#{event_name}:#{name}\"",
")",
".",
"to_sym",
"end"
] |
Generates a unique identifier for this subscription which will be used to
"serialize" it.
The goal here is to generate a identifier that is the same across different
processes and servers and that ideally changes infrequently between
application versions, but when it does change, it should do so predictably.
|
[
"Generates",
"a",
"unique",
"identifier",
"for",
"this",
"subscription",
"which",
"will",
"be",
"used",
"to",
"serialize",
"it",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/subscription.rb#L81-L90
|
9,506
|
payout/announcer
|
lib/announcer/subscription.rb
|
Announcer.Subscription._evaluate_priority_int
|
def _evaluate_priority_int(int)
raise Errors::InvalidPriorityError, int unless int > 0 && int <= config.max_priority
int
end
|
ruby
|
def _evaluate_priority_int(int)
raise Errors::InvalidPriorityError, int unless int > 0 && int <= config.max_priority
int
end
|
[
"def",
"_evaluate_priority_int",
"(",
"int",
")",
"raise",
"Errors",
"::",
"InvalidPriorityError",
",",
"int",
"unless",
"int",
">",
"0",
"&&",
"int",
"<=",
"config",
".",
"max_priority",
"int",
"end"
] |
Evaluate an integer as a priority.
|
[
"Evaluate",
"an",
"integer",
"as",
"a",
"priority",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/subscription.rb#L137-L140
|
9,507
|
payout/announcer
|
lib/announcer/subscription.rb
|
Announcer.Subscription._evaluate_priority_symbol
|
def _evaluate_priority_symbol(sym)
if (priority = _symbol_to_priority(sym))
_evaluate_priority(priority)
else
raise Errors::InvalidPriorityError, sym.inspect
end
end
|
ruby
|
def _evaluate_priority_symbol(sym)
if (priority = _symbol_to_priority(sym))
_evaluate_priority(priority)
else
raise Errors::InvalidPriorityError, sym.inspect
end
end
|
[
"def",
"_evaluate_priority_symbol",
"(",
"sym",
")",
"if",
"(",
"priority",
"=",
"_symbol_to_priority",
"(",
"sym",
")",
")",
"_evaluate_priority",
"(",
"priority",
")",
"else",
"raise",
"Errors",
"::",
"InvalidPriorityError",
",",
"sym",
".",
"inspect",
"end",
"end"
] |
Evaluate a symbol as a priority.
|
[
"Evaluate",
"a",
"symbol",
"as",
"a",
"priority",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/subscription.rb#L143-L149
|
9,508
|
payout/announcer
|
lib/announcer/subscription.rb
|
Announcer.Subscription._evaluate_priority_nil
|
def _evaluate_priority_nil
# Need to specify value explicitly here, otherwise in the call to
# _evaluate_priority, the case statement won't recognize it as a Symbol.
# That's because when calls Symbol::=== to evaluate a match.
priority = config.default_priority
if priority
_evaluate_priority(priority)
else
raise Errors::InvalidPriorityError, priority.inspect
end
end
|
ruby
|
def _evaluate_priority_nil
# Need to specify value explicitly here, otherwise in the call to
# _evaluate_priority, the case statement won't recognize it as a Symbol.
# That's because when calls Symbol::=== to evaluate a match.
priority = config.default_priority
if priority
_evaluate_priority(priority)
else
raise Errors::InvalidPriorityError, priority.inspect
end
end
|
[
"def",
"_evaluate_priority_nil",
"# Need to specify value explicitly here, otherwise in the call to",
"# _evaluate_priority, the case statement won't recognize it as a Symbol.",
"# That's because when calls Symbol::=== to evaluate a match.",
"priority",
"=",
"config",
".",
"default_priority",
"if",
"priority",
"_evaluate_priority",
"(",
"priority",
")",
"else",
"raise",
"Errors",
"::",
"InvalidPriorityError",
",",
"priority",
".",
"inspect",
"end",
"end"
] |
Evaluate nil as a priority.
|
[
"Evaluate",
"nil",
"as",
"a",
"priority",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/subscription.rb#L152-L163
|
9,509
|
ithouse/lolita-paypal
|
app/helpers/lolita_paypal/application_helper.rb
|
LolitaPaypal.ApplicationHelper.encrypt_request
|
def encrypt_request(payment_request)
variables = payment_request.request_variables.reverse_merge({
'notify_url'=> answer_paypal_url(protocol: 'https')
})
LolitaPaypal::Request.encrypt_for_paypal variables
ensure
LolitaPaypal.logger.info "[#{payment_request.payment_id}] #{variables}"
end
|
ruby
|
def encrypt_request(payment_request)
variables = payment_request.request_variables.reverse_merge({
'notify_url'=> answer_paypal_url(protocol: 'https')
})
LolitaPaypal::Request.encrypt_for_paypal variables
ensure
LolitaPaypal.logger.info "[#{payment_request.payment_id}] #{variables}"
end
|
[
"def",
"encrypt_request",
"(",
"payment_request",
")",
"variables",
"=",
"payment_request",
".",
"request_variables",
".",
"reverse_merge",
"(",
"{",
"'notify_url'",
"=>",
"answer_paypal_url",
"(",
"protocol",
":",
"'https'",
")",
"}",
")",
"LolitaPaypal",
"::",
"Request",
".",
"encrypt_for_paypal",
"variables",
"ensure",
"LolitaPaypal",
".",
"logger",
".",
"info",
"\"[#{payment_request.payment_id}] #{variables}\"",
"end"
] |
returns encrypted request variables
|
[
"returns",
"encrypted",
"request",
"variables"
] |
f18d0995aaec58a144e39d073bf32bdd2c1cb4b1
|
https://github.com/ithouse/lolita-paypal/blob/f18d0995aaec58a144e39d073bf32bdd2c1cb4b1/app/helpers/lolita_paypal/application_helper.rb#L6-L13
|
9,510
|
waka/musako
|
lib/musako/configuration.rb
|
Musako.Configuration.read_config_file
|
def read_config_file
c = clone
config = YAML.load_file(File.join(DEFAULTS[:source], "config.yml"))
unless config.is_a? Hash
raise ArgumentError.new("Configuration file: invalid #{file}")
end
c.merge(config)
rescue SystemCallError
raise LoadError, "Configuration file: not found #{file}"
end
|
ruby
|
def read_config_file
c = clone
config = YAML.load_file(File.join(DEFAULTS[:source], "config.yml"))
unless config.is_a? Hash
raise ArgumentError.new("Configuration file: invalid #{file}")
end
c.merge(config)
rescue SystemCallError
raise LoadError, "Configuration file: not found #{file}"
end
|
[
"def",
"read_config_file",
"c",
"=",
"clone",
"config",
"=",
"YAML",
".",
"load_file",
"(",
"File",
".",
"join",
"(",
"DEFAULTS",
"[",
":source",
"]",
",",
"\"config.yml\"",
")",
")",
"unless",
"config",
".",
"is_a?",
"Hash",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Configuration file: invalid #{file}\"",
")",
"end",
"c",
".",
"merge",
"(",
"config",
")",
"rescue",
"SystemCallError",
"raise",
"LoadError",
",",
"\"Configuration file: not found #{file}\"",
"end"
] |
load YAML file.
|
[
"load",
"YAML",
"file",
"."
] |
895463ae3a24555f019637d3f6ef6763b7b96735
|
https://github.com/waka/musako/blob/895463ae3a24555f019637d3f6ef6763b7b96735/lib/musako/configuration.rb#L27-L37
|
9,511
|
jarrett/ichiban
|
lib/ichiban/helpers.rb
|
Ichiban.Helpers.path_with_slashes
|
def path_with_slashes(path)
path = '/' + path unless path.start_with?('/')
path << '/' unless path.end_with?('/')
path
end
|
ruby
|
def path_with_slashes(path)
path = '/' + path unless path.start_with?('/')
path << '/' unless path.end_with?('/')
path
end
|
[
"def",
"path_with_slashes",
"(",
"path",
")",
"path",
"=",
"'/'",
"+",
"path",
"unless",
"path",
".",
"start_with?",
"(",
"'/'",
")",
"path",
"<<",
"'/'",
"unless",
"path",
".",
"end_with?",
"(",
"'/'",
")",
"path",
"end"
] |
Adds leading and trailing slashes if none are present
|
[
"Adds",
"leading",
"and",
"trailing",
"slashes",
"if",
"none",
"are",
"present"
] |
310f96b0981ea19bf01246995f3732c986915d5b
|
https://github.com/jarrett/ichiban/blob/310f96b0981ea19bf01246995f3732c986915d5b/lib/ichiban/helpers.rb#L78-L82
|
9,512
|
checkdin/checkdin-ruby
|
lib/checkdin/votes.rb
|
Checkdin.Votes.votes
|
def votes(options={})
response = connection.get do |req|
req.url "votes", options
end
return_error_or_body(response)
end
|
ruby
|
def votes(options={})
response = connection.get do |req|
req.url "votes", options
end
return_error_or_body(response)
end
|
[
"def",
"votes",
"(",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"connection",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"\"votes\"",
",",
"options",
"end",
"return_error_or_body",
"(",
"response",
")",
"end"
] |
Get a list of all votes for the authenticating client.
@param [Hash] options
@option options Integer :user_id - Only return votes for this user.
@option options Integer :limit - The maximum number of records to return.
|
[
"Get",
"a",
"list",
"of",
"all",
"votes",
"for",
"the",
"authenticating",
"client",
"."
] |
c3c4b38b0f8c710e1f805100dcf3a70649215b48
|
https://github.com/checkdin/checkdin-ruby/blob/c3c4b38b0f8c710e1f805100dcf3a70649215b48/lib/checkdin/votes.rb#L10-L15
|
9,513
|
fenton-project/fenton_shell
|
lib/fenton_shell/client.rb
|
FentonShell.Client.create
|
def create(global_options, options)
status, body = client_create(global_options, options)
if status == 201
save_message('Client': ['created!'])
true
else
save_message(body)
false
end
end
|
ruby
|
def create(global_options, options)
status, body = client_create(global_options, options)
if status == 201
save_message('Client': ['created!'])
true
else
save_message(body)
false
end
end
|
[
"def",
"create",
"(",
"global_options",
",",
"options",
")",
"status",
",",
"body",
"=",
"client_create",
"(",
"global_options",
",",
"options",
")",
"if",
"status",
"==",
"201",
"save_message",
"(",
"'Client'",
":",
"[",
"'created!'",
"]",
")",
"true",
"else",
"save_message",
"(",
"body",
")",
"false",
"end",
"end"
] |
Creates a new client on fenton server by sending a post
request with json from the command line to create the client
@param global_options [Hash] global command line options
@param options [Hash] json fields to send to fenton server
@return [String] success or failure message
|
[
"Creates",
"a",
"new",
"client",
"on",
"fenton",
"server",
"by",
"sending",
"a",
"post",
"request",
"with",
"json",
"from",
"the",
"command",
"line",
"to",
"create",
"the",
"client"
] |
6e1d76186fa7ee7a3be141afad9361e3a3e0ec91
|
https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/client.rb#L15-L25
|
9,514
|
fenton-project/fenton_shell
|
lib/fenton_shell/client.rb
|
FentonShell.Client.create_with_organization
|
def create_with_organization(global_options, options)
create(global_options, options)
if Organization.new.create(global_options, name: options[:username],
key: options[:username])
save_message('Organization': ['created!'])
true
else
save_message('Organization': ['not created!'])
false
end
end
|
ruby
|
def create_with_organization(global_options, options)
create(global_options, options)
if Organization.new.create(global_options, name: options[:username],
key: options[:username])
save_message('Organization': ['created!'])
true
else
save_message('Organization': ['not created!'])
false
end
end
|
[
"def",
"create_with_organization",
"(",
"global_options",
",",
"options",
")",
"create",
"(",
"global_options",
",",
"options",
")",
"if",
"Organization",
".",
"new",
".",
"create",
"(",
"global_options",
",",
"name",
":",
"options",
"[",
":username",
"]",
",",
"key",
":",
"options",
"[",
":username",
"]",
")",
"save_message",
"(",
"'Organization'",
":",
"[",
"'created!'",
"]",
")",
"true",
"else",
"save_message",
"(",
"'Organization'",
":",
"[",
"'not created!'",
"]",
")",
"false",
"end",
"end"
] |
Calls create new client then creates an organization for that client
via a post request with json from the command line
@param global_options [Hash] global command line options
@param options [Hash] json fields to send to fenton server
@return [String] success or failure message
|
[
"Calls",
"create",
"new",
"client",
"then",
"creates",
"an",
"organization",
"for",
"that",
"client",
"via",
"a",
"post",
"request",
"with",
"json",
"from",
"the",
"command",
"line"
] |
6e1d76186fa7ee7a3be141afad9361e3a3e0ec91
|
https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/client.rb#L34-L45
|
9,515
|
fenton-project/fenton_shell
|
lib/fenton_shell/client.rb
|
FentonShell.Client.client_json
|
def client_json(options)
{
client: {
username: options[:username],
name: options[:name],
email: options[:email],
public_key: File.read(options[:public_key])
}
}.to_json
end
|
ruby
|
def client_json(options)
{
client: {
username: options[:username],
name: options[:name],
email: options[:email],
public_key: File.read(options[:public_key])
}
}.to_json
end
|
[
"def",
"client_json",
"(",
"options",
")",
"{",
"client",
":",
"{",
"username",
":",
"options",
"[",
":username",
"]",
",",
"name",
":",
"options",
"[",
":name",
"]",
",",
"email",
":",
"options",
"[",
":email",
"]",
",",
"public_key",
":",
"File",
".",
"read",
"(",
"options",
"[",
":public_key",
"]",
")",
"}",
"}",
".",
"to_json",
"end"
] |
Formulates the client json for the post request
@param options [Hash] fields from fenton command line
@return [String] json created from the options hash
|
[
"Formulates",
"the",
"client",
"json",
"for",
"the",
"post",
"request"
] |
6e1d76186fa7ee7a3be141afad9361e3a3e0ec91
|
https://github.com/fenton-project/fenton_shell/blob/6e1d76186fa7ee7a3be141afad9361e3a3e0ec91/lib/fenton_shell/client.rb#L69-L78
|
9,516
|
caruby/scat
|
lib/scat/authorization.rb
|
Scat.Authorization.perform!
|
def perform!(email, password, &block)
login_required
CaTissue::Database.current.open(email, password, &block)
end
|
ruby
|
def perform!(email, password, &block)
login_required
CaTissue::Database.current.open(email, password, &block)
end
|
[
"def",
"perform!",
"(",
"email",
",",
"password",
",",
"&",
"block",
")",
"login_required",
"CaTissue",
"::",
"Database",
".",
"current",
".",
"open",
"(",
"email",
",",
"password",
",",
"block",
")",
"end"
] |
Runs the given caTissue operation block with the given caTissue credentials.
@yield (see #protect!)
@return [String, nil] the status message
|
[
"Runs",
"the",
"given",
"caTissue",
"operation",
"block",
"with",
"the",
"given",
"caTissue",
"credentials",
"."
] |
90291b317eb6b8ef8b0a4497622eadc15d3d9028
|
https://github.com/caruby/scat/blob/90291b317eb6b8ef8b0a4497622eadc15d3d9028/lib/scat/authorization.rb#L70-L73
|
9,517
|
parrish/attention
|
lib/attention/publisher.rb
|
Attention.Publisher.publish
|
def publish(channel, value)
redis = Attention.redis.call
yield redis if block_given?
redis.publish channel, payload_for(value)
end
|
ruby
|
def publish(channel, value)
redis = Attention.redis.call
yield redis if block_given?
redis.publish channel, payload_for(value)
end
|
[
"def",
"publish",
"(",
"channel",
",",
"value",
")",
"redis",
"=",
"Attention",
".",
"redis",
".",
"call",
"yield",
"redis",
"if",
"block_given?",
"redis",
".",
"publish",
"channel",
",",
"payload_for",
"(",
"value",
")",
"end"
] |
Publishes the value to the channel
@param channel [String] The channel to publish to
@param value [Object] The value to publish
@yield Allows an optional block to use the Redis connection
@yieldparam redis [Redis] The Redis connection
|
[
"Publishes",
"the",
"value",
"to",
"the",
"channel"
] |
ff5bd780b946636ba0e22f66bae3fb41b9c4353d
|
https://github.com/parrish/attention/blob/ff5bd780b946636ba0e22f66bae3fb41b9c4353d/lib/attention/publisher.rb#L9-L13
|
9,518
|
parrish/attention
|
lib/attention/publisher.rb
|
Attention.Publisher.payload_for
|
def payload_for(value)
case value
when Array, Hash
JSON.dump value
else
value
end
rescue
value
end
|
ruby
|
def payload_for(value)
case value
when Array, Hash
JSON.dump value
else
value
end
rescue
value
end
|
[
"def",
"payload_for",
"(",
"value",
")",
"case",
"value",
"when",
"Array",
",",
"Hash",
"JSON",
".",
"dump",
"value",
"else",
"value",
"end",
"rescue",
"value",
"end"
] |
Converts published values to JSON if possible
@api private
|
[
"Converts",
"published",
"values",
"to",
"JSON",
"if",
"possible"
] |
ff5bd780b946636ba0e22f66bae3fb41b9c4353d
|
https://github.com/parrish/attention/blob/ff5bd780b946636ba0e22f66bae3fb41b9c4353d/lib/attention/publisher.rb#L17-L26
|
9,519
|
nosolosoftware/azure_jwt_auth
|
lib/azure_jwt_auth/jwt_manager.rb
|
AzureJwtAuth.JwtManager.custom_valid?
|
def custom_valid?
@provider.validations.each do |key, value|
return false unless payload[key] == value
end
true
end
|
ruby
|
def custom_valid?
@provider.validations.each do |key, value|
return false unless payload[key] == value
end
true
end
|
[
"def",
"custom_valid?",
"@provider",
".",
"validations",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"return",
"false",
"unless",
"payload",
"[",
"key",
"]",
"==",
"value",
"end",
"true",
"end"
] |
Check custom validations defined into provider
|
[
"Check",
"custom",
"validations",
"defined",
"into",
"provider"
] |
1c7010ac29afb10b099393ec4648f919b17a2695
|
https://github.com/nosolosoftware/azure_jwt_auth/blob/1c7010ac29afb10b099393ec4648f919b17a2695/lib/azure_jwt_auth/jwt_manager.rb#L43-L49
|
9,520
|
nosolosoftware/azure_jwt_auth
|
lib/azure_jwt_auth/jwt_manager.rb
|
AzureJwtAuth.JwtManager.rsa_decode
|
def rsa_decode
kid = header['kid']
try = false
begin
rsa = @provider.keys[kid]
raise KidNotFound, 'kid not found into provider keys' unless rsa
JWT.decode(@jwt, rsa.public_key, true, algorithm: 'RS256')
rescue JWT::VerificationError, KidNotFound
raise if try
@provider.load_keys # maybe keys have been changed
try = true
retry
end
end
|
ruby
|
def rsa_decode
kid = header['kid']
try = false
begin
rsa = @provider.keys[kid]
raise KidNotFound, 'kid not found into provider keys' unless rsa
JWT.decode(@jwt, rsa.public_key, true, algorithm: 'RS256')
rescue JWT::VerificationError, KidNotFound
raise if try
@provider.load_keys # maybe keys have been changed
try = true
retry
end
end
|
[
"def",
"rsa_decode",
"kid",
"=",
"header",
"[",
"'kid'",
"]",
"try",
"=",
"false",
"begin",
"rsa",
"=",
"@provider",
".",
"keys",
"[",
"kid",
"]",
"raise",
"KidNotFound",
",",
"'kid not found into provider keys'",
"unless",
"rsa",
"JWT",
".",
"decode",
"(",
"@jwt",
",",
"rsa",
".",
"public_key",
",",
"true",
",",
"algorithm",
":",
"'RS256'",
")",
"rescue",
"JWT",
"::",
"VerificationError",
",",
"KidNotFound",
"raise",
"if",
"try",
"@provider",
".",
"load_keys",
"# maybe keys have been changed",
"try",
"=",
"true",
"retry",
"end",
"end"
] |
Decodes the JWT with the signed secret
|
[
"Decodes",
"the",
"JWT",
"with",
"the",
"signed",
"secret"
] |
1c7010ac29afb10b099393ec4648f919b17a2695
|
https://github.com/nosolosoftware/azure_jwt_auth/blob/1c7010ac29afb10b099393ec4648f919b17a2695/lib/azure_jwt_auth/jwt_manager.rb#L59-L75
|
9,521
|
jtzero/vigilem-core
|
lib/vigilem/core/hooks.rb
|
Vigilem::Core.Hooks.run_hook
|
def run_hook(hook_name, *args, &block)
hooks.find {|hook| hook.name == hook_name }.run(self, *args, &block)
end
|
ruby
|
def run_hook(hook_name, *args, &block)
hooks.find {|hook| hook.name == hook_name }.run(self, *args, &block)
end
|
[
"def",
"run_hook",
"(",
"hook_name",
",",
"*",
"args",
",",
"&",
"block",
")",
"hooks",
".",
"find",
"{",
"|",
"hook",
"|",
"hook",
".",
"name",
"==",
"hook_name",
"}",
".",
"run",
"(",
"self",
",",
"args",
",",
"block",
")",
"end"
] |
class level
finds a hook by that name and runs it
@param hook_name the hook to find
@param [Array] args arguments to be passed to the hook
@param [Proc] block Proc to be passed to the hook
@return [Hook]
|
[
"class",
"level",
"finds",
"a",
"hook",
"by",
"that",
"name",
"and",
"runs",
"it"
] |
a35864229ee76800f5197e3c3c6fb2bf34a68495
|
https://github.com/jtzero/vigilem-core/blob/a35864229ee76800f5197e3c3c6fb2bf34a68495/lib/vigilem/core/hooks.rb#L26-L28
|
9,522
|
johnwunder/stix_schema_spy
|
lib/stix_schema_spy/models/complex_type.rb
|
StixSchemaSpy.ComplexType.vocab_values
|
def vocab_values
type = Schema.find(self.schema.prefix, stix_version).find_type(name.gsub("Vocab", "Enum"))
if type
type.enumeration_values
else
raise "Unable to find corresponding enumeration for vocabulary"
end
end
|
ruby
|
def vocab_values
type = Schema.find(self.schema.prefix, stix_version).find_type(name.gsub("Vocab", "Enum"))
if type
type.enumeration_values
else
raise "Unable to find corresponding enumeration for vocabulary"
end
end
|
[
"def",
"vocab_values",
"type",
"=",
"Schema",
".",
"find",
"(",
"self",
".",
"schema",
".",
"prefix",
",",
"stix_version",
")",
".",
"find_type",
"(",
"name",
".",
"gsub",
"(",
"\"Vocab\"",
",",
"\"Enum\"",
")",
")",
"if",
"type",
"type",
".",
"enumeration_values",
"else",
"raise",
"\"Unable to find corresponding enumeration for vocabulary\"",
"end",
"end"
] |
Only valid for vocabularies
Returns a list of possible values for that vocabulary
|
[
"Only",
"valid",
"for",
"vocabularies",
"Returns",
"a",
"list",
"of",
"possible",
"values",
"for",
"that",
"vocabulary"
] |
2d551c6854d749eb330340e69f73baee1c4b52d3
|
https://github.com/johnwunder/stix_schema_spy/blob/2d551c6854d749eb330340e69f73baee1c4b52d3/lib/stix_schema_spy/models/complex_type.rb#L40-L48
|
9,523
|
moose-secret-agents/coach_assist
|
lib/coach/entity.rb
|
Coach.Entity.fetch
|
def fetch
assert_has_uri!
response = client.get clean_uri, query: { start: 0, size: 10000 }
update_attributes! filter_response_body(JSON.parse(response.body))
self
end
|
ruby
|
def fetch
assert_has_uri!
response = client.get clean_uri, query: { start: 0, size: 10000 }
update_attributes! filter_response_body(JSON.parse(response.body))
self
end
|
[
"def",
"fetch",
"assert_has_uri!",
"response",
"=",
"client",
".",
"get",
"clean_uri",
",",
"query",
":",
"{",
"start",
":",
"0",
",",
"size",
":",
"10000",
"}",
"update_attributes!",
"filter_response_body",
"(",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
")",
"self",
"end"
] |
Fetch an entity based on its uri. Each entity containing a valid uri will be retrievable through this method
|
[
"Fetch",
"an",
"entity",
"based",
"on",
"its",
"uri",
".",
"Each",
"entity",
"containing",
"a",
"valid",
"uri",
"will",
"be",
"retrievable",
"through",
"this",
"method"
] |
bc135cd3b54102993bb23c21db5723468bd77ce6
|
https://github.com/moose-secret-agents/coach_assist/blob/bc135cd3b54102993bb23c21db5723468bd77ce6/lib/coach/entity.rb#L13-L20
|
9,524
|
vjoel/funl
|
lib/funl/message.rb
|
Funl.Message.to_msgpack
|
def to_msgpack(pk = nil)
case pk
when MessagePack::Packer
pk.write_array_header(6)
pk.write @client_id
pk.write @local_tick
pk.write @global_tick
pk.write @delta
pk.write @tags
pk.write @blob
return pk
else # nil or IO
MessagePack.pack(self, pk)
end
end
|
ruby
|
def to_msgpack(pk = nil)
case pk
when MessagePack::Packer
pk.write_array_header(6)
pk.write @client_id
pk.write @local_tick
pk.write @global_tick
pk.write @delta
pk.write @tags
pk.write @blob
return pk
else # nil or IO
MessagePack.pack(self, pk)
end
end
|
[
"def",
"to_msgpack",
"(",
"pk",
"=",
"nil",
")",
"case",
"pk",
"when",
"MessagePack",
"::",
"Packer",
"pk",
".",
"write_array_header",
"(",
"6",
")",
"pk",
".",
"write",
"@client_id",
"pk",
".",
"write",
"@local_tick",
"pk",
".",
"write",
"@global_tick",
"pk",
".",
"write",
"@delta",
"pk",
".",
"write",
"@tags",
"pk",
".",
"write",
"@blob",
"return",
"pk",
"else",
"# nil or IO",
"MessagePack",
".",
"pack",
"(",
"self",
",",
"pk",
")",
"end",
"end"
] |
Call with Packer, nil, or IO. If +pk+ is nil, returns string. If +pk+ is
a Packer, returns the Packer, which will need to be flushed. If +pk+ is
IO, returns nil.
|
[
"Call",
"with",
"Packer",
"nil",
"or",
"IO",
".",
"If",
"+",
"pk",
"+",
"is",
"nil",
"returns",
"string",
".",
"If",
"+",
"pk",
"+",
"is",
"a",
"Packer",
"returns",
"the",
"Packer",
"which",
"will",
"need",
"to",
"be",
"flushed",
".",
"If",
"+",
"pk",
"+",
"is",
"IO",
"returns",
"nil",
"."
] |
3b05b89d0f9f029b31862e94311f52ff3491ab9c
|
https://github.com/vjoel/funl/blob/3b05b89d0f9f029b31862e94311f52ff3491ab9c/lib/funl/message.rb#L86-L101
|
9,525
|
christoph-buente/retentiongrid
|
lib/retentiongrid/resource.rb
|
Retentiongrid.Resource.attributes
|
def attributes
self.class::ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
value = self.send(attrib_name)
attribs[attrib_name] = value unless value.nil?
attribs
end
end
|
ruby
|
def attributes
self.class::ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
value = self.send(attrib_name)
attribs[attrib_name] = value unless value.nil?
attribs
end
end
|
[
"def",
"attributes",
"self",
".",
"class",
"::",
"ATTRIBUTES_NAMES",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"attribs",
",",
"attrib_name",
"|",
"value",
"=",
"self",
".",
"send",
"(",
"attrib_name",
")",
"attribs",
"[",
"attrib_name",
"]",
"=",
"value",
"unless",
"value",
".",
"nil?",
"attribs",
"end",
"end"
] |
Return all attributes as a hash
@return [Hash]
|
[
"Return",
"all",
"attributes",
"as",
"a",
"hash"
] |
601d256786dd2e2c42f7374b999cd4e195e0e848
|
https://github.com/christoph-buente/retentiongrid/blob/601d256786dd2e2c42f7374b999cd4e195e0e848/lib/retentiongrid/resource.rb#L28-L34
|
9,526
|
zdavatz/odba
|
lib/odba/persistable.rb
|
ODBA.Persistable.odba_cut_connection
|
def odba_cut_connection(remove_object)
odba_potentials.each { |name|
var = instance_variable_get(name)
if(var.eql?(remove_object))
instance_variable_set(name, nil)
end
}
end
|
ruby
|
def odba_cut_connection(remove_object)
odba_potentials.each { |name|
var = instance_variable_get(name)
if(var.eql?(remove_object))
instance_variable_set(name, nil)
end
}
end
|
[
"def",
"odba_cut_connection",
"(",
"remove_object",
")",
"odba_potentials",
".",
"each",
"{",
"|",
"name",
"|",
"var",
"=",
"instance_variable_get",
"(",
"name",
")",
"if",
"(",
"var",
".",
"eql?",
"(",
"remove_object",
")",
")",
"instance_variable_set",
"(",
"name",
",",
"nil",
")",
"end",
"}",
"end"
] |
Removes all connections to another persistable. This method is called
by the Cache server when _remove_object_ is deleted from the database
|
[
"Removes",
"all",
"connections",
"to",
"another",
"persistable",
".",
"This",
"method",
"is",
"called",
"by",
"the",
"Cache",
"server",
"when",
"_remove_object_",
"is",
"deleted",
"from",
"the",
"database"
] |
40a4f3a07abdc6d41d627338848ca8cb1dd52294
|
https://github.com/zdavatz/odba/blob/40a4f3a07abdc6d41d627338848ca8cb1dd52294/lib/odba/persistable.rb#L211-L218
|
9,527
|
zdavatz/odba
|
lib/odba/persistable.rb
|
ODBA.Persistable.odba_take_snapshot
|
def odba_take_snapshot
@odba_snapshot_level ||= 0
snapshot_level = @odba_snapshot_level.next
current_level = [self]
tree_level = 0
while(!current_level.empty?)
tree_level += 1
obj_count = 0
next_level = []
current_level.each { |item|
if(item.odba_unsaved?(snapshot_level))
obj_count += 1
next_level += item.odba_unsaved_neighbors(snapshot_level)
item.odba_snapshot(snapshot_level)
end
}
current_level = next_level #.uniq
end
end
|
ruby
|
def odba_take_snapshot
@odba_snapshot_level ||= 0
snapshot_level = @odba_snapshot_level.next
current_level = [self]
tree_level = 0
while(!current_level.empty?)
tree_level += 1
obj_count = 0
next_level = []
current_level.each { |item|
if(item.odba_unsaved?(snapshot_level))
obj_count += 1
next_level += item.odba_unsaved_neighbors(snapshot_level)
item.odba_snapshot(snapshot_level)
end
}
current_level = next_level #.uniq
end
end
|
[
"def",
"odba_take_snapshot",
"@odba_snapshot_level",
"||=",
"0",
"snapshot_level",
"=",
"@odba_snapshot_level",
".",
"next",
"current_level",
"=",
"[",
"self",
"]",
"tree_level",
"=",
"0",
"while",
"(",
"!",
"current_level",
".",
"empty?",
")",
"tree_level",
"+=",
"1",
"obj_count",
"=",
"0",
"next_level",
"=",
"[",
"]",
"current_level",
".",
"each",
"{",
"|",
"item",
"|",
"if",
"(",
"item",
".",
"odba_unsaved?",
"(",
"snapshot_level",
")",
")",
"obj_count",
"+=",
"1",
"next_level",
"+=",
"item",
".",
"odba_unsaved_neighbors",
"(",
"snapshot_level",
")",
"item",
".",
"odba_snapshot",
"(",
"snapshot_level",
")",
"end",
"}",
"current_level",
"=",
"next_level",
"#.uniq",
"end",
"end"
] |
Recursively stores all connected Persistables.
|
[
"Recursively",
"stores",
"all",
"connected",
"Persistables",
"."
] |
40a4f3a07abdc6d41d627338848ca8cb1dd52294
|
https://github.com/zdavatz/odba/blob/40a4f3a07abdc6d41d627338848ca8cb1dd52294/lib/odba/persistable.rb#L425-L443
|
9,528
|
noted/scholar
|
lib/scholar/citation.rb
|
Scholar.Citation.to_hash
|
def to_hash
hash = {}
instance_variables.each do |v|
hash[v.to_s[1..-1].to_sym] = instance_variable_get(v)
end
hash
end
|
ruby
|
def to_hash
hash = {}
instance_variables.each do |v|
hash[v.to_s[1..-1].to_sym] = instance_variable_get(v)
end
hash
end
|
[
"def",
"to_hash",
"hash",
"=",
"{",
"}",
"instance_variables",
".",
"each",
"do",
"|",
"v",
"|",
"hash",
"[",
"v",
".",
"to_s",
"[",
"1",
"..",
"-",
"1",
"]",
".",
"to_sym",
"]",
"=",
"instance_variable_get",
"(",
"v",
")",
"end",
"hash",
"end"
] |
Creates a new Citation from the given attributes.
==== Attributes
* +options+ - The attributes of the Citation.
==== Options
* +:type+ - Not optional. The type of source you are citing.
* +:contributors+ - An array of hashes of contributors.
==== Examples
citation = Scholar::Citation.new({
:type => :book,
:title => "Foobar",
:contributors => [
{
:role => :author,
:first => "John",
:last => "Sample"
}
]
})
Obviously, you'd include more than that, but you need to see the
specific sources for more documentation.
Returns the Citation object in Hash form.
|
[
"Creates",
"a",
"new",
"Citation",
"from",
"the",
"given",
"attributes",
"."
] |
2bfface9d90307d7d3cecfa756f921087407d394
|
https://github.com/noted/scholar/blob/2bfface9d90307d7d3cecfa756f921087407d394/lib/scholar/citation.rb#L71-L79
|
9,529
|
aapis/notifaction
|
lib/notifaction/helpers.rb
|
Notifaction.Helpers.deprecation_notice
|
def deprecation_notice(version, config = {})
handler = Notifaction::Type::Terminal.new
handler.warning(
"Deprecated as of #{version}, current #{Notifaction::VERSION}",
config
)
handler.quit_soft
end
|
ruby
|
def deprecation_notice(version, config = {})
handler = Notifaction::Type::Terminal.new
handler.warning(
"Deprecated as of #{version}, current #{Notifaction::VERSION}",
config
)
handler.quit_soft
end
|
[
"def",
"deprecation_notice",
"(",
"version",
",",
"config",
"=",
"{",
"}",
")",
"handler",
"=",
"Notifaction",
"::",
"Type",
"::",
"Terminal",
".",
"new",
"handler",
".",
"warning",
"(",
"\"Deprecated as of #{version}, current #{Notifaction::VERSION}\"",
",",
"config",
")",
"handler",
".",
"quit_soft",
"end"
] |
Alert the user that the method they've called is not supported
@since 0.4.1
|
[
"Alert",
"the",
"user",
"that",
"the",
"method",
"they",
"ve",
"called",
"is",
"not",
"supported"
] |
dbad4c2888a1a59f2a3745d1c1e55c923e0d2039
|
https://github.com/aapis/notifaction/blob/dbad4c2888a1a59f2a3745d1c1e55c923e0d2039/lib/notifaction/helpers.rb#L5-L12
|
9,530
|
donnoman/mysql2_model
|
lib/mysql2_model/composer.rb
|
Mysql2Model.Composer.compose_sql
|
def compose_sql(*statement)
raise PreparedStatementInvalid, "Statement is blank!" if statement.blank?
if statement.is_a?(Array)
if statement.size == 1 #strip the outer array
compose_sql_array(statement.first)
else
compose_sql_array(statement)
end
else
statement
end
end
|
ruby
|
def compose_sql(*statement)
raise PreparedStatementInvalid, "Statement is blank!" if statement.blank?
if statement.is_a?(Array)
if statement.size == 1 #strip the outer array
compose_sql_array(statement.first)
else
compose_sql_array(statement)
end
else
statement
end
end
|
[
"def",
"compose_sql",
"(",
"*",
"statement",
")",
"raise",
"PreparedStatementInvalid",
",",
"\"Statement is blank!\"",
"if",
"statement",
".",
"blank?",
"if",
"statement",
".",
"is_a?",
"(",
"Array",
")",
"if",
"statement",
".",
"size",
"==",
"1",
"#strip the outer array",
"compose_sql_array",
"(",
"statement",
".",
"first",
")",
"else",
"compose_sql_array",
"(",
"statement",
")",
"end",
"else",
"statement",
"end",
"end"
] |
Accepts multiple arguments, an array, or string of SQL and composes them
@example String
"name='foo''bar' and group_id='4'" #=> "name='foo''bar' and group_id='4'"
@example Array
["name='%s' and group_id='%s'", "foo'bar", 4] #=> "name='foo''bar' and group_id='4'"
@param [Array,String]
|
[
"Accepts",
"multiple",
"arguments",
"an",
"array",
"or",
"string",
"of",
"SQL",
"and",
"composes",
"them"
] |
700a2c6a09b0eb1c0ea318d1c0b6652961e3d223
|
https://github.com/donnoman/mysql2_model/blob/700a2c6a09b0eb1c0ea318d1c0b6652961e3d223/lib/mysql2_model/composer.rb#L25-L36
|
9,531
|
donnoman/mysql2_model
|
lib/mysql2_model/composer.rb
|
Mysql2Model.Composer.compose_sql_array
|
def compose_sql_array(ary)
statement, *values = ary
if values.first.is_a?(Hash) and statement =~ /:\w+/
replace_named_bind_variables(statement, values.first)
elsif statement.include?('?')
replace_bind_variables(statement, values)
else
statement % values.collect { |value| client.escape(value.to_s) }
end
end
|
ruby
|
def compose_sql_array(ary)
statement, *values = ary
if values.first.is_a?(Hash) and statement =~ /:\w+/
replace_named_bind_variables(statement, values.first)
elsif statement.include?('?')
replace_bind_variables(statement, values)
else
statement % values.collect { |value| client.escape(value.to_s) }
end
end
|
[
"def",
"compose_sql_array",
"(",
"ary",
")",
"statement",
",",
"*",
"values",
"=",
"ary",
"if",
"values",
".",
"first",
".",
"is_a?",
"(",
"Hash",
")",
"and",
"statement",
"=~",
"/",
"\\w",
"/",
"replace_named_bind_variables",
"(",
"statement",
",",
"values",
".",
"first",
")",
"elsif",
"statement",
".",
"include?",
"(",
"'?'",
")",
"replace_bind_variables",
"(",
"statement",
",",
"values",
")",
"else",
"statement",
"%",
"values",
".",
"collect",
"{",
"|",
"value",
"|",
"client",
".",
"escape",
"(",
"value",
".",
"to_s",
")",
"}",
"end",
"end"
] |
Accepts an array of conditions. The array has each value
sanitized and interpolated into the SQL statement.
@param [Array] ary
@example Array
["name='%s' and group_id='%s'", "foo'bar", 4] #=> "name='foo''bar' and group_id='4'"
@private
|
[
"Accepts",
"an",
"array",
"of",
"conditions",
".",
"The",
"array",
"has",
"each",
"value",
"sanitized",
"and",
"interpolated",
"into",
"the",
"SQL",
"statement",
"."
] |
700a2c6a09b0eb1c0ea318d1c0b6652961e3d223
|
https://github.com/donnoman/mysql2_model/blob/700a2c6a09b0eb1c0ea318d1c0b6652961e3d223/lib/mysql2_model/composer.rb#L44-L53
|
9,532
|
ideonetwork/lato-blog
|
app/models/lato_blog/tag/serializer_helpers.rb
|
LatoBlog.Tag::SerializerHelpers.serialize
|
def serialize
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
# add tag parent informations
serialized[:other_informations] = serialize_other_informations
# return serialized post
serialized
end
|
ruby
|
def serialize
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
# add tag parent informations
serialized[:other_informations] = serialize_other_informations
# return serialized post
serialized
end
|
[
"def",
"serialize",
"serialized",
"=",
"{",
"}",
"# set basic info",
"serialized",
"[",
":id",
"]",
"=",
"id",
"serialized",
"[",
":title",
"]",
"=",
"title",
"serialized",
"[",
":meta_language",
"]",
"=",
"meta_language",
"serialized",
"[",
":meta_permalink",
"]",
"=",
"meta_permalink",
"# add tag parent informations",
"serialized",
"[",
":other_informations",
"]",
"=",
"serialize_other_informations",
"# return serialized post",
"serialized",
"end"
] |
This function serializes a complete version of the tag.
|
[
"This",
"function",
"serializes",
"a",
"complete",
"version",
"of",
"the",
"tag",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/tag/serializer_helpers.rb#L5-L19
|
9,533
|
jarrett/ichiban
|
lib/ichiban/deleter.rb
|
Ichiban.Deleter.delete_dest
|
def delete_dest(path)
file = Ichiban::ProjectFile.from_abs(path)
# file will be nil if the path doesn't map to a known subclass of IchibanFile. Furthermore,
# even if file is not nil, it may be a kind of IchibanFile that does not have a destination.
if file and file.has_dest?
dest = file.dest
else
dest = nil
end
if dest and File.exist?(dest)
FileUtils.rm(dest)
end
# Log the deletion(s)
Ichiban.logger.deletion(path, dest)
end
|
ruby
|
def delete_dest(path)
file = Ichiban::ProjectFile.from_abs(path)
# file will be nil if the path doesn't map to a known subclass of IchibanFile. Furthermore,
# even if file is not nil, it may be a kind of IchibanFile that does not have a destination.
if file and file.has_dest?
dest = file.dest
else
dest = nil
end
if dest and File.exist?(dest)
FileUtils.rm(dest)
end
# Log the deletion(s)
Ichiban.logger.deletion(path, dest)
end
|
[
"def",
"delete_dest",
"(",
"path",
")",
"file",
"=",
"Ichiban",
"::",
"ProjectFile",
".",
"from_abs",
"(",
"path",
")",
"# file will be nil if the path doesn't map to a known subclass of IchibanFile. Furthermore,",
"# even if file is not nil, it may be a kind of IchibanFile that does not have a destination.",
"if",
"file",
"and",
"file",
".",
"has_dest?",
"dest",
"=",
"file",
".",
"dest",
"else",
"dest",
"=",
"nil",
"end",
"if",
"dest",
"and",
"File",
".",
"exist?",
"(",
"dest",
")",
"FileUtils",
".",
"rm",
"(",
"dest",
")",
"end",
"# Log the deletion(s)",
"Ichiban",
".",
"logger",
".",
"deletion",
"(",
"path",
",",
"dest",
")",
"end"
] |
Deletes a file's associated destination file, if any.
|
[
"Deletes",
"a",
"file",
"s",
"associated",
"destination",
"file",
"if",
"any",
"."
] |
310f96b0981ea19bf01246995f3732c986915d5b
|
https://github.com/jarrett/ichiban/blob/310f96b0981ea19bf01246995f3732c986915d5b/lib/ichiban/deleter.rb#L4-L19
|
9,534
|
mje113/couchbase-jruby-model
|
lib/couchbase/model.rb
|
Couchbase.Model.delete
|
def delete(options = {})
raise Couchbase::Error::MissingId, 'missing id attribute' unless @id
model.bucket.delete(@id, options)
@id = nil
@meta = nil
self
end
|
ruby
|
def delete(options = {})
raise Couchbase::Error::MissingId, 'missing id attribute' unless @id
model.bucket.delete(@id, options)
@id = nil
@meta = nil
self
end
|
[
"def",
"delete",
"(",
"options",
"=",
"{",
"}",
")",
"raise",
"Couchbase",
"::",
"Error",
"::",
"MissingId",
",",
"'missing id attribute'",
"unless",
"@id",
"model",
".",
"bucket",
".",
"delete",
"(",
"@id",
",",
"options",
")",
"@id",
"=",
"nil",
"@meta",
"=",
"nil",
"self",
"end"
] |
Delete this object from the bucket
@since 0.0.1
@note This method will reset +id+ attribute
@param [Hash] options options for operation, see
{{Couchbase::Bucket#delete}}
@return [Couchbase::Model] Returns a reference of itself.
@example Delete the Post model
p = Post.find('hello-world')
p.delete
|
[
"Delete",
"this",
"object",
"from",
"the",
"bucket"
] |
e801b73e6e394297e3a92ff51b92af628ae57a27
|
https://github.com/mje113/couchbase-jruby-model/blob/e801b73e6e394297e3a92ff51b92af628ae57a27/lib/couchbase/model.rb#L616-L622
|
9,535
|
mje113/couchbase-jruby-model
|
lib/couchbase/model.rb
|
Couchbase.Model.reload
|
def reload
raise Couchbase::Error::MissingId, 'missing id attribute' unless @id
pristine = model.find(@id)
update_attributes(pristine.attributes)
@meta[:cas] = pristine.meta[:cas]
self
end
|
ruby
|
def reload
raise Couchbase::Error::MissingId, 'missing id attribute' unless @id
pristine = model.find(@id)
update_attributes(pristine.attributes)
@meta[:cas] = pristine.meta[:cas]
self
end
|
[
"def",
"reload",
"raise",
"Couchbase",
"::",
"Error",
"::",
"MissingId",
",",
"'missing id attribute'",
"unless",
"@id",
"pristine",
"=",
"model",
".",
"find",
"(",
"@id",
")",
"update_attributes",
"(",
"pristine",
".",
"attributes",
")",
"@meta",
"[",
":cas",
"]",
"=",
"pristine",
".",
"meta",
"[",
":cas",
"]",
"self",
"end"
] |
Reload all the model attributes from the bucket
@since 0.0.1
@return [Model] the latest model state
@raise [Error::MissingId] for records without +id+
attribute
|
[
"Reload",
"all",
"the",
"model",
"attributes",
"from",
"the",
"bucket"
] |
e801b73e6e394297e3a92ff51b92af628ae57a27
|
https://github.com/mje113/couchbase-jruby-model/blob/e801b73e6e394297e3a92ff51b92af628ae57a27/lib/couchbase/model.rb#L734-L740
|
9,536
|
jimcar/orchestrate-api
|
lib/orchestrate/api/request.rb
|
Orchestrate::API.Request.perform
|
def perform
uri = URI(url)
response = Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => uri.scheme == 'https' ) { |http|
Orchestrate.config.logger.debug "Performing #{method.to_s.upcase} request to \"#{url}\""
http.request(request(uri))
}
Response.new(response)
end
|
ruby
|
def perform
uri = URI(url)
response = Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => uri.scheme == 'https' ) { |http|
Orchestrate.config.logger.debug "Performing #{method.to_s.upcase} request to \"#{url}\""
http.request(request(uri))
}
Response.new(response)
end
|
[
"def",
"perform",
"uri",
"=",
"URI",
"(",
"url",
")",
"response",
"=",
"Net",
"::",
"HTTP",
".",
"start",
"(",
"uri",
".",
"hostname",
",",
"uri",
".",
"port",
",",
":use_ssl",
"=>",
"uri",
".",
"scheme",
"==",
"'https'",
")",
"{",
"|",
"http",
"|",
"Orchestrate",
".",
"config",
".",
"logger",
".",
"debug",
"\"Performing #{method.to_s.upcase} request to \\\"#{url}\\\"\"",
"http",
".",
"request",
"(",
"request",
"(",
"uri",
")",
")",
"}",
"Response",
".",
"new",
"(",
"response",
")",
"end"
] |
Sets the universal attributes from the params; any additional
attributes are set from the block.
Sends the HTTP request and returns a Response object.
|
[
"Sets",
"the",
"universal",
"attributes",
"from",
"the",
"params",
";",
"any",
"additional",
"attributes",
"are",
"set",
"from",
"the",
"block",
"."
] |
8931c41d69b9e32096db7615d0b252b971a5857d
|
https://github.com/jimcar/orchestrate-api/blob/8931c41d69b9e32096db7615d0b252b971a5857d/lib/orchestrate/api/request.rb#L32-L40
|
9,537
|
octoai/gem-octocore-mongo
|
lib/octocore-mongo/trendable.rb
|
Octo.Trendable.aggregate_sum
|
def aggregate_sum(aggr)
sum = {}
aggr.each do |ts, counterVals|
sum[ts] = {} unless sum.has_key?ts
counterVals.each do |obj, count|
if obj.respond_to?(:enterprise_id)
eid = obj.public_send(:enterprise_id).to_s
sum[ts][eid] = sum[ts].fetch(eid, 0) + count
end
end
end
sum
end
|
ruby
|
def aggregate_sum(aggr)
sum = {}
aggr.each do |ts, counterVals|
sum[ts] = {} unless sum.has_key?ts
counterVals.each do |obj, count|
if obj.respond_to?(:enterprise_id)
eid = obj.public_send(:enterprise_id).to_s
sum[ts][eid] = sum[ts].fetch(eid, 0) + count
end
end
end
sum
end
|
[
"def",
"aggregate_sum",
"(",
"aggr",
")",
"sum",
"=",
"{",
"}",
"aggr",
".",
"each",
"do",
"|",
"ts",
",",
"counterVals",
"|",
"sum",
"[",
"ts",
"]",
"=",
"{",
"}",
"unless",
"sum",
".",
"has_key?",
"ts",
"counterVals",
".",
"each",
"do",
"|",
"obj",
",",
"count",
"|",
"if",
"obj",
".",
"respond_to?",
"(",
":enterprise_id",
")",
"eid",
"=",
"obj",
".",
"public_send",
"(",
":enterprise_id",
")",
".",
"to_s",
"sum",
"[",
"ts",
"]",
"[",
"eid",
"]",
"=",
"sum",
"[",
"ts",
"]",
".",
"fetch",
"(",
"eid",
",",
"0",
")",
"+",
"count",
"end",
"end",
"end",
"sum",
"end"
] |
Aggregates to find the sum of all counters for an enterprise
at a time
@param [Hash] aggr The aggregated hash
@return [Hash] The summed up hash
|
[
"Aggregates",
"to",
"find",
"the",
"sum",
"of",
"all",
"counters",
"for",
"an",
"enterprise",
"at",
"a",
"time"
] |
bf7fa833fd7e08947697d0341ab5e80e89c8d05a
|
https://github.com/octoai/gem-octocore-mongo/blob/bf7fa833fd7e08947697d0341ab5e80e89c8d05a/lib/octocore-mongo/trendable.rb#L62-L74
|
9,538
|
pixeltrix/sortifiable
|
lib/sortifiable.rb
|
Sortifiable.InstanceMethods.add_to_list
|
def add_to_list
if in_list?
move_to_bottom
else
list_class.transaction do
ids = lock_list!
last_position = ids.size
if persisted?
update_position last_position + 1
else
set_position last_position + 1
end
end
end
end
|
ruby
|
def add_to_list
if in_list?
move_to_bottom
else
list_class.transaction do
ids = lock_list!
last_position = ids.size
if persisted?
update_position last_position + 1
else
set_position last_position + 1
end
end
end
end
|
[
"def",
"add_to_list",
"if",
"in_list?",
"move_to_bottom",
"else",
"list_class",
".",
"transaction",
"do",
"ids",
"=",
"lock_list!",
"last_position",
"=",
"ids",
".",
"size",
"if",
"persisted?",
"update_position",
"last_position",
"+",
"1",
"else",
"set_position",
"last_position",
"+",
"1",
"end",
"end",
"end",
"end"
] |
Add the item to the end of the list
|
[
"Add",
"the",
"item",
"to",
"the",
"end",
"of",
"the",
"list"
] |
fa54c36e4e6a5500247e8823d77401acc8014ba7
|
https://github.com/pixeltrix/sortifiable/blob/fa54c36e4e6a5500247e8823d77401acc8014ba7/lib/sortifiable.rb#L104-L118
|
9,539
|
ideonetwork/lato-blog
|
app/helpers/lato_blog/fields_helper.rb
|
LatoBlog.FieldsHelper.render_post_fields
|
def render_post_fields(post)
post_fields = post.post_fields.visibles.roots.order('position ASC')
render 'lato_blog/back/posts/shared/fields', post_fields: post_fields
end
|
ruby
|
def render_post_fields(post)
post_fields = post.post_fields.visibles.roots.order('position ASC')
render 'lato_blog/back/posts/shared/fields', post_fields: post_fields
end
|
[
"def",
"render_post_fields",
"(",
"post",
")",
"post_fields",
"=",
"post",
".",
"post_fields",
".",
"visibles",
".",
"roots",
".",
"order",
"(",
"'position ASC'",
")",
"render",
"'lato_blog/back/posts/shared/fields'",
",",
"post_fields",
":",
"post_fields",
"end"
] |
This function render the partial used to render post fields for a
specific post.
|
[
"This",
"function",
"render",
"the",
"partial",
"used",
"to",
"render",
"post",
"fields",
"for",
"a",
"specific",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/helpers/lato_blog/fields_helper.rb#L6-L9
|
9,540
|
ideonetwork/lato-blog
|
app/helpers/lato_blog/fields_helper.rb
|
LatoBlog.FieldsHelper.render_post_field
|
def render_post_field(post_field, key_parent = 'fields')
# define key
key = "#{key_parent}[#{post_field.id}]"
# render correct field
case post_field.typology
when 'text'
render_post_field_text(post_field, key)
when 'textarea'
render_post_field_textarea(post_field, key)
when 'datetime'
render_post_field_datetime(post_field, key)
when 'editor'
render_post_field_editor(post_field, key)
when 'geolocalization'
render_post_field_geolocalization(post_field, key)
when 'image'
render_post_field_image(post_field, key)
when 'gallery'
render_post_field_gallery(post_field, key)
when 'youtube'
render_post_field_youtube(post_field, key)
when 'composed'
render_post_field_composed(post_field, key)
when 'relay'
render_post_field_relay(post_field, key)
end
end
|
ruby
|
def render_post_field(post_field, key_parent = 'fields')
# define key
key = "#{key_parent}[#{post_field.id}]"
# render correct field
case post_field.typology
when 'text'
render_post_field_text(post_field, key)
when 'textarea'
render_post_field_textarea(post_field, key)
when 'datetime'
render_post_field_datetime(post_field, key)
when 'editor'
render_post_field_editor(post_field, key)
when 'geolocalization'
render_post_field_geolocalization(post_field, key)
when 'image'
render_post_field_image(post_field, key)
when 'gallery'
render_post_field_gallery(post_field, key)
when 'youtube'
render_post_field_youtube(post_field, key)
when 'composed'
render_post_field_composed(post_field, key)
when 'relay'
render_post_field_relay(post_field, key)
end
end
|
[
"def",
"render_post_field",
"(",
"post_field",
",",
"key_parent",
"=",
"'fields'",
")",
"# define key",
"key",
"=",
"\"#{key_parent}[#{post_field.id}]\"",
"# render correct field",
"case",
"post_field",
".",
"typology",
"when",
"'text'",
"render_post_field_text",
"(",
"post_field",
",",
"key",
")",
"when",
"'textarea'",
"render_post_field_textarea",
"(",
"post_field",
",",
"key",
")",
"when",
"'datetime'",
"render_post_field_datetime",
"(",
"post_field",
",",
"key",
")",
"when",
"'editor'",
"render_post_field_editor",
"(",
"post_field",
",",
"key",
")",
"when",
"'geolocalization'",
"render_post_field_geolocalization",
"(",
"post_field",
",",
"key",
")",
"when",
"'image'",
"render_post_field_image",
"(",
"post_field",
",",
"key",
")",
"when",
"'gallery'",
"render_post_field_gallery",
"(",
"post_field",
",",
"key",
")",
"when",
"'youtube'",
"render_post_field_youtube",
"(",
"post_field",
",",
"key",
")",
"when",
"'composed'",
"render_post_field_composed",
"(",
"post_field",
",",
"key",
")",
"when",
"'relay'",
"render_post_field_relay",
"(",
"post_field",
",",
"key",
")",
"end",
"end"
] |
This function render a single post field.
|
[
"This",
"function",
"render",
"a",
"single",
"post",
"field",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/helpers/lato_blog/fields_helper.rb#L12-L38
|
9,541
|
devrieda/stylesheet
|
spec/stubs/fake_request.rb
|
Stylesheet.FakeRequest.get
|
def get(url)
begin
uri = URI.parse(url.strip)
rescue URI::InvalidURIError
uri = URI.parse(URI.escape(url.strip))
end
# simple hack to read in fixtures instead of url for tests
fixture = "#{File.dirname(__FILE__)}/../fixtures#{uri.path}"
File.read(fixture) if File.exist?(fixture)
end
|
ruby
|
def get(url)
begin
uri = URI.parse(url.strip)
rescue URI::InvalidURIError
uri = URI.parse(URI.escape(url.strip))
end
# simple hack to read in fixtures instead of url for tests
fixture = "#{File.dirname(__FILE__)}/../fixtures#{uri.path}"
File.read(fixture) if File.exist?(fixture)
end
|
[
"def",
"get",
"(",
"url",
")",
"begin",
"uri",
"=",
"URI",
".",
"parse",
"(",
"url",
".",
"strip",
")",
"rescue",
"URI",
"::",
"InvalidURIError",
"uri",
"=",
"URI",
".",
"parse",
"(",
"URI",
".",
"escape",
"(",
"url",
".",
"strip",
")",
")",
"end",
"# simple hack to read in fixtures instead of url for tests",
"fixture",
"=",
"\"#{File.dirname(__FILE__)}/../fixtures#{uri.path}\"",
"File",
".",
"read",
"(",
"fixture",
")",
"if",
"File",
".",
"exist?",
"(",
"fixture",
")",
"end"
] |
Read in fixture file instead of url
|
[
"Read",
"in",
"fixture",
"file",
"instead",
"of",
"url"
] |
d1334eb734ac2023afc6ba4df07bf2627268de11
|
https://github.com/devrieda/stylesheet/blob/d1334eb734ac2023afc6ba4df07bf2627268de11/spec/stubs/fake_request.rb#L7-L17
|
9,542
|
sanichi/icu_tournament
|
lib/icu_tournament/player.rb
|
ICU.Player.renumber
|
def renumber(map)
raise "player number #{@num} not found in renumbering hash" unless map[@num]
self.num = map[@num]
@results.each{ |r| r.renumber(map) }
self
end
|
ruby
|
def renumber(map)
raise "player number #{@num} not found in renumbering hash" unless map[@num]
self.num = map[@num]
@results.each{ |r| r.renumber(map) }
self
end
|
[
"def",
"renumber",
"(",
"map",
")",
"raise",
"\"player number #{@num} not found in renumbering hash\"",
"unless",
"map",
"[",
"@num",
"]",
"self",
".",
"num",
"=",
"map",
"[",
"@num",
"]",
"@results",
".",
"each",
"{",
"|",
"r",
"|",
"r",
".",
"renumber",
"(",
"map",
")",
"}",
"self",
"end"
] |
Renumber the player according to the supplied hash. Return self.
|
[
"Renumber",
"the",
"player",
"according",
"to",
"the",
"supplied",
"hash",
".",
"Return",
"self",
"."
] |
badd2940189feaeb9f0edb4b4e07ff6b2548bd3d
|
https://github.com/sanichi/icu_tournament/blob/badd2940189feaeb9f0edb4b4e07ff6b2548bd3d/lib/icu_tournament/player.rb#L203-L208
|
9,543
|
sanichi/icu_tournament
|
lib/icu_tournament/player.rb
|
ICU.Player.merge
|
def merge(other)
raise "cannot merge two players that are not equal" unless self == other
[:id, :fide_id, :rating, :fide_rating, :title, :fed, :gender].each do |m|
self.send("#{m}=", other.send(m)) unless self.send(m)
end
end
|
ruby
|
def merge(other)
raise "cannot merge two players that are not equal" unless self == other
[:id, :fide_id, :rating, :fide_rating, :title, :fed, :gender].each do |m|
self.send("#{m}=", other.send(m)) unless self.send(m)
end
end
|
[
"def",
"merge",
"(",
"other",
")",
"raise",
"\"cannot merge two players that are not equal\"",
"unless",
"self",
"==",
"other",
"[",
":id",
",",
":fide_id",
",",
":rating",
",",
":fide_rating",
",",
":title",
",",
":fed",
",",
":gender",
"]",
".",
"each",
"do",
"|",
"m",
"|",
"self",
".",
"send",
"(",
"\"#{m}=\"",
",",
"other",
".",
"send",
"(",
"m",
")",
")",
"unless",
"self",
".",
"send",
"(",
"m",
")",
"end",
"end"
] |
Loose equality test. Passes if the names match and the federations are not different.
Strict equality test. Passes if the playes are loosly equal and also if their IDs, rating, gender and title are not different.
Merge in some of the details of another player.
|
[
"Loose",
"equality",
"test",
".",
"Passes",
"if",
"the",
"names",
"match",
"and",
"the",
"federations",
"are",
"not",
"different",
".",
"Strict",
"equality",
"test",
".",
"Passes",
"if",
"the",
"playes",
"are",
"loosly",
"equal",
"and",
"also",
"if",
"their",
"IDs",
"rating",
"gender",
"and",
"title",
"are",
"not",
"different",
".",
"Merge",
"in",
"some",
"of",
"the",
"details",
"of",
"another",
"player",
"."
] |
badd2940189feaeb9f0edb4b4e07ff6b2548bd3d
|
https://github.com/sanichi/icu_tournament/blob/badd2940189feaeb9f0edb4b4e07ff6b2548bd3d/lib/icu_tournament/player.rb#L231-L236
|
9,544
|
bilus/kawaii
|
lib/kawaii/server_methods.rb
|
Kawaii.ServerMethods.start!
|
def start!(port) # @todo Support other handlers http://www.rubydoc.info/github/rack/rack/Rack/Handler
Rack::Handler.get(WEBRICK).run(self, Port: port) do |s|
@server = s
at_exit { stop! }
[:INT, :TERM].each do |signal|
old = trap(signal) do
stop!
old.call if old.respond_to?(:call)
end
end
end
end
|
ruby
|
def start!(port) # @todo Support other handlers http://www.rubydoc.info/github/rack/rack/Rack/Handler
Rack::Handler.get(WEBRICK).run(self, Port: port) do |s|
@server = s
at_exit { stop! }
[:INT, :TERM].each do |signal|
old = trap(signal) do
stop!
old.call if old.respond_to?(:call)
end
end
end
end
|
[
"def",
"start!",
"(",
"port",
")",
"# @todo Support other handlers http://www.rubydoc.info/github/rack/rack/Rack/Handler",
"Rack",
"::",
"Handler",
".",
"get",
"(",
"WEBRICK",
")",
".",
"run",
"(",
"self",
",",
"Port",
":",
"port",
")",
"do",
"|",
"s",
"|",
"@server",
"=",
"s",
"at_exit",
"{",
"stop!",
"}",
"[",
":INT",
",",
":TERM",
"]",
".",
"each",
"do",
"|",
"signal",
"|",
"old",
"=",
"trap",
"(",
"signal",
")",
"do",
"stop!",
"old",
".",
"call",
"if",
"old",
".",
"respond_to?",
"(",
":call",
")",
"end",
"end",
"end",
"end"
] |
Starts serving the app.
@param port [Fixnum] port number to bind to
|
[
"Starts",
"serving",
"the",
"app",
"."
] |
a72be28e713b0ed2b2cfc180a38bebe0c968b0b3
|
https://github.com/bilus/kawaii/blob/a72be28e713b0ed2b2cfc180a38bebe0c968b0b3/lib/kawaii/server_methods.rb#L10-L21
|
9,545
|
rgeyer/rs-mule
|
lib/rs-mule/run_executable.rb
|
RsMule.RunExecutable.run_executable
|
def run_executable(tags, executable, options={})
options = {
:executable_type => "auto",
:right_script_revision => "latest",
:tag_match_strategy => "all",
:inputs => {},
:update_inputs => []
}.merge(options)
execute_params = {}
tags = [tags] unless tags.is_a?(Array)
options[:update_inputs] = [options[:update_inputs]] unless options[:update_inputs].is_a?(Array)
case options[:executable_type]
when "right_script_href"
execute_params[:right_script_href] = executable
when "right_script_name"
scripts = find_right_script_lineage_by_name(executable)
execute_params[:right_script_href] = right_script_revision_from_lineage(scripts, options[:right_script_revision]).href
when "recipe_name"
execute_params[:recipe_name] = executable
when "auto"
is_recipe = executable =~ /.*::.*/
is_href = executable =~ /^\/api\/right_scripts\/[a-zA-Z0-9]*/
if is_recipe
execute_params[:recipe_name] = executable
else
if is_href
execute_params[:right_script_href] = executable
else
scripts = find_right_script_lineage_by_name(executable)
execute_params[:right_script_href] = right_script_revision_from_lineage(scripts, options[:right_script_revision]).href
end
end
else
raise ArgumentError.new("Unknown executable_type (#{options[:executable_type]})")
end
if options[:inputs].length > 0
execute_params[:inputs] = options[:inputs]
end
resources_by_tag = @right_api_client.tags.by_tag(
:resource_type => "instances",
:tags => tags,
:match_all => options[:tag_match_strategy] == "all" ? "true" : "false"
)
resources_by_tag.each do |res|
instance = @right_api_client.resource(res.links.first["href"])
instance.run_executable(execute_params)
options[:update_inputs].each do |update_type|
update_inputs(instance, options[:inputs], update_type)
end
end
end
|
ruby
|
def run_executable(tags, executable, options={})
options = {
:executable_type => "auto",
:right_script_revision => "latest",
:tag_match_strategy => "all",
:inputs => {},
:update_inputs => []
}.merge(options)
execute_params = {}
tags = [tags] unless tags.is_a?(Array)
options[:update_inputs] = [options[:update_inputs]] unless options[:update_inputs].is_a?(Array)
case options[:executable_type]
when "right_script_href"
execute_params[:right_script_href] = executable
when "right_script_name"
scripts = find_right_script_lineage_by_name(executable)
execute_params[:right_script_href] = right_script_revision_from_lineage(scripts, options[:right_script_revision]).href
when "recipe_name"
execute_params[:recipe_name] = executable
when "auto"
is_recipe = executable =~ /.*::.*/
is_href = executable =~ /^\/api\/right_scripts\/[a-zA-Z0-9]*/
if is_recipe
execute_params[:recipe_name] = executable
else
if is_href
execute_params[:right_script_href] = executable
else
scripts = find_right_script_lineage_by_name(executable)
execute_params[:right_script_href] = right_script_revision_from_lineage(scripts, options[:right_script_revision]).href
end
end
else
raise ArgumentError.new("Unknown executable_type (#{options[:executable_type]})")
end
if options[:inputs].length > 0
execute_params[:inputs] = options[:inputs]
end
resources_by_tag = @right_api_client.tags.by_tag(
:resource_type => "instances",
:tags => tags,
:match_all => options[:tag_match_strategy] == "all" ? "true" : "false"
)
resources_by_tag.each do |res|
instance = @right_api_client.resource(res.links.first["href"])
instance.run_executable(execute_params)
options[:update_inputs].each do |update_type|
update_inputs(instance, options[:inputs], update_type)
end
end
end
|
[
"def",
"run_executable",
"(",
"tags",
",",
"executable",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
":executable_type",
"=>",
"\"auto\"",
",",
":right_script_revision",
"=>",
"\"latest\"",
",",
":tag_match_strategy",
"=>",
"\"all\"",
",",
":inputs",
"=>",
"{",
"}",
",",
":update_inputs",
"=>",
"[",
"]",
"}",
".",
"merge",
"(",
"options",
")",
"execute_params",
"=",
"{",
"}",
"tags",
"=",
"[",
"tags",
"]",
"unless",
"tags",
".",
"is_a?",
"(",
"Array",
")",
"options",
"[",
":update_inputs",
"]",
"=",
"[",
"options",
"[",
":update_inputs",
"]",
"]",
"unless",
"options",
"[",
":update_inputs",
"]",
".",
"is_a?",
"(",
"Array",
")",
"case",
"options",
"[",
":executable_type",
"]",
"when",
"\"right_script_href\"",
"execute_params",
"[",
":right_script_href",
"]",
"=",
"executable",
"when",
"\"right_script_name\"",
"scripts",
"=",
"find_right_script_lineage_by_name",
"(",
"executable",
")",
"execute_params",
"[",
":right_script_href",
"]",
"=",
"right_script_revision_from_lineage",
"(",
"scripts",
",",
"options",
"[",
":right_script_revision",
"]",
")",
".",
"href",
"when",
"\"recipe_name\"",
"execute_params",
"[",
":recipe_name",
"]",
"=",
"executable",
"when",
"\"auto\"",
"is_recipe",
"=",
"executable",
"=~",
"/",
"/",
"is_href",
"=",
"executable",
"=~",
"/",
"\\/",
"\\/",
"\\/",
"/",
"if",
"is_recipe",
"execute_params",
"[",
":recipe_name",
"]",
"=",
"executable",
"else",
"if",
"is_href",
"execute_params",
"[",
":right_script_href",
"]",
"=",
"executable",
"else",
"scripts",
"=",
"find_right_script_lineage_by_name",
"(",
"executable",
")",
"execute_params",
"[",
":right_script_href",
"]",
"=",
"right_script_revision_from_lineage",
"(",
"scripts",
",",
"options",
"[",
":right_script_revision",
"]",
")",
".",
"href",
"end",
"end",
"else",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Unknown executable_type (#{options[:executable_type]})\"",
")",
"end",
"if",
"options",
"[",
":inputs",
"]",
".",
"length",
">",
"0",
"execute_params",
"[",
":inputs",
"]",
"=",
"options",
"[",
":inputs",
"]",
"end",
"resources_by_tag",
"=",
"@right_api_client",
".",
"tags",
".",
"by_tag",
"(",
":resource_type",
"=>",
"\"instances\"",
",",
":tags",
"=>",
"tags",
",",
":match_all",
"=>",
"options",
"[",
":tag_match_strategy",
"]",
"==",
"\"all\"",
"?",
"\"true\"",
":",
"\"false\"",
")",
"resources_by_tag",
".",
"each",
"do",
"|",
"res",
"|",
"instance",
"=",
"@right_api_client",
".",
"resource",
"(",
"res",
".",
"links",
".",
"first",
"[",
"\"href\"",
"]",
")",
"instance",
".",
"run_executable",
"(",
"execute_params",
")",
"options",
"[",
":update_inputs",
"]",
".",
"each",
"do",
"|",
"update_type",
"|",
"update_inputs",
"(",
"instance",
",",
"options",
"[",
":inputs",
"]",
",",
"update_type",
")",
"end",
"end",
"end"
] |
Initializes a new RunExecutable
@param [RightApi::Client] right_api_client An instantiated and authenticated
RightApi::Client instance which will be used for making the request(s)
Runs a RightScript or Chef Recipe on all instances which have all of the
specified tags.
@param [String|Array<String>] tags An array of tags. If a string is
supplied it will be converted to an array of Strings.
@param [String] executable RightScript name or href, or the name of a
recipe. This method will attempt to auto detect which it is, or you
can be friendly and provide a hint using the executable_type option.
@param [Hash] options A list of options where the possible values are
- executable_type [String] One of ["auto","right_script_name","right_script_href","recipe_name"]. When set
to "auto" we will attempt to determine if an executable is a recipe,
a RightScript name, or a RightScript href. Defaults to "auto"
- right_script_revision [String] When a RightScript name or href is specified,
this can be used to declare the revision to use. Can be a specific
revision number or "latest". Defaults to "latest"
- tag_match_strategy [String] If multiple tags are specified, this will
determine how they are matched. When set to "all" instances with all
tags will be matched. When set to "any" instances with any of the
provided tags will be matched. Defaults to "all"
- inputs [Hash] A hash where the keys are the name of an input and the
value is the desired value for that input. Uses Inputs 2.0[http://reference.rightscale.com/api1.5/resources/ResourceInputs.html#multi_update]
semantics.
- update_inputs [Array<String>] An array of values indicating which
objects should be updated with the inputs supplied. Can be empty in
which case the inputs will be used only for this execution. Acceptable
values are ["current_instance","next_instance","deployment"]
@raise [RightScriptNotFound] If the specified RightScript lineage does
not exist, or the specified revision is not available.
|
[
"Initializes",
"a",
"new",
"RunExecutable"
] |
f6396729679c7cf2525aeff9c52c26db75d87a43
|
https://github.com/rgeyer/rs-mule/blob/f6396729679c7cf2525aeff9c52c26db75d87a43/lib/rs-mule/run_executable.rb#L61-L115
|
9,546
|
rgeyer/rs-mule
|
lib/rs-mule/run_executable.rb
|
RsMule.RunExecutable.right_script_revision_from_lineage
|
def right_script_revision_from_lineage(lineage, revision="latest")
right_script = nil
if revision == "latest"
latest_script = lineage.max_by{|rs| rs.revision}
right_script = latest_script
else
desired_script = lineage.select{|rs| rs.revision == revision}
if desired_script.length == 0
raise Exception::RightScriptNotFound.new("RightScript revision (#{revision}) was not found. Available revisions are (#{lineage.map{|rs| rs.revision}})")
end
right_script = desired_script.first
end
right_script
end
|
ruby
|
def right_script_revision_from_lineage(lineage, revision="latest")
right_script = nil
if revision == "latest"
latest_script = lineage.max_by{|rs| rs.revision}
right_script = latest_script
else
desired_script = lineage.select{|rs| rs.revision == revision}
if desired_script.length == 0
raise Exception::RightScriptNotFound.new("RightScript revision (#{revision}) was not found. Available revisions are (#{lineage.map{|rs| rs.revision}})")
end
right_script = desired_script.first
end
right_script
end
|
[
"def",
"right_script_revision_from_lineage",
"(",
"lineage",
",",
"revision",
"=",
"\"latest\"",
")",
"right_script",
"=",
"nil",
"if",
"revision",
"==",
"\"latest\"",
"latest_script",
"=",
"lineage",
".",
"max_by",
"{",
"|",
"rs",
"|",
"rs",
".",
"revision",
"}",
"right_script",
"=",
"latest_script",
"else",
"desired_script",
"=",
"lineage",
".",
"select",
"{",
"|",
"rs",
"|",
"rs",
".",
"revision",
"==",
"revision",
"}",
"if",
"desired_script",
".",
"length",
"==",
"0",
"raise",
"Exception",
"::",
"RightScriptNotFound",
".",
"new",
"(",
"\"RightScript revision (#{revision}) was not found. Available revisions are (#{lineage.map{|rs| rs.revision}})\"",
")",
"end",
"right_script",
"=",
"desired_script",
".",
"first",
"end",
"right_script",
"end"
] |
Gets the specified revision of a RightScript from it's lineage
@param [Array<RightApi::Resource>] An array of RightApi::Resource objects
of media type RightScript[http://reference.rightscale.com/api1.5/media_types/MediaTypeRightScript.html]
@param [String] An optional parameter for the desired lineage. When set
to "latest" it will get the highest number committed revision. Specify
0 for the head revision.
@raise [RightScriptNotFound] If the specified revision is not in the lineage
|
[
"Gets",
"the",
"specified",
"revision",
"of",
"a",
"RightScript",
"from",
"it",
"s",
"lineage"
] |
f6396729679c7cf2525aeff9c52c26db75d87a43
|
https://github.com/rgeyer/rs-mule/blob/f6396729679c7cf2525aeff9c52c26db75d87a43/lib/rs-mule/run_executable.rb#L143-L156
|
9,547
|
thriventures/storage_room_gem
|
lib/storage_room/array.rb
|
StorageRoom.Array.each_page_each_resource
|
def each_page_each_resource(args={})
self.each_page(args) do |page|
page.resources.each do |item|
yield(item)
end
end
end
|
ruby
|
def each_page_each_resource(args={})
self.each_page(args) do |page|
page.resources.each do |item|
yield(item)
end
end
end
|
[
"def",
"each_page_each_resource",
"(",
"args",
"=",
"{",
"}",
")",
"self",
".",
"each_page",
"(",
"args",
")",
"do",
"|",
"page",
"|",
"page",
".",
"resources",
".",
"each",
"do",
"|",
"item",
"|",
"yield",
"(",
"item",
")",
"end",
"end",
"end"
] |
Iterate over all resources with pagination
|
[
"Iterate",
"over",
"all",
"resources",
"with",
"pagination"
] |
cadf132b865ff82f7b09fadfec1d294a714c6728
|
https://github.com/thriventures/storage_room_gem/blob/cadf132b865ff82f7b09fadfec1d294a714c6728/lib/storage_room/array.rb#L35-L41
|
9,548
|
orendon/diffbot.rb
|
lib/diffbot_api/article.rb
|
Diffbot.Article.extract_article
|
def extract_article
api_response = request.get article_endpoint, token: Diffbot.token, url: @url
@response = JSON.parse(api_response.body)
end
|
ruby
|
def extract_article
api_response = request.get article_endpoint, token: Diffbot.token, url: @url
@response = JSON.parse(api_response.body)
end
|
[
"def",
"extract_article",
"api_response",
"=",
"request",
".",
"get",
"article_endpoint",
",",
"token",
":",
"Diffbot",
".",
"token",
",",
"url",
":",
"@url",
"@response",
"=",
"JSON",
".",
"parse",
"(",
"api_response",
".",
"body",
")",
"end"
] |
Extracts article data through Diffbot API
|
[
"Extracts",
"article",
"data",
"through",
"Diffbot",
"API"
] |
7f292988b36304ea15e1e74a5ee9f955d82b637e
|
https://github.com/orendon/diffbot.rb/blob/7f292988b36304ea15e1e74a5ee9f955d82b637e/lib/diffbot_api/article.rb#L35-L38
|
9,549
|
jtzero/vigilem-assembly
|
lib/vigilem/assembly.rb
|
Vigilem.Assembly.find_stat
|
def find_stat(opts={}, &block)
stats = Core::Stat.all_available
# @fixme just grabs first
stat = if stats.size > 1
[*opts[:platform_defaults]].map do |os_pattern, gem_name|
if System.check[:os][os_pattern]
stats.select {|stat| stat.gem_name == gem_name }
if stats.size > 1
raise ArgumentError, "multiple handlers match :platform_defaults"\
"#{os_pattern} => #{gem_name} matches #{stats}"
else
stats.first
end
end
end.flatten.compact.first
else
stats.first
end
end
|
ruby
|
def find_stat(opts={}, &block)
stats = Core::Stat.all_available
# @fixme just grabs first
stat = if stats.size > 1
[*opts[:platform_defaults]].map do |os_pattern, gem_name|
if System.check[:os][os_pattern]
stats.select {|stat| stat.gem_name == gem_name }
if stats.size > 1
raise ArgumentError, "multiple handlers match :platform_defaults"\
"#{os_pattern} => #{gem_name} matches #{stats}"
else
stats.first
end
end
end.flatten.compact.first
else
stats.first
end
end
|
[
"def",
"find_stat",
"(",
"opts",
"=",
"{",
"}",
",",
"&",
"block",
")",
"stats",
"=",
"Core",
"::",
"Stat",
".",
"all_available",
"# @fixme just grabs first",
"stat",
"=",
"if",
"stats",
".",
"size",
">",
"1",
"[",
"opts",
"[",
":platform_defaults",
"]",
"]",
".",
"map",
"do",
"|",
"os_pattern",
",",
"gem_name",
"|",
"if",
"System",
".",
"check",
"[",
":os",
"]",
"[",
"os_pattern",
"]",
"stats",
".",
"select",
"{",
"|",
"stat",
"|",
"stat",
".",
"gem_name",
"==",
"gem_name",
"}",
"if",
"stats",
".",
"size",
">",
"1",
"raise",
"ArgumentError",
",",
"\"multiple handlers match :platform_defaults\"",
"\"#{os_pattern} => #{gem_name} matches #{stats}\"",
"else",
"stats",
".",
"first",
"end",
"end",
"end",
".",
"flatten",
".",
"compact",
".",
"first",
"else",
"stats",
".",
"first",
"end",
"end"
] |
find's an available handler
@param [Hash] opts
@option opts [Array<Regexp || String, Array<String> || String>] :platform_defaults [os_pattern, gem_name],
the default gem for os_pattern, if os_pattern matches this os
and there are mulitple handlers available, install this gem_name
and raises ArgumentError when the default matches more than one Stat
@param [Proc] block
@raise ArgumentError, when the platform default matches more than one Stat
@return [Stat || NilClass]
|
[
"find",
"s",
"an",
"available",
"handler"
] |
732af25099a5c6947e9b4770ba9d8a3f15759446
|
https://github.com/jtzero/vigilem-assembly/blob/732af25099a5c6947e9b4770ba9d8a3f15759446/lib/vigilem/assembly.rb#L49-L67
|
9,550
|
lenn4rd/chores_kit
|
lib/chores_kit/chore.rb
|
ChoresKit.Chore.task
|
def task(options, &block)
name, params = *options
raise "Couldn't create task without a name" if name.nil?
raise "Couldn't create task without a block" unless block_given?
task = Task.new(name, params)
task.instance_eval(&block)
@dag.add_vertex(name: name, task: task)
end
|
ruby
|
def task(options, &block)
name, params = *options
raise "Couldn't create task without a name" if name.nil?
raise "Couldn't create task without a block" unless block_given?
task = Task.new(name, params)
task.instance_eval(&block)
@dag.add_vertex(name: name, task: task)
end
|
[
"def",
"task",
"(",
"options",
",",
"&",
"block",
")",
"name",
",",
"params",
"=",
"options",
"raise",
"\"Couldn't create task without a name\"",
"if",
"name",
".",
"nil?",
"raise",
"\"Couldn't create task without a block\"",
"unless",
"block_given?",
"task",
"=",
"Task",
".",
"new",
"(",
"name",
",",
"params",
")",
"task",
".",
"instance_eval",
"(",
"block",
")",
"@dag",
".",
"add_vertex",
"(",
"name",
":",
"name",
",",
"task",
":",
"task",
")",
"end"
] |
Tasks and dependencies
|
[
"Tasks",
"and",
"dependencies"
] |
3349c5c62d77507f30388d2a71e10b8c40361379
|
https://github.com/lenn4rd/chores_kit/blob/3349c5c62d77507f30388d2a71e10b8c40361379/lib/chores_kit/chore.rb#L55-L65
|
9,551
|
filipjakubowski/jira_issues
|
lib/jira_issues/jira_query.rb
|
JiraIssues.JiraQuery.jql_query
|
def jql_query(query)
result = adapter.jql(query, fields:[:description, :summary, :created, :status, :issuetype, :priority, :resolutiondate], max_results: @query_max_results)
JiraIssuesNavigator.new(result.map{|i| JiraIssueMapper.new.call(i) })
end
|
ruby
|
def jql_query(query)
result = adapter.jql(query, fields:[:description, :summary, :created, :status, :issuetype, :priority, :resolutiondate], max_results: @query_max_results)
JiraIssuesNavigator.new(result.map{|i| JiraIssueMapper.new.call(i) })
end
|
[
"def",
"jql_query",
"(",
"query",
")",
"result",
"=",
"adapter",
".",
"jql",
"(",
"query",
",",
"fields",
":",
"[",
":description",
",",
":summary",
",",
":created",
",",
":status",
",",
":issuetype",
",",
":priority",
",",
":resolutiondate",
"]",
",",
"max_results",
":",
"@query_max_results",
")",
"JiraIssuesNavigator",
".",
"new",
"(",
"result",
".",
"map",
"{",
"|",
"i",
"|",
"JiraIssueMapper",
".",
"new",
".",
"call",
"(",
"i",
")",
"}",
")",
"end"
] |
Creates new Query object
and sets the maximum number of issues returned by Query
@param max_results [Integer] maximum number of issues returned by query
Handles a JQL Request and returns JiraIssueavigator for that query
@param query [String]
@return [JiraIssueNavigator] with those requests
|
[
"Creates",
"new",
"Query",
"object",
"and",
"sets",
"the",
"maximum",
"number",
"of",
"issues",
"returned",
"by",
"Query"
] |
6545c1c2b3a72226ad309386d74ca86d35ff8bb1
|
https://github.com/filipjakubowski/jira_issues/blob/6545c1c2b3a72226ad309386d74ca86d35ff8bb1/lib/jira_issues/jira_query.rb#L14-L17
|
9,552
|
marcboeker/mongolicious
|
lib/mongolicious/filesystem.rb
|
Mongolicious.Filesystem.compress
|
def compress(path, compress_tar_file)
Mongolicious.logger.info("Compressing database #{path}")
system("cd #{path} && tar -cpf#{compress_tar_file ? 'j' : ''} #{path}.tar.bz2 .")
raise "Error while compressing #{path}" if $?.to_i != 0
# Remove mongo dump now that we have the bzip
FileUtils.rm_rf(path)
return "#{path}.tar.bz2"
end
|
ruby
|
def compress(path, compress_tar_file)
Mongolicious.logger.info("Compressing database #{path}")
system("cd #{path} && tar -cpf#{compress_tar_file ? 'j' : ''} #{path}.tar.bz2 .")
raise "Error while compressing #{path}" if $?.to_i != 0
# Remove mongo dump now that we have the bzip
FileUtils.rm_rf(path)
return "#{path}.tar.bz2"
end
|
[
"def",
"compress",
"(",
"path",
",",
"compress_tar_file",
")",
"Mongolicious",
".",
"logger",
".",
"info",
"(",
"\"Compressing database #{path}\"",
")",
"system",
"(",
"\"cd #{path} && tar -cpf#{compress_tar_file ? 'j' : ''} #{path}.tar.bz2 .\"",
")",
"raise",
"\"Error while compressing #{path}\"",
"if",
"$?",
".",
"to_i",
"!=",
"0",
"# Remove mongo dump now that we have the bzip",
"FileUtils",
".",
"rm_rf",
"(",
"path",
")",
"return",
"\"#{path}.tar.bz2\"",
"end"
] |
Initialize a ne Filesystem object.
@return [Filesytem]
Compress the dump to an tar.bz2 archive.
@param [String] path the path, where the dump is located.
@return [String]
|
[
"Initialize",
"a",
"ne",
"Filesystem",
"object",
"."
] |
bc1553188df97d3df825de6d826b34ab7185a431
|
https://github.com/marcboeker/mongolicious/blob/bc1553188df97d3df825de6d826b34ab7185a431/lib/mongolicious/filesystem.rb#L16-L26
|
9,553
|
marcboeker/mongolicious
|
lib/mongolicious/filesystem.rb
|
Mongolicious.Filesystem.cleanup_tar_file
|
def cleanup_tar_file(path)
Mongolicious.logger.info("Cleaning up local path #{path}")
begin
File.delete(path)
rescue => exception
Mongolicious.logger.error("Error trying to delete: #{path}")
Mongolicious.logger.info(exception.message)
end
end
|
ruby
|
def cleanup_tar_file(path)
Mongolicious.logger.info("Cleaning up local path #{path}")
begin
File.delete(path)
rescue => exception
Mongolicious.logger.error("Error trying to delete: #{path}")
Mongolicious.logger.info(exception.message)
end
end
|
[
"def",
"cleanup_tar_file",
"(",
"path",
")",
"Mongolicious",
".",
"logger",
".",
"info",
"(",
"\"Cleaning up local path #{path}\"",
")",
"begin",
"File",
".",
"delete",
"(",
"path",
")",
"rescue",
"=>",
"exception",
"Mongolicious",
".",
"logger",
".",
"error",
"(",
"\"Error trying to delete: #{path}\"",
")",
"Mongolicious",
".",
"logger",
".",
"info",
"(",
"exception",
".",
"message",
")",
"end",
"end"
] |
Remove dump from tmp path.
@param [String] path the path, where the dump/archive is located.
@return [nil]
|
[
"Remove",
"dump",
"from",
"tmp",
"path",
"."
] |
bc1553188df97d3df825de6d826b34ab7185a431
|
https://github.com/marcboeker/mongolicious/blob/bc1553188df97d3df825de6d826b34ab7185a431/lib/mongolicious/filesystem.rb#L45-L53
|
9,554
|
marcboeker/mongolicious
|
lib/mongolicious/filesystem.rb
|
Mongolicious.Filesystem.cleanup_parts
|
def cleanup_parts(file_parts)
Mongolicious.logger.info("Cleaning up file parts.")
if file_parts
file_parts.each do |part|
Mongolicious.logger.info("Deleting part: #{part}")
begin
File.delete(part)
rescue => exception
Mongolicious.logger.error("Error trying to delete part: #{part}")
Mongolicious.logger.error(exception.message)
Mongolicious.logger.error(exception.backtrace)
end
end
end
end
|
ruby
|
def cleanup_parts(file_parts)
Mongolicious.logger.info("Cleaning up file parts.")
if file_parts
file_parts.each do |part|
Mongolicious.logger.info("Deleting part: #{part}")
begin
File.delete(part)
rescue => exception
Mongolicious.logger.error("Error trying to delete part: #{part}")
Mongolicious.logger.error(exception.message)
Mongolicious.logger.error(exception.backtrace)
end
end
end
end
|
[
"def",
"cleanup_parts",
"(",
"file_parts",
")",
"Mongolicious",
".",
"logger",
".",
"info",
"(",
"\"Cleaning up file parts.\"",
")",
"if",
"file_parts",
"file_parts",
".",
"each",
"do",
"|",
"part",
"|",
"Mongolicious",
".",
"logger",
".",
"info",
"(",
"\"Deleting part: #{part}\"",
")",
"begin",
"File",
".",
"delete",
"(",
"part",
")",
"rescue",
"=>",
"exception",
"Mongolicious",
".",
"logger",
".",
"error",
"(",
"\"Error trying to delete part: #{part}\"",
")",
"Mongolicious",
".",
"logger",
".",
"error",
"(",
"exception",
".",
"message",
")",
"Mongolicious",
".",
"logger",
".",
"error",
"(",
"exception",
".",
"backtrace",
")",
"end",
"end",
"end",
"end"
] |
Remove all the bzip parts
@param [Array] file_parts an array of paths
@return [nill]
|
[
"Remove",
"all",
"the",
"bzip",
"parts"
] |
bc1553188df97d3df825de6d826b34ab7185a431
|
https://github.com/marcboeker/mongolicious/blob/bc1553188df97d3df825de6d826b34ab7185a431/lib/mongolicious/filesystem.rb#L60-L75
|
9,555
|
iamcutler/deal-redemptions
|
app/controllers/deal_redemptions/redeem_controller.rb
|
DealRedemptions.RedeemController.validate_code
|
def validate_code
redeem_code = DealRedemptions::RedeemCode.find_by_code(params[:code])
if redeem_code
@redeem = redeem_code.validate_code(params)
else
@redeem = false
end
end
|
ruby
|
def validate_code
redeem_code = DealRedemptions::RedeemCode.find_by_code(params[:code])
if redeem_code
@redeem = redeem_code.validate_code(params)
else
@redeem = false
end
end
|
[
"def",
"validate_code",
"redeem_code",
"=",
"DealRedemptions",
"::",
"RedeemCode",
".",
"find_by_code",
"(",
"params",
"[",
":code",
"]",
")",
"if",
"redeem_code",
"@redeem",
"=",
"redeem_code",
".",
"validate_code",
"(",
"params",
")",
"else",
"@redeem",
"=",
"false",
"end",
"end"
] |
Validate valid redemption codes
|
[
"Validate",
"valid",
"redemption",
"codes"
] |
b9b06df288c84a5bb0c0588ad0beca80b14edd31
|
https://github.com/iamcutler/deal-redemptions/blob/b9b06df288c84a5bb0c0588ad0beca80b14edd31/app/controllers/deal_redemptions/redeem_controller.rb#L69-L76
|
9,556
|
seejohnrun/flexible_api
|
lib/flexible_api.rb
|
FlexibleApi.ClassMethods.define_request_level
|
def define_request_level(name, &block)
level = RequestLevel.new(name, self)
level.instance_eval &block
@levels ||= {}
@levels[name] = level
end
|
ruby
|
def define_request_level(name, &block)
level = RequestLevel.new(name, self)
level.instance_eval &block
@levels ||= {}
@levels[name] = level
end
|
[
"def",
"define_request_level",
"(",
"name",
",",
"&",
"block",
")",
"level",
"=",
"RequestLevel",
".",
"new",
"(",
"name",
",",
"self",
")",
"level",
".",
"instance_eval",
"block",
"@levels",
"||=",
"{",
"}",
"@levels",
"[",
"name",
"]",
"=",
"level",
"end"
] |
Define a request level for this class
Takes a name, and a block which defined the request level
|
[
"Define",
"a",
"request",
"level",
"for",
"this",
"class",
"Takes",
"a",
"name",
"and",
"a",
"block",
"which",
"defined",
"the",
"request",
"level"
] |
5c09ca580f96f9ecea1c00b2ea15dc65d6d1c66c
|
https://github.com/seejohnrun/flexible_api/blob/5c09ca580f96f9ecea1c00b2ea15dc65d6d1c66c/lib/flexible_api.rb#L27-L32
|
9,557
|
seejohnrun/flexible_api
|
lib/flexible_api.rb
|
FlexibleApi.ClassMethods.find_hash
|
def find_hash(id, options = {})
options.assert_valid_keys(:request_level)
level = find_level(options[:request_level])
record = self.find(id, :select => level.select_field.join(', '), :include => level.include_field)
level.receive record
end
|
ruby
|
def find_hash(id, options = {})
options.assert_valid_keys(:request_level)
level = find_level(options[:request_level])
record = self.find(id, :select => level.select_field.join(', '), :include => level.include_field)
level.receive record
end
|
[
"def",
"find_hash",
"(",
"id",
",",
"options",
"=",
"{",
"}",
")",
"options",
".",
"assert_valid_keys",
"(",
":request_level",
")",
"level",
"=",
"find_level",
"(",
"options",
"[",
":request_level",
"]",
")",
"record",
"=",
"self",
".",
"find",
"(",
"id",
",",
":select",
"=>",
"level",
".",
"select_field",
".",
"join",
"(",
"', '",
")",
",",
":include",
"=>",
"level",
".",
"include_field",
")",
"level",
".",
"receive",
"record",
"end"
] |
Find a single element and load it at the given request level
|
[
"Find",
"a",
"single",
"element",
"and",
"load",
"it",
"at",
"the",
"given",
"request",
"level"
] |
5c09ca580f96f9ecea1c00b2ea15dc65d6d1c66c
|
https://github.com/seejohnrun/flexible_api/blob/5c09ca580f96f9ecea1c00b2ea15dc65d6d1c66c/lib/flexible_api.rb#L35-L40
|
9,558
|
seejohnrun/flexible_api
|
lib/flexible_api.rb
|
FlexibleApi.ClassMethods.find_level
|
def find_level(name = nil)
@levels ||= {}
level = name.nil? ? load_default_request_level : @levels[name.to_sym]
level = superclass.find_level(name) and @levels[name.to_sym] = level if level.nil? && superclass.present?
raise NoSuchRequestLevelError.new(name, self.name) if level.nil?
level
end
|
ruby
|
def find_level(name = nil)
@levels ||= {}
level = name.nil? ? load_default_request_level : @levels[name.to_sym]
level = superclass.find_level(name) and @levels[name.to_sym] = level if level.nil? && superclass.present?
raise NoSuchRequestLevelError.new(name, self.name) if level.nil?
level
end
|
[
"def",
"find_level",
"(",
"name",
"=",
"nil",
")",
"@levels",
"||=",
"{",
"}",
"level",
"=",
"name",
".",
"nil?",
"?",
"load_default_request_level",
":",
"@levels",
"[",
"name",
".",
"to_sym",
"]",
"level",
"=",
"superclass",
".",
"find_level",
"(",
"name",
")",
"and",
"@levels",
"[",
"name",
".",
"to_sym",
"]",
"=",
"level",
"if",
"level",
".",
"nil?",
"&&",
"superclass",
".",
"present?",
"raise",
"NoSuchRequestLevelError",
".",
"new",
"(",
"name",
",",
"self",
".",
"name",
")",
"if",
"level",
".",
"nil?",
"level",
"end"
] |
Find a given level by name and return the request level
|
[
"Find",
"a",
"given",
"level",
"by",
"name",
"and",
"return",
"the",
"request",
"level"
] |
5c09ca580f96f9ecea1c00b2ea15dc65d6d1c66c
|
https://github.com/seejohnrun/flexible_api/blob/5c09ca580f96f9ecea1c00b2ea15dc65d6d1c66c/lib/flexible_api.rb#L61-L67
|
9,559
|
jimjh/reaction
|
lib/reaction/rails/mapper.rb
|
ActionDispatch::Routing.Mapper.use_reaction
|
def use_reaction(opts = {})
raise RuntimeError, 'Already using Reaction.' if Reaction.client
opts = use_reaction_defaults opts
EM.next_tick {
faye = Faye::Client.new(opts[:at] + '/bayeux')
signer = Reaction::Client::Signer.new opts[:key]
faye.add_extension signer
Reaction.client = Reaction::Client.new faye, opts[:key]
}
end
|
ruby
|
def use_reaction(opts = {})
raise RuntimeError, 'Already using Reaction.' if Reaction.client
opts = use_reaction_defaults opts
EM.next_tick {
faye = Faye::Client.new(opts[:at] + '/bayeux')
signer = Reaction::Client::Signer.new opts[:key]
faye.add_extension signer
Reaction.client = Reaction::Client.new faye, opts[:key]
}
end
|
[
"def",
"use_reaction",
"(",
"opts",
"=",
"{",
"}",
")",
"raise",
"RuntimeError",
",",
"'Already using Reaction.'",
"if",
"Reaction",
".",
"client",
"opts",
"=",
"use_reaction_defaults",
"opts",
"EM",
".",
"next_tick",
"{",
"faye",
"=",
"Faye",
"::",
"Client",
".",
"new",
"(",
"opts",
"[",
":at",
"]",
"+",
"'/bayeux'",
")",
"signer",
"=",
"Reaction",
"::",
"Client",
"::",
"Signer",
".",
"new",
"opts",
"[",
":key",
"]",
"faye",
".",
"add_extension",
"signer",
"Reaction",
".",
"client",
"=",
"Reaction",
"::",
"Client",
".",
"new",
"faye",
",",
"opts",
"[",
":key",
"]",
"}",
"end"
] |
Uses an external reaction server.
@example Using an external reaction server at +localhost:9292/reaction+.
use_reaction :at => 'http://localhost:9292/reaction'
@option opts [String] :at URL of external reaction server.
@option opts [String] :key secret token, used for signing messages
published from app server; defaults to
+Rails.application.config.secret_token+
@raise [RuntimeError] if the reaction client has already been initialized.
@return [Reaction::Client] client
|
[
"Uses",
"an",
"external",
"reaction",
"server",
"."
] |
8aff9633dbd177ea536b79f59115a2825b5adf0a
|
https://github.com/jimjh/reaction/blob/8aff9633dbd177ea536b79f59115a2825b5adf0a/lib/reaction/rails/mapper.rb#L23-L36
|
9,560
|
bambery/cloud_crooner
|
lib/cloud_crooner/storage.rb
|
CloudCrooner.Storage.upload_files
|
def upload_files
files_to_upload = local_compiled_assets.reject { |f| exists_on_remote?(f) }
files_to_upload.each do |asset|
upload_file(asset)
end
end
|
ruby
|
def upload_files
files_to_upload = local_compiled_assets.reject { |f| exists_on_remote?(f) }
files_to_upload.each do |asset|
upload_file(asset)
end
end
|
[
"def",
"upload_files",
"files_to_upload",
"=",
"local_compiled_assets",
".",
"reject",
"{",
"|",
"f",
"|",
"exists_on_remote?",
"(",
"f",
")",
"}",
"files_to_upload",
".",
"each",
"do",
"|",
"asset",
"|",
"upload_file",
"(",
"asset",
")",
"end",
"end"
] |
Upload all new files to the bucket
|
[
"Upload",
"all",
"new",
"files",
"to",
"the",
"bucket"
] |
223cd525b8b83656201a645f43af1b1181555703
|
https://github.com/bambery/cloud_crooner/blob/223cd525b8b83656201a645f43af1b1181555703/lib/cloud_crooner/storage.rb#L42-L47
|
9,561
|
bambery/cloud_crooner
|
lib/cloud_crooner/storage.rb
|
CloudCrooner.Storage.upload_file
|
def upload_file(f)
# grabs the compiled asset from public_path
full_file_path = File.join(File.dirname(@manifest.dir), f)
one_year = 31557600
mime = Rack::Mime.mime_type(File.extname(f))
file = {
:key => f,
:public => true,
:content_type => mime,
:cache_control => "public, max-age=#{one_year}",
:expires => CGI.rfc1123_date(Time.now + one_year)
}
gzipped = "#{full_file_path}.gz"
if File.exists?(gzipped)
original_size = File.size(full_file_path)
gzipped_size = File.size(gzipped)
if gzipped_size < original_size
file.merge!({
:body => File.open(gzipped),
:content_encoding => 'gzip'
})
log "Uploading #{gzipped} in place of #{f}"
else
file.merge!({
:body => File.open(full_file_path)
})
log "Gzip exists but has larger file size, uploading #{f}"
end
else
file.merge!({
:body => File.open(full_file_path)
})
log "Uploading #{f}"
end
# put in reduced redundancy option here later if desired
file = bucket.files.create( file )
end
|
ruby
|
def upload_file(f)
# grabs the compiled asset from public_path
full_file_path = File.join(File.dirname(@manifest.dir), f)
one_year = 31557600
mime = Rack::Mime.mime_type(File.extname(f))
file = {
:key => f,
:public => true,
:content_type => mime,
:cache_control => "public, max-age=#{one_year}",
:expires => CGI.rfc1123_date(Time.now + one_year)
}
gzipped = "#{full_file_path}.gz"
if File.exists?(gzipped)
original_size = File.size(full_file_path)
gzipped_size = File.size(gzipped)
if gzipped_size < original_size
file.merge!({
:body => File.open(gzipped),
:content_encoding => 'gzip'
})
log "Uploading #{gzipped} in place of #{f}"
else
file.merge!({
:body => File.open(full_file_path)
})
log "Gzip exists but has larger file size, uploading #{f}"
end
else
file.merge!({
:body => File.open(full_file_path)
})
log "Uploading #{f}"
end
# put in reduced redundancy option here later if desired
file = bucket.files.create( file )
end
|
[
"def",
"upload_file",
"(",
"f",
")",
"# grabs the compiled asset from public_path",
"full_file_path",
"=",
"File",
".",
"join",
"(",
"File",
".",
"dirname",
"(",
"@manifest",
".",
"dir",
")",
",",
"f",
")",
"one_year",
"=",
"31557600",
"mime",
"=",
"Rack",
"::",
"Mime",
".",
"mime_type",
"(",
"File",
".",
"extname",
"(",
"f",
")",
")",
"file",
"=",
"{",
":key",
"=>",
"f",
",",
":public",
"=>",
"true",
",",
":content_type",
"=>",
"mime",
",",
":cache_control",
"=>",
"\"public, max-age=#{one_year}\"",
",",
":expires",
"=>",
"CGI",
".",
"rfc1123_date",
"(",
"Time",
".",
"now",
"+",
"one_year",
")",
"}",
"gzipped",
"=",
"\"#{full_file_path}.gz\"",
"if",
"File",
".",
"exists?",
"(",
"gzipped",
")",
"original_size",
"=",
"File",
".",
"size",
"(",
"full_file_path",
")",
"gzipped_size",
"=",
"File",
".",
"size",
"(",
"gzipped",
")",
"if",
"gzipped_size",
"<",
"original_size",
"file",
".",
"merge!",
"(",
"{",
":body",
"=>",
"File",
".",
"open",
"(",
"gzipped",
")",
",",
":content_encoding",
"=>",
"'gzip'",
"}",
")",
"log",
"\"Uploading #{gzipped} in place of #{f}\"",
"else",
"file",
".",
"merge!",
"(",
"{",
":body",
"=>",
"File",
".",
"open",
"(",
"full_file_path",
")",
"}",
")",
"log",
"\"Gzip exists but has larger file size, uploading #{f}\"",
"end",
"else",
"file",
".",
"merge!",
"(",
"{",
":body",
"=>",
"File",
".",
"open",
"(",
"full_file_path",
")",
"}",
")",
"log",
"\"Uploading #{f}\"",
"end",
"# put in reduced redundancy option here later if desired",
"file",
"=",
"bucket",
".",
"files",
".",
"create",
"(",
"file",
")",
"end"
] |
Uploads a file to the bucket. Sets expires header to one year. If a
gzipped version of the file exists and is a smaller file size
|
[
"Uploads",
"a",
"file",
"to",
"the",
"bucket",
".",
"Sets",
"expires",
"header",
"to",
"one",
"year",
".",
"If",
"a",
"gzipped",
"version",
"of",
"the",
"file",
"exists",
"and",
"is",
"a",
"smaller",
"file",
"size"
] |
223cd525b8b83656201a645f43af1b1181555703
|
https://github.com/bambery/cloud_crooner/blob/223cd525b8b83656201a645f43af1b1181555703/lib/cloud_crooner/storage.rb#L57-L97
|
9,562
|
redding/undies
|
lib/undies/api.rb
|
Undies.API.__yield
|
def __yield
return if (source = @_undies_source_stack.pop).nil?
if source.file?
instance_eval(source.data, source.source, 1)
else
instance_eval(&source.data)
end
end
|
ruby
|
def __yield
return if (source = @_undies_source_stack.pop).nil?
if source.file?
instance_eval(source.data, source.source, 1)
else
instance_eval(&source.data)
end
end
|
[
"def",
"__yield",
"return",
"if",
"(",
"source",
"=",
"@_undies_source_stack",
".",
"pop",
")",
".",
"nil?",
"if",
"source",
".",
"file?",
"instance_eval",
"(",
"source",
".",
"data",
",",
"source",
".",
"source",
",",
"1",
")",
"else",
"instance_eval",
"(",
"source",
".",
"data",
")",
"end",
"end"
] |
Source handling methods
call this to render template source
use this method in layouts to insert a layout's content source
|
[
"Source",
"handling",
"methods",
"call",
"this",
"to",
"render",
"template",
"source",
"use",
"this",
"method",
"in",
"layouts",
"to",
"insert",
"a",
"layout",
"s",
"content",
"source"
] |
13555df0a49fa5638cc85d16eb144443ae4ead27
|
https://github.com/redding/undies/blob/13555df0a49fa5638cc85d16eb144443ae4ead27/lib/undies/api.rb#L143-L150
|
9,563
|
sinisterchipmunk/rink
|
lib/rink/console.rb
|
Rink.Console.apply_options
|
def apply_options(options)
return unless options
options.each do |key, value|
options[key] = value.call if value.kind_of?(Proc)
end
@_options ||= {}
@_options.merge! options
@input = setup_input_method(options[:input] || @input)
@output = setup_output_method(options[:output] || @output)
@output.silenced = options.key?(:silent) ? options[:silent] : !@output || @output.silenced?
@line_processor = options[:processor] || options[:line_processor] || @line_processor
@allow_ruby = options.key?(:allow_ruby) ? options[:allow_ruby] : @allow_ruby
if options[:namespace]
ns = options[:namespace] == :self ? self : options[:namespace]
@namespace.replace(ns)
end
if @input
@input.output = @output
@input.prompt = prompt
if @input.respond_to?(:completion_proc)
@input.completion_proc = proc { |line| autocomplete(line) }
end
end
end
|
ruby
|
def apply_options(options)
return unless options
options.each do |key, value|
options[key] = value.call if value.kind_of?(Proc)
end
@_options ||= {}
@_options.merge! options
@input = setup_input_method(options[:input] || @input)
@output = setup_output_method(options[:output] || @output)
@output.silenced = options.key?(:silent) ? options[:silent] : !@output || @output.silenced?
@line_processor = options[:processor] || options[:line_processor] || @line_processor
@allow_ruby = options.key?(:allow_ruby) ? options[:allow_ruby] : @allow_ruby
if options[:namespace]
ns = options[:namespace] == :self ? self : options[:namespace]
@namespace.replace(ns)
end
if @input
@input.output = @output
@input.prompt = prompt
if @input.respond_to?(:completion_proc)
@input.completion_proc = proc { |line| autocomplete(line) }
end
end
end
|
[
"def",
"apply_options",
"(",
"options",
")",
"return",
"unless",
"options",
"options",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"options",
"[",
"key",
"]",
"=",
"value",
".",
"call",
"if",
"value",
".",
"kind_of?",
"(",
"Proc",
")",
"end",
"@_options",
"||=",
"{",
"}",
"@_options",
".",
"merge!",
"options",
"@input",
"=",
"setup_input_method",
"(",
"options",
"[",
":input",
"]",
"||",
"@input",
")",
"@output",
"=",
"setup_output_method",
"(",
"options",
"[",
":output",
"]",
"||",
"@output",
")",
"@output",
".",
"silenced",
"=",
"options",
".",
"key?",
"(",
":silent",
")",
"?",
"options",
"[",
":silent",
"]",
":",
"!",
"@output",
"||",
"@output",
".",
"silenced?",
"@line_processor",
"=",
"options",
"[",
":processor",
"]",
"||",
"options",
"[",
":line_processor",
"]",
"||",
"@line_processor",
"@allow_ruby",
"=",
"options",
".",
"key?",
"(",
":allow_ruby",
")",
"?",
"options",
"[",
":allow_ruby",
"]",
":",
"@allow_ruby",
"if",
"options",
"[",
":namespace",
"]",
"ns",
"=",
"options",
"[",
":namespace",
"]",
"==",
":self",
"?",
"self",
":",
"options",
"[",
":namespace",
"]",
"@namespace",
".",
"replace",
"(",
"ns",
")",
"end",
"if",
"@input",
"@input",
".",
"output",
"=",
"@output",
"@input",
".",
"prompt",
"=",
"prompt",
"if",
"@input",
".",
"respond_to?",
"(",
":completion_proc",
")",
"@input",
".",
"completion_proc",
"=",
"proc",
"{",
"|",
"line",
"|",
"autocomplete",
"(",
"line",
")",
"}",
"end",
"end",
"end"
] |
Applies a new set of options. Options that are currently unset or nil will not be modified.
|
[
"Applies",
"a",
"new",
"set",
"of",
"options",
".",
"Options",
"that",
"are",
"currently",
"unset",
"or",
"nil",
"will",
"not",
"be",
"modified",
"."
] |
cea8c602623da75fcbec7efef4e3454cd7649a43
|
https://github.com/sinisterchipmunk/rink/blob/cea8c602623da75fcbec7efef4e3454cd7649a43/lib/rink/console.rb#L86-L112
|
9,564
|
sinisterchipmunk/rink
|
lib/rink/console.rb
|
Rink.Console.autocomplete
|
def autocomplete(line)
return [] unless @line_processor
result = @line_processor.autocomplete(line, namespace)
case result
when String
[result]
when nil
[]
when Array
result
else
result.to_a
end
end
|
ruby
|
def autocomplete(line)
return [] unless @line_processor
result = @line_processor.autocomplete(line, namespace)
case result
when String
[result]
when nil
[]
when Array
result
else
result.to_a
end
end
|
[
"def",
"autocomplete",
"(",
"line",
")",
"return",
"[",
"]",
"unless",
"@line_processor",
"result",
"=",
"@line_processor",
".",
"autocomplete",
"(",
"line",
",",
"namespace",
")",
"case",
"result",
"when",
"String",
"[",
"result",
"]",
"when",
"nil",
"[",
"]",
"when",
"Array",
"result",
"else",
"result",
".",
"to_a",
"end",
"end"
] |
Runs the autocomplete method from the line processor, then reformats its result to be an array.
|
[
"Runs",
"the",
"autocomplete",
"method",
"from",
"the",
"line",
"processor",
"then",
"reformats",
"its",
"result",
"to",
"be",
"an",
"array",
"."
] |
cea8c602623da75fcbec7efef4e3454cd7649a43
|
https://github.com/sinisterchipmunk/rink/blob/cea8c602623da75fcbec7efef4e3454cd7649a43/lib/rink/console.rb#L314-L327
|
9,565
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.perform
|
def perform(action, workitem)
@action, @workitem = action, workitem
send(action)
write_output('') # Triggers any remaining buffered output to be sent
run_callbacks
rescue MaestroDev::Plugin::PluginError => e
write_output('') # Triggers any remaining buffered output to be sent
set_error(e.message)
rescue Exception => e
write_output('') # Triggers any remaining buffered output to be sent
lowerstack = e.backtrace.find_index(caller[0])
stack = lowerstack ? e.backtrace[0..lowerstack - 1] : e.backtrace
msg = "Unexpected error executing task: #{e.class} #{e} at\n" + stack.join("\n")
Maestro.log.warn("#{msg}\nFull stack:\n" + e.backtrace.join("\n"))
# Let user-supplied exception handler do its thing
handle_exception(e)
set_error(msg)
ensure
# Older agents expected this method to *maybe* return something
# .. something that no longer exists, but if we return anything
# it will be *wrong* :P
return nil
end
|
ruby
|
def perform(action, workitem)
@action, @workitem = action, workitem
send(action)
write_output('') # Triggers any remaining buffered output to be sent
run_callbacks
rescue MaestroDev::Plugin::PluginError => e
write_output('') # Triggers any remaining buffered output to be sent
set_error(e.message)
rescue Exception => e
write_output('') # Triggers any remaining buffered output to be sent
lowerstack = e.backtrace.find_index(caller[0])
stack = lowerstack ? e.backtrace[0..lowerstack - 1] : e.backtrace
msg = "Unexpected error executing task: #{e.class} #{e} at\n" + stack.join("\n")
Maestro.log.warn("#{msg}\nFull stack:\n" + e.backtrace.join("\n"))
# Let user-supplied exception handler do its thing
handle_exception(e)
set_error(msg)
ensure
# Older agents expected this method to *maybe* return something
# .. something that no longer exists, but if we return anything
# it will be *wrong* :P
return nil
end
|
[
"def",
"perform",
"(",
"action",
",",
"workitem",
")",
"@action",
",",
"@workitem",
"=",
"action",
",",
"workitem",
"send",
"(",
"action",
")",
"write_output",
"(",
"''",
")",
"# Triggers any remaining buffered output to be sent",
"run_callbacks",
"rescue",
"MaestroDev",
"::",
"Plugin",
"::",
"PluginError",
"=>",
"e",
"write_output",
"(",
"''",
")",
"# Triggers any remaining buffered output to be sent",
"set_error",
"(",
"e",
".",
"message",
")",
"rescue",
"Exception",
"=>",
"e",
"write_output",
"(",
"''",
")",
"# Triggers any remaining buffered output to be sent",
"lowerstack",
"=",
"e",
".",
"backtrace",
".",
"find_index",
"(",
"caller",
"[",
"0",
"]",
")",
"stack",
"=",
"lowerstack",
"?",
"e",
".",
"backtrace",
"[",
"0",
"..",
"lowerstack",
"-",
"1",
"]",
":",
"e",
".",
"backtrace",
"msg",
"=",
"\"Unexpected error executing task: #{e.class} #{e} at\\n\"",
"+",
"stack",
".",
"join",
"(",
"\"\\n\"",
")",
"Maestro",
".",
"log",
".",
"warn",
"(",
"\"#{msg}\\nFull stack:\\n\"",
"+",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"# Let user-supplied exception handler do its thing",
"handle_exception",
"(",
"e",
")",
"set_error",
"(",
"msg",
")",
"ensure",
"# Older agents expected this method to *maybe* return something",
"# .. something that no longer exists, but if we return anything",
"# it will be *wrong* :P",
"return",
"nil",
"end"
] |
Perform the specified action with the provided workitem. Invokes the method specified by the action parameter.
|
[
"Perform",
"the",
"specified",
"action",
"with",
"the",
"provided",
"workitem",
".",
"Invokes",
"the",
"method",
"specified",
"by",
"the",
"action",
"parameter",
"."
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L100-L123
|
9,566
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.handle_exception
|
def handle_exception(e)
if self.class.exception_handler_method
send(self.class.exception_handler_method, e)
elsif self.class.exception_handler_block
self.class.exception_handler_block.call(e, self)
end
end
|
ruby
|
def handle_exception(e)
if self.class.exception_handler_method
send(self.class.exception_handler_method, e)
elsif self.class.exception_handler_block
self.class.exception_handler_block.call(e, self)
end
end
|
[
"def",
"handle_exception",
"(",
"e",
")",
"if",
"self",
".",
"class",
".",
"exception_handler_method",
"send",
"(",
"self",
".",
"class",
".",
"exception_handler_method",
",",
"e",
")",
"elsif",
"self",
".",
"class",
".",
"exception_handler_block",
"self",
".",
"class",
".",
"exception_handler_block",
".",
"call",
"(",
"e",
",",
"self",
")",
"end",
"end"
] |
Fire supplied exception handlers if supplied, otherwise do nothing
|
[
"Fire",
"supplied",
"exception",
"handlers",
"if",
"supplied",
"otherwise",
"do",
"nothing"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L126-L132
|
9,567
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.save_output_value
|
def save_output_value(name, value)
set_field(CONTEXT_OUTPUTS_META, {}) if get_field(CONTEXT_OUTPUTS_META).nil?
get_field(CONTEXT_OUTPUTS_META)[name] = value
end
|
ruby
|
def save_output_value(name, value)
set_field(CONTEXT_OUTPUTS_META, {}) if get_field(CONTEXT_OUTPUTS_META).nil?
get_field(CONTEXT_OUTPUTS_META)[name] = value
end
|
[
"def",
"save_output_value",
"(",
"name",
",",
"value",
")",
"set_field",
"(",
"CONTEXT_OUTPUTS_META",
",",
"{",
"}",
")",
"if",
"get_field",
"(",
"CONTEXT_OUTPUTS_META",
")",
".",
"nil?",
"get_field",
"(",
"CONTEXT_OUTPUTS_META",
")",
"[",
"name",
"]",
"=",
"value",
"end"
] |
Set a value in the context output
|
[
"Set",
"a",
"value",
"in",
"the",
"context",
"output"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L145-L148
|
9,568
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.read_output_value
|
def read_output_value(name)
if get_field(PREVIOUS_CONTEXT_OUTPUTS_META).nil?
set_field(CONTEXT_OUTPUTS_META, {}) if get_field(CONTEXT_OUTPUTS_META).nil?
get_field(CONTEXT_OUTPUTS_META)[name]
else
get_field(PREVIOUS_CONTEXT_OUTPUTS_META)[name]
end
end
|
ruby
|
def read_output_value(name)
if get_field(PREVIOUS_CONTEXT_OUTPUTS_META).nil?
set_field(CONTEXT_OUTPUTS_META, {}) if get_field(CONTEXT_OUTPUTS_META).nil?
get_field(CONTEXT_OUTPUTS_META)[name]
else
get_field(PREVIOUS_CONTEXT_OUTPUTS_META)[name]
end
end
|
[
"def",
"read_output_value",
"(",
"name",
")",
"if",
"get_field",
"(",
"PREVIOUS_CONTEXT_OUTPUTS_META",
")",
".",
"nil?",
"set_field",
"(",
"CONTEXT_OUTPUTS_META",
",",
"{",
"}",
")",
"if",
"get_field",
"(",
"CONTEXT_OUTPUTS_META",
")",
".",
"nil?",
"get_field",
"(",
"CONTEXT_OUTPUTS_META",
")",
"[",
"name",
"]",
"else",
"get_field",
"(",
"PREVIOUS_CONTEXT_OUTPUTS_META",
")",
"[",
"name",
"]",
"end",
"end"
] |
Read a value from the context output
|
[
"Read",
"a",
"value",
"from",
"the",
"context",
"output"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L151-L158
|
9,569
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.set_waiting
|
def set_waiting(should_wait)
workitem[WAITING_META] = should_wait
send_workitem_message
rescue Exception => e
Maestro.log.warn "Failed To Send Waiting Message To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
ensure
workitem.delete(WAITING_META) unless should_wait
end
|
ruby
|
def set_waiting(should_wait)
workitem[WAITING_META] = should_wait
send_workitem_message
rescue Exception => e
Maestro.log.warn "Failed To Send Waiting Message To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
ensure
workitem.delete(WAITING_META) unless should_wait
end
|
[
"def",
"set_waiting",
"(",
"should_wait",
")",
"workitem",
"[",
"WAITING_META",
"]",
"=",
"should_wait",
"send_workitem_message",
"rescue",
"Exception",
"=>",
"e",
"Maestro",
".",
"log",
".",
"warn",
"\"Failed To Send Waiting Message To Server #{e.class} #{e}: #{e.backtrace.join(\"\\n\")}\"",
"ensure",
"workitem",
".",
"delete",
"(",
"WAITING_META",
")",
"unless",
"should_wait",
"end"
] |
control
Sets the current task as waiting
|
[
"control",
"Sets",
"the",
"current",
"task",
"as",
"waiting"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L261-L268
|
9,570
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.cancel
|
def cancel
workitem[CANCEL_META] = true
send_workitem_message
rescue Exception => e
Maestro.log.warn "Failed To Send Cancel Message To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
ensure
workitem.delete(CANCEL_META)
end
|
ruby
|
def cancel
workitem[CANCEL_META] = true
send_workitem_message
rescue Exception => e
Maestro.log.warn "Failed To Send Cancel Message To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
ensure
workitem.delete(CANCEL_META)
end
|
[
"def",
"cancel",
"workitem",
"[",
"CANCEL_META",
"]",
"=",
"true",
"send_workitem_message",
"rescue",
"Exception",
"=>",
"e",
"Maestro",
".",
"log",
".",
"warn",
"\"Failed To Send Cancel Message To Server #{e.class} #{e}: #{e.backtrace.join(\"\\n\")}\"",
"ensure",
"workitem",
".",
"delete",
"(",
"CANCEL_META",
")",
"end"
] |
Send the "cancel" message to the server
|
[
"Send",
"the",
"cancel",
"message",
"to",
"the",
"server"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L271-L278
|
9,571
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.not_needed
|
def not_needed
workitem[NOT_NEEDED] = true
send_workitem_message
rescue Exception => e
Maestro.log.warn "Failed To Send Not Needed Message To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
ensure
workitem.delete(NOT_NEEDED)
end
|
ruby
|
def not_needed
workitem[NOT_NEEDED] = true
send_workitem_message
rescue Exception => e
Maestro.log.warn "Failed To Send Not Needed Message To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
ensure
workitem.delete(NOT_NEEDED)
end
|
[
"def",
"not_needed",
"workitem",
"[",
"NOT_NEEDED",
"]",
"=",
"true",
"send_workitem_message",
"rescue",
"Exception",
"=>",
"e",
"Maestro",
".",
"log",
".",
"warn",
"\"Failed To Send Not Needed Message To Server #{e.class} #{e}: #{e.backtrace.join(\"\\n\")}\"",
"ensure",
"workitem",
".",
"delete",
"(",
"NOT_NEEDED",
")",
"end"
] |
Send the "not needed" message to the server.
|
[
"Send",
"the",
"not",
"needed",
"message",
"to",
"the",
"server",
"."
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L282-L289
|
9,572
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.update_fields_in_record
|
def update_fields_in_record(model, name_or_id, record_field, record_value)
workitem[PERSIST_META] = true
workitem[UPDATE_META] = true
workitem[MODEL_META] = model
workitem[RECORD_ID_META] = name_or_id.to_s
workitem[RECORD_FIELD_META] = record_field
workitem[RECORD_VALUE_META] = record_value
send_workitem_message
workitem.delete(PERSIST_META)
workitem.delete(UPDATE_META)
end
|
ruby
|
def update_fields_in_record(model, name_or_id, record_field, record_value)
workitem[PERSIST_META] = true
workitem[UPDATE_META] = true
workitem[MODEL_META] = model
workitem[RECORD_ID_META] = name_or_id.to_s
workitem[RECORD_FIELD_META] = record_field
workitem[RECORD_VALUE_META] = record_value
send_workitem_message
workitem.delete(PERSIST_META)
workitem.delete(UPDATE_META)
end
|
[
"def",
"update_fields_in_record",
"(",
"model",
",",
"name_or_id",
",",
"record_field",
",",
"record_value",
")",
"workitem",
"[",
"PERSIST_META",
"]",
"=",
"true",
"workitem",
"[",
"UPDATE_META",
"]",
"=",
"true",
"workitem",
"[",
"MODEL_META",
"]",
"=",
"model",
"workitem",
"[",
"RECORD_ID_META",
"]",
"=",
"name_or_id",
".",
"to_s",
"workitem",
"[",
"RECORD_FIELD_META",
"]",
"=",
"record_field",
"workitem",
"[",
"RECORD_VALUE_META",
"]",
"=",
"record_value",
"send_workitem_message",
"workitem",
".",
"delete",
"(",
"PERSIST_META",
")",
"workitem",
".",
"delete",
"(",
"UPDATE_META",
")",
"end"
] |
end control
persistence
|
[
"end",
"control",
"persistence"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L294-L306
|
9,573
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.get_field
|
def get_field(field, default = nil)
value = fields[field]
value = default if !default.nil? && (value.nil? || (value.respond_to?(:empty?) && value.empty?))
value
end
|
ruby
|
def get_field(field, default = nil)
value = fields[field]
value = default if !default.nil? && (value.nil? || (value.respond_to?(:empty?) && value.empty?))
value
end
|
[
"def",
"get_field",
"(",
"field",
",",
"default",
"=",
"nil",
")",
"value",
"=",
"fields",
"[",
"field",
"]",
"value",
"=",
"default",
"if",
"!",
"default",
".",
"nil?",
"&&",
"(",
"value",
".",
"nil?",
"||",
"(",
"value",
".",
"respond_to?",
"(",
":empty?",
")",
"&&",
"value",
".",
"empty?",
")",
")",
"value",
"end"
] |
end persistence
Get a field from workitem, supporting default value
|
[
"end",
"persistence",
"Get",
"a",
"field",
"from",
"workitem",
"supporting",
"default",
"value"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L349-L353
|
9,574
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.add_link
|
def add_link(name, url)
set_field(LINKS_META, []) if fields[LINKS_META].nil?
fields[LINKS_META] << {'name' => name, 'url' => url}
end
|
ruby
|
def add_link(name, url)
set_field(LINKS_META, []) if fields[LINKS_META].nil?
fields[LINKS_META] << {'name' => name, 'url' => url}
end
|
[
"def",
"add_link",
"(",
"name",
",",
"url",
")",
"set_field",
"(",
"LINKS_META",
",",
"[",
"]",
")",
"if",
"fields",
"[",
"LINKS_META",
"]",
".",
"nil?",
"fields",
"[",
"LINKS_META",
"]",
"<<",
"{",
"'name'",
"=>",
"name",
",",
"'url'",
"=>",
"url",
"}",
"end"
] |
Adds a link to be displayed in the Maestro UI.
|
[
"Adds",
"a",
"link",
"to",
"be",
"displayed",
"in",
"the",
"Maestro",
"UI",
"."
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L377-L380
|
9,575
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.as_int
|
def as_int(value, default = 0)
res = default
if value
if value.is_a?(Fixnum)
res = value
elsif value.respond_to?(:to_i)
res = value.to_i
end
end
res
end
|
ruby
|
def as_int(value, default = 0)
res = default
if value
if value.is_a?(Fixnum)
res = value
elsif value.respond_to?(:to_i)
res = value.to_i
end
end
res
end
|
[
"def",
"as_int",
"(",
"value",
",",
"default",
"=",
"0",
")",
"res",
"=",
"default",
"if",
"value",
"if",
"value",
".",
"is_a?",
"(",
"Fixnum",
")",
"res",
"=",
"value",
"elsif",
"value",
".",
"respond_to?",
"(",
":to_i",
")",
"res",
"=",
"value",
".",
"to_i",
"end",
"end",
"res",
"end"
] |
Field Utility methods
Return numeric version of value
|
[
"Field",
"Utility",
"methods",
"Return",
"numeric",
"version",
"of",
"value"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L385-L397
|
9,576
|
maestrodev/maestro-ruby-plugin
|
lib/maestro_plugin/maestro_worker.rb
|
Maestro.MaestroWorker.as_boolean
|
def as_boolean(value)
res = false
if value
if value.is_a?(TrueClass) || value.is_a?(FalseClass)
res = value
elsif value.is_a?(Fixnum)
res = value != 0
elsif value.respond_to?(:to_s)
value = value.to_s.downcase
res = (value == 't' || value == 'true')
end
end
res
end
|
ruby
|
def as_boolean(value)
res = false
if value
if value.is_a?(TrueClass) || value.is_a?(FalseClass)
res = value
elsif value.is_a?(Fixnum)
res = value != 0
elsif value.respond_to?(:to_s)
value = value.to_s.downcase
res = (value == 't' || value == 'true')
end
end
res
end
|
[
"def",
"as_boolean",
"(",
"value",
")",
"res",
"=",
"false",
"if",
"value",
"if",
"value",
".",
"is_a?",
"(",
"TrueClass",
")",
"||",
"value",
".",
"is_a?",
"(",
"FalseClass",
")",
"res",
"=",
"value",
"elsif",
"value",
".",
"is_a?",
"(",
"Fixnum",
")",
"res",
"=",
"value",
"!=",
"0",
"elsif",
"value",
".",
"respond_to?",
"(",
":to_s",
")",
"value",
"=",
"value",
".",
"to_s",
".",
"downcase",
"res",
"=",
"(",
"value",
"==",
"'t'",
"||",
"value",
"==",
"'true'",
")",
"end",
"end",
"res",
"end"
] |
Return boolean version of a value
|
[
"Return",
"boolean",
"version",
"of",
"a",
"value"
] |
9a751042040b33197b8e73a352ddf609a1e6d034
|
https://github.com/maestrodev/maestro-ruby-plugin/blob/9a751042040b33197b8e73a352ddf609a1e6d034/lib/maestro_plugin/maestro_worker.rb#L400-L416
|
9,577
|
4rlm/sort_rank
|
lib/sort_rank/solver.rb
|
SortRank.Solver.parse
|
def parse(args={})
string_block = args.fetch(:text, nil)
string_block = sample_string_block if !string_block.present?
result_hash = {results: count_strings(string_block), text: string_block }
end
|
ruby
|
def parse(args={})
string_block = args.fetch(:text, nil)
string_block = sample_string_block if !string_block.present?
result_hash = {results: count_strings(string_block), text: string_block }
end
|
[
"def",
"parse",
"(",
"args",
"=",
"{",
"}",
")",
"string_block",
"=",
"args",
".",
"fetch",
"(",
":text",
",",
"nil",
")",
"string_block",
"=",
"sample_string_block",
"if",
"!",
"string_block",
".",
"present?",
"result_hash",
"=",
"{",
"results",
":",
"count_strings",
"(",
"string_block",
")",
",",
"text",
":",
"string_block",
"}",
"end"
] |
AlgoService.new.parse
|
[
"AlgoService",
".",
"new",
".",
"parse"
] |
6d6bbb1a95094b86805969f6dd15e377014c4cfe
|
https://github.com/4rlm/sort_rank/blob/6d6bbb1a95094b86805969f6dd15e377014c4cfe/lib/sort_rank/solver.rb#L6-L10
|
9,578
|
flori/dslkit
|
lib/dslkit/polite.rb
|
DSLKit.ThreadLocal.instance_thread_local
|
def instance_thread_local(name, value = nil)
sc = class << self
extend DSLKit::ThreadLocal
self
end
sc.thread_local name, value
self
end
|
ruby
|
def instance_thread_local(name, value = nil)
sc = class << self
extend DSLKit::ThreadLocal
self
end
sc.thread_local name, value
self
end
|
[
"def",
"instance_thread_local",
"(",
"name",
",",
"value",
"=",
"nil",
")",
"sc",
"=",
"class",
"<<",
"self",
"extend",
"DSLKit",
"::",
"ThreadLocal",
"self",
"end",
"sc",
".",
"thread_local",
"name",
",",
"value",
"self",
"end"
] |
Define a thread local variable for the current instance with name _name_.
If the value _value_ is given, it is used to initialize the variable.
|
[
"Define",
"a",
"thread",
"local",
"variable",
"for",
"the",
"current",
"instance",
"with",
"name",
"_name_",
".",
"If",
"the",
"value",
"_value_",
"is",
"given",
"it",
"is",
"used",
"to",
"initialize",
"the",
"variable",
"."
] |
7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf
|
https://github.com/flori/dslkit/blob/7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf/lib/dslkit/polite.rb#L97-L104
|
9,579
|
flori/dslkit
|
lib/dslkit/polite.rb
|
DSLKit.ThreadGlobal.instance_thread_global
|
def instance_thread_global(name, value = nil)
sc = class << self
extend DSLKit::ThreadGlobal
self
end
sc.thread_global name, value
self
end
|
ruby
|
def instance_thread_global(name, value = nil)
sc = class << self
extend DSLKit::ThreadGlobal
self
end
sc.thread_global name, value
self
end
|
[
"def",
"instance_thread_global",
"(",
"name",
",",
"value",
"=",
"nil",
")",
"sc",
"=",
"class",
"<<",
"self",
"extend",
"DSLKit",
"::",
"ThreadGlobal",
"self",
"end",
"sc",
".",
"thread_global",
"name",
",",
"value",
"self",
"end"
] |
Define a thread global variable for the current instance with name
_name_. If the value _value_ is given, it is used to initialize the
variable.
|
[
"Define",
"a",
"thread",
"global",
"variable",
"for",
"the",
"current",
"instance",
"with",
"name",
"_name_",
".",
"If",
"the",
"value",
"_value_",
"is",
"given",
"it",
"is",
"used",
"to",
"initialize",
"the",
"variable",
"."
] |
7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf
|
https://github.com/flori/dslkit/blob/7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf/lib/dslkit/polite.rb#L134-L141
|
9,580
|
flori/dslkit
|
lib/dslkit/polite.rb
|
DSLKit.Deflect.deflect_start
|
def deflect_start(from, id, deflector)
@@sync.synchronize do
Deflect.deflecting ||= DeflectorCollection.new
Deflect.deflecting.member?(from, id) and
raise DeflectError, "#{from}##{id} is already deflected"
Deflect.deflecting.add(from, id, deflector)
from.class_eval do
define_method(id) do |*args|
if Deflect.deflecting and d = Deflect.deflecting.find(self.class, id)
d.call(self, id, *args)
else
super(*args)
end
end
end
end
end
|
ruby
|
def deflect_start(from, id, deflector)
@@sync.synchronize do
Deflect.deflecting ||= DeflectorCollection.new
Deflect.deflecting.member?(from, id) and
raise DeflectError, "#{from}##{id} is already deflected"
Deflect.deflecting.add(from, id, deflector)
from.class_eval do
define_method(id) do |*args|
if Deflect.deflecting and d = Deflect.deflecting.find(self.class, id)
d.call(self, id, *args)
else
super(*args)
end
end
end
end
end
|
[
"def",
"deflect_start",
"(",
"from",
",",
"id",
",",
"deflector",
")",
"@@sync",
".",
"synchronize",
"do",
"Deflect",
".",
"deflecting",
"||=",
"DeflectorCollection",
".",
"new",
"Deflect",
".",
"deflecting",
".",
"member?",
"(",
"from",
",",
"id",
")",
"and",
"raise",
"DeflectError",
",",
"\"#{from}##{id} is already deflected\"",
"Deflect",
".",
"deflecting",
".",
"add",
"(",
"from",
",",
"id",
",",
"deflector",
")",
"from",
".",
"class_eval",
"do",
"define_method",
"(",
"id",
")",
"do",
"|",
"*",
"args",
"|",
"if",
"Deflect",
".",
"deflecting",
"and",
"d",
"=",
"Deflect",
".",
"deflecting",
".",
"find",
"(",
"self",
".",
"class",
",",
"id",
")",
"d",
".",
"call",
"(",
"self",
",",
"id",
",",
"args",
")",
"else",
"super",
"(",
"args",
")",
"end",
"end",
"end",
"end",
"end"
] |
Start deflecting method calls named _id_ to the _from_ class using the
Deflector instance deflector.
|
[
"Start",
"deflecting",
"method",
"calls",
"named",
"_id_",
"to",
"the",
"_from_",
"class",
"using",
"the",
"Deflector",
"instance",
"deflector",
"."
] |
7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf
|
https://github.com/flori/dslkit/blob/7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf/lib/dslkit/polite.rb#L461-L477
|
9,581
|
flori/dslkit
|
lib/dslkit/polite.rb
|
DSLKit.Deflect.deflect
|
def deflect(from, id, deflector)
@@sync.synchronize do
begin
deflect_start(from, id, deflector)
yield
ensure
deflect_stop(from, id)
end
end
end
|
ruby
|
def deflect(from, id, deflector)
@@sync.synchronize do
begin
deflect_start(from, id, deflector)
yield
ensure
deflect_stop(from, id)
end
end
end
|
[
"def",
"deflect",
"(",
"from",
",",
"id",
",",
"deflector",
")",
"@@sync",
".",
"synchronize",
"do",
"begin",
"deflect_start",
"(",
"from",
",",
"id",
",",
"deflector",
")",
"yield",
"ensure",
"deflect_stop",
"(",
"from",
",",
"id",
")",
"end",
"end",
"end"
] |
Start deflecting method calls named _id_ to the _from_ class using the
Deflector instance deflector. After that yield to the given block and
stop deflecting again.
|
[
"Start",
"deflecting",
"method",
"calls",
"named",
"_id_",
"to",
"the",
"_from_",
"class",
"using",
"the",
"Deflector",
"instance",
"deflector",
".",
"After",
"that",
"yield",
"to",
"the",
"given",
"block",
"and",
"stop",
"deflecting",
"again",
"."
] |
7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf
|
https://github.com/flori/dslkit/blob/7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf/lib/dslkit/polite.rb#L494-L503
|
9,582
|
flori/dslkit
|
lib/dslkit/polite.rb
|
DSLKit.Deflect.deflect_stop
|
def deflect_stop(from, id)
@@sync.synchronize do
Deflect.deflecting.delete(from, id) or
raise DeflectError, "#{from}##{id} is not deflected from"
from.instance_eval { remove_method id }
end
end
|
ruby
|
def deflect_stop(from, id)
@@sync.synchronize do
Deflect.deflecting.delete(from, id) or
raise DeflectError, "#{from}##{id} is not deflected from"
from.instance_eval { remove_method id }
end
end
|
[
"def",
"deflect_stop",
"(",
"from",
",",
"id",
")",
"@@sync",
".",
"synchronize",
"do",
"Deflect",
".",
"deflecting",
".",
"delete",
"(",
"from",
",",
"id",
")",
"or",
"raise",
"DeflectError",
",",
"\"#{from}##{id} is not deflected from\"",
"from",
".",
"instance_eval",
"{",
"remove_method",
"id",
"}",
"end",
"end"
] |
Stop deflection method calls named _id_ to class _from_.
|
[
"Stop",
"deflection",
"method",
"calls",
"named",
"_id_",
"to",
"class",
"_from_",
"."
] |
7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf
|
https://github.com/flori/dslkit/blob/7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf/lib/dslkit/polite.rb#L506-L512
|
9,583
|
flori/dslkit
|
lib/dslkit/polite.rb
|
DSLKit.MethodMissingDelegator.method_missing
|
def method_missing(id, *a, &b)
unless method_missing_delegator.nil?
method_missing_delegator.__send__(id, *a, &b)
else
super
end
end
|
ruby
|
def method_missing(id, *a, &b)
unless method_missing_delegator.nil?
method_missing_delegator.__send__(id, *a, &b)
else
super
end
end
|
[
"def",
"method_missing",
"(",
"id",
",",
"*",
"a",
",",
"&",
"b",
")",
"unless",
"method_missing_delegator",
".",
"nil?",
"method_missing_delegator",
".",
"__send__",
"(",
"id",
",",
"a",
",",
"b",
")",
"else",
"super",
"end",
"end"
] |
Delegates all missing method calls to _method_missing_delegator_ if this
attribute has been set. Otherwise it will call super.
|
[
"Delegates",
"all",
"missing",
"method",
"calls",
"to",
"_method_missing_delegator_",
"if",
"this",
"attribute",
"has",
"been",
"set",
".",
"Otherwise",
"it",
"will",
"call",
"super",
"."
] |
7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf
|
https://github.com/flori/dslkit/blob/7e731a6ab3705ce9bc6563a7e7b849a464d5cfaf/lib/dslkit/polite.rb#L598-L604
|
9,584
|
cordawyn/redlander
|
lib/redlander/statement.rb
|
Redlander.Statement.subject
|
def subject
if instance_variable_defined?(:@subject)
@subject
else
rdf_node = Redland.librdf_statement_get_subject(rdf_statement)
@subject = rdf_node.null? ? nil : Node.new(rdf_node)
end
end
|
ruby
|
def subject
if instance_variable_defined?(:@subject)
@subject
else
rdf_node = Redland.librdf_statement_get_subject(rdf_statement)
@subject = rdf_node.null? ? nil : Node.new(rdf_node)
end
end
|
[
"def",
"subject",
"if",
"instance_variable_defined?",
"(",
":@subject",
")",
"@subject",
"else",
"rdf_node",
"=",
"Redland",
".",
"librdf_statement_get_subject",
"(",
"rdf_statement",
")",
"@subject",
"=",
"rdf_node",
".",
"null?",
"?",
"nil",
":",
"Node",
".",
"new",
"(",
"rdf_node",
")",
"end",
"end"
] |
Create an RDF statement.
@param [Hash] source
@option source [Node, String, URI, nil] :subject
@option source [Node, String, URI, nil] :predicate
@option source [Node, String, URI, nil] :object
@raise [NotImplementedError] if cannot create a Statement from the given source.
@raise [RedlandError] if it fails to create a Statement.
Subject of the statment.
@return [Node, nil]
|
[
"Create",
"an",
"RDF",
"statement",
"."
] |
a5c84e15a7602c674606e531bda6a616b1237c44
|
https://github.com/cordawyn/redlander/blob/a5c84e15a7602c674606e531bda6a616b1237c44/lib/redlander/statement.rb#L51-L58
|
9,585
|
cordawyn/redlander
|
lib/redlander/statement.rb
|
Redlander.Statement.predicate
|
def predicate
if instance_variable_defined?(:@predicate)
@predicate
else
rdf_node = Redland.librdf_statement_get_predicate(rdf_statement)
@predicate = rdf_node.null? ? nil : Node.new(rdf_node)
end
end
|
ruby
|
def predicate
if instance_variable_defined?(:@predicate)
@predicate
else
rdf_node = Redland.librdf_statement_get_predicate(rdf_statement)
@predicate = rdf_node.null? ? nil : Node.new(rdf_node)
end
end
|
[
"def",
"predicate",
"if",
"instance_variable_defined?",
"(",
":@predicate",
")",
"@predicate",
"else",
"rdf_node",
"=",
"Redland",
".",
"librdf_statement_get_predicate",
"(",
"rdf_statement",
")",
"@predicate",
"=",
"rdf_node",
".",
"null?",
"?",
"nil",
":",
"Node",
".",
"new",
"(",
"rdf_node",
")",
"end",
"end"
] |
Predicate of the statement.
@return [Node, nil]
|
[
"Predicate",
"of",
"the",
"statement",
"."
] |
a5c84e15a7602c674606e531bda6a616b1237c44
|
https://github.com/cordawyn/redlander/blob/a5c84e15a7602c674606e531bda6a616b1237c44/lib/redlander/statement.rb#L63-L70
|
9,586
|
cordawyn/redlander
|
lib/redlander/statement.rb
|
Redlander.Statement.object
|
def object
if instance_variable_defined?(:@object)
@object
else
rdf_node = Redland.librdf_statement_get_object(rdf_statement)
@object = rdf_node.null? ? nil : Node.new(rdf_node)
end
end
|
ruby
|
def object
if instance_variable_defined?(:@object)
@object
else
rdf_node = Redland.librdf_statement_get_object(rdf_statement)
@object = rdf_node.null? ? nil : Node.new(rdf_node)
end
end
|
[
"def",
"object",
"if",
"instance_variable_defined?",
"(",
":@object",
")",
"@object",
"else",
"rdf_node",
"=",
"Redland",
".",
"librdf_statement_get_object",
"(",
"rdf_statement",
")",
"@object",
"=",
"rdf_node",
".",
"null?",
"?",
"nil",
":",
"Node",
".",
"new",
"(",
"rdf_node",
")",
"end",
"end"
] |
Object of the statement.
@return [Node, nil]
|
[
"Object",
"of",
"the",
"statement",
"."
] |
a5c84e15a7602c674606e531bda6a616b1237c44
|
https://github.com/cordawyn/redlander/blob/a5c84e15a7602c674606e531bda6a616b1237c44/lib/redlander/statement.rb#L75-L82
|
9,587
|
cordawyn/redlander
|
lib/redlander/statement.rb
|
Redlander.Statement.rdf_node_from
|
def rdf_node_from(source)
case source
when NilClass
nil
when Node
Redland.librdf_new_node_from_node(source.rdf_node)
else
Redland.librdf_new_node_from_node(Node.new(source).rdf_node)
end
end
|
ruby
|
def rdf_node_from(source)
case source
when NilClass
nil
when Node
Redland.librdf_new_node_from_node(source.rdf_node)
else
Redland.librdf_new_node_from_node(Node.new(source).rdf_node)
end
end
|
[
"def",
"rdf_node_from",
"(",
"source",
")",
"case",
"source",
"when",
"NilClass",
"nil",
"when",
"Node",
"Redland",
".",
"librdf_new_node_from_node",
"(",
"source",
".",
"rdf_node",
")",
"else",
"Redland",
".",
"librdf_new_node_from_node",
"(",
"Node",
".",
"new",
"(",
"source",
")",
".",
"rdf_node",
")",
"end",
"end"
] |
Create a Node from the source
and get its rdf_node, or return nil
@api private
|
[
"Create",
"a",
"Node",
"from",
"the",
"source",
"and",
"get",
"its",
"rdf_node",
"or",
"return",
"nil"
] |
a5c84e15a7602c674606e531bda6a616b1237c44
|
https://github.com/cordawyn/redlander/blob/a5c84e15a7602c674606e531bda6a616b1237c44/lib/redlander/statement.rb#L141-L150
|
9,588
|
xiaoxinghu/datacraft
|
lib/datacraft/runner.rb
|
Datacraft.Runner.run
|
def run(instruction)
@inst = instruction
measurements = []
# run pre_build hooks
if @inst.respond_to? :pre_hooks
measurements << Benchmark.measure('pre build:') do
@inst.pre_hooks.each(&:call)
end
end
# process the rows
measurements << Benchmark.measure('process rows:') do
@inst.options[:parallel] ? pprocess_rows : process_rows
end
# build
measurements << Benchmark.measure('build:') do
build @inst.consumers
end
# run post_build hooks
if @inst.respond_to? :post_hooks
measurements << Benchmark.measure('post build:') do
@inst.post_hooks.each(&:call)
end
end
report measurements if @inst.options[:benchmark]
end
|
ruby
|
def run(instruction)
@inst = instruction
measurements = []
# run pre_build hooks
if @inst.respond_to? :pre_hooks
measurements << Benchmark.measure('pre build:') do
@inst.pre_hooks.each(&:call)
end
end
# process the rows
measurements << Benchmark.measure('process rows:') do
@inst.options[:parallel] ? pprocess_rows : process_rows
end
# build
measurements << Benchmark.measure('build:') do
build @inst.consumers
end
# run post_build hooks
if @inst.respond_to? :post_hooks
measurements << Benchmark.measure('post build:') do
@inst.post_hooks.each(&:call)
end
end
report measurements if @inst.options[:benchmark]
end
|
[
"def",
"run",
"(",
"instruction",
")",
"@inst",
"=",
"instruction",
"measurements",
"=",
"[",
"]",
"# run pre_build hooks",
"if",
"@inst",
".",
"respond_to?",
":pre_hooks",
"measurements",
"<<",
"Benchmark",
".",
"measure",
"(",
"'pre build:'",
")",
"do",
"@inst",
".",
"pre_hooks",
".",
"each",
"(",
":call",
")",
"end",
"end",
"# process the rows",
"measurements",
"<<",
"Benchmark",
".",
"measure",
"(",
"'process rows:'",
")",
"do",
"@inst",
".",
"options",
"[",
":parallel",
"]",
"?",
"pprocess_rows",
":",
"process_rows",
"end",
"# build",
"measurements",
"<<",
"Benchmark",
".",
"measure",
"(",
"'build:'",
")",
"do",
"build",
"@inst",
".",
"consumers",
"end",
"# run post_build hooks",
"if",
"@inst",
".",
"respond_to?",
":post_hooks",
"measurements",
"<<",
"Benchmark",
".",
"measure",
"(",
"'post build:'",
")",
"do",
"@inst",
".",
"post_hooks",
".",
"each",
"(",
":call",
")",
"end",
"end",
"report",
"measurements",
"if",
"@inst",
".",
"options",
"[",
":benchmark",
"]",
"end"
] |
run the instruction
|
[
"run",
"the",
"instruction"
] |
8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107
|
https://github.com/xiaoxinghu/datacraft/blob/8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107/lib/datacraft/runner.rb#L7-L35
|
9,589
|
xiaoxinghu/datacraft
|
lib/datacraft/runner.rb
|
Datacraft.Runner.report
|
def report(measurements)
width = measurements.max_by { |m| m.label.size }.label.size + 1
puts "#{' ' * width}#{Benchmark::CAPTION}"
measurements.each do |m|
puts "#{m.label.to_s.ljust width} #{m}"
end
end
|
ruby
|
def report(measurements)
width = measurements.max_by { |m| m.label.size }.label.size + 1
puts "#{' ' * width}#{Benchmark::CAPTION}"
measurements.each do |m|
puts "#{m.label.to_s.ljust width} #{m}"
end
end
|
[
"def",
"report",
"(",
"measurements",
")",
"width",
"=",
"measurements",
".",
"max_by",
"{",
"|",
"m",
"|",
"m",
".",
"label",
".",
"size",
"}",
".",
"label",
".",
"size",
"+",
"1",
"puts",
"\"#{' ' * width}#{Benchmark::CAPTION}\"",
"measurements",
".",
"each",
"do",
"|",
"m",
"|",
"puts",
"\"#{m.label.to_s.ljust width} #{m}\"",
"end",
"end"
] |
output benchmark results
|
[
"output",
"benchmark",
"results"
] |
8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107
|
https://github.com/xiaoxinghu/datacraft/blob/8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107/lib/datacraft/runner.rb#L40-L46
|
9,590
|
xiaoxinghu/datacraft
|
lib/datacraft/runner.rb
|
Datacraft.Runner.process
|
def process(row)
@inst.tweakers.each do |tweaker|
row = tweaker.tweak row
return nil unless row
end
@inst.consumers.each do |consumer|
consumer << row
end
end
|
ruby
|
def process(row)
@inst.tweakers.each do |tweaker|
row = tweaker.tweak row
return nil unless row
end
@inst.consumers.each do |consumer|
consumer << row
end
end
|
[
"def",
"process",
"(",
"row",
")",
"@inst",
".",
"tweakers",
".",
"each",
"do",
"|",
"tweaker",
"|",
"row",
"=",
"tweaker",
".",
"tweak",
"row",
"return",
"nil",
"unless",
"row",
"end",
"@inst",
".",
"consumers",
".",
"each",
"do",
"|",
"consumer",
"|",
"consumer",
"<<",
"row",
"end",
"end"
] |
tweak & consume one row
|
[
"tweak",
"&",
"consume",
"one",
"row"
] |
8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107
|
https://github.com/xiaoxinghu/datacraft/blob/8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107/lib/datacraft/runner.rb#L58-L66
|
9,591
|
xiaoxinghu/datacraft
|
lib/datacraft/runner.rb
|
Datacraft.Runner.pprocess_rows
|
def pprocess_rows
thread_number = [@inst.sources.size,
@inst.options[:n_threads]].min
queue = Queue.new
@inst.sources.each { |p| queue << p }
threads = thread_number.times.map do
Thread.new do
begin
while p = queue.pop(true)
p.each { |row| process row }
end
rescue ThreadError
end
end
end
threads.each(&:join)
end
|
ruby
|
def pprocess_rows
thread_number = [@inst.sources.size,
@inst.options[:n_threads]].min
queue = Queue.new
@inst.sources.each { |p| queue << p }
threads = thread_number.times.map do
Thread.new do
begin
while p = queue.pop(true)
p.each { |row| process row }
end
rescue ThreadError
end
end
end
threads.each(&:join)
end
|
[
"def",
"pprocess_rows",
"thread_number",
"=",
"[",
"@inst",
".",
"sources",
".",
"size",
",",
"@inst",
".",
"options",
"[",
":n_threads",
"]",
"]",
".",
"min",
"queue",
"=",
"Queue",
".",
"new",
"@inst",
".",
"sources",
".",
"each",
"{",
"|",
"p",
"|",
"queue",
"<<",
"p",
"}",
"threads",
"=",
"thread_number",
".",
"times",
".",
"map",
"do",
"Thread",
".",
"new",
"do",
"begin",
"while",
"p",
"=",
"queue",
".",
"pop",
"(",
"true",
")",
"p",
".",
"each",
"{",
"|",
"row",
"|",
"process",
"row",
"}",
"end",
"rescue",
"ThreadError",
"end",
"end",
"end",
"threads",
".",
"each",
"(",
":join",
")",
"end"
] |
process rows in parallel
|
[
"process",
"rows",
"in",
"parallel"
] |
8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107
|
https://github.com/xiaoxinghu/datacraft/blob/8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107/lib/datacraft/runner.rb#L69-L85
|
9,592
|
xiaoxinghu/datacraft
|
lib/datacraft/runner.rb
|
Datacraft.Runner.build
|
def build(consumers)
consumers.each do |consumer|
consumer.build if consumer.respond_to? :build
consumer.close if consumer.respond_to? :close
end
end
|
ruby
|
def build(consumers)
consumers.each do |consumer|
consumer.build if consumer.respond_to? :build
consumer.close if consumer.respond_to? :close
end
end
|
[
"def",
"build",
"(",
"consumers",
")",
"consumers",
".",
"each",
"do",
"|",
"consumer",
"|",
"consumer",
".",
"build",
"if",
"consumer",
".",
"respond_to?",
":build",
"consumer",
".",
"close",
"if",
"consumer",
".",
"respond_to?",
":close",
"end",
"end"
] |
build and close consumers
|
[
"build",
"and",
"close",
"consumers"
] |
8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107
|
https://github.com/xiaoxinghu/datacraft/blob/8e97ffe9aa3c59f014bee82fb7e1d41d3ce13107/lib/datacraft/runner.rb#L88-L93
|
9,593
|
checkdin/checkdin-ruby
|
lib/checkdin/campaigns.rb
|
Checkdin.Campaigns.campaigns
|
def campaigns(options={})
response = connection.get do |req|
req.url "campaigns", options
end
return_error_or_body(response)
end
|
ruby
|
def campaigns(options={})
response = connection.get do |req|
req.url "campaigns", options
end
return_error_or_body(response)
end
|
[
"def",
"campaigns",
"(",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"connection",
".",
"get",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"\"campaigns\"",
",",
"options",
"end",
"return_error_or_body",
"(",
"response",
")",
"end"
] |
Get a list of all campaigns for the authenticating client.
@param [Hash] options
@option options Integer :limit - The maximum number of records to return.
|
[
"Get",
"a",
"list",
"of",
"all",
"campaigns",
"for",
"the",
"authenticating",
"client",
"."
] |
c3c4b38b0f8c710e1f805100dcf3a70649215b48
|
https://github.com/checkdin/checkdin-ruby/blob/c3c4b38b0f8c710e1f805100dcf3a70649215b48/lib/checkdin/campaigns.rb#L18-L23
|
9,594
|
kcierzan/Clea
|
lib/clea.rb
|
Clea.Sender.get_sender_alias
|
def get_sender_alias
puts "What is your name?"
while @from_alias = gets.chomp
catch :badalias do
puts "Are you sure your name is #{@from_alias}? [y/n]:"
while alias_confirmation = gets.chomp
case alias_confirmation
when 'y'
return
else
puts "Please re-enter your name:"
throw :badalias
end
end
end
end
end
|
ruby
|
def get_sender_alias
puts "What is your name?"
while @from_alias = gets.chomp
catch :badalias do
puts "Are you sure your name is #{@from_alias}? [y/n]:"
while alias_confirmation = gets.chomp
case alias_confirmation
when 'y'
return
else
puts "Please re-enter your name:"
throw :badalias
end
end
end
end
end
|
[
"def",
"get_sender_alias",
"puts",
"\"What is your name?\"",
"while",
"@from_alias",
"=",
"gets",
".",
"chomp",
"catch",
":badalias",
"do",
"puts",
"\"Are you sure your name is #{@from_alias}? [y/n]:\"",
"while",
"alias_confirmation",
"=",
"gets",
".",
"chomp",
"case",
"alias_confirmation",
"when",
"'y'",
"return",
"else",
"puts",
"\"Please re-enter your name:\"",
"throw",
":badalias",
"end",
"end",
"end",
"end",
"end"
] |
Get user's alias and confirm
|
[
"Get",
"user",
"s",
"alias",
"and",
"confirm"
] |
ebfa0426b139cb029e69dff1058f621bed1c8459
|
https://github.com/kcierzan/Clea/blob/ebfa0426b139cb029e69dff1058f621bed1c8459/lib/clea.rb#L16-L32
|
9,595
|
kcierzan/Clea
|
lib/clea.rb
|
Clea.Sender.get_sender_gmail
|
def get_sender_gmail
puts "Enter your gmail address:"
while @from_address = gets.chomp
catch :badfrom do
if ValidateEmail.validate(@from_address) == true
puts "Is your email address #{@from_address}? [y/n]:"
while address_confirmation = gets.chomp
case address_confirmation
when 'y'
return
else
puts "Please re-enter your gmail address:"
throw :badfrom
end
end
else
puts "Email invalid! Please enter a valid email address:"
end
end
end
end
|
ruby
|
def get_sender_gmail
puts "Enter your gmail address:"
while @from_address = gets.chomp
catch :badfrom do
if ValidateEmail.validate(@from_address) == true
puts "Is your email address #{@from_address}? [y/n]:"
while address_confirmation = gets.chomp
case address_confirmation
when 'y'
return
else
puts "Please re-enter your gmail address:"
throw :badfrom
end
end
else
puts "Email invalid! Please enter a valid email address:"
end
end
end
end
|
[
"def",
"get_sender_gmail",
"puts",
"\"Enter your gmail address:\"",
"while",
"@from_address",
"=",
"gets",
".",
"chomp",
"catch",
":badfrom",
"do",
"if",
"ValidateEmail",
".",
"validate",
"(",
"@from_address",
")",
"==",
"true",
"puts",
"\"Is your email address #{@from_address}? [y/n]:\"",
"while",
"address_confirmation",
"=",
"gets",
".",
"chomp",
"case",
"address_confirmation",
"when",
"'y'",
"return",
"else",
"puts",
"\"Please re-enter your gmail address:\"",
"throw",
":badfrom",
"end",
"end",
"else",
"puts",
"\"Email invalid! Please enter a valid email address:\"",
"end",
"end",
"end",
"end"
] |
Get, validate, and confirm user's email address
|
[
"Get",
"validate",
"and",
"confirm",
"user",
"s",
"email",
"address"
] |
ebfa0426b139cb029e69dff1058f621bed1c8459
|
https://github.com/kcierzan/Clea/blob/ebfa0426b139cb029e69dff1058f621bed1c8459/lib/clea.rb#L35-L55
|
9,596
|
kcierzan/Clea
|
lib/clea.rb
|
Clea.Sender.get_sender_password
|
def get_sender_password
puts "Enter your password:"
while @password = gets.chomp
catch :badpass do
puts "Are you sure your password is #{@password}? [y/n]:"
while pass_confirmation = gets.chomp
case pass_confirmation
when 'y'
return
else
puts "Please re-enter your password:"
throw :badpass
end
end
end
end
end
|
ruby
|
def get_sender_password
puts "Enter your password:"
while @password = gets.chomp
catch :badpass do
puts "Are you sure your password is #{@password}? [y/n]:"
while pass_confirmation = gets.chomp
case pass_confirmation
when 'y'
return
else
puts "Please re-enter your password:"
throw :badpass
end
end
end
end
end
|
[
"def",
"get_sender_password",
"puts",
"\"Enter your password:\"",
"while",
"@password",
"=",
"gets",
".",
"chomp",
"catch",
":badpass",
"do",
"puts",
"\"Are you sure your password is #{@password}? [y/n]:\"",
"while",
"pass_confirmation",
"=",
"gets",
".",
"chomp",
"case",
"pass_confirmation",
"when",
"'y'",
"return",
"else",
"puts",
"\"Please re-enter your password:\"",
"throw",
":badpass",
"end",
"end",
"end",
"end",
"end"
] |
Get and confirm user's password
|
[
"Get",
"and",
"confirm",
"user",
"s",
"password"
] |
ebfa0426b139cb029e69dff1058f621bed1c8459
|
https://github.com/kcierzan/Clea/blob/ebfa0426b139cb029e69dff1058f621bed1c8459/lib/clea.rb#L58-L74
|
9,597
|
kcierzan/Clea
|
lib/clea.rb
|
Clea.Sender.get_recipient_data
|
def get_recipient_data
puts "Enter the recipient's email address:"
while @to_address = gets.chomp
catch :badto do
if ValidateEmail.validate(@to_address) == true
puts "Is the recipient's email address #{@to_address}? [y/n]:"
while to_address_confirmation = gets.chomp
case to_address_confirmation
when 'y'
return
else
puts "Please re-enter the recipient's email address:"
throw :badto
end
end
else
puts "Email invalid! Please enter a valid email address:"
end
end
end
end
|
ruby
|
def get_recipient_data
puts "Enter the recipient's email address:"
while @to_address = gets.chomp
catch :badto do
if ValidateEmail.validate(@to_address) == true
puts "Is the recipient's email address #{@to_address}? [y/n]:"
while to_address_confirmation = gets.chomp
case to_address_confirmation
when 'y'
return
else
puts "Please re-enter the recipient's email address:"
throw :badto
end
end
else
puts "Email invalid! Please enter a valid email address:"
end
end
end
end
|
[
"def",
"get_recipient_data",
"puts",
"\"Enter the recipient's email address:\"",
"while",
"@to_address",
"=",
"gets",
".",
"chomp",
"catch",
":badto",
"do",
"if",
"ValidateEmail",
".",
"validate",
"(",
"@to_address",
")",
"==",
"true",
"puts",
"\"Is the recipient's email address #{@to_address}? [y/n]:\"",
"while",
"to_address_confirmation",
"=",
"gets",
".",
"chomp",
"case",
"to_address_confirmation",
"when",
"'y'",
"return",
"else",
"puts",
"\"Please re-enter the recipient's email address:\"",
"throw",
":badto",
"end",
"end",
"else",
"puts",
"\"Email invalid! Please enter a valid email address:\"",
"end",
"end",
"end",
"end"
] |
Get, validate, and confirm the recipient's email address. This data does not persist.
|
[
"Get",
"validate",
"and",
"confirm",
"the",
"recipient",
"s",
"email",
"address",
".",
"This",
"data",
"does",
"not",
"persist",
"."
] |
ebfa0426b139cb029e69dff1058f621bed1c8459
|
https://github.com/kcierzan/Clea/blob/ebfa0426b139cb029e69dff1058f621bed1c8459/lib/clea.rb#L86-L106
|
9,598
|
kcierzan/Clea
|
lib/clea.rb
|
Clea.Sender.send_message
|
def send_message
# Read the user's password from the persistent hash
stored_password = @sender_info.transaction { @sender_info[:password] }
# Initialize the gmail SMTP connection and upgrade to SSL/TLS
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls
# Open SMTP connection, send message, close the connection
smtp.start('gmail.com', @stored_from_address, stored_password, :login) do
smtp.send_message(@msg, @_stored_from_address, @to_address)
end
end
|
ruby
|
def send_message
# Read the user's password from the persistent hash
stored_password = @sender_info.transaction { @sender_info[:password] }
# Initialize the gmail SMTP connection and upgrade to SSL/TLS
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls
# Open SMTP connection, send message, close the connection
smtp.start('gmail.com', @stored_from_address, stored_password, :login) do
smtp.send_message(@msg, @_stored_from_address, @to_address)
end
end
|
[
"def",
"send_message",
"# Read the user's password from the persistent hash",
"stored_password",
"=",
"@sender_info",
".",
"transaction",
"{",
"@sender_info",
"[",
":password",
"]",
"}",
"# Initialize the gmail SMTP connection and upgrade to SSL/TLS",
"smtp",
"=",
"Net",
"::",
"SMTP",
".",
"new",
"(",
"'smtp.gmail.com'",
",",
"587",
")",
"smtp",
".",
"enable_starttls",
"# Open SMTP connection, send message, close the connection",
"smtp",
".",
"start",
"(",
"'gmail.com'",
",",
"@stored_from_address",
",",
"stored_password",
",",
":login",
")",
"do",
"smtp",
".",
"send_message",
"(",
"@msg",
",",
"@_stored_from_address",
",",
"@to_address",
")",
"end",
"end"
] |
Open SMTP connection, pass user info as arguments, send message and close connection
|
[
"Open",
"SMTP",
"connection",
"pass",
"user",
"info",
"as",
"arguments",
"send",
"message",
"and",
"close",
"connection"
] |
ebfa0426b139cb029e69dff1058f621bed1c8459
|
https://github.com/kcierzan/Clea/blob/ebfa0426b139cb029e69dff1058f621bed1c8459/lib/clea.rb#L132-L142
|
9,599
|
amardaxini/socketlab
|
lib/socketlab/socketklab_request.rb
|
Socketlab.SocketlabRequest.set_response
|
def set_response(item_class_name)
if @api_response.success?
@total_count = @api_response["totalCount"]
@total_pages = @api_response["totalPages"]
@count = @api_response["count"]
@timestamp = @api_response["timestamp"]
@items = []
unless @api_response["collection"].nil?
@api_response["collection"].each do |attr_item|
item = item_class_name.new
item.set_item(attr_item)
@items << item
end
end
else
@error = @api_response.parsed_response
end
end
|
ruby
|
def set_response(item_class_name)
if @api_response.success?
@total_count = @api_response["totalCount"]
@total_pages = @api_response["totalPages"]
@count = @api_response["count"]
@timestamp = @api_response["timestamp"]
@items = []
unless @api_response["collection"].nil?
@api_response["collection"].each do |attr_item|
item = item_class_name.new
item.set_item(attr_item)
@items << item
end
end
else
@error = @api_response.parsed_response
end
end
|
[
"def",
"set_response",
"(",
"item_class_name",
")",
"if",
"@api_response",
".",
"success?",
"@total_count",
"=",
"@api_response",
"[",
"\"totalCount\"",
"]",
"@total_pages",
"=",
"@api_response",
"[",
"\"totalPages\"",
"]",
"@count",
"=",
"@api_response",
"[",
"\"count\"",
"]",
"@timestamp",
"=",
"@api_response",
"[",
"\"timestamp\"",
"]",
"@items",
"=",
"[",
"]",
"unless",
"@api_response",
"[",
"\"collection\"",
"]",
".",
"nil?",
"@api_response",
"[",
"\"collection\"",
"]",
".",
"each",
"do",
"|",
"attr_item",
"|",
"item",
"=",
"item_class_name",
".",
"new",
"item",
".",
"set_item",
"(",
"attr_item",
")",
"@items",
"<<",
"item",
"end",
"end",
"else",
"@error",
"=",
"@api_response",
".",
"parsed_response",
"end",
"end"
] |
Assuming type is json
|
[
"Assuming",
"type",
"is",
"json"
] |
5f27350898d33b558c73a9685ef67bae39b857b6
|
https://github.com/amardaxini/socketlab/blob/5f27350898d33b558c73a9685ef67bae39b857b6/lib/socketlab/socketklab_request.rb#L31-L48
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.