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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | 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, prefix.to_sym, :admin) || nil
when "local"
LOCAL&.dig(@lang, prefix.to_sym) || nil
when "enterprise", "social-group"
@issuer || nil
when "professional" then "PROFESSIONAL STANDARD" # TODO
end
end | 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, prefix.to_sym, :admin) || nil
when "local"
LOCAL&.dig(@lang, prefix.to_sym) || nil
when "enterprise", "social-group"
@issuer || nil
when "professional" then "PROFESSIONAL STANDARD" # TODO
end
end | [
"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",
",",
"prefix",
".",
"to_sym",
",",
":admin",
")",
"||",
"nil",
"when",
"\"local\"",
"LOCAL",
"&.",
"dig",
"(",
"@lang",
",",
"prefix",
".",
"to_sym",
")",
"||",
"nil",
"when",
"\"enterprise\"",
",",
"\"social-group\"",
"@issuer",
"||",
"nil",
"when",
"\"professional\"",
"then",
"\"PROFESSIONAL STANDARD\"",
"end",
"end"
] | 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, prefix.to_sym) || 'XXXX'}#{@labels["local_issuer"]}"
when "enterprise", "social-group"
@issuer || nil
when "professional" then "PROFESSIONAL STANDARD" # TODO
end
end | 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, prefix.to_sym) || 'XXXX'}#{@labels["local_issuer"]}"
when "enterprise", "social-group"
@issuer || nil
when "professional" then "PROFESSIONAL STANDARD" # TODO
end
end | [
"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, prefix.to_sym) || 'XXXX'}#{@labels[\"local_issuer\"]}\"",
"when",
"\"enterprise\"",
",",
"\"social-group\"",
"@issuer",
"||",
"nil",
"when",
"\"professional\"",
"then",
"\"PROFESSIONAL STANDARD\"",
"end",
"end"
] | 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_concurrent_jobs - running_jobs.count
jobs_to_schedule = 0 if jobs_to_schedule < 0
# Finds out scheduled jobs waiting to be performed.
scheduled_jobs = []
schedulable_jobs.first(jobs_to_schedule).each do |job|
job_pid = Process.fork do
begin
job.perform_now
rescue StandardError => e
@logger.error "[Scheduler:#{@pid}] Error #{e.class}: #{e.message} "\
"(#{e.backtrace.select { |l| l.include?('app') }.first}).".red
end
end
Process.detach(job_pid)
job.update_attribute(:pid, job_pid)
scheduled_jobs << job
queue << job.id.to_s
end
# Logs launched jobs
if scheduled_jobs.any?
@logger.info "[Scheduler:#{@pid}] Launched #{scheduled_jobs.count} "\
"jobs: #{scheduled_jobs.map(&:id).map(&:to_s).join(', ')}.".cyan
else
if schedulable_jobs.count == 0
@logger.info "[Scheduler:#{@pid}] No jobs in queue.".cyan
else
@logger.warn "[Scheduler:#{@pid}] No jobs launched, reached maximum "\
"number of concurrent jobs. Jobs in queue: #{schedulable_jobs.count}.".yellow
end
end
# Checks for completed jobs: clears up queue and kills any zombie pid
queue.delete_if do |job_id|
job = @job_class.find(job_id)
if job.present? and job.status.in? [ :completed, :error ]
begin
@logger.info "[Scheduler:#{@pid}] Rimosso processo #{job.pid} per lavoro completato".cyan
Process.kill :QUIT, job.pid
rescue Errno::ENOENT, Errno::ESRCH
end
true
else false end
end
# Waits the specified amount of time before next iteration
sleep @polling_interval
rescue StandardError => error
@logger.error "[Scheduler:#{@pid}] Error #{error.message}".red
@logger.error error.backtrace.select { |line| line.include?('app') }.join("\n").red
rescue SignalException => signal
if signal.message.in? [ 'SIGINT', 'SIGTERM', 'SIGQUIT' ]
@logger.warn "[Scheduler:#{@pid}] Received interrupt, terminating scheduler..".yellow
reschedule_running_jobs
break
end
end
end
end | 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_concurrent_jobs - running_jobs.count
jobs_to_schedule = 0 if jobs_to_schedule < 0
# Finds out scheduled jobs waiting to be performed.
scheduled_jobs = []
schedulable_jobs.first(jobs_to_schedule).each do |job|
job_pid = Process.fork do
begin
job.perform_now
rescue StandardError => e
@logger.error "[Scheduler:#{@pid}] Error #{e.class}: #{e.message} "\
"(#{e.backtrace.select { |l| l.include?('app') }.first}).".red
end
end
Process.detach(job_pid)
job.update_attribute(:pid, job_pid)
scheduled_jobs << job
queue << job.id.to_s
end
# Logs launched jobs
if scheduled_jobs.any?
@logger.info "[Scheduler:#{@pid}] Launched #{scheduled_jobs.count} "\
"jobs: #{scheduled_jobs.map(&:id).map(&:to_s).join(', ')}.".cyan
else
if schedulable_jobs.count == 0
@logger.info "[Scheduler:#{@pid}] No jobs in queue.".cyan
else
@logger.warn "[Scheduler:#{@pid}] No jobs launched, reached maximum "\
"number of concurrent jobs. Jobs in queue: #{schedulable_jobs.count}.".yellow
end
end
# Checks for completed jobs: clears up queue and kills any zombie pid
queue.delete_if do |job_id|
job = @job_class.find(job_id)
if job.present? and job.status.in? [ :completed, :error ]
begin
@logger.info "[Scheduler:#{@pid}] Rimosso processo #{job.pid} per lavoro completato".cyan
Process.kill :QUIT, job.pid
rescue Errno::ENOENT, Errno::ESRCH
end
true
else false end
end
# Waits the specified amount of time before next iteration
sleep @polling_interval
rescue StandardError => error
@logger.error "[Scheduler:#{@pid}] Error #{error.message}".red
@logger.error error.backtrace.select { |line| line.include?('app') }.join("\n").red
rescue SignalException => signal
if signal.message.in? [ 'SIGINT', 'SIGTERM', 'SIGQUIT' ]
@logger.warn "[Scheduler:#{@pid}] Received interrupt, terminating scheduler..".yellow
reschedule_running_jobs
break
end
end
end
end | [
"def",
"start_loop",
"loop",
"do",
"begin",
"queue",
"=",
"[",
"]",
"running_jobs",
"=",
"@job_class",
".",
"running",
".",
"entries",
"schedulable_jobs",
"=",
"@job_class",
".",
"queued",
".",
"order_by",
"(",
"scheduled_at",
":",
":asc",
")",
".",
"entries",
"jobs_to_schedule",
"=",
"@max_concurrent_jobs",
"-",
"running_jobs",
".",
"count",
"jobs_to_schedule",
"=",
"0",
"if",
"jobs_to_schedule",
"<",
"0",
"scheduled_jobs",
"=",
"[",
"]",
"schedulable_jobs",
".",
"first",
"(",
"jobs_to_schedule",
")",
".",
"each",
"do",
"|",
"job",
"|",
"job_pid",
"=",
"Process",
".",
"fork",
"do",
"begin",
"job",
".",
"perform_now",
"rescue",
"StandardError",
"=>",
"e",
"@logger",
".",
"error",
"\"[Scheduler:#{@pid}] Error #{e.class}: #{e.message} \"",
"\"(#{e.backtrace.select { |l| l.include?('app') }.first}).\"",
".",
"red",
"end",
"end",
"Process",
".",
"detach",
"(",
"job_pid",
")",
"job",
".",
"update_attribute",
"(",
":pid",
",",
"job_pid",
")",
"scheduled_jobs",
"<<",
"job",
"queue",
"<<",
"job",
".",
"id",
".",
"to_s",
"end",
"if",
"scheduled_jobs",
".",
"any?",
"@logger",
".",
"info",
"\"[Scheduler:#{@pid}] Launched #{scheduled_jobs.count} \"",
"\"jobs: #{scheduled_jobs.map(&:id).map(&:to_s).join(', ')}.\"",
".",
"cyan",
"else",
"if",
"schedulable_jobs",
".",
"count",
"==",
"0",
"@logger",
".",
"info",
"\"[Scheduler:#{@pid}] No jobs in queue.\"",
".",
"cyan",
"else",
"@logger",
".",
"warn",
"\"[Scheduler:#{@pid}] No jobs launched, reached maximum \"",
"\"number of concurrent jobs. Jobs in queue: #{schedulable_jobs.count}.\"",
".",
"yellow",
"end",
"end",
"queue",
".",
"delete_if",
"do",
"|",
"job_id",
"|",
"job",
"=",
"@job_class",
".",
"find",
"(",
"job_id",
")",
"if",
"job",
".",
"present?",
"and",
"job",
".",
"status",
".",
"in?",
"[",
":completed",
",",
":error",
"]",
"begin",
"@logger",
".",
"info",
"\"[Scheduler:#{@pid}] Rimosso processo #{job.pid} per lavoro completato\"",
".",
"cyan",
"Process",
".",
"kill",
":QUIT",
",",
"job",
".",
"pid",
"rescue",
"Errno",
"::",
"ENOENT",
",",
"Errno",
"::",
"ESRCH",
"end",
"true",
"else",
"false",
"end",
"end",
"sleep",
"@polling_interval",
"rescue",
"StandardError",
"=>",
"error",
"@logger",
".",
"error",
"\"[Scheduler:#{@pid}] Error #{error.message}\"",
".",
"red",
"@logger",
".",
"error",
"error",
".",
"backtrace",
".",
"select",
"{",
"|",
"line",
"|",
"line",
".",
"include?",
"(",
"'app'",
")",
"}",
".",
"join",
"(",
"\"\\n\"",
")",
".",
"red",
"rescue",
"SignalException",
"=>",
"signal",
"if",
"signal",
".",
"message",
".",
"in?",
"[",
"'SIGINT'",
",",
"'SIGTERM'",
",",
"'SIGQUIT'",
"]",
"@logger",
".",
"warn",
"\"[Scheduler:#{@pid}] Received interrupt, terminating scheduler..\"",
".",
"yellow",
"reschedule_running_jobs",
"break",
"end",
"end",
"end",
"end"
] | 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",
"::",
"EPERM",
"ensure",
"job",
".",
"schedule",
"end",
"end",
"end"
] | 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/specs-#{device_hash[:udid]}.log", 'a') do |file|
file << "#{k}: #{v}\n"
end
end
end
end | 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/specs-#{device_hash[:udid]}.log", 'a') do |file|
file << "#{k}: #{v}\n"
end
end
end
end | [
"def",
"save_device_data",
"(",
"dev_array",
")",
"dev_array",
".",
"each",
"do",
"|",
"device",
"|",
"device_hash",
"=",
"{",
"}",
"device",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"device_hash",
"[",
"key",
"]",
"=",
"value",
"end",
"`",
"`",
"`",
"`",
"device",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"open",
"(",
"\"output/specs-#{device_hash[:udid]}.log\"",
",",
"'a'",
")",
"do",
"|",
"file",
"|",
"file",
"<<",
"\"#{k}: #{v}\\n\"",
"end",
"end",
"end",
"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",
".",
"new",
".",
"devices",
"end",
"end"
] | 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[:log]}" if options.key?(:log)
command << " --tmp #{ENV['BASE_DIR']}/tmp/#{options[:tmp]}" if options.key?(:tmp)
Dir.chdir('.') do
puts(command)
pid = spawn(command, out: '/dev/null')
puts 'Waiting for Appium to start up...'
sleep 10
puts "Appium PID: #{pid}"
puts 'Appium server did not start' if pid.nil?
end
end | 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[:log]}" if options.key?(:log)
command << " --tmp #{ENV['BASE_DIR']}/tmp/#{options[:tmp]}" if options.key?(:tmp)
Dir.chdir('.') do
puts(command)
pid = spawn(command, out: '/dev/null')
puts 'Waiting for Appium to start up...'
sleep 10
puts "Appium PID: #{pid}"
puts 'Appium server did not start' if pid.nil?
end
end | [
"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[:log]}\"",
"if",
"options",
".",
"key?",
"(",
":log",
")",
"command",
"<<",
"\" --tmp #{ENV['BASE_DIR']}/tmp/#{options[:tmp]}\"",
"if",
"options",
".",
"key?",
"(",
":tmp",
")",
"Dir",
".",
"chdir",
"(",
"'.'",
")",
"do",
"puts",
"(",
"command",
")",
"pid",
"=",
"spawn",
"(",
"command",
",",
"out",
":",
"'/dev/null'",
")",
"puts",
"'Waiting for Appium to start up...'",
"sleep",
"10",
"puts",
"\"Appium PID: #{pid}\"",
"puts",
"'Appium server did not start'",
"if",
"pid",
".",
"nil?",
"end",
"end"
] | 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] }],
configuration: { cleanUpCycle: 2000,
timeout: 1_800_000,
registerCycle: 5000,
proxy: 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy',
url: "http://127.0.0.1:#{appium_port}/wd/hub",
host: '127.0.0.1',
port: appium_port,
maxSession: 5,
register: true,
hubPort: 4444,
hubHost: 'localhost' }
))
f.close
end | 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] }],
configuration: { cleanUpCycle: 2000,
timeout: 1_800_000,
registerCycle: 5000,
proxy: 'org.openqa.grid.selenium.proxy.DefaultRemoteProxy',
url: "http://127.0.0.1:#{appium_port}/wd/hub",
host: '127.0.0.1',
port: appium_port,
maxSession: 5,
register: true,
hubPort: 4444,
hubHost: 'localhost' }
))
f.close
end | [
"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",
"]",
"}",
"]",
",",
"configuration",
":",
"{",
"cleanUpCycle",
":",
"2000",
",",
"timeout",
":",
"1_800_000",
",",
"registerCycle",
":",
"5000",
",",
"proxy",
":",
"'org.openqa.grid.selenium.proxy.DefaultRemoteProxy'",
",",
"url",
":",
"\"http://127.0.0.1:#{appium_port}/wd/hub\"",
",",
"host",
":",
"'127.0.0.1'",
",",
"port",
":",
"appium_port",
",",
"maxSession",
":",
"5",
",",
"register",
":",
"true",
",",
"hubPort",
":",
"4444",
",",
"hubHost",
":",
"'localhost'",
"}",
")",
")",
"f",
".",
"close",
"end"
] | 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
appium_server_start udid: udid, log: "appium-#{udid}.log", port: port
end | 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
appium_server_start udid: udid, log: "appium-#{udid}.log", port: port
end | [
"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",
"appium_server_start",
"udid",
":",
"udid",
",",
"log",
":",
"\"appium-#{udid}.log\"",
",",
"port",
":",
"port",
"end"
] | 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 devices.size < threads
puts "Not enough available devices, reducing to #{devices.size} threads"
ENV['THREADS'] = devices.size.to_s
else
puts "Using #{threads} of the available #{devices.size} devices"
devices = devices[0, threads]
end
Parallel.map_with_index(devices, in_processes: devices.size) do |device, index|
offset = platform == 'android' ? 0 : threads
port = 4000 + index + offset
bp = 2250 + index + offset
config_name = "#{device[:udid]}.json"
generate_node_config config_name, port, device
node_config = "#{Dir.pwd}/node_configs/#{config_name}"
puts port
appium_server_start config: node_config, port: port, bp: bp, udid: device[:udid],
log: "appium-#{device[:udid]}.log", tmp: device[:udid]
end
end | 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 devices.size < threads
puts "Not enough available devices, reducing to #{devices.size} threads"
ENV['THREADS'] = devices.size.to_s
else
puts "Using #{threads} of the available #{devices.size} devices"
devices = devices[0, threads]
end
Parallel.map_with_index(devices, in_processes: devices.size) do |device, index|
offset = platform == 'android' ? 0 : threads
port = 4000 + index + offset
bp = 2250 + index + offset
config_name = "#{device[:udid]}.json"
generate_node_config config_name, port, device
node_config = "#{Dir.pwd}/node_configs/#{config_name}"
puts port
appium_server_start config: node_config, port: port, bp: bp, udid: device[:udid],
log: "appium-#{device[:udid]}.log", tmp: device[:udid]
end
end | [
"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",
"devices",
".",
"size",
"<",
"threads",
"puts",
"\"Not enough available devices, reducing to #{devices.size} threads\"",
"ENV",
"[",
"'THREADS'",
"]",
"=",
"devices",
".",
"size",
".",
"to_s",
"else",
"puts",
"\"Using #{threads} of the available #{devices.size} devices\"",
"devices",
"=",
"devices",
"[",
"0",
",",
"threads",
"]",
"end",
"Parallel",
".",
"map_with_index",
"(",
"devices",
",",
"in_processes",
":",
"devices",
".",
"size",
")",
"do",
"|",
"device",
",",
"index",
"|",
"offset",
"=",
"platform",
"==",
"'android'",
"?",
"0",
":",
"threads",
"port",
"=",
"4000",
"+",
"index",
"+",
"offset",
"bp",
"=",
"2250",
"+",
"index",
"+",
"offset",
"config_name",
"=",
"\"#{device[:udid]}.json\"",
"generate_node_config",
"config_name",
",",
"port",
",",
"device",
"node_config",
"=",
"\"#{Dir.pwd}/node_configs/#{config_name}\"",
"puts",
"port",
"appium_server_start",
"config",
":",
"node_config",
",",
"port",
":",
"port",
",",
"bp",
":",
"bp",
",",
"udid",
":",
"device",
"[",
":udid",
"]",
",",
"log",
":",
"\"appium-#{device[:udid]}.log\"",
",",
"tmp",
":",
"device",
"[",
":udid",
"]",
"end",
"end"
] | 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 and replacing with the appropriate value
final_opts = options.dup
options.keys.each do |key|
orig_key = key
new_key = orig_key.to_s.gsub("_", "").downcase
if (new_key == src_creds_name.downcase)
final_opts[src_creds_name] = final_opts[key] #Set "SourceCredentials" to hash referenced by similarly named
final_opts.delete(orig_key)
end
end
opts = {};
final_opts.each do |key, value|
new_val = value
if value.kind_of?(Array)
tranformed = {}
if item[0].kind_of? Integer
transformed[:int] = value
elsif item[0].kind_of? String
transformed[:string] = value
else
break #Don't know how to deal with it, return regular
end
new_val = transformed
end
opts[key] = new_val
end
request_body =
{
"PageSize" => 10,
"CurrentPageIndex" => 0
}
request_body["XMLDetail"] = "Bare" unless opts["Fields"]
request_body[src_creds_name] = @src_creds.to_hash if @src_creds
request_body["UserCredentials"] = @usr_creds.to_hash if @usr_creds
return request_body.merge!(opts)
end | 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 and replacing with the appropriate value
final_opts = options.dup
options.keys.each do |key|
orig_key = key
new_key = orig_key.to_s.gsub("_", "").downcase
if (new_key == src_creds_name.downcase)
final_opts[src_creds_name] = final_opts[key] #Set "SourceCredentials" to hash referenced by similarly named
final_opts.delete(orig_key)
end
end
opts = {};
final_opts.each do |key, value|
new_val = value
if value.kind_of?(Array)
tranformed = {}
if item[0].kind_of? Integer
transformed[:int] = value
elsif item[0].kind_of? String
transformed[:string] = value
else
break #Don't know how to deal with it, return regular
end
new_val = transformed
end
opts[key] = new_val
end
request_body =
{
"PageSize" => 10,
"CurrentPageIndex" => 0
}
request_body["XMLDetail"] = "Bare" unless opts["Fields"]
request_body[src_creds_name] = @src_creds.to_hash if @src_creds
request_body["UserCredentials"] = @usr_creds.to_hash if @usr_creds
return request_body.merge!(opts)
end | [
"def",
"build_request",
"(",
"options",
"=",
"{",
"}",
")",
"src_creds_name",
"=",
"SRC_CREDS",
"options",
"=",
"options",
".",
"dup",
"final_opts",
"=",
"options",
".",
"dup",
"options",
".",
"keys",
".",
"each",
"do",
"|",
"key",
"|",
"orig_key",
"=",
"key",
"new_key",
"=",
"orig_key",
".",
"to_s",
".",
"gsub",
"(",
"\"_\"",
",",
"\"\"",
")",
".",
"downcase",
"if",
"(",
"new_key",
"==",
"src_creds_name",
".",
"downcase",
")",
"final_opts",
"[",
"src_creds_name",
"]",
"=",
"final_opts",
"[",
"key",
"]",
"final_opts",
".",
"delete",
"(",
"orig_key",
")",
"end",
"end",
"opts",
"=",
"{",
"}",
";",
"final_opts",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"new_val",
"=",
"value",
"if",
"value",
".",
"kind_of?",
"(",
"Array",
")",
"tranformed",
"=",
"{",
"}",
"if",
"item",
"[",
"0",
"]",
".",
"kind_of?",
"Integer",
"transformed",
"[",
":int",
"]",
"=",
"value",
"elsif",
"item",
"[",
"0",
"]",
".",
"kind_of?",
"String",
"transformed",
"[",
":string",
"]",
"=",
"value",
"else",
"break",
"end",
"new_val",
"=",
"transformed",
"end",
"opts",
"[",
"key",
"]",
"=",
"new_val",
"end",
"request_body",
"=",
"{",
"\"PageSize\"",
"=>",
"10",
",",
"\"CurrentPageIndex\"",
"=>",
"0",
"}",
"request_body",
"[",
"\"XMLDetail\"",
"]",
"=",
"\"Bare\"",
"unless",
"opts",
"[",
"\"Fields\"",
"]",
"request_body",
"[",
"src_creds_name",
"]",
"=",
"@src_creds",
".",
"to_hash",
"if",
"@src_creds",
"request_body",
"[",
"\"UserCredentials\"",
"]",
"=",
"@usr_creds",
".",
"to_hash",
"if",
"@usr_creds",
"return",
"request_body",
".",
"merge!",
"(",
"opts",
")",
"end"
] | 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 as "SourceCredentials",
response = @client.request Mb::Meta::NS, service_symbol do
soap.body =
{
"Request" => request_options
}
end
if unwrap_bool
#Unwrap response to hash array underneath)
plural = service_symbol.to_s.gsub("get_", "")
singular =plural[0..-2] #Remove last
r = response.to_hash
basify = lambda {|enda| (service_symbol.to_s + "_" + enda).to_sym }
r = r[basify.call('response')][basify.call('result')]
return [] if r[:result_count] == "0"
r = r[plural.to_sym][singular.to_sym]
return r
end
response
end | 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 as "SourceCredentials",
response = @client.request Mb::Meta::NS, service_symbol do
soap.body =
{
"Request" => request_options
}
end
if unwrap_bool
#Unwrap response to hash array underneath)
plural = service_symbol.to_s.gsub("get_", "")
singular =plural[0..-2] #Remove last
r = response.to_hash
basify = lambda {|enda| (service_symbol.to_s + "_" + enda).to_sym }
r = r[basify.call('response')][basify.call('result')]
return [] if r[:result_count] == "0"
r = r[plural.to_sym][singular.to_sym]
return r
end
response
end | [
"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",
"]",
"response",
"=",
"@client",
".",
"request",
"Mb",
"::",
"Meta",
"::",
"NS",
",",
"service_symbol",
"do",
"soap",
".",
"body",
"=",
"{",
"\"Request\"",
"=>",
"request_options",
"}",
"end",
"if",
"unwrap_bool",
"plural",
"=",
"service_symbol",
".",
"to_s",
".",
"gsub",
"(",
"\"get_\"",
",",
"\"\"",
")",
"singular",
"=",
"plural",
"[",
"0",
"..",
"-",
"2",
"]",
"r",
"=",
"response",
".",
"to_hash",
"basify",
"=",
"lambda",
"{",
"|",
"enda",
"|",
"(",
"service_symbol",
".",
"to_s",
"+",
"\"_\"",
"+",
"enda",
")",
".",
"to_sym",
"}",
"r",
"=",
"r",
"[",
"basify",
".",
"call",
"(",
"'response'",
")",
"]",
"[",
"basify",
".",
"call",
"(",
"'result'",
")",
"]",
"return",
"[",
"]",
"if",
"r",
"[",
":result_count",
"]",
"==",
"\"0\"",
"r",
"=",
"r",
"[",
"plural",
".",
"to_sym",
"]",
"[",
"singular",
".",
"to_sym",
"]",
"return",
"r",
"end",
"response",
"end"
] | 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(env[:body], @key)
end | 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(env[:body], @key)
end | [
"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",
"(",
"env",
"[",
":body",
"]",
",",
"@key",
")",
"end"
] | 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",
"find_key_in_hash",
"val",
",",
"index",
"end",
"else",
"val",
"end",
"end",
"end"
] | 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?",
"Zyps",
"::",
"Vector",
"self",
".",
"vector",
"=",
"item",
"else",
"raise",
"\"Invalid item: #{item.class}\"",
"end",
"self",
"end"
] | 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",
"class",
"of",
"item",
"."
] | 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",
"attribute",
".",
"Assignment",
"is",
"done",
"based",
"on",
"item",
"s",
"class",
"or",
"a",
"parent",
"class",
"of",
"item",
"."
] | 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.atan2(new_y, new_x)))
#Calculate speed and angle of new vector with components.
Vector.new(new_length, new_angle)
end | 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.atan2(new_y, new_x)))
#Calculate speed and angle of new vector with components.
Vector.new(new_length, new_angle)
end | [
"def",
"+",
"(",
"vector2",
")",
"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",
".",
"atan2",
"(",
"new_y",
",",
"new_x",
")",
")",
")",
"Vector",
".",
"new",
"(",
"new_length",
",",
"new_angle",
")",
"end"
] | 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",
")",
"else",
"super",
"end",
"end"
] | 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!",
"(",
"prepare_json",
"(",
"params",
")",
")",
"Hyperb",
"::",
"Request",
".",
"new",
"(",
"self",
",",
"path",
",",
"{",
"}",
",",
"'post'",
",",
"body",
")",
".",
"perform",
"end"
] | 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
@raise [Hyperb::Error::InternalServerError] server error on hyper side.
@raise [ArgumentError] when required arguments are not provided.
@param params [Hash] A customizable set of params.
@param params :name [String] the function name.
@param params :container_size [String] the size of containers
to run the function (e.g. s1,s2, s3, s4, m1, m2, m3, l1, l2, l3)
@param params :timeout [String] default is 300 seconds, maximum is 86400 seconds.
@param params :uuid [String] The uuid of function.
@param params :config [Hash] func configurations
@param params config :tty [Boolean] attach streams to a tty
@param params config :exposed_ports [Hash] an object mapping ports to an empty
object in the form of: "ExposedPorts": { "<port>/<tcp|udp>: {}" }
@param params config :env [Array] list of env vars, "VAR=VALUE"
@param params config :cmd [Array|String] list of env vars, "VAR=VALUE"
@param params config :image [String] image to run
@param params config :entrypoint [String] entrypoint
@param params config :working_dir [String] working directory
@param params config :labels [Hash] labels
@param params :host_config [Hash] func host configurations
@param params host_config :links [Array] list of links
@param params host_config :port_bindings [Hash]
@param params host_config :publish_all_ports [Boolean]
@param params host_config :volumes_from [Array]
@param params host_config :network_mode [String] | [
"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",
"::",
"Request",
".",
"new",
"(",
"self",
",",
"path",
",",
"{",
"}",
",",
"'delete'",
")",
".",
"perform",
"end"
] | 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 is sent
@raise [Hyperb::Error::InternalServerError] server error on hyper side.
@raise [ArgumentError] when required arguments are not provided.
@param params [Hash] A customizable set of params.
@param params :name [String] the function name. | [
"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",
".",
"concat",
"(",
"'/sync'",
")",
"if",
"params",
".",
"key?",
"(",
":sync",
")",
"&&",
"params",
"[",
":sync",
"]",
"Hyperb",
"::",
"FuncCallRequest",
".",
"new",
"(",
"self",
",",
"path",
",",
"{",
"}",
",",
"'post'",
")",
".",
"perform",
"end"
] | 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 customizable set of params.
@param params :name [String] the function name.
@param params :uuid [String] function uuid.
@param params :sync [Boolean] block until function reply | [
"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",
".",
"make_source",
"(",
"http_method",
".",
"to_s",
".",
"upcase",
",",
"url",
",",
"params",
")",
")",
"params",
"end"
] | 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_lookup = orig
end
end | 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_lookup = orig
end
end | [
"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",
"s",
".",
"addr",
".",
"last",
"end",
"ensure",
"Socket",
".",
"do_not_reverse_lookup",
"=",
"orig",
"end",
"end"
] | 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",
"==",
"ip",
"end",
"return",
"Pcap",
".",
"lookupdev",
"end"
] | 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(config)
op.debrief = Trebuchet::Debrief.new({ :operation => op.class.name, :name => config['name'] })
op.run
op.save_debrief
operation_run = true
end
end
raise "No Operation Run!" unless operation_run
end | 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(config)
op.debrief = Trebuchet::Debrief.new({ :operation => op.class.name, :name => config['name'] })
op.run
op.save_debrief
operation_run = true
end
end
raise "No Operation Run!" unless operation_run
end | [
"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",
"(",
"config",
")",
"op",
".",
"debrief",
"=",
"Trebuchet",
"::",
"Debrief",
".",
"new",
"(",
"{",
":operation",
"=>",
"op",
".",
"class",
".",
"name",
",",
":name",
"=>",
"config",
"[",
"'name'",
"]",
"}",
")",
"op",
".",
"run",
"op",
".",
"save_debrief",
"operation_run",
"=",
"true",
"end",
"end",
"raise",
"\"No Operation Run!\"",
"unless",
"operation_run",
"end"
] | 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(dir.parent)
end
end | 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(dir.parent)
end
end | [
"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",
"(",
"dir",
".",
"parent",
")",
"end",
"end"
] | 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 project | [
"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_size / Math::PI)
x_range = (actor.location.x - max_diff .. actor.location.x + max_diff)
y_range = (actor.location.y - max_diff .. actor.location.y + max_diff)
targets.select do | target |
x_range.include?(target.location.x) and y_range.include?(target.location.y) and Utility.collided?(actor, target)
end
end | 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_size / Math::PI)
x_range = (actor.location.x - max_diff .. actor.location.x + max_diff)
y_range = (actor.location.y - max_diff .. actor.location.y + max_diff)
targets.select do | target |
x_range.include?(target.location.x) and y_range.include?(target.location.y) and Utility.collided?(actor, target)
end
end | [
"def",
"select",
"(",
"actor",
",",
"targets",
")",
"return",
"[",
"]",
"unless",
"targets",
".",
"length",
">",
"0",
"max_size",
"=",
"targets",
".",
"map",
"{",
"|",
"t",
"|",
"t",
".",
"size",
"}",
".",
"max",
"max_diff",
"=",
"Math",
".",
"sqrt",
"(",
"actor",
".",
"size",
"/",
"Math",
"::",
"PI",
")",
"+",
"Math",
".",
"sqrt",
"(",
"max_size",
"/",
"Math",
"::",
"PI",
")",
"x_range",
"=",
"(",
"actor",
".",
"location",
".",
"x",
"-",
"max_diff",
"..",
"actor",
".",
"location",
".",
"x",
"+",
"max_diff",
")",
"y_range",
"=",
"(",
"actor",
".",
"location",
".",
"y",
"-",
"max_diff",
"..",
"actor",
".",
"location",
".",
"y",
"+",
"max_diff",
")",
"targets",
".",
"select",
"do",
"|",
"target",
"|",
"x_range",
".",
"include?",
"(",
"target",
".",
"location",
".",
"x",
")",
"and",
"y_range",
".",
"include?",
"(",
"target",
".",
"location",
".",
"y",
")",
"and",
"Utility",
".",
"collided?",
"(",
"actor",
",",
"target",
")",
"end",
"end"
] | 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",
"true",
"else",
"return",
"false",
"end",
"end"
] | 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",
"(",
"unit",
",",
"@unit",
".",
"as",
"(",
"quantity",
",",
"unit",
")",
")",
"end"
] | 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",
")",
":",
"to_f",
".",
"send",
"(",
"method",
",",
"other",
")",
"Measurement",
".",
"new",
"(",
"unit",
",",
"new_quantity",
")",
"end"
] | 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.new(:mg, 2000), :div) #=> 1 gram | [
"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",
"."
] | 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",
"==",
"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"
] | 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",
"this",
"Measurement",
"s",
"unit",
"and",
"the",
"other",
"Measurement",
"s",
"unit",
"."
] | 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_objects) }
end
rescue StandardError => e
Rails.logger.error("Error continuing flow #{self.id}: #{e.message}")
end | 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_objects) }
end
rescue StandardError => e
Rails.logger.error("Error continuing flow #{self.id}: #{e.message}")
end | [
"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",
"}",
"]",
"workers",
".",
"each",
"{",
"|",
"worker",
",",
"num_objects",
"|",
"create_jobs",
"(",
"worker",
",",
"num_objects",
")",
"}",
"end",
"rescue",
"StandardError",
"=>",
"e",
"Rails",
".",
"logger",
".",
"error",
"(",
"\"Error continuing flow #{self.id}: #{e.message}\"",
")",
"end"
] | 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",
"end"
] | 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 = @threshold unless @severities.any?
@logger.formatter = @formatter unless @formatter.nil?
end | 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 = @threshold unless @severities.any?
@logger.formatter = @formatter unless @formatter.nil?
end | [
"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",
"=",
"@threshold",
"unless",
"@severities",
".",
"any?",
"@logger",
".",
"formatter",
"=",
"@formatter",
"unless",
"@formatter",
".",
"nil?",
"end"
] | 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",
"should_log?",
"(",
"severity",
")",
"end"
] | 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",
"end"
] | 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",
"(",
"JSON",
".",
"parse",
"(",
"Hyperb",
"::",
"Request",
".",
"new",
"(",
"self",
",",
"path",
",",
"query",
",",
"'get'",
")",
".",
"perform",
")",
")",
"end"
] | 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 [Hash] A customizable set of params.
@option params [String] :filters | [
"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",
".",
"new",
"(",
"self",
",",
"path",
",",
"query",
",",
"'post'",
")",
".",
"perform",
"end"
] | 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.
@option params [String] :ip the number of free fips to allocate | [
"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
end | 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
end | [
"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",
"end"
] | 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] :count the number of free fips to allocate | [
"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",
")",
"end",
"end"
] | 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",
"*",
"elapsed_time",
",",
"@vector",
".",
"pitch",
")",
"end",
"end"
] | 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 += acceleration
speed = 0 if speed > 0
end
object.vector.speed = speed
end
end | 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 += acceleration
speed = 0 if speed > 0
end
object.vector.speed = speed
end
end | [
"def",
"act",
"(",
"environment",
")",
"elapsed_time",
"=",
"@clock",
".",
"elapsed_time",
"environment",
".",
"objects",
".",
"each",
"do",
"|",
"object",
"|",
"acceleration",
"=",
"@force",
"*",
"elapsed_time",
"speed",
"=",
"object",
".",
"vector",
".",
"speed",
"if",
"speed",
">",
"0",
"speed",
"-=",
"acceleration",
"speed",
"=",
"0",
"if",
"speed",
"<",
"0",
"elsif",
"speed",
"<",
"0",
"speed",
"+=",
"acceleration",
"speed",
"=",
"0",
"if",
"speed",
">",
"0",
"end",
"object",
".",
"vector",
".",
"speed",
"=",
"speed",
"end",
"end"
] | 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.remove_object(object.identifier)}
end
end | 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.remove_object(object.identifier)}
end
end | [
"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",
".",
"remove_object",
"(",
"object",
".",
"identifier",
")",
"}",
"end",
"end"
] | 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 will be called on the characterized object to retrieve its raw value.
@param [Hash] options The options hash.
@option [Symbol] display_with A symbol that gets sent as a method on the characteristic to retrieve its display value.
@option [Class, Symbol] measures Specifies a measurement for the characteristic. Either provide a class constant that conforms to the Charisma::Measurement API, or use a symbol to specify a built-in Charisma measurement.
@option [Proc] blk A proc that defines how the characteristic should be displayed.
@see Charisma::Base::ClassMethods#characterize
@see Charisma::Characteristic
@see Charisma::Measurement | [
"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_eval %{
def self.find_by_#{key_column}(arg)
self.static_record_cache[:key][arg.to_s]
end
}, __FILE__, __LINE__
end
end | 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_eval %{
def self.find_by_#{key_column}(arg)
self.static_record_cache[:key][arg.to_s]
end
}, __FILE__, __LINE__
end
end | [
"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",
".",
"include?",
"(",
"key_column",
".",
"to_sym",
")",
")",
")",
"class_eval",
"%{ def self.find_by_#{key_column}(arg) self.static_record_cache[:key][arg.to_s] end }",
",",
"__FILE__",
",",
"__LINE__",
"end",
"end"
] | 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(' ', '_').gsub(/\W/, "").underscore
end
end | 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(' ', '_').gsub(/\W/, "").underscore
end
end | [
"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",
"]",
"||",
"primary_key",
")",
")",
"else",
"value",
".",
"to_s",
".",
"gsub",
"(",
"' '",
",",
"'_'",
")",
".",
"gsub",
"(",
"/",
"\\W",
"/",
",",
"\"\"",
")",
".",
"underscore",
"end",
"end"
] | 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
end
finder == :all ? list : list.last
end | 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
end
finder == :all ? list : list.last
end | [
"def",
"find_in_static_record_cache",
"(",
"finder",
",",
"attributes",
")",
"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",
"end",
"finder",
"==",
":all",
"?",
"list",
":",
"list",
".",
"last",
"end"
] | 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) => values
User.find_in_static_cache(:first, {:password => 'fun', :user_name => 'giraffe'}) | [
"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 && args.length == 1
return static_record_cache[:primary_key].values
end
end
find_without_static_record(*args)
end | 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 && args.length == 1
return static_record_cache[:primary_key].values
end
end
find_without_static_record(*args)
end | [
"def",
"find_with_static_record",
"(",
"*",
"args",
")",
"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",
"&&",
"args",
".",
"length",
"==",
"1",
"return",
"static_record_cache",
"[",
":primary_key",
"]",
".",
"values",
"end",
"end",
"find_without_static_record",
"(",
"*",
"args",
")",
"end"
] | 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
when 'count' then
#count the cache if we want all or the unique primary key
if ['all', '', '*', primary_key].include?(column_name.to_s)
static_record_cache[:primary_key].length
#otherwise compute the length of the output
else
static_records_for_calculation(column_name, options) {|records| records.length }
end
#compute the method directly on the result array
when 'sum', 'max', 'min' then
if columns_hash[column_name.to_s].try(:type) == :integer
static_records_for_calculation(column_name, options) {|records| records.send(operation).to_i }
end
end
return static_record_cache[:calc][key] if static_record_cache[:calc][key]
end
calculate_without_static_record(operation, column_name, options)
end | 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
when 'count' then
#count the cache if we want all or the unique primary key
if ['all', '', '*', primary_key].include?(column_name.to_s)
static_record_cache[:primary_key].length
#otherwise compute the length of the output
else
static_records_for_calculation(column_name, options) {|records| records.length }
end
#compute the method directly on the result array
when 'sum', 'max', 'min' then
if columns_hash[column_name.to_s].try(:type) == :integer
static_records_for_calculation(column_name, options) {|records| records.send(operation).to_i }
end
end
return static_record_cache[:calc][key] if static_record_cache[:calc][key]
end
calculate_without_static_record(operation, column_name, options)
end | [
"def",
"calculate_with_static_record",
"(",
"operation",
",",
"column_name",
",",
"options",
"=",
"{",
"}",
")",
"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",
"when",
"'count'",
"then",
"if",
"[",
"'all'",
",",
"''",
",",
"'*'",
",",
"primary_key",
"]",
".",
"include?",
"(",
"column_name",
".",
"to_s",
")",
"static_record_cache",
"[",
":primary_key",
"]",
".",
"length",
"else",
"static_records_for_calculation",
"(",
"column_name",
",",
"options",
")",
"{",
"|",
"records",
"|",
"records",
".",
"length",
"}",
"end",
"when",
"'sum'",
",",
"'max'",
",",
"'min'",
"then",
"if",
"columns_hash",
"[",
"column_name",
".",
"to_s",
"]",
".",
"try",
"(",
":type",
")",
"==",
":integer",
"static_records_for_calculation",
"(",
"column_name",
",",
"options",
")",
"{",
"|",
"records",
"|",
"records",
".",
"send",
"(",
"operation",
")",
".",
"to_i",
"}",
"end",
"end",
"return",
"static_record_cache",
"[",
":calc",
"]",
"[",
"key",
"]",
"if",
"static_record_cache",
"[",
":calc",
"]",
"[",
"key",
"]",
"end",
"calculate_without_static_record",
"(",
"operation",
",",
"column_name",
",",
"options",
")",
"end"
] | 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
block ? yield(results) : results
else
nil
end
end | 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
block ? yield(results) : results
else
nil
end
end | [
"def",
"static_records_for_calculation",
"(",
"column_name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"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",
"block",
"?",
"yield",
"(",
"results",
")",
":",
"results",
"else",
"nil",
"end",
"end"
] | 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_key][record.send(self.primary_key)] = record
if acts_as_static_record_options[:key]
cache[:key][record.send(acts_as_static_record_options[:key])] = record
end
cache
end
end | 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_key][record.send(self.primary_key)] = record
if acts_as_static_record_options[:key]
cache[:key][record.send(acts_as_static_record_options[:key])] = record
end
cache
end
end | [
"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",
"=",
"records",
".",
"inject",
"(",
"{",
":primary_key",
"=>",
"{",
"}",
",",
":key",
"=>",
"{",
"}",
",",
":calc",
"=>",
"{",
"}",
"}",
")",
"do",
"|",
"cache",
",",
"record",
"|",
"cache",
"[",
":primary_key",
"]",
"[",
"record",
".",
"send",
"(",
"self",
".",
"primary_key",
")",
"]",
"=",
"record",
"if",
"acts_as_static_record_options",
"[",
":key",
"]",
"cache",
"[",
":key",
"]",
"[",
"record",
".",
"send",
"(",
"acts_as_static_record_options",
"[",
":key",
"]",
")",
"]",
"=",
"record",
"end",
"cache",
"end",
"end"
] | 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.to_i]
when acts_as_static_record_options[:key] then [:key, attributes.values.first.to_s]
end
method_to_call = "static_record_cache[#{key_value[0].inspect}][#{key_value[1].inspect}]" if key_value
end
method_to_call
end | 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.to_i]
when acts_as_static_record_options[:key] then [:key, attributes.values.first.to_s]
end
method_to_call = "static_record_cache[#{key_value[0].inspect}][#{key_value[1].inspect}]" if key_value
end
method_to_call
end | [
"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",
".",
"keys",
".",
"first",
".",
"to_s",
"when",
"self",
".",
"primary_key",
"then",
"[",
":primary_key",
",",
"attributes",
".",
"values",
".",
"first",
".",
"to_i",
"]",
"when",
"acts_as_static_record_options",
"[",
":key",
"]",
"then",
"[",
":key",
",",
"attributes",
".",
"values",
".",
"first",
".",
"to_s",
"]",
"end",
"method_to_call",
"=",
"\"static_record_cache[#{key_value[0].inspect}][#{key_value[1].inspect}]\"",
"if",
"key_value",
"end",
"method_to_call",
"end"
] | 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",
"the",
"cache"
] | 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 %{
def self.#{method_with_static_record}(*args)
if (args.dup.extract_options!).any?
#{method_id}_without_static_rc(*args)
else
result = #{method_to_call}
#{'result || raise(RecordNotFound, "Couldn\'t find #{name} with #{attributes.to_a.collect {|pair| "#{pair.first} = #{pair.second}"}.join(\', \')}")' if bang}
end
end
}, __FILE__, __LINE__
method_with_static_record
end | 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 %{
def self.#{method_with_static_record}(*args)
if (args.dup.extract_options!).any?
#{method_id}_without_static_rc(*args)
else
result = #{method_to_call}
#{'result || raise(RecordNotFound, "Couldn\'t find #{name} with #{attributes.to_a.collect {|pair| "#{pair.first} = #{pair.second}"}.join(\', \')}")' if bang}
end
end
}, __FILE__, __LINE__
method_with_static_record
end | [
"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_rc\"",
"class_eval",
"%{ def self.#{method_with_static_record}(*args) if (args.dup.extract_options!).any? #{method_id}_without_static_rc(*args) else result = #{method_to_call} #{'result || raise(RecordNotFound, \"Couldn\\'t find #{name} with #{attributes.to_a.collect {|pair| \"#{pair.first} = #{pair.second}\"}.join(\\', \\')}\")' if bang} end end }",
",",
"__FILE__",
",",
"__LINE__",
"method_with_static_record",
"end"
] | 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$/)) &&
(base_method_id = match[1]))
begin
return super(base_method_id, *arguments, &block)
ensure
define_static_rc_alias(base_method_id)
end
end
# If the missing method is a finder like find_by_name
# Define on the class then invoke find_by_name_with_static_rc
if match = ActiveRecord::DynamicFinderMatch.match(method_id)
attribute_names = match.attribute_names
if all_attributes_exists?(attribute_names) && match.finder?
attributes = construct_attributes_from_arguments(attribute_names, arguments)
method_name = define_static_record_finder_method(method_id, match.finder, match.bang?, attributes)
return self.send method_name, *arguments
end
end
#If nothing matches, invoke the super
super(method_id, *arguments, &block)
end | 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$/)) &&
(base_method_id = match[1]))
begin
return super(base_method_id, *arguments, &block)
ensure
define_static_rc_alias(base_method_id)
end
end
# If the missing method is a finder like find_by_name
# Define on the class then invoke find_by_name_with_static_rc
if match = ActiveRecord::DynamicFinderMatch.match(method_id)
attribute_names = match.attribute_names
if all_attributes_exists?(attribute_names) && match.finder?
attributes = construct_attributes_from_arguments(attribute_names, arguments)
method_name = define_static_record_finder_method(method_id, match.finder, match.bang?, attributes)
return self.send method_name, *arguments
end
end
#If nothing matches, invoke the super
super(method_id, *arguments, &block)
end | [
"def",
"method_missing",
"(",
"method_id",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"if",
"(",
"(",
"match",
"=",
"method_id",
".",
"to_s",
".",
"match",
"(",
"/",
"/",
")",
")",
"&&",
"(",
"base_method_id",
"=",
"match",
"[",
"1",
"]",
")",
")",
"begin",
"return",
"super",
"(",
"base_method_id",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"ensure",
"define_static_rc_alias",
"(",
"base_method_id",
")",
"end",
"end",
"if",
"match",
"=",
"ActiveRecord",
"::",
"DynamicFinderMatch",
".",
"match",
"(",
"method_id",
")",
"attribute_names",
"=",
"match",
".",
"attribute_names",
"if",
"all_attributes_exists?",
"(",
"attribute_names",
")",
"&&",
"match",
".",
"finder?",
"attributes",
"=",
"construct_attributes_from_arguments",
"(",
"attribute_names",
",",
"arguments",
")",
"method_name",
"=",
"define_static_record_finder_method",
"(",
"method_id",
",",
"match",
".",
"finder",
",",
"match",
".",
"bang?",
",",
"attributes",
")",
"return",
"self",
".",
"send",
"method_name",
",",
"*",
"arguments",
"end",
"end",
"super",
"(",
"method_id",
",",
"*",
"arguments",
",",
"&",
"block",
")",
"end"
] | 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",
".",
"render",
"(",
"image",
",",
"slip",
")",
"image",
".",
"write",
"path",
"end"
] | 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] if params.key?(:rmi)
query[:rmorphans] = params[:rmorphans] if params.key?(:rmorphans)
Hyperb::Request.new(self, path, query, 'post').perform
end | 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] if params.key?(:rmi)
query[:rmorphans] = params[:rmorphans] if params.key?(:rmorphans)
Hyperb::Request.new(self, path, query, 'post').perform
end | [
"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",
"]",
"if",
"params",
".",
"key?",
"(",
":rmi",
")",
"query",
"[",
":rmorphans",
"]",
"=",
"params",
"[",
":rmorphans",
"]",
"if",
"params",
".",
"key?",
"(",
":rmorphans",
")",
"Hyperb",
"::",
"Request",
".",
"new",
"(",
"self",
",",
"path",
",",
"query",
",",
"'post'",
")",
".",
"perform",
"end"
] | 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 response object
@param params [Hash] A customizable set of params.
@option params [String] :project project name
@option params [Boolean] :rmorphans rm containers for services not defined in the compose file
@option params [String] :rmi remove images, all/local
@option params [Boolean] :vol remove data volumes | [
"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 libcompose
body[:serviceconfigs][:M] = params[:serviceconfigs]
params.delete(:serviceconfigs)
body.merge!(params)
Hyperb::Request.new(self, path, query, 'post', body).perform
end | 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 libcompose
body[:serviceconfigs][:M] = params[:serviceconfigs]
params.delete(:serviceconfigs)
body.merge!(params)
Hyperb::Request.new(self, path, query, 'post', body).perform
end | [
"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'",
":",
"{",
"}",
"}",
"body",
"[",
":serviceconfigs",
"]",
"[",
":M",
"]",
"=",
"params",
"[",
":serviceconfigs",
"]",
"params",
".",
"delete",
"(",
":serviceconfigs",
")",
"body",
".",
"merge!",
"(",
"params",
")",
"Hyperb",
"::",
"Request",
".",
"new",
"(",
"self",
",",
"path",
",",
"query",
",",
"'post'",
",",
"body",
")",
".",
"perform",
"end"
] | 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 object
@param params [Hash] A customizable set of params.
@option params [String] :project project name
@option params [Hash] :serviceconfigs a hash representing a docker compose file services block
@option params [Hash] :networkconfigs
@option params [Hash] :volumeconfigs | [
"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",
")",
"end"
] | 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",
"(",
"targets",
")",
".",
"location",
")",
")",
"end"
] | 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",
"-",
"actor",
".",
"color",
".",
"green",
")",
"*",
"delta",
"actor",
".",
"color",
".",
"blue",
"+=",
"(",
"@color",
".",
"blue",
"-",
"actor",
".",
"color",
".",
"blue",
")",
"*",
"delta",
"end"
] | 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.vector += Vector.new(push_force, push_angle)
end
end | 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.vector += Vector.new(push_force, push_angle)
end
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"push_force",
"=",
"delta",
"targets",
".",
"each",
"do",
"|",
"target",
"|",
"push_angle",
"=",
"Utility",
".",
"find_angle",
"(",
"actor",
".",
"location",
",",
"target",
".",
"location",
")",
"target",
".",
"vector",
"+=",
"Vector",
".",
"new",
"(",
"push_force",
",",
"push_angle",
")",
"end",
"end"
] | 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 creature's movement vector.
target.vector += Vector.new(pull_force, pull_angle)
end
end | 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 creature's movement vector.
target.vector += Vector.new(pull_force, pull_angle)
end
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"pull_force",
"=",
"delta",
"targets",
".",
"each",
"do",
"|",
"target",
"|",
"pull_angle",
"=",
"Utility",
".",
"find_angle",
"(",
"target",
".",
"location",
",",
"actor",
".",
"location",
")",
"target",
".",
"vector",
"+=",
"Vector",
".",
"new",
"(",
"pull_force",
",",
"pull_angle",
")",
"end",
"end"
] | 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[@target_index]))
end
#Otherwise copy the single prototype.
else
targets[@target_index].environment.add_object(generate_child(actor, prototypes[@prototype_index], targets[@target_index]))
end
#Move to next target and prototype group, wrapping to start of array if need be.
@target_index = (@target_index + 1) % targets.length
@prototype_index = (@prototype_index + 1) % prototypes.length
end | 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[@target_index]))
end
#Otherwise copy the single prototype.
else
targets[@target_index].environment.add_object(generate_child(actor, prototypes[@prototype_index], targets[@target_index]))
end
#Move to next target and prototype group, wrapping to start of array if need be.
@target_index = (@target_index + 1) % targets.length
@prototype_index = (@prototype_index + 1) % prototypes.length
end | [
"def",
"do",
"(",
"actor",
",",
"targets",
")",
"return",
"if",
"targets",
".",
"empty?",
"if",
"prototypes",
"[",
"@prototype_index",
"]",
".",
"respond_to?",
"(",
":each",
")",
"prototypes",
"[",
"@prototype_index",
"]",
".",
"each",
"do",
"|",
"prototype",
"|",
"actor",
".",
"environment",
".",
"add_object",
"(",
"generate_child",
"(",
"actor",
",",
"prototype",
",",
"targets",
"[",
"@target_index",
"]",
")",
")",
"end",
"else",
"targets",
"[",
"@target_index",
"]",
".",
"environment",
".",
"add_object",
"(",
"generate_child",
"(",
"actor",
",",
"prototypes",
"[",
"@prototype_index",
"]",
",",
"targets",
"[",
"@target_index",
"]",
")",
")",
"end",
"@target_index",
"=",
"(",
"@target_index",
"+",
"1",
")",
"%",
"targets",
".",
"length",
"@prototype_index",
"=",
"(",
"@prototype_index",
"+",
"1",
")",
"%",
"prototypes",
".",
"length",
"end"
] | 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",
".",
"location",
")",
"+",
"child",
".",
"vector",
".",
"pitch",
"child",
"end"
] | 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
raise "Bad facet return type #{result.class.name.dump}"
end
end | 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
raise "Bad facet return type #{result.class.name.dump}"
end
end | [
"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",
"raise",
"\"Bad facet return type #{result.class.name.dump}\"",
"end",
"end"
] | 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 if the file doesn't exist.
end
if facet = @adapter.load_facet(context, facet_name)
@facet_cache[cache_key] = facet
end
end
facet
end | 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 if the file doesn't exist.
end
if facet = @adapter.load_facet(context, facet_name)
@facet_cache[cache_key] = facet
end
end
facet
end | [
"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",
"end",
"if",
"facet",
"=",
"@adapter",
".",
"load_facet",
"(",
"context",
",",
"facet_name",
")",
"@facet_cache",
"[",
"cache_key",
"]",
"=",
"facet",
"end",
"end",
"facet",
"end"
] | 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, path, {}, 'post', body).perform))
end | 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, path, {}, 'post', body).perform))
end | [
"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",
",",
"path",
",",
"{",
"}",
",",
"'post'",
",",
"body",
")",
".",
"perform",
")",
")",
"end"
] | 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] :image service name
@param params [String] :name image name
@param params [Fixnum] :replicas numer of replicas
@param params [Fixnum] :serviceport service port
@param params [Fixnum] :containerport container port
@param params [Hash] :labels hash containing labels
@param params [String] :entrypoint entrypoint
@param params [String] :cmd command
@param params [Boolean] :stdin keep STDIN open even if not attached.
@param params [Array] :env array of envs ["env=value", ["env2=value"]]
@param params [String] :algorithm algorithm of the service, 'roundrobin', 'leastconn'
@param params [String] :protocol prot
@param params [String] :workingdir working directory
@param params [Boolean] :sessionaffinity whether the service uses sticky sessions.
@param params [String] :securitygroups security group for the container. | [
"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",
"[",
"1",
"..",
"-",
"1",
"]",
".",
"to_sym",
"]",
"=",
"deeply_to_hash",
"(",
"obj",
".",
"instance_variable_get",
"(",
"key",
")",
")",
"end",
"hash",
"end"
] | 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("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
transaction.zadd("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
end
else
add_following_followers_reciprocated(from_id, to_id, scope)
end
end | 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("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
transaction.zadd("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
end
else
add_following_followers_reciprocated(from_id, to_id, scope)
end
end | [
"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",
"(",
"\"#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}\"",
",",
"Time",
".",
"now",
".",
"to_i",
",",
"from_id",
")",
"transaction",
".",
"zadd",
"(",
"\"#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}\"",
",",
"Time",
".",
"now",
".",
"to_i",
",",
"to_id",
")",
"end",
"else",
"add_following_followers_reciprocated",
"(",
"from_id",
",",
"to_id",
",",
"scope",
")",
"end",
"end"
] | 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 to be followed.
@param scope [String] Scope for the call.
Examples
Amico.follow(1, 11) | [
"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)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
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)
end
end | 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)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
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)
end
end | [
"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",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}\"",
",",
"to_id",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}\"",
",",
"from_id",
")",
"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",
")",
"end",
"end"
] | 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 [String] Scope for the call.
Examples
Amico.follow(1, 11)
Amico.unfollow(1, 11) | [
"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)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
end
end | 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)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
end
end | [
"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",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}\"",
",",
"from_id",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{from_id}\"",
",",
"to_id",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}\"",
",",
"to_id",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}\"",
",",
"from_id",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{from_id}\"",
",",
"to_id",
")",
"Amico",
".",
"redis",
".",
"zrem",
"(",
"\"#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}\"",
",",
"from_id",
")",
"Amico",
".",
"redis",
".",
"zadd",
"(",
"\"#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}\"",
",",
"Time",
".",
"now",
".",
"to_i",
",",
"to_id",
")",
"Amico",
".",
"redis",
".",
"zadd",
"(",
"\"#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{to_id}\"",
",",
"Time",
".",
"now",
".",
"to_i",
",",
"from_id",
")",
"end",
"end"
] | 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 for the call.
Examples
Amico.block(1, 11) | [
"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.accept(1, 11)
Amico.pending?(1, 11) # false
Amico.following?(1, 11) #true | [
"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)
end
end | 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)
end
end | [
"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",
")",
"end",
"end"
] | 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)
Amico.pending?(1, 11) # false
Amico.following?(1, 11) #false | [
"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?",
"end"
] | 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.following?(1, 11)
@return true if id is following following_id, false otherwise | [
"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?(1, 11)
@return true if follower_id is following id, false otherwise | [
"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)
@return true if id has blocked blocked_id, false otherwise | [
"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?",
"end"
] | 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, 1)
@return true if id is blocked by blocked_by_id, false otherwise | [
"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(1, 11)
Amico.follow(11, 1)
Amico.reciprocated?(1, 11)
@return true if both individuals are following each other, false otherwise | [
"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?",
"end"
] | 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.follow(1, 11)
Amico.pending_with?(11, 1) # true
@return true if the relationship is pending, false otherwise | [
"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 following relationships for an individual. | [
"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 the number of pages of follower relationships for an individual. | [
"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 number of pages of blocked relationships for an individual. | [
"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 the number of pages of blocked_by relationships for an individual. | [
"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(12, 1)
Amico.reciprocated_page_count(1)
@return the number of pages of reciprocated relationships for an individual. | [
"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.