repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
stvvan/hoiio-ruby | lib/hoiio-ruby/util/response_util.rb | Hoiio.ResponseUtil.create_hash | def create_hash(response)
begin
JSON.parse response
rescue JSON::ParserError
response
rescue StandardError
response
end
end | ruby | def create_hash(response)
begin
JSON.parse response
rescue JSON::ParserError
response
rescue StandardError
response
end
end | [
"def",
"create_hash",
"(",
"response",
")",
"begin",
"JSON",
".",
"parse",
"response",
"rescue",
"JSON",
"::",
"ParserError",
"response",
"rescue",
"StandardError",
"response",
"end",
"end"
] | Create a Hash from a JSON response
@param response response of Hoiio API
@return response parsed as a Hash | [
"Create",
"a",
"Hash",
"from",
"a",
"JSON",
"response"
] | 7f6840b94c5f61c221619ca069bc008d502dd339 | https://github.com/stvvan/hoiio-ruby/blob/7f6840b94c5f61c221619ca069bc008d502dd339/lib/hoiio-ruby/util/response_util.rb#L48-L56 | train |
metanorma/gb-agencies | lib/gb_agencies/gb_agencies.rb | GbAgencies.Agencies.standard_agency1 | def standard_agency1(scope, prefix, mandate)
case scope
when "national"
ret = NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
:admin) || nil
ret = ret.join(" ") if ret && ret.is_a?(Array)
ret
when "sector"
SECTOR&.dig(@lang, p... | ruby | def standard_agency1(scope, prefix, mandate)
case scope
when "national"
ret = NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
:admin) || nil
ret = ret.join(" ") if ret && ret.is_a?(Array)
ret
when "sector"
SECTOR&.dig(@lang, p... | [
"def",
"standard_agency1",
"(",
"scope",
",",
"prefix",
",",
"mandate",
")",
"case",
"scope",
"when",
"\"national\"",
"ret",
"=",
"NATIONAL",
"&.",
"dig",
"(",
"@lang",
",",
"gb_mandate_suffix",
"(",
"prefix",
",",
"mandate",
")",
".",
"to_sym",
",",
":adm... | return agency name as single string | [
"return",
"agency",
"name",
"as",
"single",
"string"
] | 3840dcdcb8dd4b88f40542a3b3ee8931e065fac0 | https://github.com/metanorma/gb-agencies/blob/3840dcdcb8dd4b88f40542a3b3ee8931e065fac0/lib/gb_agencies/gb_agencies.rb#L287-L302 | train |
metanorma/gb-agencies | lib/gb_agencies/gb_agencies.rb | GbAgencies.Agencies.standard_agency | def standard_agency(scope, prefix, mandate)
case scope
when "national"
NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
:admin) || nil
when "sector"
SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil
when "local"
"#{LOCAL&.dig(@lang, pre... | ruby | def standard_agency(scope, prefix, mandate)
case scope
when "national"
NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
:admin) || nil
when "sector"
SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil
when "local"
"#{LOCAL&.dig(@lang, pre... | [
"def",
"standard_agency",
"(",
"scope",
",",
"prefix",
",",
"mandate",
")",
"case",
"scope",
"when",
"\"national\"",
"NATIONAL",
"&.",
"dig",
"(",
"@lang",
",",
"gb_mandate_suffix",
"(",
"prefix",
",",
"mandate",
")",
".",
"to_sym",
",",
":admin",
")",
"||... | return agency name, allowing arrays in output | [
"return",
"agency",
"name",
"allowing",
"arrays",
"in",
"output"
] | 3840dcdcb8dd4b88f40542a3b3ee8931e065fac0 | https://github.com/metanorma/gb-agencies/blob/3840dcdcb8dd4b88f40542a3b3ee8931e065fac0/lib/gb_agencies/gb_agencies.rb#L305-L318 | train |
Pluvie/rails-scheduler | lib/scheduler/main_process.rb | Scheduler.MainProcess.start_loop | def start_loop
loop do
begin
# Loads up a job queue.
queue = []
# Counts jobs to schedule.
running_jobs = @job_class.running.entries
schedulable_jobs = @job_class.queued.order_by(scheduled_at: :asc).entries
jobs_to_schedule = @max_conc... | ruby | def start_loop
loop do
begin
# Loads up a job queue.
queue = []
# Counts jobs to schedule.
running_jobs = @job_class.running.entries
schedulable_jobs = @job_class.queued.order_by(scheduled_at: :asc).entries
jobs_to_schedule = @max_conc... | [
"def",
"start_loop",
"loop",
"do",
"begin",
"queue",
"=",
"[",
"]",
"running_jobs",
"=",
"@job_class",
".",
"running",
".",
"entries",
"schedulable_jobs",
"=",
"@job_class",
".",
"queued",
".",
"order_by",
"(",
"scheduled_at",
":",
":asc",
")",
".",
"entries... | Creates a MainProcess which keeps running
and continuously checks if new jobs are queued.
@return [Scheduler::MainProcess] the created MainProcess.
Main loop.
@return [nil] | [
"Creates",
"a",
"MainProcess",
"which",
"keeps",
"running",
"and",
"continuously",
"checks",
"if",
"new",
"jobs",
"are",
"queued",
"."
] | 9421c6f1465ae93780e5177b20ac613a6bbd5b9c | https://github.com/Pluvie/rails-scheduler/blob/9421c6f1465ae93780e5177b20ac613a6bbd5b9c/lib/scheduler/main_process.rb#L50-L118 | train |
Pluvie/rails-scheduler | lib/scheduler/main_process.rb | Scheduler.MainProcess.reschedule_running_jobs | def reschedule_running_jobs
@job_class.running.each do |job|
begin
Process.kill :QUIT, job.pid if job.pid.present?
rescue Errno::ESRCH, Errno::EPERM
ensure
job.schedule
end
end
end | ruby | def reschedule_running_jobs
@job_class.running.each do |job|
begin
Process.kill :QUIT, job.pid if job.pid.present?
rescue Errno::ESRCH, Errno::EPERM
ensure
job.schedule
end
end
end | [
"def",
"reschedule_running_jobs",
"@job_class",
".",
"running",
".",
"each",
"do",
"|",
"job",
"|",
"begin",
"Process",
".",
"kill",
":QUIT",
",",
"job",
".",
"pid",
"if",
"job",
".",
"pid",
".",
"present?",
"rescue",
"Errno",
"::",
"ESRCH",
",",
"Errno"... | Reschedules currently running jobs.
@return [nil] | [
"Reschedules",
"currently",
"running",
"jobs",
"."
] | 9421c6f1465ae93780e5177b20ac613a6bbd5b9c | https://github.com/Pluvie/rails-scheduler/blob/9421c6f1465ae93780e5177b20ac613a6bbd5b9c/lib/scheduler/main_process.rb#L124-L133 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.device_data | def device_data
JSON.parse(ENV['DEVICES']).find { |t| t['thread'].eql? thread } unless ENV['DEVICES'].nil?
end | ruby | def device_data
JSON.parse(ENV['DEVICES']).find { |t| t['thread'].eql? thread } unless ENV['DEVICES'].nil?
end | [
"def",
"device_data",
"JSON",
".",
"parse",
"(",
"ENV",
"[",
"'DEVICES'",
"]",
")",
".",
"find",
"{",
"|",
"t",
"|",
"t",
"[",
"'thread'",
"]",
".",
"eql?",
"thread",
"}",
"unless",
"ENV",
"[",
"'DEVICES'",
"]",
".",
"nil?",
"end"
] | Get the device data from the DEVICES environment variable | [
"Get",
"the",
"device",
"data",
"from",
"the",
"DEVICES",
"environment",
"variable"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L10-L12 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.save_device_data | def save_device_data(dev_array)
dev_array.each do |device|
device_hash = {}
device.each do |key, value|
device_hash[key] = value
end
# Delete and create output folder
`rm -rf output`
`mkdir output`
device.each do |k, v|
open("output/spe... | ruby | def save_device_data(dev_array)
dev_array.each do |device|
device_hash = {}
device.each do |key, value|
device_hash[key] = value
end
# Delete and create output folder
`rm -rf output`
`mkdir output`
device.each do |k, v|
open("output/spe... | [
"def",
"save_device_data",
"(",
"dev_array",
")",
"dev_array",
".",
"each",
"do",
"|",
"device",
"|",
"device_hash",
"=",
"{",
"}",
"device",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"device_hash",
"[",
"key",
"]",
"=",
"value",
"end",
"`",
... | Save device specifications to output directory | [
"Save",
"device",
"specifications",
"to",
"output",
"directory"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L15-L32 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.get_devices | def get_devices(platform)
ENV['THREADS'] = '1' if ENV['THREADS'].nil?
if platform == 'android'
Android.new.devices
elsif platform == 'ios'
IOS.new.devices
end
end | ruby | def get_devices(platform)
ENV['THREADS'] = '1' if ENV['THREADS'].nil?
if platform == 'android'
Android.new.devices
elsif platform == 'ios'
IOS.new.devices
end
end | [
"def",
"get_devices",
"(",
"platform",
")",
"ENV",
"[",
"'THREADS'",
"]",
"=",
"'1'",
"if",
"ENV",
"[",
"'THREADS'",
"]",
".",
"nil?",
"if",
"platform",
"==",
"'android'",
"Android",
".",
"new",
".",
"devices",
"elsif",
"platform",
"==",
"'ios'",
"IOS",
... | Get the device information for the respective platform | [
"Get",
"the",
"device",
"information",
"for",
"the",
"respective",
"platform"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L41-L48 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.appium_server_start | def appium_server_start(**options)
command = +'appium'
command << " --nodeconfig #{options[:config]}" if options.key?(:config)
command << " -p #{options[:port]}" if options.key?(:port)
command << " -bp #{options[:bp]}" if options.key?(:bp)
command << " --log #{Dir.pwd}/output/#{options[:lo... | ruby | def appium_server_start(**options)
command = +'appium'
command << " --nodeconfig #{options[:config]}" if options.key?(:config)
command << " -p #{options[:port]}" if options.key?(:port)
command << " -bp #{options[:bp]}" if options.key?(:bp)
command << " --log #{Dir.pwd}/output/#{options[:lo... | [
"def",
"appium_server_start",
"(",
"**",
"options",
")",
"command",
"=",
"+",
"'appium'",
"command",
"<<",
"\" --nodeconfig #{options[:config]}\"",
"if",
"options",
".",
"key?",
"(",
":config",
")",
"command",
"<<",
"\" -p #{options[:port]}\"",
"if",
"options",
".",... | Start the appium server with the specified options | [
"Start",
"the",
"appium",
"server",
"with",
"the",
"specified",
"options"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L51-L66 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.generate_node_config | def generate_node_config(file_name, appium_port, device)
system 'mkdir node_configs >> /dev/null 2>&1'
f = File.new("#{Dir.pwd}/node_configs/#{file_name}", 'w')
f.write(JSON.generate(
capabilities: [{ browserName: device[:udid], maxInstances: 5, platform: device[:platform] }],
... | ruby | def generate_node_config(file_name, appium_port, device)
system 'mkdir node_configs >> /dev/null 2>&1'
f = File.new("#{Dir.pwd}/node_configs/#{file_name}", 'w')
f.write(JSON.generate(
capabilities: [{ browserName: device[:udid], maxInstances: 5, platform: device[:platform] }],
... | [
"def",
"generate_node_config",
"(",
"file_name",
",",
"appium_port",
",",
"device",
")",
"system",
"'mkdir node_configs >> /dev/null 2>&1'",
"f",
"=",
"File",
".",
"new",
"(",
"\"#{Dir.pwd}/node_configs/#{file_name}\"",
",",
"'w'",
")",
"f",
".",
"write",
"(",
"JSON... | Generate node config for sellenium grid | [
"Generate",
"node",
"config",
"for",
"sellenium",
"grid"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L69-L87 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.start_single_appium | def start_single_appium(platform, port)
puts 'Getting Device data'
devices = get_devices(platform)[0]
if devices.nil?
puts "No devices for #{platform}, Exiting..."
exit
else
udid = devices[:udid]
save_device_data [devices]
end
ENV['UDID'] = udid
... | ruby | def start_single_appium(platform, port)
puts 'Getting Device data'
devices = get_devices(platform)[0]
if devices.nil?
puts "No devices for #{platform}, Exiting..."
exit
else
udid = devices[:udid]
save_device_data [devices]
end
ENV['UDID'] = udid
... | [
"def",
"start_single_appium",
"(",
"platform",
",",
"port",
")",
"puts",
"'Getting Device data'",
"devices",
"=",
"get_devices",
"(",
"platform",
")",
"[",
"0",
"]",
"if",
"devices",
".",
"nil?",
"puts",
"\"No devices for #{platform}, Exiting...\"",
"exit",
"else",
... | Start an appium server or the platform on the specified port | [
"Start",
"an",
"appium",
"server",
"or",
"the",
"platform",
"on",
"the",
"specified",
"port"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L97-L109 | train |
JavonDavis/parallel_appium | lib/parallel_appium/server.rb | ParallelAppium.Server.launch_hub_and_nodes | def launch_hub_and_nodes(platform)
start_hub unless port_open?('localhost', 4444)
devices = get_devices(platform)
if devices.nil?
puts "No devices for #{platform}, Exiting...."
exit
else
save_device_data [devices]
end
threads = ENV['THREADS'].to_i
if d... | ruby | def launch_hub_and_nodes(platform)
start_hub unless port_open?('localhost', 4444)
devices = get_devices(platform)
if devices.nil?
puts "No devices for #{platform}, Exiting...."
exit
else
save_device_data [devices]
end
threads = ENV['THREADS'].to_i
if d... | [
"def",
"launch_hub_and_nodes",
"(",
"platform",
")",
"start_hub",
"unless",
"port_open?",
"(",
"'localhost'",
",",
"4444",
")",
"devices",
"=",
"get_devices",
"(",
"platform",
")",
"if",
"devices",
".",
"nil?",
"puts",
"\"No devices for #{platform}, Exiting....\"",
... | Launch the Selenium grid hub and required appium instances | [
"Launch",
"the",
"Selenium",
"grid",
"hub",
"and",
"required",
"appium",
"instances"
] | 2e92bf6f4cf6142909080f471dda196ee12c41ea | https://github.com/JavonDavis/parallel_appium/blob/2e92bf6f4cf6142909080f471dda196ee12c41ea/lib/parallel_appium/server.rb#L130-L162 | train |
trisrael/mindbody | lib/mindbody/service.rb | Mb.Service.build_request | def build_request(options = {})
src_creds_name = SRC_CREDS
options = options.dup #Don't clobber the original hash
#NOTE: Could extend this to read WSDL document or using Savon client to tell which nodes are allowed in the request
#performing the same type of test against passed in variables on each an... | ruby | def build_request(options = {})
src_creds_name = SRC_CREDS
options = options.dup #Don't clobber the original hash
#NOTE: Could extend this to read WSDL document or using Savon client to tell which nodes are allowed in the request
#performing the same type of test against passed in variables on each an... | [
"def",
"build_request",
"(",
"options",
"=",
"{",
"}",
")",
"src_creds_name",
"=",
"SRC_CREDS",
"options",
"=",
"options",
".",
"dup",
"final_opts",
"=",
"options",
".",
"dup",
"options",
".",
"keys",
".",
"each",
"do",
"|",
"key",
"|",
"orig_key",
"=",
... | Builds the inner XML of the Mindbody SOAP call | [
"Builds",
"the",
"inner",
"XML",
"of",
"the",
"Mindbody",
"SOAP",
"call"
] | 3adc8dd4ab09bf74ffc9155f036629edbbbe1dad | https://github.com/trisrael/mindbody/blob/3adc8dd4ab09bf74ffc9155f036629edbbbe1dad/lib/mindbody/service.rb#L58-L107 | train |
trisrael/mindbody | lib/mindbody/service.rb | Mb.Service.get_service | def get_service(service_symbol, options, unwrap_bool)
raise "No SOAP client instantiated" unless @client
request_options = build_request(options)
raise "No SourceCredentials supplied" if !@src_creds || !request_options[SRC_CREDS] #Just checking for :source_credentials does not
#check all possiblities ... | ruby | def get_service(service_symbol, options, unwrap_bool)
raise "No SOAP client instantiated" unless @client
request_options = build_request(options)
raise "No SourceCredentials supplied" if !@src_creds || !request_options[SRC_CREDS] #Just checking for :source_credentials does not
#check all possiblities ... | [
"def",
"get_service",
"(",
"service_symbol",
",",
"options",
",",
"unwrap_bool",
")",
"raise",
"\"No SOAP client instantiated\"",
"unless",
"@client",
"request_options",
"=",
"build_request",
"(",
"options",
")",
"raise",
"\"No SourceCredentials supplied\"",
"if",
"!",
... | Build a Mindbody SOAP request for the given service | [
"Build",
"a",
"Mindbody",
"SOAP",
"request",
"for",
"the",
"given",
"service"
] | 3adc8dd4ab09bf74ffc9155f036629edbbbe1dad | https://github.com/trisrael/mindbody/blob/3adc8dd4ab09bf74ffc9155f036629edbbbe1dad/lib/mindbody/service.rb#L110-L137 | train |
Bweeb/malcolm | lib/malcolm/response/soap_parser.rb | Malcolm.SOAPParser.on_complete | def on_complete(env)
env[:body] = Nori.new(
strip_namespaces: true,
convert_tags_to: ->(tag) { tag.snakecase.to_sym }
).parse(env[:body])
raise SOAPError, "Invalid SOAP response" if env[:body].empty?
env[:body] = env[:body][:envelope][:body]
env[:body] = find_key_in_hash(... | ruby | def on_complete(env)
env[:body] = Nori.new(
strip_namespaces: true,
convert_tags_to: ->(tag) { tag.snakecase.to_sym }
).parse(env[:body])
raise SOAPError, "Invalid SOAP response" if env[:body].empty?
env[:body] = env[:body][:envelope][:body]
env[:body] = find_key_in_hash(... | [
"def",
"on_complete",
"(",
"env",
")",
"env",
"[",
":body",
"]",
"=",
"Nori",
".",
"new",
"(",
"strip_namespaces",
":",
"true",
",",
"convert_tags_to",
":",
"->",
"(",
"tag",
")",
"{",
"tag",
".",
"snakecase",
".",
"to_sym",
"}",
")",
".",
"parse",
... | Expects response XML to already be parsed | [
"Expects",
"response",
"XML",
"to",
"already",
"be",
"parsed"
] | 8a6253ec72a6c15a25fb765d4fceb4d0ede165e7 | https://github.com/Bweeb/malcolm/blob/8a6253ec72a6c15a25fb765d4fceb4d0ede165e7/lib/malcolm/response/soap_parser.rb#L10-L20 | train |
Bweeb/malcolm | lib/malcolm/response/soap_parser.rb | Malcolm.SOAPParser.find_key_in_hash | def find_key_in_hash(hash, index)
hash.each do |key, val|
if val.respond_to? :has_key?
if val.has_key? index
return val[index]
else
return find_key_in_hash val, index
end
else
val
end
end
end | ruby | def find_key_in_hash(hash, index)
hash.each do |key, val|
if val.respond_to? :has_key?
if val.has_key? index
return val[index]
else
return find_key_in_hash val, index
end
else
val
end
end
end | [
"def",
"find_key_in_hash",
"(",
"hash",
",",
"index",
")",
"hash",
".",
"each",
"do",
"|",
"key",
",",
"val",
"|",
"if",
"val",
".",
"respond_to?",
":has_key?",
"if",
"val",
".",
"has_key?",
"index",
"return",
"val",
"[",
"index",
"]",
"else",
"return"... | Finds +index+ in +hash+ by searching recursively
@param [Hash] hash
The hash to search
@param index
The hash key to look for | [
"Finds",
"+",
"index",
"+",
"in",
"+",
"hash",
"+",
"by",
"searching",
"recursively"
] | 8a6253ec72a6c15a25fb765d4fceb4d0ede165e7 | https://github.com/Bweeb/malcolm/blob/8a6253ec72a6c15a25fb765d4fceb4d0ede165e7/lib/malcolm/response/soap_parser.rb#L31-L43 | train |
jaymcgavren/zyps | lib/zyps.rb | Zyps.GameObject.<< | def <<(item)
if item.kind_of? Zyps::Location
self.location = item
elsif item.kind_of? Zyps::Color
self.color = item
elsif item.kind_of? Zyps::Vector
self.vector = item
else
raise "Invalid item: #{item.class}"
end
self
end | ruby | def <<(item)
if item.kind_of? Zyps::Location
self.location = item
elsif item.kind_of? Zyps::Color
self.color = item
elsif item.kind_of? Zyps::Vector
self.vector = item
else
raise "Invalid item: #{item.class}"
end
self
end | [
"def",
"<<",
"(",
"item",
")",
"if",
"item",
".",
"kind_of?",
"Zyps",
"::",
"Location",
"self",
".",
"location",
"=",
"item",
"elsif",
"item",
".",
"kind_of?",
"Zyps",
"::",
"Color",
"self",
".",
"color",
"=",
"item",
"elsif",
"item",
".",
"kind_of?",
... | Overloads the << operator to put the new item into the correct
list or assign it to the correct attribute.
Assignment is done based on item's class or a parent class of item. | [
"Overloads",
"the",
"<<",
"operator",
"to",
"put",
"the",
"new",
"item",
"into",
"the",
"correct",
"list",
"or",
"assign",
"it",
"to",
"the",
"correct",
"attribute",
".",
"Assignment",
"is",
"done",
"based",
"on",
"item",
"s",
"class",
"or",
"a",
"parent... | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps.rb#L270-L281 | train |
jaymcgavren/zyps | lib/zyps.rb | Zyps.Behavior.<< | def <<(item)
if item.kind_of? Condition
add_condition(item)
elsif item.kind_of? Action
add_action(item)
else
raise "Invalid item: #{item.class}"
end
self
end | ruby | def <<(item)
if item.kind_of? Condition
add_condition(item)
elsif item.kind_of? Action
add_action(item)
else
raise "Invalid item: #{item.class}"
end
self
end | [
"def",
"<<",
"(",
"item",
")",
"if",
"item",
".",
"kind_of?",
"Condition",
"add_condition",
"(",
"item",
")",
"elsif",
"item",
".",
"kind_of?",
"Action",
"add_action",
"(",
"item",
")",
"else",
"raise",
"\"Invalid item: #{item.class}\"",
"end",
"self",
"end"
] | True if all attributes, actions and conditions are the same.
Overloads the << operator to put the new item into the correct
list or assign it to the correct attribute.
Assignment is done based on item's class or a parent class of item. | [
"True",
"if",
"all",
"attributes",
"actions",
"and",
"conditions",
"are",
"the",
"same",
".",
"Overloads",
"the",
"<<",
"operator",
"to",
"put",
"the",
"new",
"item",
"into",
"the",
"correct",
"list",
"or",
"assign",
"it",
"to",
"the",
"correct",
"attribut... | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps.rb#L599-L608 | train |
jaymcgavren/zyps | lib/zyps.rb | Zyps.Vector.+ | def +(vector2)
#Get the x and y components of the new vector.
new_x = (self.x + vector2.x)
new_y = (self.y + vector2.y)
new_length_squared = new_x ** 2 + new_y ** 2
new_length = (new_length_squared == 0 ? 0 : Math.sqrt(new_length_squared))
new_angle = (new_x == 0 ? 0 : Utility.to_degrees(Math.at... | ruby | def +(vector2)
#Get the x and y components of the new vector.
new_x = (self.x + vector2.x)
new_y = (self.y + vector2.y)
new_length_squared = new_x ** 2 + new_y ** 2
new_length = (new_length_squared == 0 ? 0 : Math.sqrt(new_length_squared))
new_angle = (new_x == 0 ? 0 : Utility.to_degrees(Math.at... | [
"def",
"+",
"(",
"vector2",
")",
"new_x",
"=",
"(",
"self",
".",
"x",
"+",
"vector2",
".",
"x",
")",
"new_y",
"=",
"(",
"self",
".",
"y",
"+",
"vector2",
".",
"y",
")",
"new_length_squared",
"=",
"new_x",
"**",
"2",
"+",
"new_y",
"**",
"2",
"ne... | Add this Vector to vector2, returning a new Vector.
This operation is useful when calculating the effect of wind or thrust on an object's current heading. | [
"Add",
"this",
"Vector",
"to",
"vector2",
"returning",
"a",
"new",
"Vector",
".",
"This",
"operation",
"is",
"useful",
"when",
"calculating",
"the",
"effect",
"of",
"wind",
"or",
"thrust",
"on",
"an",
"object",
"s",
"current",
"heading",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps.rb#L765-L774 | train |
faradayio/charisma | lib/charisma/measurement.rb | Charisma.Measurement.method_missing | def method_missing(*args)
if Conversions.conversions[units.to_sym][args.first]
to_f.send(units.to_sym).to(args.first)
else
super
end
end | ruby | def method_missing(*args)
if Conversions.conversions[units.to_sym][args.first]
to_f.send(units.to_sym).to(args.first)
else
super
end
end | [
"def",
"method_missing",
"(",
"*",
"args",
")",
"if",
"Conversions",
".",
"conversions",
"[",
"units",
".",
"to_sym",
"]",
"[",
"args",
".",
"first",
"]",
"to_f",
".",
"send",
"(",
"units",
".",
"to_sym",
")",
".",
"to",
"(",
"args",
".",
"first",
... | Handle conversion methods | [
"Handle",
"conversion",
"methods"
] | 87d26ff48c9611f99ebfd01cee9cd15b5d79cabe | https://github.com/faradayio/charisma/blob/87d26ff48c9611f99ebfd01cee9cd15b5d79cabe/lib/charisma/measurement.rb#L44-L50 | train |
spudtrooper/rdiorb | lib/rdio/types.rb | Rdio.Artist.albums | def albums(featuring=nil,extras=nil,start=nil,count=nil)
api.getAlbumsForArtist self,featuring,extras,start,count
end | ruby | def albums(featuring=nil,extras=nil,start=nil,count=nil)
api.getAlbumsForArtist self,featuring,extras,start,count
end | [
"def",
"albums",
"(",
"featuring",
"=",
"nil",
",",
"extras",
"=",
"nil",
",",
"start",
"=",
"nil",
",",
"count",
"=",
"nil",
")",
"api",
".",
"getAlbumsForArtist",
"self",
",",
"featuring",
",",
"extras",
",",
"start",
",",
"count",
"end"
] | Get all the albums by this artist | [
"Get",
"all",
"the",
"albums",
"by",
"this",
"artist"
] | e137fd016bfba42d9e50f421b009b2ad3c41baaf | https://github.com/spudtrooper/rdiorb/blob/e137fd016bfba42d9e50f421b009b2ad3c41baaf/lib/rdio/types.rb#L45-L47 | train |
spudtrooper/rdiorb | lib/rdio/types.rb | Rdio.Playlist.tracks | def tracks
ids = track_keys
return [] if not ids
return ids.map {|id| Track.get id}
end | ruby | def tracks
ids = track_keys
return [] if not ids
return ids.map {|id| Track.get id}
end | [
"def",
"tracks",
"ids",
"=",
"track_keys",
"return",
"[",
"]",
"if",
"not",
"ids",
"return",
"ids",
".",
"map",
"{",
"|",
"id",
"|",
"Track",
".",
"get",
"id",
"}",
"end"
] | Returns an array of tracks | [
"Returns",
"an",
"array",
"of",
"tracks"
] | e137fd016bfba42d9e50f421b009b2ad3c41baaf | https://github.com/spudtrooper/rdiorb/blob/e137fd016bfba42d9e50f421b009b2ad3c41baaf/lib/rdio/types.rb#L342-L346 | train |
drish/hyperb | lib/hyperb/funcs/funcs.rb | Hyperb.Funcs.create_func | def create_func(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
path = '/funcs/create'
body = {}
body.merge!(prepare_json(params))
Hyperb::Request.new(self, path, {}, 'post', body).perform
end | ruby | def create_func(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
path = '/funcs/create'
body = {}
body.merge!(prepare_json(params))
Hyperb::Request.new(self, path, {}, 'post', body).perform
end | [
"def",
"create_func",
"(",
"params",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Invalid arguments.'",
"unless",
"check_arguments",
"(",
"params",
",",
"'name'",
")",
"path",
"=",
"'/funcs/create'",
"body",
"=",
"{",
"}",
"body",
".",
"merge!",
"(",... | create a func
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/create.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::Conflict] raised when func already exist
@raise [Hyperb::Error::BadRequest] raised when a bad parameter is sent
@ra... | [
"create",
"a",
"func"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/funcs/funcs.rb#L80-L88 | train |
drish/hyperb | lib/hyperb/funcs/funcs.rb | Hyperb.Funcs.remove_func | def remove_func(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
path = '/funcs/' + params[:name]
Hyperb::Request.new(self, path, {}, 'delete').perform
end | ruby | def remove_func(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
path = '/funcs/' + params[:name]
Hyperb::Request.new(self, path, {}, 'delete').perform
end | [
"def",
"remove_func",
"(",
"params",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Invalid arguments.'",
"unless",
"check_arguments",
"(",
"params",
",",
"'name'",
")",
"path",
"=",
"'/funcs/'",
"+",
"params",
"[",
":name",
"]",
"Hyperb",
"::",
"Reque... | remove a func
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/remove.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::Conflict] raised when func with that name is running
@raise [Hyperb::Error::BadRequest] raised when a bad parameter ... | [
"remove",
"a",
"func"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/funcs/funcs.rb#L103-L107 | train |
drish/hyperb | lib/hyperb/funcs/funcs.rb | Hyperb.Funcs.call_func | def call_func(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'uuid')
path = "call/#{params[:name]}/#{params[:uuid]}"
path.concat('/sync') if params.key?(:sync) && params[:sync]
Hyperb::FuncCallRequest.new(self, path, {}, 'post').perform
end | ruby | def call_func(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'uuid')
path = "call/#{params[:name]}/#{params[:uuid]}"
path.concat('/sync') if params.key?(:sync) && params[:sync]
Hyperb::FuncCallRequest.new(self, path, {}, 'post').perform
end | [
"def",
"call_func",
"(",
"params",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Invalid arguments.'",
"unless",
"check_arguments",
"(",
"params",
",",
"'name'",
",",
"'uuid'",
")",
"path",
"=",
"\"call/#{params[:name]}/#{params[:uuid]}\"",
"path",
".",
"co... | call a func
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/call.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::NotFound] no such func
@raise [ArgumentError] when required arguments are not provided.
@param params [Hash] A customi... | [
"call",
"a",
"func"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/funcs/funcs.rb#L122-L127 | train |
zires/open_qq | lib/open_qq/gateway.rb | OpenQq.Gateway.wrap | def wrap(http_method, url, params)
params = params.merge(:appid => @appid)
params[:sig] = Gateway.signature( "#{@appkey}&", Gateway.make_source(http_method.to_s.upcase, url, params) )
params
end | ruby | def wrap(http_method, url, params)
params = params.merge(:appid => @appid)
params[:sig] = Gateway.signature( "#{@appkey}&", Gateway.make_source(http_method.to_s.upcase, url, params) )
params
end | [
"def",
"wrap",
"(",
"http_method",
",",
"url",
",",
"params",
")",
"params",
"=",
"params",
".",
"merge",
"(",
":appid",
"=>",
"@appid",
")",
"params",
"[",
":sig",
"]",
"=",
"Gateway",
".",
"signature",
"(",
"\"#{@appkey}&\"",
",",
"Gateway",
".",
"ma... | wrap `http_method`, `url`, `params` together | [
"wrap",
"http_method",
"url",
"params",
"together"
] | 14bb3dba0aff3152307bd82d69b602e1a7a4ac9e | https://github.com/zires/open_qq/blob/14bb3dba0aff3152307bd82d69b602e1a7a4ac9e/lib/open_qq/gateway.rb#L75-L79 | train |
picatz/Willow-Run | lib/willow_run/sniffer.rb | WillowRun.Sniffer.default_ip | def default_ip
begin
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
UDPSocket.open do |s|
s.connect rand_routable_daddr.to_s, rand_port
s.addr.last
end
ensure
Socket.do_not_reverse_loo... | ruby | def default_ip
begin
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
UDPSocket.open do |s|
s.connect rand_routable_daddr.to_s, rand_port
s.addr.last
end
ensure
Socket.do_not_reverse_loo... | [
"def",
"default_ip",
"begin",
"orig",
",",
"Socket",
".",
"do_not_reverse_lookup",
"=",
"Socket",
".",
"do_not_reverse_lookup",
",",
"true",
"UDPSocket",
".",
"open",
"do",
"|",
"s",
"|",
"s",
".",
"connect",
"rand_routable_daddr",
".",
"to_s",
",",
"rand_port... | Determine the default ip address, taken from packetfu's utils.rb | [
"Determine",
"the",
"default",
"ip",
"address",
"taken",
"from",
"packetfu",
"s",
"utils",
".",
"rb"
] | 0953e31fc0e1aac1664f9c06208839c3b4de7359 | https://github.com/picatz/Willow-Run/blob/0953e31fc0e1aac1664f9c06208839c3b4de7359/lib/willow_run/sniffer.rb#L81-L91 | train |
picatz/Willow-Run | lib/willow_run/sniffer.rb | WillowRun.Sniffer.default_interface | def default_interface
ip = default_ip
Socket.getifaddrs.each do |ifaddr|
next unless ifaddr.addr.ip?
return ifaddr.name if ifaddr.addr.ip_address == ip
end
# Fall back to libpcap as last resort
return Pcap.lookupdev
end | ruby | def default_interface
ip = default_ip
Socket.getifaddrs.each do |ifaddr|
next unless ifaddr.addr.ip?
return ifaddr.name if ifaddr.addr.ip_address == ip
end
# Fall back to libpcap as last resort
return Pcap.lookupdev
end | [
"def",
"default_interface",
"ip",
"=",
"default_ip",
"Socket",
".",
"getifaddrs",
".",
"each",
"do",
"|",
"ifaddr",
"|",
"next",
"unless",
"ifaddr",
".",
"addr",
".",
"ip?",
"return",
"ifaddr",
".",
"name",
"if",
"ifaddr",
".",
"addr",
".",
"ip_address",
... | Determine the default routeable interface, taken from packetfu's utils.rb | [
"Determine",
"the",
"default",
"routeable",
"interface",
"taken",
"from",
"packetfu",
"s",
"utils",
".",
"rb"
] | 0953e31fc0e1aac1664f9c06208839c3b4de7359 | https://github.com/picatz/Willow-Run/blob/0953e31fc0e1aac1664f9c06208839c3b4de7359/lib/willow_run/sniffer.rb#L94-L102 | train |
Katello/trebuchet | lib/trebuchet/runner.rb | Trebuchet.Runner.run | def run(config, operation_name=nil)
config = config.with_indifferent_access
config.merge!(load_config(config[:config])) if config[:config]
operation_run = false
gather_operations.each do |operation|
if operation_name.nil? || operation_name == operation.name
op = operation.new(... | ruby | def run(config, operation_name=nil)
config = config.with_indifferent_access
config.merge!(load_config(config[:config])) if config[:config]
operation_run = false
gather_operations.each do |operation|
if operation_name.nil? || operation_name == operation.name
op = operation.new(... | [
"def",
"run",
"(",
"config",
",",
"operation_name",
"=",
"nil",
")",
"config",
"=",
"config",
".",
"with_indifferent_access",
"config",
".",
"merge!",
"(",
"load_config",
"(",
"config",
"[",
":config",
"]",
")",
")",
"if",
"config",
"[",
":config",
"]",
... | Run all operations, or a specific operation
@param [Hash] config config hash to pass to operations (currently :host, :user, :password)
@param [String] operation_name the single operation to run, otherwise all | [
"Run",
"all",
"operations",
"or",
"a",
"specific",
"operation"
] | 83a34c6cadf8dcf5632b1cb4b2af5bc43dbe1fa5 | https://github.com/Katello/trebuchet/blob/83a34c6cadf8dcf5632b1cb4b2af5bc43dbe1fa5/lib/trebuchet/runner.rb#L44-L60 | train |
ic-factory/ecic | lib/ecic/source_file_info.rb | Ecic.SourceFileInfo.find_sources_file_dir | def find_sources_file_dir(dir = @relative_path_from_project.dirname)
return nil if is_outside_project?
file = File.join(@project.root, dir, "sources.rb")
if dir.root? or dir.to_s == "."
return nil
elsif File.exists?(file)
return dir
else
return find_sources_file_dir... | ruby | def find_sources_file_dir(dir = @relative_path_from_project.dirname)
return nil if is_outside_project?
file = File.join(@project.root, dir, "sources.rb")
if dir.root? or dir.to_s == "."
return nil
elsif File.exists?(file)
return dir
else
return find_sources_file_dir... | [
"def",
"find_sources_file_dir",
"(",
"dir",
"=",
"@relative_path_from_project",
".",
"dirname",
")",
"return",
"nil",
"if",
"is_outside_project?",
"file",
"=",
"File",
".",
"join",
"(",
"@project",
".",
"root",
",",
"dir",
",",
"\"sources.rb\"",
")",
"if",
"di... | def within_expected_folder?
rel_design_path_list = @relative_path_from_project.to_s.split('/')
return nil if rel_design_path_list.length < 3
str = [rel_design_path_list.first(2)].join('/')
STANDARD_LIBRARY_FOLDERS_LIST.include? str
end
Function that looks for a sources.rb file within the pro... | [
"def",
"within_expected_folder?",
"rel_design_path_list",
"="
] | b1b13440046779a603526f43473cb94c4dbe7fb7 | https://github.com/ic-factory/ecic/blob/b1b13440046779a603526f43473cb94c4dbe7fb7/lib/ecic/source_file_info.rb#L56-L66 | train |
jaymcgavren/zyps | lib/zyps/conditions.rb | Zyps.ProximityCondition.select | def select(actor, targets)
targets.find_all {|target| Utility.find_distance(actor.location, target.location) <= @distance}
end | ruby | def select(actor, targets)
targets.find_all {|target| Utility.find_distance(actor.location, target.location) <= @distance}
end | [
"def",
"select",
"(",
"actor",
",",
"targets",
")",
"targets",
".",
"find_all",
"{",
"|",
"target",
"|",
"Utility",
".",
"find_distance",
"(",
"actor",
".",
"location",
",",
"target",
".",
"location",
")",
"<=",
"@distance",
"}",
"end"
] | Returns an array of targets that are at the given distance or closer. | [
"Returns",
"an",
"array",
"of",
"targets",
"that",
"are",
"at",
"the",
"given",
"distance",
"or",
"closer",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/conditions.rb#L69-L71 | train |
jaymcgavren/zyps | lib/zyps/conditions.rb | Zyps.CollisionCondition.select | def select(actor, targets)
return [] unless targets.length > 0
#The size of the largest other object
max_size = targets.map{|t| t.size}.max
#The maximum distance on a straight line the largest object and self could be and still be touching.
max_diff = Math.sqrt(actor.size / Math::PI) + Math.sqrt(max... | ruby | def select(actor, targets)
return [] unless targets.length > 0
#The size of the largest other object
max_size = targets.map{|t| t.size}.max
#The maximum distance on a straight line the largest object and self could be and still be touching.
max_diff = Math.sqrt(actor.size / Math::PI) + Math.sqrt(max... | [
"def",
"select",
"(",
"actor",
",",
"targets",
")",
"return",
"[",
"]",
"unless",
"targets",
".",
"length",
">",
"0",
"max_size",
"=",
"targets",
".",
"map",
"{",
"|",
"t",
"|",
"t",
".",
"size",
"}",
".",
"max",
"max_diff",
"=",
"Math",
".",
"sq... | Returns an array of targets that have collided with the actor. | [
"Returns",
"an",
"array",
"of",
"targets",
"that",
"have",
"collided",
"with",
"the",
"actor",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/conditions.rb#L86-L97 | train |
jaymcgavren/zyps | lib/zyps/conditions.rb | Zyps.StrengthCondition.select | def select(actor, targets)
targets.find_all {|target| actor.size >= target.size}
end | ruby | def select(actor, targets)
targets.find_all {|target| actor.size >= target.size}
end | [
"def",
"select",
"(",
"actor",
",",
"targets",
")",
"targets",
".",
"find_all",
"{",
"|",
"target",
"|",
"actor",
".",
"size",
">=",
"target",
".",
"size",
"}",
"end"
] | Returns an array of targets that are weaker than the actor.
For now, strength is based merely on size. | [
"Returns",
"an",
"array",
"of",
"targets",
"that",
"are",
"weaker",
"than",
"the",
"actor",
".",
"For",
"now",
"strength",
"is",
"based",
"merely",
"on",
"size",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/conditions.rb#L105-L107 | train |
raygao/asf-soap-adapter | lib/salesforce/sf_base.rb | Salesforce.SfBase.logout | def logout(session_ids=Hash.new)
result = SfBase.connection.binding.invalidateSessions(session_ids)
if"invalidateSessionsResponse" == result.to_s
return true
else
return false
end
#result this.connection.binding.logout(Hash.new)
end | ruby | def logout(session_ids=Hash.new)
result = SfBase.connection.binding.invalidateSessions(session_ids)
if"invalidateSessionsResponse" == result.to_s
return true
else
return false
end
#result this.connection.binding.logout(Hash.new)
end | [
"def",
"logout",
"(",
"session_ids",
"=",
"Hash",
".",
"new",
")",
"result",
"=",
"SfBase",
".",
"connection",
".",
"binding",
".",
"invalidateSessions",
"(",
"session_ids",
")",
"if",
"\"invalidateSessionsResponse\"",
"==",
"result",
".",
"to_s",
"return",
"t... | Logs out of the Salesforce session | [
"Logs",
"out",
"of",
"the",
"Salesforce",
"session"
] | ab96dc48d60a6410d620cafe68ae7add012dc9d4 | https://github.com/raygao/asf-soap-adapter/blob/ab96dc48d60a6410d620cafe68ae7add012dc9d4/lib/salesforce/sf_base.rb#L51-L59 | train |
caruby/uom | lib/uom/measurement.rb | UOM.Measurement.as | def as(unit)
unit = UOM::Unit.for(unit.to_sym) if String === unit or Symbol === unit
return self if @unit == unit
Measurement.new(unit, @unit.as(quantity, unit))
end | ruby | def as(unit)
unit = UOM::Unit.for(unit.to_sym) if String === unit or Symbol === unit
return self if @unit == unit
Measurement.new(unit, @unit.as(quantity, unit))
end | [
"def",
"as",
"(",
"unit",
")",
"unit",
"=",
"UOM",
"::",
"Unit",
".",
"for",
"(",
"unit",
".",
"to_sym",
")",
"if",
"String",
"===",
"unit",
"or",
"Symbol",
"===",
"unit",
"return",
"self",
"if",
"@unit",
"==",
"unit",
"Measurement",
".",
"new",
"(... | Returns a new Measurement which expresses this measurement as the given unit. | [
"Returns",
"a",
"new",
"Measurement",
"which",
"expresses",
"this",
"measurement",
"as",
"the",
"given",
"unit",
"."
] | 04597e0fe44f1f58d5c08303ab90f8c68bb8ebc1 | https://github.com/caruby/uom/blob/04597e0fe44f1f58d5c08303ab90f8c68bb8ebc1/lib/uom/measurement.rb#L52-L56 | train |
caruby/uom | lib/uom/measurement.rb | UOM.Measurement.apply_to_quantity | def apply_to_quantity(method, other)
other = other.as(unit).quantity if Measurement === other
new_quantity = block_given? ? yield(to_f, other) : to_f.send(method, other)
Measurement.new(unit, new_quantity)
end | ruby | def apply_to_quantity(method, other)
other = other.as(unit).quantity if Measurement === other
new_quantity = block_given? ? yield(to_f, other) : to_f.send(method, other)
Measurement.new(unit, new_quantity)
end | [
"def",
"apply_to_quantity",
"(",
"method",
",",
"other",
")",
"other",
"=",
"other",
".",
"as",
"(",
"unit",
")",
".",
"quantity",
"if",
"Measurement",
"===",
"other",
"new_quantity",
"=",
"block_given?",
"?",
"yield",
"(",
"to_f",
",",
"other",
")",
":"... | Returns a new Measurement whose unit is this Measurement's unit and quantity is the
result of applying the given method to this Measurement's quantity and the other quantity.
If other is a Measurement, then the operation argument is the other Measurement quantity, e.g.:
Measurement.new(:g, 3).apply(Measurement.ne... | [
"Returns",
"a",
"new",
"Measurement",
"whose",
"unit",
"is",
"this",
"Measurement",
"s",
"unit",
"and",
"quantity",
"is",
"the",
"result",
"of",
"applying",
"the",
"given",
"method",
"to",
"this",
"Measurement",
"s",
"quantity",
"and",
"the",
"other",
"quant... | 04597e0fe44f1f58d5c08303ab90f8c68bb8ebc1 | https://github.com/caruby/uom/blob/04597e0fe44f1f58d5c08303ab90f8c68bb8ebc1/lib/uom/measurement.rb#L72-L76 | train |
caruby/uom | lib/uom/measurement.rb | UOM.Measurement.compose | def compose(method, other)
return apply_to_quantity(method, other) unless Measurement === other
other = other.as(unit) if other.unit.axis == unit.axis
new_quantity = quantity.zero? ? 0.0 : quantity.to_f.send(method, other.quantity)
Measurement.new(unit.send(method, other.unit), new_quantity)
end | ruby | def compose(method, other)
return apply_to_quantity(method, other) unless Measurement === other
other = other.as(unit) if other.unit.axis == unit.axis
new_quantity = quantity.zero? ? 0.0 : quantity.to_f.send(method, other.quantity)
Measurement.new(unit.send(method, other.unit), new_quantity)
end | [
"def",
"compose",
"(",
"method",
",",
"other",
")",
"return",
"apply_to_quantity",
"(",
"method",
",",
"other",
")",
"unless",
"Measurement",
"===",
"other",
"other",
"=",
"other",
".",
"as",
"(",
"unit",
")",
"if",
"other",
".",
"unit",
".",
"axis",
"... | Returns the application of method to this measurement and the other measurement or Numeric.
If other is a Measurement, then the returned Measurement Unit is the composition of this
Measurement's unit and the other Measurement's unit. | [
"Returns",
"the",
"application",
"of",
"method",
"to",
"this",
"measurement",
"and",
"the",
"other",
"measurement",
"or",
"Numeric",
".",
"If",
"other",
"is",
"a",
"Measurement",
"then",
"the",
"returned",
"Measurement",
"Unit",
"is",
"the",
"composition",
"of... | 04597e0fe44f1f58d5c08303ab90f8c68bb8ebc1 | https://github.com/caruby/uom/blob/04597e0fe44f1f58d5c08303ab90f8c68bb8ebc1/lib/uom/measurement.rb#L81-L86 | train |
barcoo/rworkflow | lib/rworkflow/sidekiq_flow.rb | Rworkflow.SidekiqFlow.continue | def continue
return if self.finished? || !self.valid? || !self.paused?
if @flow_data.decr(:paused) == 0
workers = Hash[self.counters.select { |name, _| !self.class.terminal?(name) && name != :processing }]
# enqueue jobs
workers.each { |worker, num_objects| create_jobs(worker, num_o... | ruby | def continue
return if self.finished? || !self.valid? || !self.paused?
if @flow_data.decr(:paused) == 0
workers = Hash[self.counters.select { |name, _| !self.class.terminal?(name) && name != :processing }]
# enqueue jobs
workers.each { |worker, num_objects| create_jobs(worker, num_o... | [
"def",
"continue",
"return",
"if",
"self",
".",
"finished?",
"||",
"!",
"self",
".",
"valid?",
"||",
"!",
"self",
".",
"paused?",
"if",
"@flow_data",
".",
"decr",
"(",
":paused",
")",
"==",
"0",
"workers",
"=",
"Hash",
"[",
"self",
".",
"counters",
"... | for now assumes | [
"for",
"now",
"assumes"
] | 1dccaabd47144c846e3d87e65c11ee056ae597a1 | https://github.com/barcoo/rworkflow/blob/1dccaabd47144c846e3d87e65c11ee056ae597a1/lib/rworkflow/sidekiq_flow.rb#L44-L54 | train |
egonbraun/logmsg | lib/logmsg/logfile.rb | Logmsg.LogFile.init_formatter | def init_formatter
@formatter = proc do |s, d, p, m|
"#{@format}\n" % { severity: s, datetime: d, progname: p, msg: m }
end
end | ruby | def init_formatter
@formatter = proc do |s, d, p, m|
"#{@format}\n" % { severity: s, datetime: d, progname: p, msg: m }
end
end | [
"def",
"init_formatter",
"@formatter",
"=",
"proc",
"do",
"|",
"s",
",",
"d",
",",
"p",
",",
"m",
"|",
"\"#{@format}\\n\"",
"%",
"{",
"severity",
":",
"s",
",",
"datetime",
":",
"d",
",",
"progname",
":",
"p",
",",
"msg",
":",
"m",
"}",
"end",
"e... | Initializes the logger's formatter proc based on the value of format
instance variable. This method should only be called inside the register
method
@private | [
"Initializes",
"the",
"logger",
"s",
"formatter",
"proc",
"based",
"on",
"the",
"value",
"of",
"format",
"instance",
"variable",
".",
"This",
"method",
"should",
"only",
"be",
"called",
"inside",
"the",
"register",
"method"
] | 7ca139edb856ada08cb7465acd68bd60bc2837fa | https://github.com/egonbraun/logmsg/blob/7ca139edb856ada08cb7465acd68bd60bc2837fa/lib/logmsg/logfile.rb#L155-L159 | train |
egonbraun/logmsg | lib/logmsg/logfile.rb | Logmsg.LogFile.init_logger | def init_logger
@logger = case @path
when STDOUT_STREAM then Logger.new(STDOUT)
when STDERR_STREAM then Logger.new(STDERR)
else Logger.new(File.open(@path, 'a'))
end
@logger.datetime_format = @datetime_format
@logger.sev_threshold = @thre... | ruby | def init_logger
@logger = case @path
when STDOUT_STREAM then Logger.new(STDOUT)
when STDERR_STREAM then Logger.new(STDERR)
else Logger.new(File.open(@path, 'a'))
end
@logger.datetime_format = @datetime_format
@logger.sev_threshold = @thre... | [
"def",
"init_logger",
"@logger",
"=",
"case",
"@path",
"when",
"STDOUT_STREAM",
"then",
"Logger",
".",
"new",
"(",
"STDOUT",
")",
"when",
"STDERR_STREAM",
"then",
"Logger",
".",
"new",
"(",
"STDERR",
")",
"else",
"Logger",
".",
"new",
"(",
"File",
".",
"... | Initializes the logger object from the standard library. This method
should only be called inside the register method
@private | [
"Initializes",
"the",
"logger",
"object",
"from",
"the",
"standard",
"library",
".",
"This",
"method",
"should",
"only",
"be",
"called",
"inside",
"the",
"register",
"method"
] | 7ca139edb856ada08cb7465acd68bd60bc2837fa | https://github.com/egonbraun/logmsg/blob/7ca139edb856ada08cb7465acd68bd60bc2837fa/lib/logmsg/logfile.rb#L164-L173 | train |
egonbraun/logmsg | lib/logmsg/logfile.rb | Logmsg.LogFile.log | def log(message, severity = DEFAULT_SEVERITY)
fail 'Logfile not registered' unless @registered
return if message.nil?
@logger.add(severity, message, @name) if should_log?(severity)
end | ruby | def log(message, severity = DEFAULT_SEVERITY)
fail 'Logfile not registered' unless @registered
return if message.nil?
@logger.add(severity, message, @name) if should_log?(severity)
end | [
"def",
"log",
"(",
"message",
",",
"severity",
"=",
"DEFAULT_SEVERITY",
")",
"fail",
"'Logfile not registered'",
"unless",
"@registered",
"return",
"if",
"message",
".",
"nil?",
"@logger",
".",
"add",
"(",
"severity",
",",
"message",
",",
"@name",
")",
"if",
... | Log a message to the configured logger using the severity and program name
as specified
@param [String] message message to be logged
@param [Number] severity message's severity
@see http://ruby-doc.org/stdlib-2.2.4/libdoc/logger/rdoc/Logger.html
@private | [
"Log",
"a",
"message",
"to",
"the",
"configured",
"logger",
"using",
"the",
"severity",
"and",
"program",
"name",
"as",
"specified"
] | 7ca139edb856ada08cb7465acd68bd60bc2837fa | https://github.com/egonbraun/logmsg/blob/7ca139edb856ada08cb7465acd68bd60bc2837fa/lib/logmsg/logfile.rb#L183-L187 | train |
stvvan/hoiio-ruby | lib/hoiio-ruby/api/ivr.rb | Hoiio.IVR.set_up | def set_up
@start = Hoiio::IVRBlock::Start.new @client
@middle = Hoiio::IVRBlock::Middle.new @client
@end = Hoiio::IVRBlock::End.new @client
end | ruby | def set_up
@start = Hoiio::IVRBlock::Start.new @client
@middle = Hoiio::IVRBlock::Middle.new @client
@end = Hoiio::IVRBlock::End.new @client
end | [
"def",
"set_up",
"@start",
"=",
"Hoiio",
"::",
"IVRBlock",
"::",
"Start",
".",
"new",
"@client",
"@middle",
"=",
"Hoiio",
"::",
"IVRBlock",
"::",
"Middle",
".",
"new",
"@client",
"@end",
"=",
"Hoiio",
"::",
"IVRBlock",
"::",
"End",
".",
"new",
"@client",... | Set up the sub resources using shared @client object | [
"Set",
"up",
"the",
"sub",
"resources",
"using",
"shared"
] | 7f6840b94c5f61c221619ca069bc008d502dd339 | https://github.com/stvvan/hoiio-ruby/blob/7f6840b94c5f61c221619ca069bc008d502dd339/lib/hoiio-ruby/api/ivr.rb#L45-L49 | train |
drish/hyperb | lib/hyperb/network/fips.rb | Hyperb.Network.fips_ls | def fips_ls(params = {})
path = '/fips'
query = {}
query[:filters] = params[:filters] if params.key?(:filters)
downcase_symbolize(JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform))
end | ruby | def fips_ls(params = {})
path = '/fips'
query = {}
query[:filters] = params[:filters] if params.key?(:filters)
downcase_symbolize(JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform))
end | [
"def",
"fips_ls",
"(",
"params",
"=",
"{",
"}",
")",
"path",
"=",
"'/fips'",
"query",
"=",
"{",
"}",
"query",
"[",
":filters",
"]",
"=",
"params",
"[",
":filters",
"]",
"if",
"params",
".",
"key?",
"(",
":filters",
")",
"downcase_symbolize",
"(",
"JS... | list floating ips
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Network/fip_ls.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::NotFound] raised when ips are not found.
@returns [Array] array of downcased symbolized has
@param params ... | [
"list",
"floating",
"ips"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/network/fips.rb#L60-L65 | train |
drish/hyperb | lib/hyperb/network/fips.rb | Hyperb.Network.fip_release | def fip_release(params = {})
path = '/fips/release'
query = {}
query[:ip] = params[:ip] if params.key?(:ip)
Hyperb::Request.new(self, path, query, 'post').perform
end | ruby | def fip_release(params = {})
path = '/fips/release'
query = {}
query[:ip] = params[:ip] if params.key?(:ip)
Hyperb::Request.new(self, path, query, 'post').perform
end | [
"def",
"fip_release",
"(",
"params",
"=",
"{",
"}",
")",
"path",
"=",
"'/fips/release'",
"query",
"=",
"{",
"}",
"query",
"[",
":ip",
"]",
"=",
"params",
"[",
":ip",
"]",
"if",
"params",
".",
"key?",
"(",
":ip",
")",
"Hyperb",
"::",
"Request",
".",... | release a floating ip
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Network/fip_release.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::NotFound] raised when ips are not found.
@param params [Hash] A customizable set of params.
@optio... | [
"release",
"a",
"floating",
"ip"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/network/fips.rb#L76-L81 | train |
drish/hyperb | lib/hyperb/network/fips.rb | Hyperb.Network.fip_allocate | def fip_allocate(params = {})
raise ArgumentError, 'Invalid Arguments' unless check_arguments(params, 'count')
path = '/fips/allocate'
query = {}
query[:count] = params[:count] if params.key?(:count)
fips = JSON.parse(Hyperb::Request.new(self, path, query, 'post').perform)
fips
e... | ruby | def fip_allocate(params = {})
raise ArgumentError, 'Invalid Arguments' unless check_arguments(params, 'count')
path = '/fips/allocate'
query = {}
query[:count] = params[:count] if params.key?(:count)
fips = JSON.parse(Hyperb::Request.new(self, path, query, 'post').perform)
fips
e... | [
"def",
"fip_allocate",
"(",
"params",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Invalid Arguments'",
"unless",
"check_arguments",
"(",
"params",
",",
"'count'",
")",
"path",
"=",
"'/fips/allocate'",
"query",
"=",
"{",
"}",
"query",
"[",
":count",
... | allocate a new floating ip
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Network/fip_allocate.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@return [Array] Array of ips (string).
@param params [Hash] A customizable set of params.
@option params [String] ... | [
"allocate",
"a",
"new",
"floating",
"ip"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/network/fips.rb#L93-L100 | train |
jaymcgavren/zyps | lib/zyps/environmental_factors.rb | Zyps.SpeedLimit.act | def act(environment)
environment.objects.each do |object|
object.vector.speed = Utility.constrain_value(object.vector.speed, @maximum)
end
end | ruby | def act(environment)
environment.objects.each do |object|
object.vector.speed = Utility.constrain_value(object.vector.speed, @maximum)
end
end | [
"def",
"act",
"(",
"environment",
")",
"environment",
".",
"objects",
".",
"each",
"do",
"|",
"object",
"|",
"object",
".",
"vector",
".",
"speed",
"=",
"Utility",
".",
"constrain_value",
"(",
"object",
".",
"vector",
".",
"speed",
",",
"@maximum",
")",
... | If object is over the speed, reduce its speed. | [
"If",
"object",
"is",
"over",
"the",
"speed",
"reduce",
"its",
"speed",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/environmental_factors.rb#L132-L136 | train |
jaymcgavren/zyps | lib/zyps/environmental_factors.rb | Zyps.Accelerator.act | def act(environment)
elapsed_time = @clock.elapsed_time
environment.objects.each do |object|
#Push on object.
object.vector += Vector.new(@vector.speed * elapsed_time, @vector.pitch)
end
end | ruby | def act(environment)
elapsed_time = @clock.elapsed_time
environment.objects.each do |object|
#Push on object.
object.vector += Vector.new(@vector.speed * elapsed_time, @vector.pitch)
end
end | [
"def",
"act",
"(",
"environment",
")",
"elapsed_time",
"=",
"@clock",
".",
"elapsed_time",
"environment",
".",
"objects",
".",
"each",
"do",
"|",
"object",
"|",
"object",
".",
"vector",
"+=",
"Vector",
".",
"new",
"(",
"@vector",
".",
"speed",
"*",
"elap... | Add the given vector to each object, but limited by elapsed time. | [
"Add",
"the",
"given",
"vector",
"to",
"each",
"object",
"but",
"limited",
"by",
"elapsed",
"time",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/environmental_factors.rb#L169-L175 | train |
jaymcgavren/zyps | lib/zyps/environmental_factors.rb | Zyps.Friction.act | def act(environment)
elapsed_time = @clock.elapsed_time
environment.objects.each do |object|
#Slow object.
acceleration = @force * elapsed_time
speed = object.vector.speed
if speed > 0
speed -= acceleration
speed = 0 if speed < 0
elsif speed < 0
speed += ac... | ruby | def act(environment)
elapsed_time = @clock.elapsed_time
environment.objects.each do |object|
#Slow object.
acceleration = @force * elapsed_time
speed = object.vector.speed
if speed > 0
speed -= acceleration
speed = 0 if speed < 0
elsif speed < 0
speed += ac... | [
"def",
"act",
"(",
"environment",
")",
"elapsed_time",
"=",
"@clock",
".",
"elapsed_time",
"environment",
".",
"objects",
".",
"each",
"do",
"|",
"object",
"|",
"acceleration",
"=",
"@force",
"*",
"elapsed_time",
"speed",
"=",
"object",
".",
"vector",
".",
... | Reduce each object's speed at the given rate. | [
"Reduce",
"each",
"object",
"s",
"speed",
"at",
"the",
"given",
"rate",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/environmental_factors.rb#L227-L242 | train |
jaymcgavren/zyps | lib/zyps/environmental_factors.rb | Zyps.PopulationLimit.act | def act(environment)
excess = environment.object_count - @count
if excess > 0
objects_for_removal = []
environment.objects.each do |object|
objects_for_removal << object
break if objects_for_removal.length >= excess
end
objects_for_removal.each {|object| environment.remov... | ruby | def act(environment)
excess = environment.object_count - @count
if excess > 0
objects_for_removal = []
environment.objects.each do |object|
objects_for_removal << object
break if objects_for_removal.length >= excess
end
objects_for_removal.each {|object| environment.remov... | [
"def",
"act",
"(",
"environment",
")",
"excess",
"=",
"environment",
".",
"object_count",
"-",
"@count",
"if",
"excess",
">",
"0",
"objects_for_removal",
"=",
"[",
"]",
"environment",
".",
"objects",
".",
"each",
"do",
"|",
"object",
"|",
"objects_for_remova... | Remove objects if there are too many objects in environment. | [
"Remove",
"objects",
"if",
"there",
"are",
"too",
"many",
"objects",
"in",
"environment",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/environmental_factors.rb#L263-L273 | train |
faradayio/charisma | lib/charisma/characterization.rb | Charisma.Characterization.has | def has(name, options = {}, &blk)
name = name.to_sym
self[name] = Characteristic.new(name, options, &blk)
end | ruby | def has(name, options = {}, &blk)
name = name.to_sym
self[name] = Characteristic.new(name, options, &blk)
end | [
"def",
"has",
"(",
"name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"blk",
")",
"name",
"=",
"name",
".",
"to_sym",
"self",
"[",
"name",
"]",
"=",
"Characteristic",
".",
"new",
"(",
"name",
",",
"options",
",",
"&",
"blk",
")",
"end"
] | Define a characteristic.
This is used within <tt>Charisma::Base::ClassMethods#characterize</tt> blocks to curate attributes on a class. Internally, a <tt>Charisma::Characteristic</tt> is created to store the definition.
@param [Symbol]
@param [Symbol] name The name of the characteristic. The method with this name w... | [
"Define",
"a",
"characteristic",
"."
] | 87d26ff48c9611f99ebfd01cee9cd15b5d79cabe | https://github.com/faradayio/charisma/blob/87d26ff48c9611f99ebfd01cee9cd15b5d79cabe/lib/charisma/characterization.rb#L18-L21 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.ClassMethods.define_static_cache_key_finder | def define_static_cache_key_finder#:nodoc:
return unless acts_as_static_record_options[:find_by_attribute_support]
#define the key column if it is not a hash column
if ((key_column = acts_as_static_record_options[:key]) &&
(!column_methods_hash.include?(key_column.to_sym)))
class_eva... | ruby | def define_static_cache_key_finder#:nodoc:
return unless acts_as_static_record_options[:find_by_attribute_support]
#define the key column if it is not a hash column
if ((key_column = acts_as_static_record_options[:key]) &&
(!column_methods_hash.include?(key_column.to_sym)))
class_eva... | [
"def",
"define_static_cache_key_finder",
"return",
"unless",
"acts_as_static_record_options",
"[",
":find_by_attribute_support",
"]",
"if",
"(",
"(",
"key_column",
"=",
"acts_as_static_record_options",
"[",
":key",
"]",
")",
"&&",
"(",
"!",
"column_methods_hash",
".",
"... | Define a method find_by_KEY if the specified cache key
is not an active record column | [
"Define",
"a",
"method",
"find_by_KEY",
"if",
"the",
"specified",
"cache",
"key",
"is",
"not",
"an",
"active",
"record",
"column"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L242-L253 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.SingletonMethods.static_record_lookup_key | def static_record_lookup_key(value)#:nodoc:
if value.is_a? self
static_record_lookup_key(
value.send(
acts_as_static_record_options[:lookup_key] ||
acts_as_static_record_options[:key] ||
primary_key
)
)
else
value.to_s.gsub(' ',... | ruby | def static_record_lookup_key(value)#:nodoc:
if value.is_a? self
static_record_lookup_key(
value.send(
acts_as_static_record_options[:lookup_key] ||
acts_as_static_record_options[:key] ||
primary_key
)
)
else
value.to_s.gsub(' ',... | [
"def",
"static_record_lookup_key",
"(",
"value",
")",
"if",
"value",
".",
"is_a?",
"self",
"static_record_lookup_key",
"(",
"value",
".",
"send",
"(",
"acts_as_static_record_options",
"[",
":lookup_key",
"]",
"||",
"acts_as_static_record_options",
"[",
":key",
"]",
... | Parse the lookup key | [
"Parse",
"the",
"lookup",
"key"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L311-L323 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.SingletonMethods.find_in_static_record_cache | def find_in_static_record_cache(finder, attributes)#:nodoc:
list = static_record_cache[:primary_key].values.inject([]) do |list, record|
unless attributes.select{|k,v| record.send(k).to_s != v.to_s}.any?
return record if finder == :first
list << record
end
list
en... | ruby | def find_in_static_record_cache(finder, attributes)#:nodoc:
list = static_record_cache[:primary_key].values.inject([]) do |list, record|
unless attributes.select{|k,v| record.send(k).to_s != v.to_s}.any?
return record if finder == :first
list << record
end
list
en... | [
"def",
"find_in_static_record_cache",
"(",
"finder",
",",
"attributes",
")",
"list",
"=",
"static_record_cache",
"[",
":primary_key",
"]",
".",
"values",
".",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"list",
",",
"record",
"|",
"unless",
"attributes",
".",
... | Search the cache for records with the specified attributes
* +finder+ - Same as with +find+ specify <tt>:all</tt>, <tt>:last</tt> or <tt>:first</tt>
<tt>:all</all> returns an array of active records, <tt>:last</tt> or <tt>:first</tt> returns a single instance
* +attributes+ - a hash map of fields (or methods) => ... | [
"Search",
"the",
"cache",
"for",
"records",
"with",
"the",
"specified",
"attributes"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L332-L341 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.SingletonMethods.find_with_static_record | def find_with_static_record(*args)#:nodoc:
if scope(:find).nil? && args
if args.first.is_a?(Fixnum) &&
((args.length == 1 ||
(args[1].is_a?(Hash) && args[1].values.delete(nil).nil?)))
return static_record_cache[:primary_key][args.first]
elsif args.first == :all &&... | ruby | def find_with_static_record(*args)#:nodoc:
if scope(:find).nil? && args
if args.first.is_a?(Fixnum) &&
((args.length == 1 ||
(args[1].is_a?(Hash) && args[1].values.delete(nil).nil?)))
return static_record_cache[:primary_key][args.first]
elsif args.first == :all &&... | [
"def",
"find_with_static_record",
"(",
"*",
"args",
")",
"if",
"scope",
"(",
":find",
")",
".",
"nil?",
"&&",
"args",
"if",
"args",
".",
"first",
".",
"is_a?",
"(",
"Fixnum",
")",
"&&",
"(",
"(",
"args",
".",
"length",
"==",
"1",
"||",
"(",
"args",... | Perform find by searching through the static record cache
if only an id is specified | [
"Perform",
"find",
"by",
"searching",
"through",
"the",
"static",
"record",
"cache",
"if",
"only",
"an",
"id",
"is",
"specified"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L345-L357 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.SingletonMethods.calculate_with_static_record | def calculate_with_static_record(operation, column_name, options={})#:nodoc:
if scope(:find).nil? && !options.any?{ |k,v| k.to_s.downcase != 'distinct' }
key = "#{operation}_#{column_name}_#{options.none?{|k,v| v.blank? }}"
static_record_cache[:calc][key]||=
case operation.to_s
... | ruby | def calculate_with_static_record(operation, column_name, options={})#:nodoc:
if scope(:find).nil? && !options.any?{ |k,v| k.to_s.downcase != 'distinct' }
key = "#{operation}_#{column_name}_#{options.none?{|k,v| v.blank? }}"
static_record_cache[:calc][key]||=
case operation.to_s
... | [
"def",
"calculate_with_static_record",
"(",
"operation",
",",
"column_name",
",",
"options",
"=",
"{",
"}",
")",
"if",
"scope",
"(",
":find",
")",
".",
"nil?",
"&&",
"!",
"options",
".",
"any?",
"{",
"|",
"k",
",",
"v",
"|",
"k",
".",
"to_s",
".",
... | Override calculate to compute data in memory if possible
Only processes results if there is no scope and the no keys other than distinct | [
"Override",
"calculate",
"to",
"compute",
"data",
"in",
"memory",
"if",
"possible",
"Only",
"processes",
"results",
"if",
"there",
"is",
"no",
"scope",
"and",
"the",
"no",
"keys",
"other",
"than",
"distinct"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L361-L388 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.SingletonMethods.static_records_for_calculation | def static_records_for_calculation(column_name, options={}, &block)#:nodoc:
if columns_hash.has_key?(column_name.to_s)
records = static_record_cache[:primary_key].values.collect(&(column_name.to_sym)).compact
results = (options[:distinct]||options['distinct']) ? records.uniq : records
bloc... | ruby | def static_records_for_calculation(column_name, options={}, &block)#:nodoc:
if columns_hash.has_key?(column_name.to_s)
records = static_record_cache[:primary_key].values.collect(&(column_name.to_sym)).compact
results = (options[:distinct]||options['distinct']) ? records.uniq : records
bloc... | [
"def",
"static_records_for_calculation",
"(",
"column_name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"if",
"columns_hash",
".",
"has_key?",
"(",
"column_name",
".",
"to_s",
")",
"records",
"=",
"static_record_cache",
"[",
":primary_key",
"]",
".... | Return the array of results to calculate if they are available | [
"Return",
"the",
"array",
"of",
"results",
"to",
"calculate",
"if",
"they",
"are",
"available"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L391-L399 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.SingletonMethods.initialize_static_record_cache | def initialize_static_record_cache#:nodoc:
return unless @static_record_cache.nil?
records = self.find_without_static_record(:all, acts_as_static_record_options[:find]||{})
@static_record_cache = records.inject({:primary_key => {}, :key => {}, :calc => {}}) do |cache, record|
cache[:primary_ke... | ruby | def initialize_static_record_cache#:nodoc:
return unless @static_record_cache.nil?
records = self.find_without_static_record(:all, acts_as_static_record_options[:find]||{})
@static_record_cache = records.inject({:primary_key => {}, :key => {}, :calc => {}}) do |cache, record|
cache[:primary_ke... | [
"def",
"initialize_static_record_cache",
"return",
"unless",
"@static_record_cache",
".",
"nil?",
"records",
"=",
"self",
".",
"find_without_static_record",
"(",
":all",
",",
"acts_as_static_record_options",
"[",
":find",
"]",
"||",
"{",
"}",
")",
"@static_record_cache"... | Find all the record and initialize the cache | [
"Find",
"all",
"the",
"record",
"and",
"initialize",
"the",
"cache"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L414-L424 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.DefineFinderMethods.static_record_finder_method_name | def static_record_finder_method_name(finder, attributes)#:nodoc:
method_to_call = "find_in_static_record_cache(#{finder.inspect}, #{attributes.inspect})"
if attributes.length == 1
key_value = case attributes.keys.first.to_s
when self.primary_key then [:primary_key, attributes.values.first.... | ruby | def static_record_finder_method_name(finder, attributes)#:nodoc:
method_to_call = "find_in_static_record_cache(#{finder.inspect}, #{attributes.inspect})"
if attributes.length == 1
key_value = case attributes.keys.first.to_s
when self.primary_key then [:primary_key, attributes.values.first.... | [
"def",
"static_record_finder_method_name",
"(",
"finder",
",",
"attributes",
")",
"method_to_call",
"=",
"\"find_in_static_record_cache(#{finder.inspect}, #{attributes.inspect})\"",
"if",
"attributes",
".",
"length",
"==",
"1",
"key_value",
"=",
"case",
"attributes",
".",
"... | Retrieve the method name to call based on the attributes
Single attributes on primary key or the specified key call directly to the cache
All other methods iterate through the cache | [
"Retrieve",
"the",
"method",
"name",
"to",
"call",
"based",
"on",
"the",
"attributes",
"Single",
"attributes",
"on",
"primary",
"key",
"or",
"the",
"specified",
"key",
"call",
"directly",
"to",
"the",
"cache",
"All",
"other",
"methods",
"iterate",
"through",
... | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L447-L458 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.DefineFinderMethods.define_static_record_finder_method | def define_static_record_finder_method(method_id, finder, bang, attributes)#:nodoc:
method_to_call = static_record_finder_method_name(finder, attributes)
method_with_static_record = "#{method_id}_with_static_rc"
#override the method to search memory if there are no args
class_eval %{
de... | ruby | def define_static_record_finder_method(method_id, finder, bang, attributes)#:nodoc:
method_to_call = static_record_finder_method_name(finder, attributes)
method_with_static_record = "#{method_id}_with_static_rc"
#override the method to search memory if there are no args
class_eval %{
de... | [
"def",
"define_static_record_finder_method",
"(",
"method_id",
",",
"finder",
",",
"bang",
",",
"attributes",
")",
"method_to_call",
"=",
"static_record_finder_method_name",
"(",
"finder",
",",
"attributes",
")",
"method_with_static_record",
"=",
"\"#{method_id}_with_static... | Define the finder method on the class, and return the name of the method
Ex. find_by_id will define find_by_id_with_static_rc
The cache is searched if no additional arguments (:conditions, :joins, etc) are specified
If additional arguments do exist find_by_id_without_static_rc is invoked | [
"Define",
"the",
"finder",
"method",
"on",
"the",
"class",
"and",
"return",
"the",
"name",
"of",
"the",
"method",
"Ex",
".",
"find_by_id",
"will",
"define",
"find_by_id_with_static_rc"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L465-L482 | train |
blythedunham/static_record_cache | lib/acts_as_static_record.rb | ActsAsStaticRecord.DefineFinderMethods.method_missing | def method_missing(method_id, *arguments, &block)#:nodoc:
# If the missing method is XXX_without_static_rc, define XXX
# using the superclass ActiveRecord::Base method_missing then
# Finally, alias chain it to XXX_with_static_rc
if ((match = method_id.to_s.match(/(.*)_without_static_rc$/)) &&
... | ruby | def method_missing(method_id, *arguments, &block)#:nodoc:
# If the missing method is XXX_without_static_rc, define XXX
# using the superclass ActiveRecord::Base method_missing then
# Finally, alias chain it to XXX_with_static_rc
if ((match = method_id.to_s.match(/(.*)_without_static_rc$/)) &&
... | [
"def",
"method_missing",
"(",
"method_id",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"if",
"(",
"(",
"match",
"=",
"method_id",
".",
"to_s",
".",
"match",
"(",
"/",
"/",
")",
")",
"&&",
"(",
"base_method_id",
"=",
"match",
"[",
"1",
"]",
")",
... | Method missing is overridden to use cache calls for finder methods | [
"Method",
"missing",
"is",
"overridden",
"to",
"use",
"cache",
"calls",
"for",
"finder",
"methods"
] | 3c8226886a99128a776b5a81f27c7aab8f4ce529 | https://github.com/blythedunham/static_record_cache/blob/3c8226886a99128a776b5a81f27c7aab8f4ce529/lib/acts_as_static_record.rb#L485-L512 | train |
interconn-isp/bollettino | lib/bollettino/generator.rb | Bollettino.Generator.generate! | def generate!(slip, path)
image = MiniMagick::Image.open(File.expand_path('../../../assets/slip.png', __FILE__))
Bollettino::Renderer::Slip.render(image, slip)
image.write path
end | ruby | def generate!(slip, path)
image = MiniMagick::Image.open(File.expand_path('../../../assets/slip.png', __FILE__))
Bollettino::Renderer::Slip.render(image, slip)
image.write path
end | [
"def",
"generate!",
"(",
"slip",
",",
"path",
")",
"image",
"=",
"MiniMagick",
"::",
"Image",
".",
"open",
"(",
"File",
".",
"expand_path",
"(",
"'../../../assets/slip.png'",
",",
"__FILE__",
")",
")",
"Bollettino",
"::",
"Renderer",
"::",
"Slip",
".",
"re... | Initializes the generator.
@param options [Hash]
Generates the given slip.
@param slip [Bollettino::Slip]
@param path [String] | [
"Initializes",
"the",
"generator",
"."
] | adc43d0ba6d1a82da33ba2042f26e67c65e769ba | https://github.com/interconn-isp/bollettino/blob/adc43d0ba6d1a82da33ba2042f26e67c65e769ba/lib/bollettino/generator.rb#L23-L27 | train |
drish/hyperb | lib/hyperb/compose/compose.rb | Hyperb.Compose.compose_down | def compose_down(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'project')
path = '/compose/down'
query = {}
query[:project] = params[:project] if params.key?(:project)
query[:vol] = params[:vol] if params.key?(:vol)
query[:rmi] = params[:rmi] i... | ruby | def compose_down(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'project')
path = '/compose/down'
query = {}
query[:project] = params[:project] if params.key?(:project)
query[:vol] = params[:vol] if params.key?(:vol)
query[:rmi] = params[:rmi] i... | [
"def",
"compose_down",
"(",
"params",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Invalid arguments.'",
"unless",
"check_arguments",
"(",
"params",
",",
"'project'",
")",
"path",
"=",
"'/compose/down'",
"query",
"=",
"{",
"}",
"query",
"[",
":project"... | stop and remove a compose project
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Compose/compose_down.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::NotFound] raised ips are not found.
@returns [HTTP::Response::Body] a streamable respo... | [
"stop",
"and",
"remove",
"a",
"compose",
"project"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/compose/compose.rb#L27-L36 | train |
drish/hyperb | lib/hyperb/compose/compose.rb | Hyperb.Compose.compose_create | def compose_create(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'project')
path = '/compose/create'
query = {}
body = {}
query[:project] = params[:project] if params.key?(:project)
body[:serviceconfigs] = { 'M': {} } # inherited from libcompo... | ruby | def compose_create(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'project')
path = '/compose/create'
query = {}
body = {}
query[:project] = params[:project] if params.key?(:project)
body[:serviceconfigs] = { 'M': {} } # inherited from libcompo... | [
"def",
"compose_create",
"(",
"params",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Invalid arguments.'",
"unless",
"check_arguments",
"(",
"params",
",",
"'project'",
")",
"path",
"=",
"'/compose/create'",
"query",
"=",
"{",
"}",
"body",
"=",
"{",
... | create a compose project
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/
Compose/compose_create.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@raise [Hyperb::Error::NotFound] raised ips are not found.
@returns [HTTP::Response::Body] a streamable response o... | [
"create",
"a",
"compose",
"project"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/compose/compose.rb#L102-L114 | train |
peter-edge/jprotobuf_ruby | lib/jprotobuf/message.rb | JProtobuf.Message.write_to_string_io | def write_to_string_io(string_io)
java_proto.write_to(org.jruby.util.IOOutputStream.new(string_io))
nil
end | ruby | def write_to_string_io(string_io)
java_proto.write_to(org.jruby.util.IOOutputStream.new(string_io))
nil
end | [
"def",
"write_to_string_io",
"(",
"string_io",
")",
"java_proto",
".",
"write_to",
"(",
"org",
".",
"jruby",
".",
"util",
".",
"IOOutputStream",
".",
"new",
"(",
"string_io",
")",
")",
"nil",
"end"
] | Serialize the message to the given StringIO.
@return [nil] | [
"Serialize",
"the",
"message",
"to",
"the",
"given",
"StringIO",
"."
] | 764a39b82bea75654995002606b8fb72f830e4c0 | https://github.com/peter-edge/jprotobuf_ruby/blob/764a39b82bea75654995002606b8fb72f830e4c0/lib/jprotobuf/message.rb#L225-L228 | train |
peter-edge/jprotobuf_ruby | lib/jprotobuf/message.rb | JProtobuf.Message.write_to_string | def write_to_string
string_io = StringIO.new.set_encoding(Encoding::BINARY)
write_to_string_io(string_io)
string_io.string
end | ruby | def write_to_string
string_io = StringIO.new.set_encoding(Encoding::BINARY)
write_to_string_io(string_io)
string_io.string
end | [
"def",
"write_to_string",
"string_io",
"=",
"StringIO",
".",
"new",
".",
"set_encoding",
"(",
"Encoding",
"::",
"BINARY",
")",
"write_to_string_io",
"(",
"string_io",
")",
"string_io",
".",
"string",
"end"
] | Serialize the message to a String.
@return [String] the serialized message, in a String | [
"Serialize",
"the",
"message",
"to",
"a",
"String",
"."
] | 764a39b82bea75654995002606b8fb72f830e4c0 | https://github.com/peter-edge/jprotobuf_ruby/blob/764a39b82bea75654995002606b8fb72f830e4c0/lib/jprotobuf/message.rb#L233-L237 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.FaceAction.do | def do(actor, targets)
return if targets.empty?
actor.vector.pitch = Utility.find_angle(actor.location, random_target(targets).location)
end | ruby | def do(actor, targets)
return if targets.empty?
actor.vector.pitch = Utility.find_angle(actor.location, random_target(targets).location)
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"return",
"if",
"targets",
".",
"empty?",
"actor",
".",
"vector",
".",
"pitch",
"=",
"Utility",
".",
"find_angle",
"(",
"actor",
".",
"location",
",",
"random_target",
"(",
"targets",
")",
".",
"location",
... | Set the actor's heading to point directly at first target. | [
"Set",
"the",
"actor",
"s",
"heading",
"to",
"point",
"directly",
"at",
"first",
"target",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L62-L65 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.ApproachAction.do | def do(actor, targets)
return if targets.empty?
#Apply thrust to the creature's movement vector, adjusted by elapsed time.
actor.vector += Vector.new(
delta,
Utility.find_angle(actor.location, random_target(targets).location)
)
end | ruby | def do(actor, targets)
return if targets.empty?
#Apply thrust to the creature's movement vector, adjusted by elapsed time.
actor.vector += Vector.new(
delta,
Utility.find_angle(actor.location, random_target(targets).location)
)
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"return",
"if",
"targets",
".",
"empty?",
"actor",
".",
"vector",
"+=",
"Vector",
".",
"new",
"(",
"delta",
",",
"Utility",
".",
"find_angle",
"(",
"actor",
".",
"location",
",",
"random_target",
"(",
"ta... | Accelerate toward the first target, but limited by rate. | [
"Accelerate",
"toward",
"the",
"first",
"target",
"but",
"limited",
"by",
"rate",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L110-L117 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.DestroyAction.do | def do(actor, targets)
targets.each do |target|
target.environment.remove_object(target.identifier)
end
end | ruby | def do(actor, targets)
targets.each do |target|
target.environment.remove_object(target.identifier)
end
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"targets",
".",
"each",
"do",
"|",
"target",
"|",
"target",
".",
"environment",
".",
"remove_object",
"(",
"target",
".",
"identifier",
")",
"end",
"end"
] | Remove the target from the environment. | [
"Remove",
"the",
"target",
"from",
"the",
"environment",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L138-L142 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.TagAction.do | def do(actor, targets)
targets.each do |target|
target.tags << tag unless target.tags.include?(tag)
end
end | ruby | def do(actor, targets)
targets.each do |target|
target.tags << tag unless target.tags.include?(tag)
end
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"targets",
".",
"each",
"do",
"|",
"target",
"|",
"target",
".",
"tags",
"<<",
"tag",
"unless",
"target",
".",
"tags",
".",
"include?",
"(",
"tag",
")",
"end",
"end"
] | Apply the given tag to the targets. | [
"Apply",
"the",
"given",
"tag",
"to",
"the",
"targets",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L168-L172 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.BlendAction.do | def do(actor, targets)
actor.color.red += (@color.red - actor.color.red) * delta
actor.color.green += (@color.green - actor.color.green) * delta
actor.color.blue += (@color.blue - actor.color.blue) * delta
end | ruby | def do(actor, targets)
actor.color.red += (@color.red - actor.color.red) * delta
actor.color.green += (@color.green - actor.color.green) * delta
actor.color.blue += (@color.blue - actor.color.blue) * delta
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"actor",
".",
"color",
".",
"red",
"+=",
"(",
"@color",
".",
"red",
"-",
"actor",
".",
"color",
".",
"red",
")",
"*",
"delta",
"actor",
".",
"color",
".",
"green",
"+=",
"(",
"@color",
".",
"green",... | Blend the actor's color with the assigned color. | [
"Blend",
"the",
"actor",
"s",
"color",
"with",
"the",
"assigned",
"color",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L193-L197 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.PushAction.do | def do(actor, targets)
#Acceleration will be limited by elapsed time.
push_force = delta
targets.each do |target|
#Angle to target is also angle of push force.
push_angle = Utility.find_angle(actor.location, target.location)
#Apply the force to the creature's movement vector.
target.... | ruby | def do(actor, targets)
#Acceleration will be limited by elapsed time.
push_force = delta
targets.each do |target|
#Angle to target is also angle of push force.
push_angle = Utility.find_angle(actor.location, target.location)
#Apply the force to the creature's movement vector.
target.... | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"push_force",
"=",
"delta",
"targets",
".",
"each",
"do",
"|",
"target",
"|",
"push_angle",
"=",
"Utility",
".",
"find_angle",
"(",
"actor",
".",
"location",
",",
"target",
".",
"location",
")",
"target",
... | Push the targets away from the actor, with force limited by elapsed time. | [
"Push",
"the",
"targets",
"away",
"from",
"the",
"actor",
"with",
"force",
"limited",
"by",
"elapsed",
"time",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L214-L223 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.PullAction.do | def do(actor, targets)
#Acceleration will be limited by elapsed time.
pull_force = delta
targets.each do |target|
#Angle from target to actor is also angle of pull force (opposite of that for push).
pull_angle = Utility.find_angle(target.location, actor.location)
#Apply the force to the cr... | ruby | def do(actor, targets)
#Acceleration will be limited by elapsed time.
pull_force = delta
targets.each do |target|
#Angle from target to actor is also angle of pull force (opposite of that for push).
pull_angle = Utility.find_angle(target.location, actor.location)
#Apply the force to the cr... | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"pull_force",
"=",
"delta",
"targets",
".",
"each",
"do",
"|",
"target",
"|",
"pull_angle",
"=",
"Utility",
".",
"find_angle",
"(",
"target",
".",
"location",
",",
"actor",
".",
"location",
")",
"target",
... | Pull the targets toward the actor, with force limited by elapsed time. | [
"Pull",
"the",
"targets",
"toward",
"the",
"actor",
"with",
"force",
"limited",
"by",
"elapsed",
"time",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L232-L241 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.SpawnAction.do | def do(actor, targets)
prototypes.each do |prototype|
actor.environment.add_object(generate_child(actor, prototype))
end
end | ruby | def do(actor, targets)
prototypes.each do |prototype|
actor.environment.add_object(generate_child(actor, prototype))
end
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"prototypes",
".",
"each",
"do",
"|",
"prototype",
"|",
"actor",
".",
"environment",
".",
"add_object",
"(",
"generate_child",
"(",
"actor",
",",
"prototype",
")",
")",
"end",
"end"
] | Add children to environment. | [
"Add",
"children",
"to",
"environment",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L280-L284 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.SpawnAction.generate_child | def generate_child(actor, prototype)
#Copy prototype so it can be spawned repeatedly if need be.
child = prototype.copy
child.location = actor.location.copy
child
end | ruby | def generate_child(actor, prototype)
#Copy prototype so it can be spawned repeatedly if need be.
child = prototype.copy
child.location = actor.location.copy
child
end | [
"def",
"generate_child",
"(",
"actor",
",",
"prototype",
")",
"child",
"=",
"prototype",
".",
"copy",
"child",
".",
"location",
"=",
"actor",
".",
"location",
".",
"copy",
"child",
"end"
] | Copy prototype to actor's location. | [
"Copy",
"prototype",
"to",
"actor",
"s",
"location",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L286-L291 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.ExplodeAction.generate_child | def generate_child(actor, prototype)
child = super
child.vector += actor.vector
child.size = actor.size / prototypes.length
child
end | ruby | def generate_child(actor, prototype)
child = super
child.vector += actor.vector
child.size = actor.size / prototypes.length
child
end | [
"def",
"generate_child",
"(",
"actor",
",",
"prototype",
")",
"child",
"=",
"super",
"child",
".",
"vector",
"+=",
"actor",
".",
"vector",
"child",
".",
"size",
"=",
"actor",
".",
"size",
"/",
"prototypes",
".",
"length",
"child",
"end"
] | Calls super method.
Also adds actor's vector to child's.
Finally, reduces child's size to actor's size divided by number of shrapnel pieces. | [
"Calls",
"super",
"method",
".",
"Also",
"adds",
"actor",
"s",
"vector",
"to",
"child",
"s",
".",
"Finally",
"reduces",
"child",
"s",
"size",
"to",
"actor",
"s",
"size",
"divided",
"by",
"number",
"of",
"shrapnel",
"pieces",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L319-L324 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.ShootAction.do | def do(actor, targets)
return if targets.empty?
#If next item is a collection of prototypes, copy them all in at once.
if prototypes[@prototype_index].respond_to?(:each)
prototypes[@prototype_index].each do |prototype|
actor.environment.add_object(generate_child(actor, prototype, targets[@targ... | ruby | def do(actor, targets)
return if targets.empty?
#If next item is a collection of prototypes, copy them all in at once.
if prototypes[@prototype_index].respond_to?(:each)
prototypes[@prototype_index].each do |prototype|
actor.environment.add_object(generate_child(actor, prototype, targets[@targ... | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"return",
"if",
"targets",
".",
"empty?",
"if",
"prototypes",
"[",
"@prototype_index",
"]",
".",
"respond_to?",
"(",
":each",
")",
"prototypes",
"[",
"@prototype_index",
"]",
".",
"each",
"do",
"|",
"prototyp... | Copies next prototype into environment. | [
"Copies",
"next",
"prototype",
"into",
"environment",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L342-L356 | train |
jaymcgavren/zyps | lib/zyps/actions.rb | Zyps.ShootAction.generate_child | def generate_child(actor, prototype, target)
child = super(actor, prototype)
child.vector.pitch = Utility.find_angle(actor.location, target.location) + child.vector.pitch
child
end | ruby | def generate_child(actor, prototype, target)
child = super(actor, prototype)
child.vector.pitch = Utility.find_angle(actor.location, target.location) + child.vector.pitch
child
end | [
"def",
"generate_child",
"(",
"actor",
",",
"prototype",
",",
"target",
")",
"child",
"=",
"super",
"(",
"actor",
",",
"prototype",
")",
"child",
".",
"vector",
".",
"pitch",
"=",
"Utility",
".",
"find_angle",
"(",
"actor",
".",
"location",
",",
"target"... | Calls super method.
Also adds angle to target to child's vector angle. | [
"Calls",
"super",
"method",
".",
"Also",
"adds",
"angle",
"to",
"target",
"to",
"child",
"s",
"vector",
"angle",
"."
] | 7fa9dc497abc30fe2d1a2a17e129628ffb0456fb | https://github.com/jaymcgavren/zyps/blob/7fa9dc497abc30fe2d1a2a17e129628ffb0456fb/lib/zyps/actions.rb#L359-L363 | train |
carsomyr/percolate | lib/percolate/percolator.rb | Percolate.Percolator.find | def find(context, facet_name, *args)
facet = find_facet(context, facet_name)
if !facet
return nil
end
case result = facet.find(*args)
when Array
result.map { |item| @entities[item] }
when String
@entities[result]
when NilClass
nil
else
... | ruby | def find(context, facet_name, *args)
facet = find_facet(context, facet_name)
if !facet
return nil
end
case result = facet.find(*args)
when Array
result.map { |item| @entities[item] }
when String
@entities[result]
when NilClass
nil
else
... | [
"def",
"find",
"(",
"context",
",",
"facet_name",
",",
"*",
"args",
")",
"facet",
"=",
"find_facet",
"(",
"context",
",",
"facet_name",
")",
"if",
"!",
"facet",
"return",
"nil",
"end",
"case",
"result",
"=",
"facet",
".",
"find",
"(",
"*",
"args",
")... | Finds an entity or entities.
@param context [String] the lookup context.
@param facet_name [Symbol] the facet name.
@param args [Array] the argument splat passed to the facet.
@return [Object] the retrieved entity or entities. | [
"Finds",
"an",
"entity",
"or",
"entities",
"."
] | 7c9e38ca5e3b62a7a6c6d470945c694499316dc9 | https://github.com/carsomyr/percolate/blob/7c9e38ca5e3b62a7a6c6d470945c694499316dc9/lib/percolate/percolator.rb#L71-L88 | train |
carsomyr/percolate | lib/percolate/percolator.rb | Percolate.Percolator.find_facet | def find_facet(context, facet_name)
cache_key = [context, facet_name]
if @facet_cache.include?(cache_key)
facet = @facet_cache[cache_key]
else
begin
require "percolate/facet/#{facet_name}_facet"
rescue LoadError
# Do nothing. Give the benefit of the doubt i... | ruby | def find_facet(context, facet_name)
cache_key = [context, facet_name]
if @facet_cache.include?(cache_key)
facet = @facet_cache[cache_key]
else
begin
require "percolate/facet/#{facet_name}_facet"
rescue LoadError
# Do nothing. Give the benefit of the doubt i... | [
"def",
"find_facet",
"(",
"context",
",",
"facet_name",
")",
"cache_key",
"=",
"[",
"context",
",",
"facet_name",
"]",
"if",
"@facet_cache",
".",
"include?",
"(",
"cache_key",
")",
"facet",
"=",
"@facet_cache",
"[",
"cache_key",
"]",
"else",
"begin",
"requir... | Finds a facet.
@param context [String] the lookup context.
@param facet_name [Symbol] the facet name.
@return [Object] the facet. | [
"Finds",
"a",
"facet",
"."
] | 7c9e38ca5e3b62a7a6c6d470945c694499316dc9 | https://github.com/carsomyr/percolate/blob/7c9e38ca5e3b62a7a6c6d470945c694499316dc9/lib/percolate/percolator.rb#L96-L114 | train |
tsonntag/gitter | lib/gitter/utils.rb | Gitter.Utils.url_for | def url_for params
p = params.dup
query = p.map{|key, value| value.to_query(key) } * '&'
"#{h.url_for({})}?#{query}"
end | ruby | def url_for params
p = params.dup
query = p.map{|key, value| value.to_query(key) } * '&'
"#{h.url_for({})}?#{query}"
end | [
"def",
"url_for",
"params",
"p",
"=",
"params",
".",
"dup",
"query",
"=",
"p",
".",
"map",
"{",
"|",
"key",
",",
"value",
"|",
"value",
".",
"to_query",
"(",
"key",
")",
"}",
"*",
"'&'",
"\"#{h.url_for({})}?#{query}\"",
"end"
] | dirty hack to avoid rails' sorted query in url | [
"dirty",
"hack",
"to",
"avoid",
"rails",
"sorted",
"query",
"in",
"url"
] | 55c79a5d8012129517510d1d1758621f4baf5344 | https://github.com/tsonntag/gitter/blob/55c79a5d8012129517510d1d1758621f4baf5344/lib/gitter/utils.rb#L5-L9 | train |
drish/hyperb | lib/hyperb/services/services.rb | Hyperb.Services.create_service | def create_service(params = {})
valid = check_arguments(params, 'name', 'image', 'replicas', 'serviceport', 'labels')
raise ArgumentError, 'Invalid arguments.' unless valid
path = '/services/create'
body = {}
body.merge!(params)
downcase_symbolize(JSON.parse(Hyperb::Request.new(self,... | ruby | def create_service(params = {})
valid = check_arguments(params, 'name', 'image', 'replicas', 'serviceport', 'labels')
raise ArgumentError, 'Invalid arguments.' unless valid
path = '/services/create'
body = {}
body.merge!(params)
downcase_symbolize(JSON.parse(Hyperb::Request.new(self,... | [
"def",
"create_service",
"(",
"params",
"=",
"{",
"}",
")",
"valid",
"=",
"check_arguments",
"(",
"params",
",",
"'name'",
",",
"'image'",
",",
"'replicas'",
",",
"'serviceport'",
",",
"'labels'",
")",
"raise",
"ArgumentError",
",",
"'Invalid arguments.'",
"un... | create a service
@see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Service/create.html
@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
@return [Hash] Hash containing service information.
@param params [Hash] A customizable set of params.
@param params [String] :ima... | [
"create",
"a",
"service"
] | 637de68dc304d8d07470a771f499e33f227955f4 | https://github.com/drish/hyperb/blob/637de68dc304d8d07470a771f499e33f227955f4/lib/hyperb/services/services.rb#L36-L43 | train |
Sage/hash_kit | lib/hash_kit/helper.rb | HashKit.Helper.symbolize | def symbolize(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_sym] = map_value_symbol(value) }
end
end | ruby | def symbolize(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_sym] = map_value_symbol(value) }
end
end | [
"def",
"symbolize",
"(",
"hash",
")",
"{",
"}",
".",
"tap",
"do",
"|",
"h",
"|",
"hash",
".",
"each",
"{",
"|",
"key",
",",
"value",
"|",
"h",
"[",
"key",
".",
"to_sym",
"]",
"=",
"map_value_symbol",
"(",
"value",
")",
"}",
"end",
"end"
] | This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application. | [
"This",
"method",
"is",
"called",
"to",
"convert",
"all",
"the",
"keys",
"of",
"a",
"hash",
"into",
"symbols",
"to",
"allow",
"consistent",
"usage",
"of",
"hashes",
"within",
"your",
"Ruby",
"application",
"."
] | b46019965325c51df3f53985a8c22e15037d9b8c | https://github.com/Sage/hash_kit/blob/b46019965325c51df3f53985a8c22e15037d9b8c/lib/hash_kit/helper.rb#L50-L54 | train |
Sage/hash_kit | lib/hash_kit/helper.rb | HashKit.Helper.stringify | def stringify(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_s] = map_value_string(value) }
end
end | ruby | def stringify(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_s] = map_value_string(value) }
end
end | [
"def",
"stringify",
"(",
"hash",
")",
"{",
"}",
".",
"tap",
"do",
"|",
"h",
"|",
"hash",
".",
"each",
"{",
"|",
"key",
",",
"value",
"|",
"h",
"[",
"key",
".",
"to_s",
"]",
"=",
"map_value_string",
"(",
"value",
")",
"}",
"end",
"end"
] | This method is called to convert all the keys of a hash into strings to allow consistent usage of hashes within your Ruby application. | [
"This",
"method",
"is",
"called",
"to",
"convert",
"all",
"the",
"keys",
"of",
"a",
"hash",
"into",
"strings",
"to",
"allow",
"consistent",
"usage",
"of",
"hashes",
"within",
"your",
"Ruby",
"application",
"."
] | b46019965325c51df3f53985a8c22e15037d9b8c | https://github.com/Sage/hash_kit/blob/b46019965325c51df3f53985a8c22e15037d9b8c/lib/hash_kit/helper.rb#L57-L61 | train |
Sage/hash_kit | lib/hash_kit/helper.rb | HashKit.Helper.to_hash | def to_hash(obj)
return nil unless obj
return obj if obj.is_a?(Hash)
hash = {}
obj.instance_variables.each do |key|
hash[key[1..-1].to_sym] = deeply_to_hash(obj.instance_variable_get(key))
end
hash
end | ruby | def to_hash(obj)
return nil unless obj
return obj if obj.is_a?(Hash)
hash = {}
obj.instance_variables.each do |key|
hash[key[1..-1].to_sym] = deeply_to_hash(obj.instance_variable_get(key))
end
hash
end | [
"def",
"to_hash",
"(",
"obj",
")",
"return",
"nil",
"unless",
"obj",
"return",
"obj",
"if",
"obj",
".",
"is_a?",
"(",
"Hash",
")",
"hash",
"=",
"{",
"}",
"obj",
".",
"instance_variables",
".",
"each",
"do",
"|",
"key",
"|",
"hash",
"[",
"key",
"[",... | Convert an object to a hash representation of its instance variables.
@return [Hash] if the object is not nil, otherwise nil is returned. | [
"Convert",
"an",
"object",
"to",
"a",
"hash",
"representation",
"of",
"its",
"instance",
"variables",
"."
] | b46019965325c51df3f53985a8c22e15037d9b8c | https://github.com/Sage/hash_kit/blob/b46019965325c51df3f53985a8c22e15037d9b8c/lib/hash_kit/helper.rb#L65-L74 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.follow | def follow(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
return if blocked?(to_id, from_id, scope)
return if Amico.pending_follow && pending?(from_id, to_id, scope)
if Amico.pending_follow
Amico.redis.multi do |transaction|
transaction.zadd("#{Ami... | ruby | def follow(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
return if blocked?(to_id, from_id, scope)
return if Amico.pending_follow && pending?(from_id, to_id, scope)
if Amico.pending_follow
Amico.redis.multi do |transaction|
transaction.zadd("#{Ami... | [
"def",
"follow",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"return",
"if",
"from_id",
"==",
"to_id",
"return",
"if",
"blocked?",
"(",
"to_id",
",",
"from_id",
",",
"scope",
")",
"return",
"if",
"Amico",
".",... | Establish a follow relationship between two IDs. After adding the follow
relationship, it checks to see if the relationship is reciprocated and establishes that
relationship if so.
@param from_id [String] The ID of the individual establishing the follow relationship.
@param to_id [String] The ID of the individual ... | [
"Establish",
"a",
"follow",
"relationship",
"between",
"two",
"IDs",
".",
"After",
"adding",
"the",
"follow",
"relationship",
"it",
"checks",
"to",
"see",
"if",
"the",
"relationship",
"is",
"reciprocated",
"and",
"establishes",
"that",
"relationship",
"if",
"so"... | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L14-L27 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.unfollow | def unfollow(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
... | ruby | def unfollow(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
... | [
"def",
"unfollow",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"return",
"if",
"from_id",
"==",
"to_id",
"Amico",
".",
"redis",
".",
"multi",
"do",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:... | Remove a follow relationship between two IDs. After removing the follow
relationship, if a reciprocated relationship was established, it is
also removed.
@param from_id [String] The ID of the individual removing the follow relationship.
@param to_id [String] The ID of the individual to be unfollowed.
@param scope... | [
"Remove",
"a",
"follow",
"relationship",
"between",
"two",
"IDs",
".",
"After",
"removing",
"the",
"follow",
"relationship",
"if",
"a",
"reciprocated",
"relationship",
"was",
"established",
"it",
"is",
"also",
"removed",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L41-L52 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.block | def block(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{to_id}", from_id)
... | ruby | def block(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{to_id}", from_id)
... | [
"def",
"block",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"return",
"if",
"from_id",
"==",
"to_id",
"Amico",
".",
"redis",
".",
"multi",
"do",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{A... | Block a relationship between two IDs. This method also has the side effect
of removing any follower or following relationship between the two IDs.
@param from_id [String] The ID of the individual blocking the relationship.
@param to_id [String] The ID of the individual being blocked.
@param scope [String] Scope fo... | [
"Block",
"a",
"relationship",
"between",
"two",
"IDs",
".",
"This",
"method",
"also",
"has",
"the",
"side",
"effect",
"of",
"removing",
"any",
"follower",
"or",
"following",
"relationship",
"between",
"the",
"two",
"IDs",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L64-L79 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.accept | def accept(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
add_following_followers_reciprocated(from_id, to_id, scope)
end | ruby | def accept(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
add_following_followers_reciprocated(from_id, to_id, scope)
end | [
"def",
"accept",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"return",
"if",
"from_id",
"==",
"to_id",
"add_following_followers_reciprocated",
"(",
"from_id",
",",
"to_id",
",",
"scope",
")",
"end"
] | Accept a relationship that is pending between two IDs.
@param from_id [String] The ID of the individual accepting the relationship.
@param to_id [String] The ID of the individual to be accepted.
@param scope [String] Scope for the call.
Example
Amico.follow(1, 11)
Amico.pending?(1, 11) # true
Amico.acce... | [
"Accept",
"a",
"relationship",
"that",
"is",
"pending",
"between",
"two",
"IDs",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L113-L117 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.deny | def deny(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
... | ruby | def deny(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
... | [
"def",
"deny",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"return",
"if",
"from_id",
"==",
"to_id",
"Amico",
".",
"redis",
".",
"multi",
"do",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Am... | Deny a relationship that is pending between two IDs.
@param from_id [String] The ID of the individual denying the relationship.
@param to_id [String] The ID of the individual to be denied.
@param scope [String] Scope for the call.
Example
Amico.follow(1, 11)
Amico.pending?(1, 11) # true
Amico.deny(1, 11... | [
"Deny",
"a",
"relationship",
"that",
"is",
"pending",
"between",
"two",
"IDs",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L132-L139 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.following? | def following?(id, following_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", following_id).nil?
end | ruby | def following?(id, following_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", following_id).nil?
end | [
"def",
"following?",
"(",
"id",
",",
"following_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"!",
"Amico",
".",
"redis",
".",
"zscore",
"(",
"\"#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}\"",
",",
"following_id",
")",
".",
"nil?",
"... | Check to see if one individual is following another individual.
@param id [String] ID of the individual checking the following status.
@param following_id [String] ID of the individual to see if they are being followed by id.
@param scope [String] Scope for the call.
Examples
Amico.follow(1, 11)
Amico.foll... | [
"Check",
"to",
"see",
"if",
"one",
"individual",
"is",
"following",
"another",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L286-L288 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.follower? | def follower?(id, follower_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", follower_id).nil?
end | ruby | def follower?(id, follower_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", follower_id).nil?
end | [
"def",
"follower?",
"(",
"id",
",",
"follower_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"!",
"Amico",
".",
"redis",
".",
"zscore",
"(",
"\"#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}\"",
",",
"follower_id",
")",
".",
"nil?",
"end... | Check to see if one individual is a follower of another individual.
@param id [String] ID of the individual checking the follower status.
@param following_id [String] ID of the individual to see if they are following id.
@param scope [String] Scope for the call.
Examples
Amico.follow(11, 1)
Amico.follower?... | [
"Check",
"to",
"see",
"if",
"one",
"individual",
"is",
"a",
"follower",
"of",
"another",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L302-L304 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.blocked? | def blocked?(id, blocked_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", blocked_id).nil?
end | ruby | def blocked?(id, blocked_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", blocked_id).nil?
end | [
"def",
"blocked?",
"(",
"id",
",",
"blocked_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"!",
"Amico",
".",
"redis",
".",
"zscore",
"(",
"\"#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}\"",
",",
"blocked_id",
")",
".",
"nil?",
"end"
] | Check to see if one individual has blocked another individual.
@param id [String] ID of the individual checking the blocked status.
@param blocked_id [String] ID of the individual to see if they are blocked by id.
@param scope [String] Scope for the call.
Examples
Amico.block(1, 11)
Amico.blocked?(1, 11)
... | [
"Check",
"to",
"see",
"if",
"one",
"individual",
"has",
"blocked",
"another",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L318-L320 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.blocked_by? | def blocked_by?(id, blocked_by_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", blocked_by_id).nil?
end | ruby | def blocked_by?(id, blocked_by_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", blocked_by_id).nil?
end | [
"def",
"blocked_by?",
"(",
"id",
",",
"blocked_by_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"!",
"Amico",
".",
"redis",
".",
"zscore",
"(",
"\"#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}\"",
",",
"blocked_by_id",
")",
".",
"nil?",... | Check to see if one individual is blocked by another individual.
@param id [String] ID of the individual checking the blocked by status.
@param blocked_id [String] ID of the individual to see if they have blocked id.
@param scope [String] Scope for the call.
Examples
Amico.block(1, 11)
Amico.blocked_by?(11... | [
"Check",
"to",
"see",
"if",
"one",
"individual",
"is",
"blocked",
"by",
"another",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L334-L336 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.reciprocated? | def reciprocated?(from_id, to_id, scope = Amico.default_scope_key)
following?(from_id, to_id, scope) && following?(to_id, from_id, scope)
end | ruby | def reciprocated?(from_id, to_id, scope = Amico.default_scope_key)
following?(from_id, to_id, scope) && following?(to_id, from_id, scope)
end | [
"def",
"reciprocated?",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"following?",
"(",
"from_id",
",",
"to_id",
",",
"scope",
")",
"&&",
"following?",
"(",
"to_id",
",",
"from_id",
",",
"scope",
")",
"end"
] | Check to see if one individual has reciprocated in following another individual.
@param from_id [String] ID of the individual checking the reciprocated relationship.
@param to_id [String] ID of the individual to see if they are following from_id.
@param scope [String] Scope for the call.
Examples
Amico.follow... | [
"Check",
"to",
"see",
"if",
"one",
"individual",
"has",
"reciprocated",
"in",
"following",
"another",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L351-L353 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.pending_with? | def pending_with?(from_id, to_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id).nil?
end | ruby | def pending_with?(from_id, to_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id).nil?
end | [
"def",
"pending_with?",
"(",
"from_id",
",",
"to_id",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"!",
"Amico",
".",
"redis",
".",
"zscore",
"(",
"\"#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}\"",
",",
"from_id",
")",
".",
"nil?",
... | Check to see if one individual has a pending relationship with another.
@param from_id [String] ID of the individual checking the pending relationships.
@param to_id [String] ID of the individual to see if they are pending an approval from from_id.
@param scope [String] Scope for the call.
Examples
Amico.foll... | [
"Check",
"to",
"see",
"if",
"one",
"individual",
"has",
"a",
"pending",
"relationship",
"with",
"another",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L383-L385 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.following_page_count | def following_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", page_size)
end | ruby | def following_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", page_size)
end | [
"def",
"following_page_count",
"(",
"id",
",",
"page_size",
"=",
"Amico",
".",
"page_size",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"total_pages",
"(",
"\"#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}\"",
",",
"page_size",
")",
"end"
] | Count the number of pages of following relationships for an individual.
@param id [String] ID of the individual.
@param page_size [int] Page size.
@param scope [String] Scope for the call.
Examples
Amico.follow(1, 11)
Amico.follow(1, 12)
Amico.following_page_count(1)
@return the number of pages of fol... | [
"Count",
"the",
"number",
"of",
"pages",
"of",
"following",
"relationships",
"for",
"an",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L521-L523 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.followers_page_count | def followers_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", page_size)
end | ruby | def followers_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", page_size)
end | [
"def",
"followers_page_count",
"(",
"id",
",",
"page_size",
"=",
"Amico",
".",
"page_size",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"total_pages",
"(",
"\"#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}\"",
",",
"page_size",
")",
"end"
] | Count the number of pages of follower relationships for an individual.
@param id [String] ID of the individual.
@param page_size [int] Page size (default: Amico.page_size).
@param scope [String] Scope for the call.
Examples
Amico.follow(11, 1)
Amico.follow(12, 1)
Amico.followers_page_count(1)
@return ... | [
"Count",
"the",
"number",
"of",
"pages",
"of",
"follower",
"relationships",
"for",
"an",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L538-L540 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.blocked_page_count | def blocked_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_size)
end | ruby | def blocked_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_size)
end | [
"def",
"blocked_page_count",
"(",
"id",
",",
"page_size",
"=",
"Amico",
".",
"page_size",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"total_pages",
"(",
"\"#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}\"",
",",
"page_size",
")",
"end"
] | Count the number of pages of blocked relationships for an individual.
@param id [String] ID of the individual.
@param page_size [int] Page size (default: Amico.page_size).
@param scope [String] Scope for the call.
Examples
Amico.block(1, 11)
Amico.block(1, 12)
Amico.blocked_page_count(1)
@return the n... | [
"Count",
"the",
"number",
"of",
"pages",
"of",
"blocked",
"relationships",
"for",
"an",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L555-L557 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.blocked_by_page_count | def blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", page_size)
end | ruby | def blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", page_size)
end | [
"def",
"blocked_by_page_count",
"(",
"id",
",",
"page_size",
"=",
"Amico",
".",
"page_size",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"total_pages",
"(",
"\"#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}\"",
",",
"page_size",
")",
"end"
] | Count the number of pages of blocked_by relationships for an individual.
@param id [String] ID of the individual.
@param page_size [int] Page size (default: Amico.page_size).
@param scope [String] Scope for the call.
Examples
Amico.block(11, 1)
Amico.block(12, 1)
Amico.blocked_by_page_count(1)
@return... | [
"Count",
"the",
"number",
"of",
"pages",
"of",
"blocked_by",
"relationships",
"for",
"an",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L572-L574 | train |
agoragames/amico | lib/amico/relationships.rb | Amico.Relationships.reciprocated_page_count | def reciprocated_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}", page_size)
end | ruby | def reciprocated_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}", page_size)
end | [
"def",
"reciprocated_page_count",
"(",
"id",
",",
"page_size",
"=",
"Amico",
".",
"page_size",
",",
"scope",
"=",
"Amico",
".",
"default_scope_key",
")",
"total_pages",
"(",
"\"#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}\"",
",",
"page_size",
")",
"end"
... | Count the number of pages of reciprocated relationships for an individual.
@param id [String] ID of the individual.
@param page_size [int] Page size (default: Amico.page_size).
@param scope [String] Scope for the call.
Examples
Amico.follow(1, 11)
Amico.follow(1, 12)
Amico.follow(11, 1)
Amico.follow(... | [
"Count",
"the",
"number",
"of",
"pages",
"of",
"reciprocated",
"relationships",
"for",
"an",
"individual",
"."
] | 60309bd2f9466bce3ec42235c44f4dae55f6f45e | https://github.com/agoragames/amico/blob/60309bd2f9466bce3ec42235c44f4dae55f6f45e/lib/amico/relationships.rb#L591-L593 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.