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
SciRuby/daru-view
lib/daru/view/adapters/highcharts/display.rb
LazyHighCharts.HighChart.extract_export_code_iruby
def extract_export_code_iruby( placeholder=random_canvas_id, export_type='png', file_name='chart' ) js = '' js << "\n <script>" js << "\n (function() {" js << "\n \tvar chartDom = document.getElementById('#{placeholder}');" js << "\n \tvar chart = Highcharts.charts[Highcharts.attr(chartDom," js << " 'data-highcharts-chart')]" js << "\n \tchart.exportChart({" js << "\n \t\t" + append_chart_type(export_type) js << "\n \t\tfilename: '#{file_name}'" js << "\n \t});" js << "\n })();" js << "\n </script>" js end
ruby
def extract_export_code_iruby( placeholder=random_canvas_id, export_type='png', file_name='chart' ) js = '' js << "\n <script>" js << "\n (function() {" js << "\n \tvar chartDom = document.getElementById('#{placeholder}');" js << "\n \tvar chart = Highcharts.charts[Highcharts.attr(chartDom," js << " 'data-highcharts-chart')]" js << "\n \tchart.exportChart({" js << "\n \t\t" + append_chart_type(export_type) js << "\n \t\tfilename: '#{file_name}'" js << "\n \t});" js << "\n })();" js << "\n </script>" js end
[ "def", "extract_export_code_iruby", "(", "placeholder", "=", "random_canvas_id", ",", "export_type", "=", "'png'", ",", "file_name", "=", "'chart'", ")", "js", "=", "''", "js", "<<", "\"\\n <script>\"", "js", "<<", "\"\\n (function() {\"", "js", "<<", "\"\\n \\tvar chartDom = document.getElementById('#{placeholder}');\"", "js", "<<", "\"\\n \\tvar chart = Highcharts.charts[Highcharts.attr(chartDom,\"", "js", "<<", "\" 'data-highcharts-chart')]\"", "js", "<<", "\"\\n \\tchart.exportChart({\"", "js", "<<", "\"\\n \\t\\t\"", "+", "append_chart_type", "(", "export_type", ")", "js", "<<", "\"\\n \\t\\tfilename: '#{file_name}'\"", "js", "<<", "\"\\n \\t});\"", "js", "<<", "\"\\n })();\"", "js", "<<", "\"\\n </script>\"", "js", "end" ]
Returns the script to export the chart in different formats in IRuby notebook @param (see #extract_export_code) @return [String] the script to export the chart in IRuby notebook
[ "Returns", "the", "script", "to", "export", "the", "chart", "in", "different", "formats", "in", "IRuby", "notebook" ]
7662fae07a2f339d9600c1dda263b8e409fc5592
https://github.com/SciRuby/daru-view/blob/7662fae07a2f339d9600c1dda263b8e409fc5592/lib/daru/view/adapters/highcharts/display.rb#L229-L245
train
chef/omnibus-ctl
lib/omnibus-ctl.rb
Omnibus.Ctl.get_all_commands_hash
def get_all_commands_hash without_categories = {} category_command_map.each do |category, commands| without_categories.merge!(commands) end command_map.merge(without_categories) end
ruby
def get_all_commands_hash without_categories = {} category_command_map.each do |category, commands| without_categories.merge!(commands) end command_map.merge(without_categories) end
[ "def", "get_all_commands_hash", "without_categories", "=", "{", "}", "category_command_map", ".", "each", "do", "|", "category", ",", "commands", "|", "without_categories", ".", "merge!", "(", "commands", ")", "end", "command_map", ".", "merge", "(", "without_categories", ")", "end" ]
merges category_command_map and command_map, removing categories
[ "merges", "category_command_map", "and", "command_map", "removing", "categories" ]
e160156deaa0afc037748b10d1c9ef0a5be97dc1
https://github.com/chef/omnibus-ctl/blob/e160156deaa0afc037748b10d1c9ef0a5be97dc1/lib/omnibus-ctl.rb#L173-L179
train
chef/omnibus-ctl
lib/omnibus-ctl.rb
Omnibus.Ctl.run_sv_command_for_service
def run_sv_command_for_service(sv_cmd, service_name) if service_enabled?(service_name) status = run_command("#{base_path}/init/#{service_name} #{sv_cmd}") status.exitstatus else log "#{service_name} disabled" if sv_cmd == "status" && verbose 0 end end
ruby
def run_sv_command_for_service(sv_cmd, service_name) if service_enabled?(service_name) status = run_command("#{base_path}/init/#{service_name} #{sv_cmd}") status.exitstatus else log "#{service_name} disabled" if sv_cmd == "status" && verbose 0 end end
[ "def", "run_sv_command_for_service", "(", "sv_cmd", ",", "service_name", ")", "if", "service_enabled?", "(", "service_name", ")", "status", "=", "run_command", "(", "\"#{base_path}/init/#{service_name} #{sv_cmd}\"", ")", "status", ".", "exitstatus", "else", "log", "\"#{service_name} disabled\"", "if", "sv_cmd", "==", "\"status\"", "&&", "verbose", "0", "end", "end" ]
run an sv command for a specific service name
[ "run", "an", "sv", "command", "for", "a", "specific", "service", "name" ]
e160156deaa0afc037748b10d1c9ef0a5be97dc1
https://github.com/chef/omnibus-ctl/blob/e160156deaa0afc037748b10d1c9ef0a5be97dc1/lib/omnibus-ctl.rb#L363-L371
train
chef/omnibus-ctl
lib/omnibus-ctl.rb
Omnibus.Ctl.parse_options
def parse_options(args) args.select do |option| case option when "--quiet", "-q" @quiet = true false when "--verbose", "-v" @verbose = true false end end end
ruby
def parse_options(args) args.select do |option| case option when "--quiet", "-q" @quiet = true false when "--verbose", "-v" @verbose = true false end end end
[ "def", "parse_options", "(", "args", ")", "args", ".", "select", "do", "|", "option", "|", "case", "option", "when", "\"--quiet\"", ",", "\"-q\"", "@quiet", "=", "true", "false", "when", "\"--verbose\"", ",", "\"-v\"", "@verbose", "=", "true", "false", "end", "end", "end" ]
Set global options and remove them from the args list we pass into commands.
[ "Set", "global", "options", "and", "remove", "them", "from", "the", "args", "list", "we", "pass", "into", "commands", "." ]
e160156deaa0afc037748b10d1c9ef0a5be97dc1
https://github.com/chef/omnibus-ctl/blob/e160156deaa0afc037748b10d1c9ef0a5be97dc1/lib/omnibus-ctl.rb#L651-L662
train
chef/omnibus-ctl
lib/omnibus-ctl.rb
Omnibus.Ctl.retrieve_command
def retrieve_command(command_to_run) if command_map.has_key?(command_to_run) command_map[command_to_run] else command = nil category_command_map.each do |category, commands| command = commands[command_to_run] if commands.has_key?(command_to_run) end # return the command, or nil if it wasn't found command end end
ruby
def retrieve_command(command_to_run) if command_map.has_key?(command_to_run) command_map[command_to_run] else command = nil category_command_map.each do |category, commands| command = commands[command_to_run] if commands.has_key?(command_to_run) end # return the command, or nil if it wasn't found command end end
[ "def", "retrieve_command", "(", "command_to_run", ")", "if", "command_map", ".", "has_key?", "(", "command_to_run", ")", "command_map", "[", "command_to_run", "]", "else", "command", "=", "nil", "category_command_map", ".", "each", "do", "|", "category", ",", "commands", "|", "command", "=", "commands", "[", "command_to_run", "]", "if", "commands", ".", "has_key?", "(", "command_to_run", ")", "end", "# return the command, or nil if it wasn't found", "command", "end", "end" ]
retrieves the commmand from either the command_map or the category_command_map, if the command is not found return nil
[ "retrieves", "the", "commmand", "from", "either", "the", "command_map", "or", "the", "category_command_map", "if", "the", "command", "is", "not", "found", "return", "nil" ]
e160156deaa0afc037748b10d1c9ef0a5be97dc1
https://github.com/chef/omnibus-ctl/blob/e160156deaa0afc037748b10d1c9ef0a5be97dc1/lib/omnibus-ctl.rb#L672-L683
train
chef/omnibus-ctl
lib/omnibus-ctl.rb
Omnibus.Ctl.run
def run(args) # Ensure Omnibus related binaries are in the PATH ENV["PATH"] = [File.join(base_path, "bin"), File.join(base_path, "embedded","bin"), ENV['PATH']].join(":") command_to_run = args[0] ## when --help is run as the command itself, we need to strip off the ## `--` to ensure the command maps correctly. if command_to_run == "--help" command_to_run = "help" end # This piece of code checks if the argument is an option. If it is, # then it sets service to nil and adds the argument into the options # argument. This is ugly. A better solution is having a proper parser. # But if we are going to implement a proper parser, we might as well # port this to Thor rather than reinventing Thor. For now, this preserves # the behavior to complain and exit with an error if one attempts to invoke # a pcc command that does not accept an argument. Like "help". options = args[2..-1] || [] if is_option?(args[1]) options.unshift(args[1]) service = nil else service = args[1] end # returns either hash content of command or nil command = retrieve_command(command_to_run) if command.nil? log "I don't know that command." if args.length == 2 log "Did you mean: #{exe_name} #{service} #{command_to_run}?" end help Kernel.exit 1 end if args.length > 1 && command[:arity] != 2 log "The command #{command_to_run} does not accept any arguments" Kernel.exit 2 end parse_options options @force_exit = false exit_code = 0 run_global_pre_hooks # Filter args to just command and service. If you are loading # custom commands and need access to the command line argument, # use ARGV directly. actual_args = [command_to_run, service].reject(&:nil?) if command_pre_hook(*actual_args) method_to_call = to_method_name(command_to_run) begin ret = send(method_to_call, *actual_args) rescue SystemExit => e @force_exit = true ret = e.status end command_post_hook(*actual_args) exit_code = ret unless ret.nil? else exit_code = 8 @force_exit = true end if @force_exit Kernel.exit exit_code else exit_code end end
ruby
def run(args) # Ensure Omnibus related binaries are in the PATH ENV["PATH"] = [File.join(base_path, "bin"), File.join(base_path, "embedded","bin"), ENV['PATH']].join(":") command_to_run = args[0] ## when --help is run as the command itself, we need to strip off the ## `--` to ensure the command maps correctly. if command_to_run == "--help" command_to_run = "help" end # This piece of code checks if the argument is an option. If it is, # then it sets service to nil and adds the argument into the options # argument. This is ugly. A better solution is having a proper parser. # But if we are going to implement a proper parser, we might as well # port this to Thor rather than reinventing Thor. For now, this preserves # the behavior to complain and exit with an error if one attempts to invoke # a pcc command that does not accept an argument. Like "help". options = args[2..-1] || [] if is_option?(args[1]) options.unshift(args[1]) service = nil else service = args[1] end # returns either hash content of command or nil command = retrieve_command(command_to_run) if command.nil? log "I don't know that command." if args.length == 2 log "Did you mean: #{exe_name} #{service} #{command_to_run}?" end help Kernel.exit 1 end if args.length > 1 && command[:arity] != 2 log "The command #{command_to_run} does not accept any arguments" Kernel.exit 2 end parse_options options @force_exit = false exit_code = 0 run_global_pre_hooks # Filter args to just command and service. If you are loading # custom commands and need access to the command line argument, # use ARGV directly. actual_args = [command_to_run, service].reject(&:nil?) if command_pre_hook(*actual_args) method_to_call = to_method_name(command_to_run) begin ret = send(method_to_call, *actual_args) rescue SystemExit => e @force_exit = true ret = e.status end command_post_hook(*actual_args) exit_code = ret unless ret.nil? else exit_code = 8 @force_exit = true end if @force_exit Kernel.exit exit_code else exit_code end end
[ "def", "run", "(", "args", ")", "# Ensure Omnibus related binaries are in the PATH", "ENV", "[", "\"PATH\"", "]", "=", "[", "File", ".", "join", "(", "base_path", ",", "\"bin\"", ")", ",", "File", ".", "join", "(", "base_path", ",", "\"embedded\"", ",", "\"bin\"", ")", ",", "ENV", "[", "'PATH'", "]", "]", ".", "join", "(", "\":\"", ")", "command_to_run", "=", "args", "[", "0", "]", "## when --help is run as the command itself, we need to strip off the", "## `--` to ensure the command maps correctly.", "if", "command_to_run", "==", "\"--help\"", "command_to_run", "=", "\"help\"", "end", "# This piece of code checks if the argument is an option. If it is,", "# then it sets service to nil and adds the argument into the options", "# argument. This is ugly. A better solution is having a proper parser.", "# But if we are going to implement a proper parser, we might as well", "# port this to Thor rather than reinventing Thor. For now, this preserves", "# the behavior to complain and exit with an error if one attempts to invoke", "# a pcc command that does not accept an argument. Like \"help\".", "options", "=", "args", "[", "2", "..", "-", "1", "]", "||", "[", "]", "if", "is_option?", "(", "args", "[", "1", "]", ")", "options", ".", "unshift", "(", "args", "[", "1", "]", ")", "service", "=", "nil", "else", "service", "=", "args", "[", "1", "]", "end", "# returns either hash content of command or nil", "command", "=", "retrieve_command", "(", "command_to_run", ")", "if", "command", ".", "nil?", "log", "\"I don't know that command.\"", "if", "args", ".", "length", "==", "2", "log", "\"Did you mean: #{exe_name} #{service} #{command_to_run}?\"", "end", "help", "Kernel", ".", "exit", "1", "end", "if", "args", ".", "length", ">", "1", "&&", "command", "[", ":arity", "]", "!=", "2", "log", "\"The command #{command_to_run} does not accept any arguments\"", "Kernel", ".", "exit", "2", "end", "parse_options", "options", "@force_exit", "=", "false", "exit_code", "=", "0", "run_global_pre_hooks", "# Filter args to just command and service. If you are loading", "# custom commands and need access to the command line argument,", "# use ARGV directly.", "actual_args", "=", "[", "command_to_run", ",", "service", "]", ".", "reject", "(", ":nil?", ")", "if", "command_pre_hook", "(", "actual_args", ")", "method_to_call", "=", "to_method_name", "(", "command_to_run", ")", "begin", "ret", "=", "send", "(", "method_to_call", ",", "actual_args", ")", "rescue", "SystemExit", "=>", "e", "@force_exit", "=", "true", "ret", "=", "e", ".", "status", "end", "command_post_hook", "(", "actual_args", ")", "exit_code", "=", "ret", "unless", "ret", ".", "nil?", "else", "exit_code", "=", "8", "@force_exit", "=", "true", "end", "if", "@force_exit", "Kernel", ".", "exit", "exit_code", "else", "exit_code", "end", "end" ]
Previously this would exit immediately with the provided exit code; however this would prevent post-run hooks from continuing Instead, we'll just track whether a an exit was requested and use that to determine how we exit from 'run'
[ "Previously", "this", "would", "exit", "immediately", "with", "the", "provided", "exit", "code", ";", "however", "this", "would", "prevent", "post", "-", "run", "hooks", "from", "continuing", "Instead", "we", "ll", "just", "track", "whether", "a", "an", "exit", "was", "requested", "and", "use", "that", "to", "determine", "how", "we", "exit", "from", "run" ]
e160156deaa0afc037748b10d1c9ef0a5be97dc1
https://github.com/chef/omnibus-ctl/blob/e160156deaa0afc037748b10d1c9ef0a5be97dc1/lib/omnibus-ctl.rb#L689-L764
train
chef/omnibus-ctl
lib/omnibus-ctl.rb
Omnibus.Ctl.status_post_hook
def status_post_hook(service = nil) if service.nil? log_external_service_header external_services.each_key do |service_name| status = send(to_method_name("external_status_#{service_name}"), :sparse) log status end else # Request verbose status if the service is asked for by name. if service_external?(service) status = send(to_method_name("external_status_#{service}"), :verbose) log status end end end
ruby
def status_post_hook(service = nil) if service.nil? log_external_service_header external_services.each_key do |service_name| status = send(to_method_name("external_status_#{service_name}"), :sparse) log status end else # Request verbose status if the service is asked for by name. if service_external?(service) status = send(to_method_name("external_status_#{service}"), :verbose) log status end end end
[ "def", "status_post_hook", "(", "service", "=", "nil", ")", "if", "service", ".", "nil?", "log_external_service_header", "external_services", ".", "each_key", "do", "|", "service_name", "|", "status", "=", "send", "(", "to_method_name", "(", "\"external_status_#{service_name}\"", ")", ",", ":sparse", ")", "log", "status", "end", "else", "# Request verbose status if the service is asked for by name.", "if", "service_external?", "(", "service", ")", "status", "=", "send", "(", "to_method_name", "(", "\"external_status_#{service}\"", ")", ",", ":verbose", ")", "log", "status", "end", "end", "end" ]
Status gets its own hook because each externalized service will have its own things to do in order to report status. As above, we may also include an output header to show that we're reporting on external services. Your callback for this function should be in the form 'external_status_#{service_name}(detail_level) where detail_level is :sparse|:verbose :sparse is used when it's a summary service status list, eg "$appname-ctl status" :verbose is used when the specific service has been named, eg "$appname-ctl status postgresql"
[ "Status", "gets", "its", "own", "hook", "because", "each", "externalized", "service", "will", "have", "its", "own", "things", "to", "do", "in", "order", "to", "report", "status", ".", "As", "above", "we", "may", "also", "include", "an", "output", "header", "to", "show", "that", "we", "re", "reporting", "on", "external", "services", "." ]
e160156deaa0afc037748b10d1c9ef0a5be97dc1
https://github.com/chef/omnibus-ctl/blob/e160156deaa0afc037748b10d1c9ef0a5be97dc1/lib/omnibus-ctl.rb#L834-L848
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.enable_rate_limit_forward
def enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key) headers[Protocol::HEADER_API_KEY] = admin_api_key headers[Protocol::HEADER_FORWARDED_IP] = end_user_ip headers[Protocol::HEADER_FORWARDED_API_KEY] = rate_limit_api_key end
ruby
def enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key) headers[Protocol::HEADER_API_KEY] = admin_api_key headers[Protocol::HEADER_FORWARDED_IP] = end_user_ip headers[Protocol::HEADER_FORWARDED_API_KEY] = rate_limit_api_key end
[ "def", "enable_rate_limit_forward", "(", "admin_api_key", ",", "end_user_ip", ",", "rate_limit_api_key", ")", "headers", "[", "Protocol", "::", "HEADER_API_KEY", "]", "=", "admin_api_key", "headers", "[", "Protocol", "::", "HEADER_FORWARDED_IP", "]", "=", "end_user_ip", "headers", "[", "Protocol", "::", "HEADER_FORWARDED_API_KEY", "]", "=", "rate_limit_api_key", "end" ]
Allow to use IP rate limit when you have a proxy between end-user and Algolia. This option will set the X-Forwarded-For HTTP header with the client IP and the X-Forwarded-API-Key with the API Key having rate limits. @param admin_api_key the admin API Key you can find in your dashboard @param end_user_ip the end user IP (you can use both IPV4 or IPV6 syntax) @param rate_limit_api_key the API key on which you have a rate limit
[ "Allow", "to", "use", "IP", "rate", "limit", "when", "you", "have", "a", "proxy", "between", "end", "-", "user", "and", "Algolia", ".", "This", "option", "will", "set", "the", "X", "-", "Forwarded", "-", "For", "HTTP", "header", "with", "the", "client", "IP", "and", "the", "X", "-", "Forwarded", "-", "API", "-", "Key", "with", "the", "API", "Key", "having", "rate", "limits", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L85-L89
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.multiple_queries
def multiple_queries(queries, options = nil, strategy = nil) if options.is_a?(Hash) index_name_key = options.delete(:index_name_key) || options.delete('index_name_key') strategy = options.delete(:strategy) || options.delete('strategy') request_options = options.delete(:request_options) || options.delete('request_options') else # Deprecated def multiple_queries(queries, index_name_key, strategy) index_name_key = options end index_name_key ||= :index_name strategy ||= 'none' request_options ||= {} requests = { :requests => queries.map do |query| query = query.dup index_name = query.delete(index_name_key) || query.delete(index_name_key.to_s) raise ArgumentError.new("Missing '#{index_name_key}' option") if index_name.nil? encoded_params = Hash[query.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }] { :indexName => index_name, :params => Protocol.to_query(encoded_params) } end } post(Protocol.multiple_queries_uri(strategy), requests.to_json, :search, request_options) end
ruby
def multiple_queries(queries, options = nil, strategy = nil) if options.is_a?(Hash) index_name_key = options.delete(:index_name_key) || options.delete('index_name_key') strategy = options.delete(:strategy) || options.delete('strategy') request_options = options.delete(:request_options) || options.delete('request_options') else # Deprecated def multiple_queries(queries, index_name_key, strategy) index_name_key = options end index_name_key ||= :index_name strategy ||= 'none' request_options ||= {} requests = { :requests => queries.map do |query| query = query.dup index_name = query.delete(index_name_key) || query.delete(index_name_key.to_s) raise ArgumentError.new("Missing '#{index_name_key}' option") if index_name.nil? encoded_params = Hash[query.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }] { :indexName => index_name, :params => Protocol.to_query(encoded_params) } end } post(Protocol.multiple_queries_uri(strategy), requests.to_json, :search, request_options) end
[ "def", "multiple_queries", "(", "queries", ",", "options", "=", "nil", ",", "strategy", "=", "nil", ")", "if", "options", ".", "is_a?", "(", "Hash", ")", "index_name_key", "=", "options", ".", "delete", "(", ":index_name_key", ")", "||", "options", ".", "delete", "(", "'index_name_key'", ")", "strategy", "=", "options", ".", "delete", "(", ":strategy", ")", "||", "options", ".", "delete", "(", "'strategy'", ")", "request_options", "=", "options", ".", "delete", "(", ":request_options", ")", "||", "options", ".", "delete", "(", "'request_options'", ")", "else", "# Deprecated def multiple_queries(queries, index_name_key, strategy)", "index_name_key", "=", "options", "end", "index_name_key", "||=", ":index_name", "strategy", "||=", "'none'", "request_options", "||=", "{", "}", "requests", "=", "{", ":requests", "=>", "queries", ".", "map", "do", "|", "query", "|", "query", "=", "query", ".", "dup", "index_name", "=", "query", ".", "delete", "(", "index_name_key", ")", "||", "query", ".", "delete", "(", "index_name_key", ".", "to_s", ")", "raise", "ArgumentError", ".", "new", "(", "\"Missing '#{index_name_key}' option\"", ")", "if", "index_name", ".", "nil?", "encoded_params", "=", "Hash", "[", "query", ".", "map", "{", "|", "k", ",", "v", "|", "[", "k", ".", "to_s", ",", "v", ".", "is_a?", "(", "Array", ")", "?", "v", ".", "to_json", ":", "v", "]", "}", "]", "{", ":indexName", "=>", "index_name", ",", ":params", "=>", "Protocol", ".", "to_query", "(", "encoded_params", ")", "}", "end", "}", "post", "(", "Protocol", ".", "multiple_queries_uri", "(", "strategy", ")", ",", "requests", ".", "to_json", ",", ":search", ",", "request_options", ")", "end" ]
This method allows to query multiple indexes with one API call @param queries the array of hash representing the query and associated index name @param options - accepts those keys: - index_name_key the name of the key used to fetch the index_name (:index_name by default) - strategy define the strategy applied on the sequential searches (none by default) - request_options contains extra parameters to send with your query
[ "This", "method", "allows", "to", "query", "multiple", "indexes", "with", "one", "API", "call" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L121-L144
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.move_index
def move_index(src_index, dst_index, request_options = {}) request = { 'operation' => 'move', 'destination' => dst_index } post(Protocol.index_operation_uri(src_index), request.to_json, :write, request_options) end
ruby
def move_index(src_index, dst_index, request_options = {}) request = { 'operation' => 'move', 'destination' => dst_index } post(Protocol.index_operation_uri(src_index), request.to_json, :write, request_options) end
[ "def", "move_index", "(", "src_index", ",", "dst_index", ",", "request_options", "=", "{", "}", ")", "request", "=", "{", "'operation'", "=>", "'move'", ",", "'destination'", "=>", "dst_index", "}", "post", "(", "Protocol", ".", "index_operation_uri", "(", "src_index", ")", ",", "request", ".", "to_json", ",", ":write", ",", "request_options", ")", "end" ]
Move an existing index. @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist). @param request_options contains extra parameters to send with your query
[ "Move", "an", "existing", "index", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L177-L180
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.move_index!
def move_index!(src_index, dst_index, request_options = {}) res = move_index(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def move_index!(src_index, dst_index, request_options = {}) res = move_index(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "move_index!", "(", "src_index", ",", "dst_index", ",", "request_options", "=", "{", "}", ")", "res", "=", "move_index", "(", "src_index", ",", "dst_index", ",", "request_options", ")", "wait_task", "(", "dst_index", ",", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Move an existing index and wait until the move has been processed @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist). @param request_options contains extra parameters to send with your query
[ "Move", "an", "existing", "index", "and", "wait", "until", "the", "move", "has", "been", "processed" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L189-L193
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.copy_index
def copy_index(src_index, dst_index, scope = nil, request_options = {}) request = { 'operation' => 'copy', 'destination' => dst_index } request['scope'] = scope unless scope.nil? post(Protocol.index_operation_uri(src_index), request.to_json, :write, request_options) end
ruby
def copy_index(src_index, dst_index, scope = nil, request_options = {}) request = { 'operation' => 'copy', 'destination' => dst_index } request['scope'] = scope unless scope.nil? post(Protocol.index_operation_uri(src_index), request.to_json, :write, request_options) end
[ "def", "copy_index", "(", "src_index", ",", "dst_index", ",", "scope", "=", "nil", ",", "request_options", "=", "{", "}", ")", "request", "=", "{", "'operation'", "=>", "'copy'", ",", "'destination'", "=>", "dst_index", "}", "request", "[", "'scope'", "]", "=", "scope", "unless", "scope", ".", "nil?", "post", "(", "Protocol", ".", "index_operation_uri", "(", "src_index", ")", ",", "request", ".", "to_json", ",", ":write", ",", "request_options", ")", "end" ]
Copy an existing index. @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist). @param scope the optional list of scopes to copy (all if not specified). @param request_options contains extra parameters to send with your query
[ "Copy", "an", "existing", "index", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L203-L207
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.copy_index!
def copy_index!(src_index, dst_index, scope = nil, request_options = {}) res = copy_index(src_index, dst_index, scope, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def copy_index!(src_index, dst_index, scope = nil, request_options = {}) res = copy_index(src_index, dst_index, scope, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "copy_index!", "(", "src_index", ",", "dst_index", ",", "scope", "=", "nil", ",", "request_options", "=", "{", "}", ")", "res", "=", "copy_index", "(", "src_index", ",", "dst_index", ",", "scope", ",", "request_options", ")", "wait_task", "(", "dst_index", ",", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Copy an existing index and wait until the copy has been processed. @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist). @param scope the optional list of scopes to copy (all if not specified). @param request_options contains extra parameters to send with your query
[ "Copy", "an", "existing", "index", "and", "wait", "until", "the", "copy", "has", "been", "processed", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L217-L221
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.copy_settings!
def copy_settings!(src_index, dst_index, request_options = {}) res = copy_settings(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def copy_settings!(src_index, dst_index, request_options = {}) res = copy_settings(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "copy_settings!", "(", "src_index", ",", "dst_index", ",", "request_options", "=", "{", "}", ")", "res", "=", "copy_settings", "(", "src_index", ",", "dst_index", ",", "request_options", ")", "wait_task", "(", "dst_index", ",", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Copy an existing index settings and wait until the copy has been processed. @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName settings (destination settings will be overriten if it already exist). @param request_options contains extra parameters to send with your query
[ "Copy", "an", "existing", "index", "settings", "and", "wait", "until", "the", "copy", "has", "been", "processed", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L241-L245
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.copy_synonyms!
def copy_synonyms!(src_index, dst_index, request_options = {}) res = copy_synonyms(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def copy_synonyms!(src_index, dst_index, request_options = {}) res = copy_synonyms(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "copy_synonyms!", "(", "src_index", ",", "dst_index", ",", "request_options", "=", "{", "}", ")", "res", "=", "copy_synonyms", "(", "src_index", ",", "dst_index", ",", "request_options", ")", "wait_task", "(", "dst_index", ",", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Copy an existing index synonyms and wait until the copy has been processed. @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName synonyms (destination synonyms will be overriten if it already exist). @param request_options contains extra parameters to send with your query
[ "Copy", "an", "existing", "index", "synonyms", "and", "wait", "until", "the", "copy", "has", "been", "processed", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L265-L269
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.copy_rules!
def copy_rules!(src_index, dst_index, request_options = {}) res = copy_rules(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def copy_rules!(src_index, dst_index, request_options = {}) res = copy_rules(src_index, dst_index, request_options) wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "copy_rules!", "(", "src_index", ",", "dst_index", ",", "request_options", "=", "{", "}", ")", "res", "=", "copy_rules", "(", "src_index", ",", "dst_index", ",", "request_options", ")", "wait_task", "(", "dst_index", ",", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Copy an existing index rules and wait until the copy has been processed. @param src_index the name of index to copy. @param dst_index the new index name that will contains a copy of srcIndexName rules (destination rules will be overriten if it already exist). @param request_options contains extra parameters to send with your query
[ "Copy", "an", "existing", "index", "rules", "and", "wait", "until", "the", "copy", "has", "been", "processed", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L289-L293
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.get_logs
def get_logs(options = nil, length = nil, type = nil) if options.is_a?(Hash) offset = options.delete('offset') || options.delete(:offset) length = options.delete('length') || options.delete(:length) type = options.delete('type') || options.delete(:type) request_options = options.delete('request_options') || options.delete(:request_options) else # Deprecated def get_logs(offset, length, type) offset = options end length ||= 10 type = 'all' if type.nil? type = type ? 'error' : 'all' if type.is_a?(true.class) request_options ||= {} get(Protocol.logs(offset, length, type), :write, request_options) end
ruby
def get_logs(options = nil, length = nil, type = nil) if options.is_a?(Hash) offset = options.delete('offset') || options.delete(:offset) length = options.delete('length') || options.delete(:length) type = options.delete('type') || options.delete(:type) request_options = options.delete('request_options') || options.delete(:request_options) else # Deprecated def get_logs(offset, length, type) offset = options end length ||= 10 type = 'all' if type.nil? type = type ? 'error' : 'all' if type.is_a?(true.class) request_options ||= {} get(Protocol.logs(offset, length, type), :write, request_options) end
[ "def", "get_logs", "(", "options", "=", "nil", ",", "length", "=", "nil", ",", "type", "=", "nil", ")", "if", "options", ".", "is_a?", "(", "Hash", ")", "offset", "=", "options", ".", "delete", "(", "'offset'", ")", "||", "options", ".", "delete", "(", ":offset", ")", "length", "=", "options", ".", "delete", "(", "'length'", ")", "||", "options", ".", "delete", "(", ":length", ")", "type", "=", "options", ".", "delete", "(", "'type'", ")", "||", "options", ".", "delete", "(", ":type", ")", "request_options", "=", "options", ".", "delete", "(", "'request_options'", ")", "||", "options", ".", "delete", "(", ":request_options", ")", "else", "# Deprecated def get_logs(offset, length, type)", "offset", "=", "options", "end", "length", "||=", "10", "type", "=", "'all'", "if", "type", ".", "nil?", "type", "=", "type", "?", "'error'", ":", "'all'", "if", "type", ".", "is_a?", "(", "true", ".", "class", ")", "request_options", "||=", "{", "}", "get", "(", "Protocol", ".", "logs", "(", "offset", ",", "length", ",", "type", ")", ",", ":write", ",", "request_options", ")", "end" ]
Return last logs entries. @param options - accepts those keys: - offset Specify the first entry to retrieve (0-based, 0 is the most recent log entry) - Default = 0 - length Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000 - Default = 10 - type Type of log entries to retrieve ("all", "query", "build" or "error") - Default = 'all' - request_options contains extra parameters to send with your query
[ "Return", "last", "logs", "entries", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L322-L338
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.batch!
def batch!(operations, request_options = {}) res = batch(operations, request_options) res['taskID'].each do |index, taskID| wait_task(index, taskID, WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end end
ruby
def batch!(operations, request_options = {}) res = batch(operations, request_options) res['taskID'].each do |index, taskID| wait_task(index, taskID, WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end end
[ "def", "batch!", "(", "operations", ",", "request_options", "=", "{", "}", ")", "res", "=", "batch", "(", "operations", ",", "request_options", ")", "res", "[", "'taskID'", "]", ".", "each", "do", "|", "index", ",", "taskID", "|", "wait_task", "(", "index", ",", "taskID", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "end", "end" ]
Send a batch request targeting multiple indices and wait the end of the indexing
[ "Send", "a", "batch", "request", "targeting", "multiple", "indices", "and", "wait", "the", "end", "of", "the", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L475-L480
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.get_task_status
def get_task_status(index_name, taskID, request_options = {}) get(Protocol.task_uri(index_name, taskID), :read, request_options)['status'] end
ruby
def get_task_status(index_name, taskID, request_options = {}) get(Protocol.task_uri(index_name, taskID), :read, request_options)['status'] end
[ "def", "get_task_status", "(", "index_name", ",", "taskID", ",", "request_options", "=", "{", "}", ")", "get", "(", "Protocol", ".", "task_uri", "(", "index_name", ",", "taskID", ")", ",", ":read", ",", "request_options", ")", "[", "'status'", "]", "end" ]
Check the status of a task on the server. All server task are asynchronous and you can check the status of a task with this method. @param index_name the index name owning the taskID @param taskID the id of the task returned by server @param request_options contains extra parameters to send with your query
[ "Check", "the", "status", "of", "a", "task", "on", "the", "server", ".", "All", "server", "task", "are", "asynchronous", "and", "you", "can", "check", "the", "status", "of", "a", "task", "with", "this", "method", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L490-L492
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.request
def request(uri, method, data = nil, type = :write, request_options = {}) exceptions = [] connect_timeout = @connect_timeout send_timeout = if type == :search @search_timeout elsif type == :batch type = :write @batch_timeout else @send_timeout end receive_timeout = type == :search ? @search_timeout : @receive_timeout thread_local_hosts(type != :write).each_with_index do |host, i| connect_timeout += 2 if i == 2 send_timeout += 10 if i == 2 receive_timeout += 10 if i == 2 thread_index_key = type != :write ? "algolia_search_host_index_#{application_id}" : "algolia_host_index_#{application_id}" Thread.current[thread_index_key] = host[:index] host[:last_call] = Time.now.to_i host[:session].connect_timeout = connect_timeout host[:session].send_timeout = send_timeout host[:session].receive_timeout = receive_timeout begin return perform_request(host[:session], host[:base_url] + uri, method, data, request_options) rescue AlgoliaProtocolError => e raise if e.code / 100 == 4 exceptions << e rescue => e exceptions << e end host[:session].reset_all end raise AlgoliaProtocolError.new(0, "Cannot reach any host: #{exceptions.map { |e| e.to_s }.join(', ')}") end
ruby
def request(uri, method, data = nil, type = :write, request_options = {}) exceptions = [] connect_timeout = @connect_timeout send_timeout = if type == :search @search_timeout elsif type == :batch type = :write @batch_timeout else @send_timeout end receive_timeout = type == :search ? @search_timeout : @receive_timeout thread_local_hosts(type != :write).each_with_index do |host, i| connect_timeout += 2 if i == 2 send_timeout += 10 if i == 2 receive_timeout += 10 if i == 2 thread_index_key = type != :write ? "algolia_search_host_index_#{application_id}" : "algolia_host_index_#{application_id}" Thread.current[thread_index_key] = host[:index] host[:last_call] = Time.now.to_i host[:session].connect_timeout = connect_timeout host[:session].send_timeout = send_timeout host[:session].receive_timeout = receive_timeout begin return perform_request(host[:session], host[:base_url] + uri, method, data, request_options) rescue AlgoliaProtocolError => e raise if e.code / 100 == 4 exceptions << e rescue => e exceptions << e end host[:session].reset_all end raise AlgoliaProtocolError.new(0, "Cannot reach any host: #{exceptions.map { |e| e.to_s }.join(', ')}") end
[ "def", "request", "(", "uri", ",", "method", ",", "data", "=", "nil", ",", "type", "=", ":write", ",", "request_options", "=", "{", "}", ")", "exceptions", "=", "[", "]", "connect_timeout", "=", "@connect_timeout", "send_timeout", "=", "if", "type", "==", ":search", "@search_timeout", "elsif", "type", "==", ":batch", "type", "=", ":write", "@batch_timeout", "else", "@send_timeout", "end", "receive_timeout", "=", "type", "==", ":search", "?", "@search_timeout", ":", "@receive_timeout", "thread_local_hosts", "(", "type", "!=", ":write", ")", ".", "each_with_index", "do", "|", "host", ",", "i", "|", "connect_timeout", "+=", "2", "if", "i", "==", "2", "send_timeout", "+=", "10", "if", "i", "==", "2", "receive_timeout", "+=", "10", "if", "i", "==", "2", "thread_index_key", "=", "type", "!=", ":write", "?", "\"algolia_search_host_index_#{application_id}\"", ":", "\"algolia_host_index_#{application_id}\"", "Thread", ".", "current", "[", "thread_index_key", "]", "=", "host", "[", ":index", "]", "host", "[", ":last_call", "]", "=", "Time", ".", "now", ".", "to_i", "host", "[", ":session", "]", ".", "connect_timeout", "=", "connect_timeout", "host", "[", ":session", "]", ".", "send_timeout", "=", "send_timeout", "host", "[", ":session", "]", ".", "receive_timeout", "=", "receive_timeout", "begin", "return", "perform_request", "(", "host", "[", ":session", "]", ",", "host", "[", ":base_url", "]", "+", "uri", ",", "method", ",", "data", ",", "request_options", ")", "rescue", "AlgoliaProtocolError", "=>", "e", "raise", "if", "e", ".", "code", "/", "100", "==", "4", "exceptions", "<<", "e", "rescue", "=>", "e", "exceptions", "<<", "e", "end", "host", "[", ":session", "]", ".", "reset_all", "end", "raise", "AlgoliaProtocolError", ".", "new", "(", "0", ",", "\"Cannot reach any host: #{exceptions.map { |e| e.to_s }.join(', ')}\"", ")", "end" ]
Perform an HTTP request for the given uri and method with common basic response handling. Will raise a AlgoliaProtocolError if the response has an error status code, and will return the parsed JSON body on success, if there is one.
[ "Perform", "an", "HTTP", "request", "for", "the", "given", "uri", "and", "method", "with", "common", "basic", "response", "handling", ".", "Will", "raise", "a", "AlgoliaProtocolError", "if", "the", "response", "has", "an", "error", "status", "code", "and", "will", "return", "the", "parsed", "JSON", "body", "on", "success", "if", "there", "is", "one", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L566-L603
train
algolia/algoliasearch-client-ruby
lib/algolia/client.rb
Algolia.Client.thread_local_hosts
def thread_local_hosts(read) thread_hosts_key = read ? "algolia_search_hosts_#{application_id}" : "algolia_hosts_#{application_id}" Thread.current[thread_hosts_key] ||= (read ? search_hosts : hosts).each_with_index.map do |host, i| client = HTTPClient.new client.ssl_config.ssl_version = @ssl_version if @ssl && @ssl_version client.transparent_gzip_decompression = @gzip client.ssl_config.add_trust_ca File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'ca-bundle.crt')) { :index => i, :base_url => "http#{@ssl ? 's' : ''}://#{host}", :session => client, :last_call => nil } end hosts = Thread.current[thread_hosts_key] thread_index_key = read ? "algolia_search_host_index_#{application_id}" : "algolia_host_index_#{application_id}" current_host = Thread.current[thread_index_key].to_i # `to_i` to ensure first call is 0 # we want to always target host 0 first # if the current host is not 0, then we want to use it first only if (we never used it OR we're using it since less than 1 minute) if current_host != 0 && (hosts[current_host][:last_call].nil? || hosts[current_host][:last_call] > Time.now.to_i - 60) # first host will be `current_host` first = hosts[current_host] [first] + hosts.reject { |h| h[:index] == 0 || h == first } + hosts.select { |h| h[:index] == 0 } else # first host will be `0` hosts end end
ruby
def thread_local_hosts(read) thread_hosts_key = read ? "algolia_search_hosts_#{application_id}" : "algolia_hosts_#{application_id}" Thread.current[thread_hosts_key] ||= (read ? search_hosts : hosts).each_with_index.map do |host, i| client = HTTPClient.new client.ssl_config.ssl_version = @ssl_version if @ssl && @ssl_version client.transparent_gzip_decompression = @gzip client.ssl_config.add_trust_ca File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'ca-bundle.crt')) { :index => i, :base_url => "http#{@ssl ? 's' : ''}://#{host}", :session => client, :last_call => nil } end hosts = Thread.current[thread_hosts_key] thread_index_key = read ? "algolia_search_host_index_#{application_id}" : "algolia_host_index_#{application_id}" current_host = Thread.current[thread_index_key].to_i # `to_i` to ensure first call is 0 # we want to always target host 0 first # if the current host is not 0, then we want to use it first only if (we never used it OR we're using it since less than 1 minute) if current_host != 0 && (hosts[current_host][:last_call].nil? || hosts[current_host][:last_call] > Time.now.to_i - 60) # first host will be `current_host` first = hosts[current_host] [first] + hosts.reject { |h| h[:index] == 0 || h == first } + hosts.select { |h| h[:index] == 0 } else # first host will be `0` hosts end end
[ "def", "thread_local_hosts", "(", "read", ")", "thread_hosts_key", "=", "read", "?", "\"algolia_search_hosts_#{application_id}\"", ":", "\"algolia_hosts_#{application_id}\"", "Thread", ".", "current", "[", "thread_hosts_key", "]", "||=", "(", "read", "?", "search_hosts", ":", "hosts", ")", ".", "each_with_index", ".", "map", "do", "|", "host", ",", "i", "|", "client", "=", "HTTPClient", ".", "new", "client", ".", "ssl_config", ".", "ssl_version", "=", "@ssl_version", "if", "@ssl", "&&", "@ssl_version", "client", ".", "transparent_gzip_decompression", "=", "@gzip", "client", ".", "ssl_config", ".", "add_trust_ca", "File", ".", "expand_path", "(", "File", ".", "join", "(", "File", ".", "dirname", "(", "__FILE__", ")", ",", "'..'", ",", "'..'", ",", "'resources'", ",", "'ca-bundle.crt'", ")", ")", "{", ":index", "=>", "i", ",", ":base_url", "=>", "\"http#{@ssl ? 's' : ''}://#{host}\"", ",", ":session", "=>", "client", ",", ":last_call", "=>", "nil", "}", "end", "hosts", "=", "Thread", ".", "current", "[", "thread_hosts_key", "]", "thread_index_key", "=", "read", "?", "\"algolia_search_host_index_#{application_id}\"", ":", "\"algolia_host_index_#{application_id}\"", "current_host", "=", "Thread", ".", "current", "[", "thread_index_key", "]", ".", "to_i", "# `to_i` to ensure first call is 0", "# we want to always target host 0 first", "# if the current host is not 0, then we want to use it first only if (we never used it OR we're using it since less than 1 minute)", "if", "current_host", "!=", "0", "&&", "(", "hosts", "[", "current_host", "]", "[", ":last_call", "]", ".", "nil?", "||", "hosts", "[", "current_host", "]", "[", ":last_call", "]", ">", "Time", ".", "now", ".", "to_i", "-", "60", ")", "# first host will be `current_host`", "first", "=", "hosts", "[", "current_host", "]", "[", "first", "]", "+", "hosts", ".", "reject", "{", "|", "h", "|", "h", "[", ":index", "]", "==", "0", "||", "h", "==", "first", "}", "+", "hosts", ".", "select", "{", "|", "h", "|", "h", "[", ":index", "]", "==", "0", "}", "else", "# first host will be `0`", "hosts", "end", "end" ]
This method returns a thread-local array of sessions
[ "This", "method", "returns", "a", "thread", "-", "local", "array", "of", "sessions" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/client.rb#L626-L653
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete!
def delete!(request_options = {}) res = delete(request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def delete!(request_options = {}) res = delete(request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "delete!", "(", "request_options", "=", "{", "}", ")", "res", "=", "delete", "(", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Delete an index and wait until the deletion has been processed @param request_options contains extra parameters to send with your query return an hash of the form { "deletedAt" => "2013-01-18T15:33:13.556Z", "taskID" => "42" }
[ "Delete", "an", "index", "and", "wait", "until", "the", "deletion", "has", "been", "processed" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L33-L37
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.add_object
def add_object(object, objectID = nil, request_options = {}) check_object(object) if objectID.nil? || objectID.to_s.empty? client.post(Protocol.index_uri(name), object.to_json, :write, request_options) else client.put(Protocol.object_uri(name, objectID), object.to_json, :write, request_options) end end
ruby
def add_object(object, objectID = nil, request_options = {}) check_object(object) if objectID.nil? || objectID.to_s.empty? client.post(Protocol.index_uri(name), object.to_json, :write, request_options) else client.put(Protocol.object_uri(name, objectID), object.to_json, :write, request_options) end end
[ "def", "add_object", "(", "object", ",", "objectID", "=", "nil", ",", "request_options", "=", "{", "}", ")", "check_object", "(", "object", ")", "if", "objectID", ".", "nil?", "||", "objectID", ".", "to_s", ".", "empty?", "client", ".", "post", "(", "Protocol", ".", "index_uri", "(", "name", ")", ",", "object", ".", "to_json", ",", ":write", ",", "request_options", ")", "else", "client", ".", "put", "(", "Protocol", ".", "object_uri", "(", "name", ",", "objectID", ")", ",", "object", ".", "to_json", ",", ":write", ",", "request_options", ")", "end", "end" ]
Add an object in this index @param object the object to add to the index. The object is represented by an associative array @param objectID (optional) an objectID you want to attribute to this object (if the attribute already exist the old object will be overridden) @param request_options contains extra parameters to send with your query
[ "Add", "an", "object", "in", "this", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L49-L56
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.add_object!
def add_object!(object, objectID = nil, request_options = {}) res = add_object(object, objectID, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def add_object!(object, objectID = nil, request_options = {}) res = add_object(object, objectID, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "add_object!", "(", "object", ",", "objectID", "=", "nil", ",", "request_options", "=", "{", "}", ")", "res", "=", "add_object", "(", "object", ",", "objectID", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Add an object in this index and wait end of indexing @param object the object to add to the index. The object is represented by an associative array @param objectID (optional) an objectID you want to attribute to this object (if the attribute already exist the old object will be overridden) @param Request options object. Contains extra URL parameters or headers
[ "Add", "an", "object", "in", "this", "index", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L67-L71
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.add_objects!
def add_objects!(objects, request_options = {}) res = add_objects(objects, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def add_objects!(objects, request_options = {}) res = add_objects(objects, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "add_objects!", "(", "objects", ",", "request_options", "=", "{", "}", ")", "res", "=", "add_objects", "(", "objects", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Add several objects in this index and wait end of indexing @param objects the array of objects to add inside the index. Each object is represented by an associative array @param request_options contains extra parameters to send with your query
[ "Add", "several", "objects", "in", "this", "index", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L91-L95
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.search
def search(query, params = {}, request_options = {}) encoded_params = Hash[params.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }] encoded_params[:query] = query client.post(Protocol.search_post_uri(name), { :params => Protocol.to_query(encoded_params) }.to_json, :search, request_options) end
ruby
def search(query, params = {}, request_options = {}) encoded_params = Hash[params.map { |k, v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }] encoded_params[:query] = query client.post(Protocol.search_post_uri(name), { :params => Protocol.to_query(encoded_params) }.to_json, :search, request_options) end
[ "def", "search", "(", "query", ",", "params", "=", "{", "}", ",", "request_options", "=", "{", "}", ")", "encoded_params", "=", "Hash", "[", "params", ".", "map", "{", "|", "k", ",", "v", "|", "[", "k", ".", "to_s", ",", "v", ".", "is_a?", "(", "Array", ")", "?", "v", ".", "to_json", ":", "v", "]", "}", "]", "encoded_params", "[", ":query", "]", "=", "query", "client", ".", "post", "(", "Protocol", ".", "search_post_uri", "(", "name", ")", ",", "{", ":params", "=>", "Protocol", ".", "to_query", "(", "encoded_params", ")", "}", ".", "to_json", ",", ":search", ",", "request_options", ")", "end" ]
Search inside the index @param query the full text query @param args (optional) if set, contains an associative array with query parameters: - page: (integer) Pagination parameter used to select the page to retrieve. Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9 - hitsPerPage: (integer) Pagination parameter used to select the number of hits per page. Defaults to 20. - attributesToRetrieve: a string that contains the list of object attributes you want to retrieve (let you minimize the answer size). Attributes are separated with a comma (for example "name,address"). You can also use a string array encoding (for example ["name","address"]). By default, all attributes are retrieved. You can also use '*' to retrieve all values when an attributesToRetrieve setting is specified for your index. - attributesToHighlight: a string that contains the list of attributes you want to highlight according to the query. Attributes are separated by a comma. You can also use a string array encoding (for example ["name","address"]). If an attribute has no match for the query, the raw value is returned. By default all indexed text attributes are highlighted. You can use `*` if you want to highlight all textual attributes. Numerical attributes are not highlighted. A matchLevel is returned for each highlighted attribute and can contain: - full: if all the query terms were found in the attribute, - partial: if only some of the query terms were found, - none: if none of the query terms were found. - attributesToSnippet: a string that contains the list of attributes to snippet alongside the number of words to return (syntax is `attributeName:nbWords`). Attributes are separated by a comma (Example: attributesToSnippet=name:10,content:10). You can also use a string array encoding (Example: attributesToSnippet: ["name:10","content:10"]). By default no snippet is computed. - minWordSizefor1Typo: the minimum number of characters in a query word to accept one typo in this word. Defaults to 3. - minWordSizefor2Typos: the minimum number of characters in a query word to accept two typos in this word. Defaults to 7. - getRankingInfo: if set to 1, the result hits will contain ranking information in _rankingInfo attribute. - aroundLatLng: search for entries around a given latitude/longitude (specified as two floats separated by a comma). For example aroundLatLng=47.316669,5.016670). You can specify the maximum distance in meters with the aroundRadius parameter (in meters) and the precision for ranking with aroundPrecision (for example if you set aroundPrecision=100, two objects that are distant of less than 100m will be considered as identical for "geo" ranking parameter). At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}}) - insideBoundingBox: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng). For example insideBoundingBox=47.3165,4.9665,47.3424,5.0201). At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}}) - numericFilters: a string that contains the list of numeric filters you want to apply separated by a comma. The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`. You can have multiple conditions on one attribute like for example numericFilters=price>100,price<1000. You can also use a string array encoding (for example numericFilters: ["price>100","price<1000"]). - tagFilters: filter the query by a set of tags. You can AND tags by separating them by commas. To OR tags, you must add parentheses. For example, tags=tag1,(tag2,tag3) means tag1 AND (tag2 OR tag3). You can also use a string array encoding, for example tagFilters: ["tag1",["tag2","tag3"]] means tag1 AND (tag2 OR tag3). At indexing, tags should be added in the _tags** attribute of objects (for example {"_tags":["tag1","tag2"]}). - facetFilters: filter the query by a list of facets. Facets are separated by commas and each facet is encoded as `attributeName:value`. For example: `facetFilters=category:Book,author:John%20Doe`. You can also use a string array encoding (for example `["category:Book","author:John%20Doe"]`). - facets: List of object attributes that you want to use for faceting. Attributes are separated with a comma (for example `"category,author"` ). You can also use a JSON string array encoding (for example ["category","author"]). Only attributes that have been added in **attributesForFaceting** index setting can be used in this parameter. You can also use `*` to perform faceting on all attributes specified in **attributesForFaceting**. - queryType: select how the query words are interpreted, it can be one of the following value: - prefixAll: all query words are interpreted as prefixes, - prefixLast: only the last word is interpreted as a prefix (default behavior), - prefixNone: no query word is interpreted as a prefix. This option is not recommended. - optionalWords: a string that contains the list of words that should be considered as optional when found in the query. The list of words is comma separated. - distinct: If set to 1, enable the distinct feature (disabled by default) if the attributeForDistinct index setting is set. This feature is similar to the SQL "distinct" keyword: when enabled in a query with the distinct=1 parameter, all hits containing a duplicate value for the attributeForDistinct attribute are removed from results. For example, if the chosen attribute is show_name and several hits have the same value for show_name, then only the best one is kept and others are removed. @param request_options contains extra parameters to send with your query
[ "Search", "inside", "the", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L161-L165
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.browse
def browse(page_or_query_parameters = nil, hits_per_page = nil, request_options = {}, &block) params = {} if page_or_query_parameters.is_a?(Hash) params.merge!(page_or_query_parameters) else params[:page] = page_or_query_parameters unless page_or_query_parameters.nil? end if hits_per_page.is_a?(Hash) params.merge!(hits_per_page) else params[:hitsPerPage] = hits_per_page unless hits_per_page.nil? end if block_given? IndexBrowser.new(client, name, params).browse(request_options, &block) else params[:page] ||= 0 params[:hitsPerPage] ||= 1000 client.get(Protocol.browse_uri(name, params), :read, request_options) end end
ruby
def browse(page_or_query_parameters = nil, hits_per_page = nil, request_options = {}, &block) params = {} if page_or_query_parameters.is_a?(Hash) params.merge!(page_or_query_parameters) else params[:page] = page_or_query_parameters unless page_or_query_parameters.nil? end if hits_per_page.is_a?(Hash) params.merge!(hits_per_page) else params[:hitsPerPage] = hits_per_page unless hits_per_page.nil? end if block_given? IndexBrowser.new(client, name, params).browse(request_options, &block) else params[:page] ||= 0 params[:hitsPerPage] ||= 1000 client.get(Protocol.browse_uri(name, params), :read, request_options) end end
[ "def", "browse", "(", "page_or_query_parameters", "=", "nil", ",", "hits_per_page", "=", "nil", ",", "request_options", "=", "{", "}", ",", "&", "block", ")", "params", "=", "{", "}", "if", "page_or_query_parameters", ".", "is_a?", "(", "Hash", ")", "params", ".", "merge!", "(", "page_or_query_parameters", ")", "else", "params", "[", ":page", "]", "=", "page_or_query_parameters", "unless", "page_or_query_parameters", ".", "nil?", "end", "if", "hits_per_page", ".", "is_a?", "(", "Hash", ")", "params", ".", "merge!", "(", "hits_per_page", ")", "else", "params", "[", ":hitsPerPage", "]", "=", "hits_per_page", "unless", "hits_per_page", ".", "nil?", "end", "if", "block_given?", "IndexBrowser", ".", "new", "(", "client", ",", "name", ",", "params", ")", ".", "browse", "(", "request_options", ",", "block", ")", "else", "params", "[", ":page", "]", "||=", "0", "params", "[", ":hitsPerPage", "]", "||=", "1000", "client", ".", "get", "(", "Protocol", ".", "browse_uri", "(", "name", ",", "params", ")", ",", ":read", ",", "request_options", ")", "end", "end" ]
Browse all index content @param queryParameters The hash of query parameters to use to browse To browse from a specific cursor, just add a ":cursor" parameters @param queryParameters An optional second parameters hash here for backward-compatibility (which will be merged with the first) @param request_options contains extra parameters to send with your query @DEPRECATED: @param page Pagination parameter used to select the page to retrieve. @param hits_per_page Pagination parameter used to select the number of hits per page. Defaults to 1000.
[ "Browse", "all", "index", "content" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L203-L223
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.browse_from
def browse_from(cursor, hits_per_page = 1000, request_options = {}) client.post(Protocol.browse_uri(name), { :cursor => cursor, :hitsPerPage => hits_per_page }.to_json, :read, request_options) end
ruby
def browse_from(cursor, hits_per_page = 1000, request_options = {}) client.post(Protocol.browse_uri(name), { :cursor => cursor, :hitsPerPage => hits_per_page }.to_json, :read, request_options) end
[ "def", "browse_from", "(", "cursor", ",", "hits_per_page", "=", "1000", ",", "request_options", "=", "{", "}", ")", "client", ".", "post", "(", "Protocol", ".", "browse_uri", "(", "name", ")", ",", "{", ":cursor", "=>", "cursor", ",", ":hitsPerPage", "=>", "hits_per_page", "}", ".", "to_json", ",", ":read", ",", "request_options", ")", "end" ]
Browse a single page from a specific cursor @param request_options contains extra parameters to send with your query
[ "Browse", "a", "single", "page", "from", "a", "specific", "cursor" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L230-L232
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.get_object
def get_object(objectID, attributes_to_retrieve = nil, request_options = {}) attributes_to_retrieve = attributes_to_retrieve.join(',') if attributes_to_retrieve.is_a?(Array) if attributes_to_retrieve.nil? client.get(Protocol.object_uri(name, objectID, nil), :read, request_options) else client.get(Protocol.object_uri(name, objectID, { :attributes => attributes_to_retrieve }), :read, request_options) end end
ruby
def get_object(objectID, attributes_to_retrieve = nil, request_options = {}) attributes_to_retrieve = attributes_to_retrieve.join(',') if attributes_to_retrieve.is_a?(Array) if attributes_to_retrieve.nil? client.get(Protocol.object_uri(name, objectID, nil), :read, request_options) else client.get(Protocol.object_uri(name, objectID, { :attributes => attributes_to_retrieve }), :read, request_options) end end
[ "def", "get_object", "(", "objectID", ",", "attributes_to_retrieve", "=", "nil", ",", "request_options", "=", "{", "}", ")", "attributes_to_retrieve", "=", "attributes_to_retrieve", ".", "join", "(", "','", ")", "if", "attributes_to_retrieve", ".", "is_a?", "(", "Array", ")", "if", "attributes_to_retrieve", ".", "nil?", "client", ".", "get", "(", "Protocol", ".", "object_uri", "(", "name", ",", "objectID", ",", "nil", ")", ",", ":read", ",", "request_options", ")", "else", "client", ".", "get", "(", "Protocol", ".", "object_uri", "(", "name", ",", "objectID", ",", "{", ":attributes", "=>", "attributes_to_retrieve", "}", ")", ",", ":read", ",", "request_options", ")", "end", "end" ]
Get an object from this index @param objectID the unique identifier of the object to retrieve @param attributes_to_retrieve (optional) if set, contains the list of attributes to retrieve as an array of strings of a string separated by "," @param request_options contains extra parameters to send with your query
[ "Get", "an", "object", "from", "this", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L241-L248
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.get_objects
def get_objects(objectIDs, attributes_to_retrieve = nil, request_options = {}) attributes_to_retrieve = attributes_to_retrieve.join(',') if attributes_to_retrieve.is_a?(Array) requests = objectIDs.map do |objectID| req = { :indexName => name, :objectID => objectID.to_s } req[:attributesToRetrieve] = attributes_to_retrieve unless attributes_to_retrieve.nil? req end client.post(Protocol.objects_uri, { :requests => requests }.to_json, :read, request_options)['results'] end
ruby
def get_objects(objectIDs, attributes_to_retrieve = nil, request_options = {}) attributes_to_retrieve = attributes_to_retrieve.join(',') if attributes_to_retrieve.is_a?(Array) requests = objectIDs.map do |objectID| req = { :indexName => name, :objectID => objectID.to_s } req[:attributesToRetrieve] = attributes_to_retrieve unless attributes_to_retrieve.nil? req end client.post(Protocol.objects_uri, { :requests => requests }.to_json, :read, request_options)['results'] end
[ "def", "get_objects", "(", "objectIDs", ",", "attributes_to_retrieve", "=", "nil", ",", "request_options", "=", "{", "}", ")", "attributes_to_retrieve", "=", "attributes_to_retrieve", ".", "join", "(", "','", ")", "if", "attributes_to_retrieve", ".", "is_a?", "(", "Array", ")", "requests", "=", "objectIDs", ".", "map", "do", "|", "objectID", "|", "req", "=", "{", ":indexName", "=>", "name", ",", ":objectID", "=>", "objectID", ".", "to_s", "}", "req", "[", ":attributesToRetrieve", "]", "=", "attributes_to_retrieve", "unless", "attributes_to_retrieve", ".", "nil?", "req", "end", "client", ".", "post", "(", "Protocol", ".", "objects_uri", ",", "{", ":requests", "=>", "requests", "}", ".", "to_json", ",", ":read", ",", "request_options", ")", "[", "'results'", "]", "end" ]
Get a list of objects from this index @param objectIDs the array of unique identifier of the objects to retrieve @param attributes_to_retrieve (optional) if set, contains the list of attributes to retrieve as an array of strings of a string separated by "," @param request_options contains extra parameters to send with your query
[ "Get", "a", "list", "of", "objects", "from", "this", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L257-L265
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_object
def save_object(object, objectID = nil, request_options = {}) client.put(Protocol.object_uri(name, get_objectID(object, objectID)), object.to_json, :write, request_options) end
ruby
def save_object(object, objectID = nil, request_options = {}) client.put(Protocol.object_uri(name, get_objectID(object, objectID)), object.to_json, :write, request_options) end
[ "def", "save_object", "(", "object", ",", "objectID", "=", "nil", ",", "request_options", "=", "{", "}", ")", "client", ".", "put", "(", "Protocol", ".", "object_uri", "(", "name", ",", "get_objectID", "(", "object", ",", "objectID", ")", ")", ",", "object", ".", "to_json", ",", ":write", ",", "request_options", ")", "end" ]
Override the content of an object @param object the object to save @param objectID the associated objectID, if nil 'object' must contain an 'objectID' key @param request_options contains extra parameters to send with your query
[ "Override", "the", "content", "of", "an", "object" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L297-L299
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_object!
def save_object!(object, objectID = nil, request_options = {}) res = save_object(object, objectID, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def save_object!(object, objectID = nil, request_options = {}) res = save_object(object, objectID, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "save_object!", "(", "object", ",", "objectID", "=", "nil", ",", "request_options", "=", "{", "}", ")", "res", "=", "save_object", "(", "object", ",", "objectID", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Override the content of object and wait end of indexing @param object the object to save @param objectID the associated objectID, if nil 'object' must contain an 'objectID' key @param request_options contains extra parameters to send with your query
[ "Override", "the", "content", "of", "object", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L308-L312
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_objects!
def save_objects!(objects, request_options = {}) res = save_objects(objects, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def save_objects!(objects, request_options = {}) res = save_objects(objects, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "save_objects!", "(", "objects", ",", "request_options", "=", "{", "}", ")", "res", "=", "save_objects", "(", "objects", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Override the content of several objects and wait end of indexing @param objects the array of objects to save, each object must contain an objectID attribute @param request_options contains extra parameters to send with your query
[ "Override", "the", "content", "of", "several", "objects", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L330-L334
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.replace_all_objects
def replace_all_objects(objects, request_options = {}) safe = request_options[:safe] || request_options['safe'] || false request_options.delete(:safe) request_options.delete('safe') tmp_index = @client.init_index(@name + '_tmp_' + rand(10000000).to_s) responses = [] scope = ['settings', 'synonyms', 'rules'] res = @client.copy_index(@name, tmp_index.name, scope, request_options) responses << res if safe wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end batch = [] batch_size = 1000 count = 0 objects.each do |object| batch << object count += 1 if count == batch_size res = tmp_index.add_objects(batch, request_options) responses << res batch = [] count = 0 end end if batch.any? res = tmp_index.add_objects(batch, request_options) responses << res end if safe responses.each do |res| tmp_index.wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end end res = @client.move_index(tmp_index.name, @name, request_options) responses << res if safe wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end responses end
ruby
def replace_all_objects(objects, request_options = {}) safe = request_options[:safe] || request_options['safe'] || false request_options.delete(:safe) request_options.delete('safe') tmp_index = @client.init_index(@name + '_tmp_' + rand(10000000).to_s) responses = [] scope = ['settings', 'synonyms', 'rules'] res = @client.copy_index(@name, tmp_index.name, scope, request_options) responses << res if safe wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end batch = [] batch_size = 1000 count = 0 objects.each do |object| batch << object count += 1 if count == batch_size res = tmp_index.add_objects(batch, request_options) responses << res batch = [] count = 0 end end if batch.any? res = tmp_index.add_objects(batch, request_options) responses << res end if safe responses.each do |res| tmp_index.wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end end res = @client.move_index(tmp_index.name, @name, request_options) responses << res if safe wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) end responses end
[ "def", "replace_all_objects", "(", "objects", ",", "request_options", "=", "{", "}", ")", "safe", "=", "request_options", "[", ":safe", "]", "||", "request_options", "[", "'safe'", "]", "||", "false", "request_options", ".", "delete", "(", ":safe", ")", "request_options", ".", "delete", "(", "'safe'", ")", "tmp_index", "=", "@client", ".", "init_index", "(", "@name", "+", "'_tmp_'", "+", "rand", "(", "10000000", ")", ".", "to_s", ")", "responses", "=", "[", "]", "scope", "=", "[", "'settings'", ",", "'synonyms'", ",", "'rules'", "]", "res", "=", "@client", ".", "copy_index", "(", "@name", ",", "tmp_index", ".", "name", ",", "scope", ",", "request_options", ")", "responses", "<<", "res", "if", "safe", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "end", "batch", "=", "[", "]", "batch_size", "=", "1000", "count", "=", "0", "objects", ".", "each", "do", "|", "object", "|", "batch", "<<", "object", "count", "+=", "1", "if", "count", "==", "batch_size", "res", "=", "tmp_index", ".", "add_objects", "(", "batch", ",", "request_options", ")", "responses", "<<", "res", "batch", "=", "[", "]", "count", "=", "0", "end", "end", "if", "batch", ".", "any?", "res", "=", "tmp_index", ".", "add_objects", "(", "batch", ",", "request_options", ")", "responses", "<<", "res", "end", "if", "safe", "responses", ".", "each", "do", "|", "res", "|", "tmp_index", ".", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "end", "end", "res", "=", "@client", ".", "move_index", "(", "tmp_index", ".", "name", ",", "@name", ",", "request_options", ")", "responses", "<<", "res", "if", "safe", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "end", "responses", "end" ]
Override the current objects by the given array of objects and wait end of indexing. Settings, synonyms and query rules are untouched. The objects are replaced without any downtime. @param objects the array of objects to save @param request_options contains extra parameters to send with your query
[ "Override", "the", "current", "objects", "by", "the", "given", "array", "of", "objects", "and", "wait", "end", "of", "indexing", ".", "Settings", "synonyms", "and", "query", "rules", "are", "untouched", ".", "The", "objects", "are", "replaced", "without", "any", "downtime", "." ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L343-L394
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.partial_update_objects
def partial_update_objects(objects, create_if_not_exits = true, request_options = {}) if create_if_not_exits batch(build_batch('partialUpdateObject', objects, true), request_options) else batch(build_batch('partialUpdateObjectNoCreate', objects, true), request_options) end end
ruby
def partial_update_objects(objects, create_if_not_exits = true, request_options = {}) if create_if_not_exits batch(build_batch('partialUpdateObject', objects, true), request_options) else batch(build_batch('partialUpdateObjectNoCreate', objects, true), request_options) end end
[ "def", "partial_update_objects", "(", "objects", ",", "create_if_not_exits", "=", "true", ",", "request_options", "=", "{", "}", ")", "if", "create_if_not_exits", "batch", "(", "build_batch", "(", "'partialUpdateObject'", ",", "objects", ",", "true", ")", ",", "request_options", ")", "else", "batch", "(", "build_batch", "(", "'partialUpdateObjectNoCreate'", ",", "objects", ",", "true", ")", ",", "request_options", ")", "end", "end" ]
Partially override the content of several objects @param objects an array of objects to update (each object must contains a objectID attribute) @param create_if_not_exits a boolean, if true create the objects if they don't exist @param request_options contains extra parameters to send with your query
[ "Partially", "override", "the", "content", "of", "several", "objects" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L425-L431
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.partial_update_objects!
def partial_update_objects!(objects, create_if_not_exits = true, request_options = {}) res = partial_update_objects(objects, create_if_not_exits, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def partial_update_objects!(objects, create_if_not_exits = true, request_options = {}) res = partial_update_objects(objects, create_if_not_exits, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "partial_update_objects!", "(", "objects", ",", "create_if_not_exits", "=", "true", ",", "request_options", "=", "{", "}", ")", "res", "=", "partial_update_objects", "(", "objects", ",", "create_if_not_exits", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Partially override the content of several objects and wait end of indexing @param objects an array of objects to update (each object must contains a objectID attribute) @param create_if_not_exits a boolean, if true create the objects if they don't exist @param request_options contains extra parameters to send with your query
[ "Partially", "override", "the", "content", "of", "several", "objects", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L440-L444
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_object
def delete_object(objectID, request_options = {}) raise ArgumentError.new('objectID must not be blank') if objectID.nil? || objectID == '' client.delete(Protocol.object_uri(name, objectID), :write, request_options) end
ruby
def delete_object(objectID, request_options = {}) raise ArgumentError.new('objectID must not be blank') if objectID.nil? || objectID == '' client.delete(Protocol.object_uri(name, objectID), :write, request_options) end
[ "def", "delete_object", "(", "objectID", ",", "request_options", "=", "{", "}", ")", "raise", "ArgumentError", ".", "new", "(", "'objectID must not be blank'", ")", "if", "objectID", ".", "nil?", "||", "objectID", "==", "''", "client", ".", "delete", "(", "Protocol", ".", "object_uri", "(", "name", ",", "objectID", ")", ",", ":write", ",", "request_options", ")", "end" ]
Delete an object from the index @param objectID the unique identifier of object to delete @param request_options contains extra parameters to send with your query
[ "Delete", "an", "object", "from", "the", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L466-L469
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_object!
def delete_object!(objectID, request_options = {}) res = delete_object(objectID, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def delete_object!(objectID, request_options = {}) res = delete_object(objectID, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "delete_object!", "(", "objectID", ",", "request_options", "=", "{", "}", ")", "res", "=", "delete_object", "(", "objectID", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Delete an object from the index and wait end of indexing @param objectID the unique identifier of object to delete @param request_options contains extra parameters to send with your query
[ "Delete", "an", "object", "from", "the", "index", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L477-L481
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_objects
def delete_objects(objects, request_options = {}) check_array(objects) batch(build_batch('deleteObject', objects.map { |objectID| { :objectID => objectID } }, false), request_options) end
ruby
def delete_objects(objects, request_options = {}) check_array(objects) batch(build_batch('deleteObject', objects.map { |objectID| { :objectID => objectID } }, false), request_options) end
[ "def", "delete_objects", "(", "objects", ",", "request_options", "=", "{", "}", ")", "check_array", "(", "objects", ")", "batch", "(", "build_batch", "(", "'deleteObject'", ",", "objects", ".", "map", "{", "|", "objectID", "|", "{", ":objectID", "=>", "objectID", "}", "}", ",", "false", ")", ",", "request_options", ")", "end" ]
Delete several objects @param objects an array of objectIDs @param request_options contains extra parameters to send with your query
[ "Delete", "several", "objects" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L489-L492
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_objects!
def delete_objects!(objects, request_options = {}) res = delete_objects(objects, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def delete_objects!(objects, request_options = {}) res = delete_objects(objects, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "delete_objects!", "(", "objects", ",", "request_options", "=", "{", "}", ")", "res", "=", "delete_objects", "(", "objects", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Delete several objects and wait end of indexing @param objects an array of objectIDs @param request_options contains extra parameters to send with your query
[ "Delete", "several", "objects", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L500-L504
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_by_query
def delete_by_query(query, params = nil, request_options = {}) raise ArgumentError.new('query cannot be nil, use the `clear` method to wipe the entire index') if query.nil? && params.nil? params = sanitized_delete_by_query_params(params) params[:query] = query params[:hitsPerPage] = 1000 params[:distinct] = false params[:attributesToRetrieve] = ['objectID'] params[:cursor] = '' ids = [] while params[:cursor] != nil result = browse(params, nil, request_options) params[:cursor] = result['cursor'] hits = result['hits'] break if hits.empty? ids += hits.map { |hit| hit['objectID'] } end delete_objects(ids, request_options) end
ruby
def delete_by_query(query, params = nil, request_options = {}) raise ArgumentError.new('query cannot be nil, use the `clear` method to wipe the entire index') if query.nil? && params.nil? params = sanitized_delete_by_query_params(params) params[:query] = query params[:hitsPerPage] = 1000 params[:distinct] = false params[:attributesToRetrieve] = ['objectID'] params[:cursor] = '' ids = [] while params[:cursor] != nil result = browse(params, nil, request_options) params[:cursor] = result['cursor'] hits = result['hits'] break if hits.empty? ids += hits.map { |hit| hit['objectID'] } end delete_objects(ids, request_options) end
[ "def", "delete_by_query", "(", "query", ",", "params", "=", "nil", ",", "request_options", "=", "{", "}", ")", "raise", "ArgumentError", ".", "new", "(", "'query cannot be nil, use the `clear` method to wipe the entire index'", ")", "if", "query", ".", "nil?", "&&", "params", ".", "nil?", "params", "=", "sanitized_delete_by_query_params", "(", "params", ")", "params", "[", ":query", "]", "=", "query", "params", "[", ":hitsPerPage", "]", "=", "1000", "params", "[", ":distinct", "]", "=", "false", "params", "[", ":attributesToRetrieve", "]", "=", "[", "'objectID'", "]", "params", "[", ":cursor", "]", "=", "''", "ids", "=", "[", "]", "while", "params", "[", ":cursor", "]", "!=", "nil", "result", "=", "browse", "(", "params", ",", "nil", ",", "request_options", ")", "params", "[", ":cursor", "]", "=", "result", "[", "'cursor'", "]", "hits", "=", "result", "[", "'hits'", "]", "break", "if", "hits", ".", "empty?", "ids", "+=", "hits", ".", "map", "{", "|", "hit", "|", "hit", "[", "'objectID'", "]", "}", "end", "delete_objects", "(", "ids", ",", "request_options", ")", "end" ]
Delete all objects matching a query This method retrieves all objects synchronously but deletes in batch asynchronously @param query the query string @param params the optional query parameters @param request_options contains extra parameters to send with your query
[ "Delete", "all", "objects", "matching", "a", "query", "This", "method", "retrieves", "all", "objects", "synchronously", "but", "deletes", "in", "batch", "asynchronously" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L515-L538
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_by_query!
def delete_by_query!(query, params = nil, request_options = {}) res = delete_by_query(query, params, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) if res res end
ruby
def delete_by_query!(query, params = nil, request_options = {}) res = delete_by_query(query, params, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) if res res end
[ "def", "delete_by_query!", "(", "query", ",", "params", "=", "nil", ",", "request_options", "=", "{", "}", ")", "res", "=", "delete_by_query", "(", "query", ",", "params", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "if", "res", "res", "end" ]
Delete all objects matching a query and wait end of indexing @param query the query string @param params the optional query parameters @param request_options contains extra parameters to send with your query
[ "Delete", "all", "objects", "matching", "a", "query", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L547-L551
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.clear!
def clear!(request_options = {}) res = clear(request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def clear!(request_options = {}) res = clear(request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "clear!", "(", "request_options", "=", "{", "}", ")", "res", "=", "clear", "(", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Delete the index content and wait end of indexing
[ "Delete", "the", "index", "content", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L591-L595
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.set_settings
def set_settings(new_settings, options = {}, request_options = {}) client.put(Protocol.settings_uri(name, options), new_settings.to_json, :write, request_options) end
ruby
def set_settings(new_settings, options = {}, request_options = {}) client.put(Protocol.settings_uri(name, options), new_settings.to_json, :write, request_options) end
[ "def", "set_settings", "(", "new_settings", ",", "options", "=", "{", "}", ",", "request_options", "=", "{", "}", ")", "client", ".", "put", "(", "Protocol", ".", "settings_uri", "(", "name", ",", "options", ")", ",", "new_settings", ".", "to_json", ",", ":write", ",", "request_options", ")", "end" ]
Set settings for this index
[ "Set", "settings", "for", "this", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L601-L603
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.set_settings!
def set_settings!(new_settings, options = {}, request_options = {}) res = set_settings(new_settings, options, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def set_settings!(new_settings, options = {}, request_options = {}) res = set_settings(new_settings, options, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "set_settings!", "(", "new_settings", ",", "options", "=", "{", "}", ",", "request_options", "=", "{", "}", ")", "res", "=", "set_settings", "(", "new_settings", ",", "options", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Set settings for this index and wait end of indexing
[ "Set", "settings", "for", "this", "index", "and", "wait", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L608-L612
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.get_settings
def get_settings(options = {}, request_options = {}) options['getVersion'] = 2 if !options[:getVersion] && !options['getVersion'] client.get(Protocol.settings_uri(name, options).to_s, :read, request_options) end
ruby
def get_settings(options = {}, request_options = {}) options['getVersion'] = 2 if !options[:getVersion] && !options['getVersion'] client.get(Protocol.settings_uri(name, options).to_s, :read, request_options) end
[ "def", "get_settings", "(", "options", "=", "{", "}", ",", "request_options", "=", "{", "}", ")", "options", "[", "'getVersion'", "]", "=", "2", "if", "!", "options", "[", ":getVersion", "]", "&&", "!", "options", "[", "'getVersion'", "]", "client", ".", "get", "(", "Protocol", ".", "settings_uri", "(", "name", ",", "options", ")", ".", "to_s", ",", ":read", ",", "request_options", ")", "end" ]
Get settings of this index
[ "Get", "settings", "of", "this", "index" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L617-L620
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.get_api_key
def get_api_key(key, request_options = {}) client.get(Protocol.index_key_uri(name, key), :read, request_options) end
ruby
def get_api_key(key, request_options = {}) client.get(Protocol.index_key_uri(name, key), :read, request_options) end
[ "def", "get_api_key", "(", "key", ",", "request_options", "=", "{", "}", ")", "client", ".", "get", "(", "Protocol", ".", "index_key_uri", "(", "name", ",", "key", ")", ",", ":read", ",", "request_options", ")", "end" ]
Get ACL of a user key Deprecated: Please us `client.get_api_key` instead.
[ "Get", "ACL", "of", "a", "user", "key" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L634-L636
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_api_key
def delete_api_key(key, request_options = {}) client.delete(Protocol.index_key_uri(name, key), :write, request_options) end
ruby
def delete_api_key(key, request_options = {}) client.delete(Protocol.index_key_uri(name, key), :write, request_options) end
[ "def", "delete_api_key", "(", "key", ",", "request_options", "=", "{", "}", ")", "client", ".", "delete", "(", "Protocol", ".", "index_key_uri", "(", "name", ",", "key", ")", ",", ":write", ",", "request_options", ")", "end" ]
Delete an existing user key Deprecated: Please use `client.delete_api_key` instead
[ "Delete", "an", "existing", "user", "key" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L723-L725
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.batch
def batch(request, request_options = {}) client.post(Protocol.batch_uri(name), request.to_json, :batch, request_options) end
ruby
def batch(request, request_options = {}) client.post(Protocol.batch_uri(name), request.to_json, :batch, request_options) end
[ "def", "batch", "(", "request", ",", "request_options", "=", "{", "}", ")", "client", ".", "post", "(", "Protocol", ".", "batch_uri", "(", "name", ")", ",", "request", ".", "to_json", ",", ":batch", ",", "request_options", ")", "end" ]
Send a batch request
[ "Send", "a", "batch", "request" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L730-L732
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.batch!
def batch!(request, request_options = {}) res = batch(request, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def batch!(request, request_options = {}) res = batch(request, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "batch!", "(", "request", ",", "request_options", "=", "{", "}", ")", "res", "=", "batch", "(", "request", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Send a batch request and wait the end of the indexing
[ "Send", "a", "batch", "request", "and", "wait", "the", "end", "of", "the", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L737-L741
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.search_for_facet_values
def search_for_facet_values(facet_name, facet_query, search_parameters = {}, request_options = {}) params = search_parameters.clone params['facetQuery'] = facet_query client.post(Protocol.search_facet_uri(name, facet_name), params.to_json, :read, request_options) end
ruby
def search_for_facet_values(facet_name, facet_query, search_parameters = {}, request_options = {}) params = search_parameters.clone params['facetQuery'] = facet_query client.post(Protocol.search_facet_uri(name, facet_name), params.to_json, :read, request_options) end
[ "def", "search_for_facet_values", "(", "facet_name", ",", "facet_query", ",", "search_parameters", "=", "{", "}", ",", "request_options", "=", "{", "}", ")", "params", "=", "search_parameters", ".", "clone", "params", "[", "'facetQuery'", "]", "=", "facet_query", "client", ".", "post", "(", "Protocol", ".", "search_facet_uri", "(", "name", ",", "facet_name", ")", ",", "params", ".", "to_json", ",", ":read", ",", "request_options", ")", "end" ]
Search for facet values @param facet_name Name of the facet to search. It must have been declared in the index's`attributesForFaceting` setting with the `searchable()` modifier. @param facet_query Text to search for in the facet's values @param search_parameters An optional query to take extra search parameters into account. These parameters apply to index objects like in a regular search query. Only facet values contained in the matched objects will be returned. @param request_options contains extra parameters to send with your query
[ "Search", "for", "facet", "values" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L754-L758
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.search_disjunctive_faceting
def search_disjunctive_faceting(query, disjunctive_facets, params = {}, refinements = {}, request_options = {}) raise ArgumentError.new('Argument "disjunctive_facets" must be a String or an Array') unless disjunctive_facets.is_a?(String) || disjunctive_facets.is_a?(Array) raise ArgumentError.new('Argument "refinements" must be a Hash of Arrays') if !refinements.is_a?(Hash) || !refinements.select { |k, v| !v.is_a?(Array) }.empty? # extract disjunctive facets & associated refinements disjunctive_facets = disjunctive_facets.split(',') if disjunctive_facets.is_a?(String) disjunctive_refinements = {} refinements.each do |k, v| disjunctive_refinements[k] = v if disjunctive_facets.include?(k) || disjunctive_facets.include?(k.to_s) end # build queries queries = [] ## hits + regular facets query filters = [] refinements.to_a.each do |k, values| r = values.map { |v| "#{k}:#{v}" } if disjunctive_refinements[k.to_s] || disjunctive_refinements[k.to_sym] # disjunctive refinements are ORed filters << r else # regular refinements are ANDed filters += r end end queries << params.merge({ :index_name => self.name, :query => query, :facetFilters => filters }) ## one query per disjunctive facet (use all refinements but the current one + hitsPerPage=1 + single facet) disjunctive_facets.each do |disjunctive_facet| filters = [] refinements.each do |k, values| if k.to_s != disjunctive_facet.to_s r = values.map { |v| "#{k}:#{v}" } if disjunctive_refinements[k.to_s] || disjunctive_refinements[k.to_sym] # disjunctive refinements are ORed filters << r else # regular refinements are ANDed filters += r end end end queries << params.merge({ :index_name => self.name, :query => query, :page => 0, :hitsPerPage => 1, :attributesToRetrieve => [], :attributesToHighlight => [], :attributesToSnippet => [], :facets => disjunctive_facet, :facetFilters => filters, :analytics => false }) end answers = client.multiple_queries(queries, { :request_options => request_options }) # aggregate answers ## first answer stores the hits + regular facets aggregated_answer = answers['results'][0] ## others store the disjunctive facets aggregated_answer['disjunctiveFacets'] = {} answers['results'].each_with_index do |a, i| next if i == 0 a['facets'].each do |facet, values| ## add the facet to the disjunctive facet hash aggregated_answer['disjunctiveFacets'][facet] = values ## concatenate missing refinements (disjunctive_refinements[facet.to_s] || disjunctive_refinements[facet.to_sym] || []).each do |r| if aggregated_answer['disjunctiveFacets'][facet][r].nil? aggregated_answer['disjunctiveFacets'][facet][r] = 0 end end end end aggregated_answer end
ruby
def search_disjunctive_faceting(query, disjunctive_facets, params = {}, refinements = {}, request_options = {}) raise ArgumentError.new('Argument "disjunctive_facets" must be a String or an Array') unless disjunctive_facets.is_a?(String) || disjunctive_facets.is_a?(Array) raise ArgumentError.new('Argument "refinements" must be a Hash of Arrays') if !refinements.is_a?(Hash) || !refinements.select { |k, v| !v.is_a?(Array) }.empty? # extract disjunctive facets & associated refinements disjunctive_facets = disjunctive_facets.split(',') if disjunctive_facets.is_a?(String) disjunctive_refinements = {} refinements.each do |k, v| disjunctive_refinements[k] = v if disjunctive_facets.include?(k) || disjunctive_facets.include?(k.to_s) end # build queries queries = [] ## hits + regular facets query filters = [] refinements.to_a.each do |k, values| r = values.map { |v| "#{k}:#{v}" } if disjunctive_refinements[k.to_s] || disjunctive_refinements[k.to_sym] # disjunctive refinements are ORed filters << r else # regular refinements are ANDed filters += r end end queries << params.merge({ :index_name => self.name, :query => query, :facetFilters => filters }) ## one query per disjunctive facet (use all refinements but the current one + hitsPerPage=1 + single facet) disjunctive_facets.each do |disjunctive_facet| filters = [] refinements.each do |k, values| if k.to_s != disjunctive_facet.to_s r = values.map { |v| "#{k}:#{v}" } if disjunctive_refinements[k.to_s] || disjunctive_refinements[k.to_sym] # disjunctive refinements are ORed filters << r else # regular refinements are ANDed filters += r end end end queries << params.merge({ :index_name => self.name, :query => query, :page => 0, :hitsPerPage => 1, :attributesToRetrieve => [], :attributesToHighlight => [], :attributesToSnippet => [], :facets => disjunctive_facet, :facetFilters => filters, :analytics => false }) end answers = client.multiple_queries(queries, { :request_options => request_options }) # aggregate answers ## first answer stores the hits + regular facets aggregated_answer = answers['results'][0] ## others store the disjunctive facets aggregated_answer['disjunctiveFacets'] = {} answers['results'].each_with_index do |a, i| next if i == 0 a['facets'].each do |facet, values| ## add the facet to the disjunctive facet hash aggregated_answer['disjunctiveFacets'][facet] = values ## concatenate missing refinements (disjunctive_refinements[facet.to_s] || disjunctive_refinements[facet.to_sym] || []).each do |r| if aggregated_answer['disjunctiveFacets'][facet][r].nil? aggregated_answer['disjunctiveFacets'][facet][r] = 0 end end end end aggregated_answer end
[ "def", "search_disjunctive_faceting", "(", "query", ",", "disjunctive_facets", ",", "params", "=", "{", "}", ",", "refinements", "=", "{", "}", ",", "request_options", "=", "{", "}", ")", "raise", "ArgumentError", ".", "new", "(", "'Argument \"disjunctive_facets\" must be a String or an Array'", ")", "unless", "disjunctive_facets", ".", "is_a?", "(", "String", ")", "||", "disjunctive_facets", ".", "is_a?", "(", "Array", ")", "raise", "ArgumentError", ".", "new", "(", "'Argument \"refinements\" must be a Hash of Arrays'", ")", "if", "!", "refinements", ".", "is_a?", "(", "Hash", ")", "||", "!", "refinements", ".", "select", "{", "|", "k", ",", "v", "|", "!", "v", ".", "is_a?", "(", "Array", ")", "}", ".", "empty?", "# extract disjunctive facets & associated refinements", "disjunctive_facets", "=", "disjunctive_facets", ".", "split", "(", "','", ")", "if", "disjunctive_facets", ".", "is_a?", "(", "String", ")", "disjunctive_refinements", "=", "{", "}", "refinements", ".", "each", "do", "|", "k", ",", "v", "|", "disjunctive_refinements", "[", "k", "]", "=", "v", "if", "disjunctive_facets", ".", "include?", "(", "k", ")", "||", "disjunctive_facets", ".", "include?", "(", "k", ".", "to_s", ")", "end", "# build queries", "queries", "=", "[", "]", "## hits + regular facets query", "filters", "=", "[", "]", "refinements", ".", "to_a", ".", "each", "do", "|", "k", ",", "values", "|", "r", "=", "values", ".", "map", "{", "|", "v", "|", "\"#{k}:#{v}\"", "}", "if", "disjunctive_refinements", "[", "k", ".", "to_s", "]", "||", "disjunctive_refinements", "[", "k", ".", "to_sym", "]", "# disjunctive refinements are ORed", "filters", "<<", "r", "else", "# regular refinements are ANDed", "filters", "+=", "r", "end", "end", "queries", "<<", "params", ".", "merge", "(", "{", ":index_name", "=>", "self", ".", "name", ",", ":query", "=>", "query", ",", ":facetFilters", "=>", "filters", "}", ")", "## one query per disjunctive facet (use all refinements but the current one + hitsPerPage=1 + single facet)", "disjunctive_facets", ".", "each", "do", "|", "disjunctive_facet", "|", "filters", "=", "[", "]", "refinements", ".", "each", "do", "|", "k", ",", "values", "|", "if", "k", ".", "to_s", "!=", "disjunctive_facet", ".", "to_s", "r", "=", "values", ".", "map", "{", "|", "v", "|", "\"#{k}:#{v}\"", "}", "if", "disjunctive_refinements", "[", "k", ".", "to_s", "]", "||", "disjunctive_refinements", "[", "k", ".", "to_sym", "]", "# disjunctive refinements are ORed", "filters", "<<", "r", "else", "# regular refinements are ANDed", "filters", "+=", "r", "end", "end", "end", "queries", "<<", "params", ".", "merge", "(", "{", ":index_name", "=>", "self", ".", "name", ",", ":query", "=>", "query", ",", ":page", "=>", "0", ",", ":hitsPerPage", "=>", "1", ",", ":attributesToRetrieve", "=>", "[", "]", ",", ":attributesToHighlight", "=>", "[", "]", ",", ":attributesToSnippet", "=>", "[", "]", ",", ":facets", "=>", "disjunctive_facet", ",", ":facetFilters", "=>", "filters", ",", ":analytics", "=>", "false", "}", ")", "end", "answers", "=", "client", ".", "multiple_queries", "(", "queries", ",", "{", ":request_options", "=>", "request_options", "}", ")", "# aggregate answers", "## first answer stores the hits + regular facets", "aggregated_answer", "=", "answers", "[", "'results'", "]", "[", "0", "]", "## others store the disjunctive facets", "aggregated_answer", "[", "'disjunctiveFacets'", "]", "=", "{", "}", "answers", "[", "'results'", "]", ".", "each_with_index", "do", "|", "a", ",", "i", "|", "next", "if", "i", "==", "0", "a", "[", "'facets'", "]", ".", "each", "do", "|", "facet", ",", "values", "|", "## add the facet to the disjunctive facet hash", "aggregated_answer", "[", "'disjunctiveFacets'", "]", "[", "facet", "]", "=", "values", "## concatenate missing refinements", "(", "disjunctive_refinements", "[", "facet", ".", "to_s", "]", "||", "disjunctive_refinements", "[", "facet", ".", "to_sym", "]", "||", "[", "]", ")", ".", "each", "do", "|", "r", "|", "if", "aggregated_answer", "[", "'disjunctiveFacets'", "]", "[", "facet", "]", "[", "r", "]", ".", "nil?", "aggregated_answer", "[", "'disjunctiveFacets'", "]", "[", "facet", "]", "[", "r", "]", "=", "0", "end", "end", "end", "end", "aggregated_answer", "end" ]
Perform a search with disjunctive facets generating as many queries as number of disjunctive facets @param query the query @param disjunctive_facets the array of disjunctive facets @param params a hash representing the regular query parameters @param refinements a hash ("string" -> ["array", "of", "refined", "values"]) representing the current refinements ex: { "my_facet1" => ["my_value1", ["my_value2"], "my_disjunctive_facet1" => ["my_value1", "my_value2"] } @param request_options contains extra parameters to send with your query
[ "Perform", "a", "search", "with", "disjunctive", "facets", "generating", "as", "many", "queries", "as", "number", "of", "disjunctive", "facets" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L773-L849
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.get_synonym
def get_synonym(objectID, request_options = {}) client.get(Protocol.synonym_uri(name, objectID), :read, request_options) end
ruby
def get_synonym(objectID, request_options = {}) client.get(Protocol.synonym_uri(name, objectID), :read, request_options) end
[ "def", "get_synonym", "(", "objectID", ",", "request_options", "=", "{", "}", ")", "client", ".", "get", "(", "Protocol", ".", "synonym_uri", "(", "name", ",", "objectID", ")", ",", ":read", ",", "request_options", ")", "end" ]
Get a synonym @param objectID the synonym objectID @param request_options contains extra parameters to send with your query
[ "Get", "a", "synonym" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L886-L888
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_synonym!
def delete_synonym!(objectID, forward_to_replicas = false, request_options = {}) res = delete_synonym(objectID, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def delete_synonym!(objectID, forward_to_replicas = false, request_options = {}) res = delete_synonym(objectID, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "delete_synonym!", "(", "objectID", ",", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "res", "=", "delete_synonym", "(", "objectID", ",", "forward_to_replicas", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Delete a synonym and wait the end of indexing @param objectID the synonym objectID @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Delete", "a", "synonym", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L908-L912
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_synonym
def save_synonym(objectID, synonym, forward_to_replicas = false, request_options = {}) client.put("#{Protocol.synonym_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", synonym.to_json, :write, request_options) end
ruby
def save_synonym(objectID, synonym, forward_to_replicas = false, request_options = {}) client.put("#{Protocol.synonym_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", synonym.to_json, :write, request_options) end
[ "def", "save_synonym", "(", "objectID", ",", "synonym", ",", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "client", ".", "put", "(", "\"#{Protocol.synonym_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}\"", ",", "synonym", ".", "to_json", ",", ":write", ",", "request_options", ")", "end" ]
Save a synonym @param objectID the synonym objectID @param synonym the synonym @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Save", "a", "synonym" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L922-L924
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_synonym!
def save_synonym!(objectID, synonym, forward_to_replicas = false, request_options = {}) res = save_synonym(objectID, synonym, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def save_synonym!(objectID, synonym, forward_to_replicas = false, request_options = {}) res = save_synonym(objectID, synonym, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "save_synonym!", "(", "objectID", ",", "synonym", ",", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "res", "=", "save_synonym", "(", "objectID", ",", "synonym", ",", "forward_to_replicas", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Save a synonym and wait the end of indexing @param objectID the synonym objectID @param synonym the synonym @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Save", "a", "synonym", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L934-L938
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.clear_synonyms!
def clear_synonyms!(forward_to_replicas = false, request_options = {}) res = clear_synonyms(forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def clear_synonyms!(forward_to_replicas = false, request_options = {}) res = clear_synonyms(forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "clear_synonyms!", "(", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "res", "=", "clear_synonyms", "(", "forward_to_replicas", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Clear all synonyms and wait the end of indexing @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Clear", "all", "synonyms", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L956-L960
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.replace_all_synonyms
def replace_all_synonyms(synonyms, request_options = {}) forward_to_replicas = request_options[:forwardToReplicas] || request_options['forwardToReplicas'] || false batch_synonyms(synonyms, forward_to_replicas, true, request_options) end
ruby
def replace_all_synonyms(synonyms, request_options = {}) forward_to_replicas = request_options[:forwardToReplicas] || request_options['forwardToReplicas'] || false batch_synonyms(synonyms, forward_to_replicas, true, request_options) end
[ "def", "replace_all_synonyms", "(", "synonyms", ",", "request_options", "=", "{", "}", ")", "forward_to_replicas", "=", "request_options", "[", ":forwardToReplicas", "]", "||", "request_options", "[", "'forwardToReplicas'", "]", "||", "false", "batch_synonyms", "(", "synonyms", ",", "forward_to_replicas", ",", "true", ",", "request_options", ")", "end" ]
Replace synonyms in the index by the given array of synonyms @param synonyms the array of synonyms to add @param request_options contains extra parameters to send with your query
[ "Replace", "synonyms", "in", "the", "index", "by", "the", "given", "array", "of", "synonyms" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L994-L997
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.replace_all_synonyms!
def replace_all_synonyms!(synonyms, request_options = {}) res = replace_all_synonyms(synonyms, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def replace_all_synonyms!(synonyms, request_options = {}) res = replace_all_synonyms(synonyms, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "replace_all_synonyms!", "(", "synonyms", ",", "request_options", "=", "{", "}", ")", "res", "=", "replace_all_synonyms", "(", "synonyms", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Replace synonyms in the index by the given array of synonyms and wait the end of indexing @param synonyms the array of synonyms to add @param request_options contains extra parameters to send with your query
[ "Replace", "synonyms", "in", "the", "index", "by", "the", "given", "array", "of", "synonyms", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1005-L1009
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.export_synonyms
def export_synonyms(hits_per_page = 100, request_options = {}, &_block) res = [] page = 0 loop do curr = search_synonyms('', { :hitsPerPage => hits_per_page, :page => page }, request_options)['hits'] curr.each do |synonym| res << synonym yield synonym if block_given? end break if curr.size < hits_per_page page += 1 end res end
ruby
def export_synonyms(hits_per_page = 100, request_options = {}, &_block) res = [] page = 0 loop do curr = search_synonyms('', { :hitsPerPage => hits_per_page, :page => page }, request_options)['hits'] curr.each do |synonym| res << synonym yield synonym if block_given? end break if curr.size < hits_per_page page += 1 end res end
[ "def", "export_synonyms", "(", "hits_per_page", "=", "100", ",", "request_options", "=", "{", "}", ",", "&", "_block", ")", "res", "=", "[", "]", "page", "=", "0", "loop", "do", "curr", "=", "search_synonyms", "(", "''", ",", "{", ":hitsPerPage", "=>", "hits_per_page", ",", ":page", "=>", "page", "}", ",", "request_options", ")", "[", "'hits'", "]", "curr", ".", "each", "do", "|", "synonym", "|", "res", "<<", "synonym", "yield", "synonym", "if", "block_given?", "end", "break", "if", "curr", ".", "size", "<", "hits_per_page", "page", "+=", "1", "end", "res", "end" ]
Export the full list of synonyms Accepts an optional block to which it will pass each synonym Also returns an array with all the synonyms @param hits_per_page Amount of synonyms to retrieve on each internal request - Optional - Default: 100 @param request_options contains extra parameters to send with your query - Optional
[ "Export", "the", "full", "list", "of", "synonyms", "Accepts", "an", "optional", "block", "to", "which", "it", "will", "pass", "each", "synonym", "Also", "returns", "an", "array", "with", "all", "the", "synonyms" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1019-L1032
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.get_rule
def get_rule(objectID, request_options = {}) client.get(Protocol.rule_uri(name, objectID), :read, request_options) end
ruby
def get_rule(objectID, request_options = {}) client.get(Protocol.rule_uri(name, objectID), :read, request_options) end
[ "def", "get_rule", "(", "objectID", ",", "request_options", "=", "{", "}", ")", "client", ".", "get", "(", "Protocol", ".", "rule_uri", "(", "name", ",", "objectID", ")", ",", ":read", ",", "request_options", ")", "end" ]
Get a rule @param objectID the rule objectID @param request_options contains extra parameters to send with your query
[ "Get", "a", "rule" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1062-L1064
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.delete_rule!
def delete_rule!(objectID, forward_to_replicas = false, request_options = {}) res = delete_rule(objectID, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) return res end
ruby
def delete_rule!(objectID, forward_to_replicas = false, request_options = {}) res = delete_rule(objectID, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) return res end
[ "def", "delete_rule!", "(", "objectID", ",", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "res", "=", "delete_rule", "(", "objectID", ",", "forward_to_replicas", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "return", "res", "end" ]
Delete a rule and wait the end of indexing @param objectID the rule objectID @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Delete", "a", "rule", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1084-L1088
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_rule
def save_rule(objectID, rule, forward_to_replicas = false, request_options = {}) raise ArgumentError.new('objectID must not be blank') if objectID.nil? || objectID == '' client.put("#{Protocol.rule_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", rule.to_json, :write, request_options) end
ruby
def save_rule(objectID, rule, forward_to_replicas = false, request_options = {}) raise ArgumentError.new('objectID must not be blank') if objectID.nil? || objectID == '' client.put("#{Protocol.rule_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}", rule.to_json, :write, request_options) end
[ "def", "save_rule", "(", "objectID", ",", "rule", ",", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "raise", "ArgumentError", ".", "new", "(", "'objectID must not be blank'", ")", "if", "objectID", ".", "nil?", "||", "objectID", "==", "''", "client", ".", "put", "(", "\"#{Protocol.rule_uri(name, objectID)}?forwardToReplicas=#{forward_to_replicas}\"", ",", "rule", ".", "to_json", ",", ":write", ",", "request_options", ")", "end" ]
Save a rule @param objectID the rule objectID @param rule the rule @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Save", "a", "rule" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1098-L1101
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.save_rule!
def save_rule!(objectID, rule, forward_to_replicas = false, request_options = {}) res = save_rule(objectID, rule, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) return res end
ruby
def save_rule!(objectID, rule, forward_to_replicas = false, request_options = {}) res = save_rule(objectID, rule, forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) return res end
[ "def", "save_rule!", "(", "objectID", ",", "rule", ",", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "res", "=", "save_rule", "(", "objectID", ",", "rule", ",", "forward_to_replicas", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "return", "res", "end" ]
Save a rule and wait the end of indexing @param objectID the rule objectID @param rule the rule @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Save", "a", "rule", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1111-L1115
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.clear_rules!
def clear_rules!(forward_to_replicas = false, request_options = {}) res = clear_rules(forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) return res end
ruby
def clear_rules!(forward_to_replicas = false, request_options = {}) res = clear_rules(forward_to_replicas, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) return res end
[ "def", "clear_rules!", "(", "forward_to_replicas", "=", "false", ",", "request_options", "=", "{", "}", ")", "res", "=", "clear_rules", "(", "forward_to_replicas", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "return", "res", "end" ]
Clear all rules and wait the end of indexing @param forward_to_replicas should we forward the delete to replica indices @param request_options contains extra parameters to send with your query
[ "Clear", "all", "rules", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1133-L1137
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.replace_all_rules
def replace_all_rules(rules, request_options = {}) forward_to_replicas = request_options[:forwardToReplicas] || request_options['forwardToReplicas'] || false batch_rules(rules, forward_to_replicas, true, request_options) end
ruby
def replace_all_rules(rules, request_options = {}) forward_to_replicas = request_options[:forwardToReplicas] || request_options['forwardToReplicas'] || false batch_rules(rules, forward_to_replicas, true, request_options) end
[ "def", "replace_all_rules", "(", "rules", ",", "request_options", "=", "{", "}", ")", "forward_to_replicas", "=", "request_options", "[", ":forwardToReplicas", "]", "||", "request_options", "[", "'forwardToReplicas'", "]", "||", "false", "batch_rules", "(", "rules", ",", "forward_to_replicas", ",", "true", ",", "request_options", ")", "end" ]
Replace rules in the index by the given array of rules @param rules the array of rules to add @param request_options contains extra parameters to send with your query
[ "Replace", "rules", "in", "the", "index", "by", "the", "given", "array", "of", "rules" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1171-L1174
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.replace_all_rules!
def replace_all_rules!(rules, request_options = {}) res = replace_all_rules(rules, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
ruby
def replace_all_rules!(rules, request_options = {}) res = replace_all_rules(rules, request_options) wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options) res end
[ "def", "replace_all_rules!", "(", "rules", ",", "request_options", "=", "{", "}", ")", "res", "=", "replace_all_rules", "(", "rules", ",", "request_options", ")", "wait_task", "(", "res", "[", "'taskID'", "]", ",", "WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY", ",", "request_options", ")", "res", "end" ]
Replace rules in the index by the given array of rules and wait the end of indexing @param rules the array of rules to add @param request_options contains extra parameters to send with your query
[ "Replace", "rules", "in", "the", "index", "by", "the", "given", "array", "of", "rules", "and", "wait", "the", "end", "of", "indexing" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1182-L1186
train
algolia/algoliasearch-client-ruby
lib/algolia/index.rb
Algolia.Index.export_rules
def export_rules(hits_per_page = 100, request_options = {}, &_block) res = [] page = 0 loop do curr = search_rules('', { :hits_per_page => hits_per_page, :page => page }, request_options)['hits'] curr.each do |rule| res << rule yield rule if block_given? end break if curr.size < hits_per_page page += 1 end res end
ruby
def export_rules(hits_per_page = 100, request_options = {}, &_block) res = [] page = 0 loop do curr = search_rules('', { :hits_per_page => hits_per_page, :page => page }, request_options)['hits'] curr.each do |rule| res << rule yield rule if block_given? end break if curr.size < hits_per_page page += 1 end res end
[ "def", "export_rules", "(", "hits_per_page", "=", "100", ",", "request_options", "=", "{", "}", ",", "&", "_block", ")", "res", "=", "[", "]", "page", "=", "0", "loop", "do", "curr", "=", "search_rules", "(", "''", ",", "{", ":hits_per_page", "=>", "hits_per_page", ",", ":page", "=>", "page", "}", ",", "request_options", ")", "[", "'hits'", "]", "curr", ".", "each", "do", "|", "rule", "|", "res", "<<", "rule", "yield", "rule", "if", "block_given?", "end", "break", "if", "curr", ".", "size", "<", "hits_per_page", "page", "+=", "1", "end", "res", "end" ]
Export the full list of rules Accepts an optional block to which it will pass each rule Also returns an array with all the rules @param hits_per_page Amount of rules to retrieve on each internal request - Optional - Default: 100 @param request_options contains extra parameters to send with your query - Optional
[ "Export", "the", "full", "list", "of", "rules", "Accepts", "an", "optional", "block", "to", "which", "it", "will", "pass", "each", "rule", "Also", "returns", "an", "array", "with", "all", "the", "rules" ]
5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b
https://github.com/algolia/algoliasearch-client-ruby/blob/5292cd9b1029f879e4e0257a3e89d0dc9ad0df3b/lib/algolia/index.rb#L1196-L1209
train
goco-inc/graphql-activerecord
lib/graphql/models/attribute_loader.rb
GraphQL::Models.AttributeLoader.hash_to_condition
def hash_to_condition(table, hash) conditions = hash.map do |attr, value| if value.is_a?(Array) && value.size > 1 table[attr].in(value) elsif value.is_a?(Array) table[attr].eq(value[0]) else table[attr].eq(value) end end conditions.reduce { |memo, cond| memo.and(cond) } end
ruby
def hash_to_condition(table, hash) conditions = hash.map do |attr, value| if value.is_a?(Array) && value.size > 1 table[attr].in(value) elsif value.is_a?(Array) table[attr].eq(value[0]) else table[attr].eq(value) end end conditions.reduce { |memo, cond| memo.and(cond) } end
[ "def", "hash_to_condition", "(", "table", ",", "hash", ")", "conditions", "=", "hash", ".", "map", "do", "|", "attr", ",", "value", "|", "if", "value", ".", "is_a?", "(", "Array", ")", "&&", "value", ".", "size", ">", "1", "table", "[", "attr", "]", ".", "in", "(", "value", ")", "elsif", "value", ".", "is_a?", "(", "Array", ")", "table", "[", "attr", "]", ".", "eq", "(", "value", "[", "0", "]", ")", "else", "table", "[", "attr", "]", ".", "eq", "(", "value", ")", "end", "end", "conditions", ".", "reduce", "{", "|", "memo", ",", "cond", "|", "memo", ".", "and", "(", "cond", ")", "}", "end" ]
Converts a hash into arel conditions
[ "Converts", "a", "hash", "into", "arel", "conditions" ]
2567f558fda3f7dadafe62b845e18cc307c9dd34
https://github.com/goco-inc/graphql-activerecord/blob/2567f558fda3f7dadafe62b845e18cc307c9dd34/lib/graphql/models/attribute_loader.rb#L71-L83
train
activerecord-hackery/squeel
lib/squeel/dsl.rb
Squeel.DSL.method_missing
def method_missing(method_id, *args) super if method_id == :to_ary if args.empty? Nodes::Stub.new method_id elsif (args.size == 1) && (Class === args[0]) Nodes::Join.new(method_id, InnerJoin, args[0]) else Nodes::Function.new method_id, args end end
ruby
def method_missing(method_id, *args) super if method_id == :to_ary if args.empty? Nodes::Stub.new method_id elsif (args.size == 1) && (Class === args[0]) Nodes::Join.new(method_id, InnerJoin, args[0]) else Nodes::Function.new method_id, args end end
[ "def", "method_missing", "(", "method_id", ",", "*", "args", ")", "super", "if", "method_id", "==", ":to_ary", "if", "args", ".", "empty?", "Nodes", "::", "Stub", ".", "new", "method_id", "elsif", "(", "args", ".", "size", "==", "1", ")", "&&", "(", "Class", "===", "args", "[", "0", "]", ")", "Nodes", "::", "Join", ".", "new", "(", "method_id", ",", "InnerJoin", ",", "args", "[", "0", "]", ")", "else", "Nodes", "::", "Function", ".", "new", "method_id", ",", "args", "end", "end" ]
Node generation inside DSL blocks. @overload node_name Creates a Stub. Method calls chained from this Stub will determine what type of node we eventually end up with. @return [Nodes::Stub] A stub with the name of the method @overload node_name(klass) Creates a Join with a polymorphic class matching the given parameter @param [Class] klass The polymorphic class of the join node @return [Nodes::Join] A join node with the name of the method and the given class @overload node_name(first_arg, *other_args) Creates a Function with the given arguments becoming the function's arguments @param first_arg The first argument @param *other_args Optional additional arguments @return [Nodes::Function] A function node for the given method name with the given arguments
[ "Node", "generation", "inside", "DSL", "blocks", "." ]
5542266d502db8022e14105f9dfb455a79d6fc4a
https://github.com/activerecord-hackery/squeel/blob/5542266d502db8022e14105f9dfb455a79d6fc4a/lib/squeel/dsl.rb#L107-L117
train
markevans/dragonfly
lib/dragonfly/job.rb
Dragonfly.Job.initialize_copy
def initialize_copy(other) @steps = other.steps.map do |step| step.class.new(self, *step.args) end @content = other.content.dup @url_attributes = other.url_attributes.dup end
ruby
def initialize_copy(other) @steps = other.steps.map do |step| step.class.new(self, *step.args) end @content = other.content.dup @url_attributes = other.url_attributes.dup end
[ "def", "initialize_copy", "(", "other", ")", "@steps", "=", "other", ".", "steps", ".", "map", "do", "|", "step", "|", "step", ".", "class", ".", "new", "(", "self", ",", "step", ".", "args", ")", "end", "@content", "=", "other", ".", "content", ".", "dup", "@url_attributes", "=", "other", ".", "url_attributes", ".", "dup", "end" ]
Used by 'dup' and 'clone'
[ "Used", "by", "dup", "and", "clone" ]
2516f24557dc32c4ab147db7c878c5be3f5e57f0
https://github.com/markevans/dragonfly/blob/2516f24557dc32c4ab147db7c878c5be3f5e57f0/lib/dragonfly/job.rb#L90-L96
train
markevans/dragonfly
lib/dragonfly/content.rb
Dragonfly.Content.update
def update(obj, meta=nil) meta ||= {} self.temp_object = TempObject.new(obj, meta['name']) self.meta['name'] ||= temp_object.name if temp_object.name clear_analyser_cache add_meta(obj.meta) if obj.respond_to?(:meta) add_meta(meta) self end
ruby
def update(obj, meta=nil) meta ||= {} self.temp_object = TempObject.new(obj, meta['name']) self.meta['name'] ||= temp_object.name if temp_object.name clear_analyser_cache add_meta(obj.meta) if obj.respond_to?(:meta) add_meta(meta) self end
[ "def", "update", "(", "obj", ",", "meta", "=", "nil", ")", "meta", "||=", "{", "}", "self", ".", "temp_object", "=", "TempObject", ".", "new", "(", "obj", ",", "meta", "[", "'name'", "]", ")", "self", ".", "meta", "[", "'name'", "]", "||=", "temp_object", ".", "name", "if", "temp_object", ".", "name", "clear_analyser_cache", "add_meta", "(", "obj", ".", "meta", ")", "if", "obj", ".", "respond_to?", "(", ":meta", ")", "add_meta", "(", "meta", ")", "self", "end" ]
Update the content @param obj [String, Pathname, Tempfile, File, Content, TempObject] can be any of these types @param meta [Hash] - should be json-like, i.e. contain no types other than String, Number, Boolean @return [Content] self
[ "Update", "the", "content" ]
2516f24557dc32c4ab147db7c878c5be3f5e57f0
https://github.com/markevans/dragonfly/blob/2516f24557dc32c4ab147db7c878c5be3f5e57f0/lib/dragonfly/content.rb#L114-L122
train
markevans/dragonfly
lib/dragonfly/content.rb
Dragonfly.Content.shell_eval
def shell_eval(opts={}) should_escape = opts[:escape] != false command = yield(should_escape ? shell.escape(path) : path) run command, :escape => should_escape end
ruby
def shell_eval(opts={}) should_escape = opts[:escape] != false command = yield(should_escape ? shell.escape(path) : path) run command, :escape => should_escape end
[ "def", "shell_eval", "(", "opts", "=", "{", "}", ")", "should_escape", "=", "opts", "[", ":escape", "]", "!=", "false", "command", "=", "yield", "(", "should_escape", "?", "shell", ".", "escape", "(", "path", ")", ":", "path", ")", "run", "command", ",", ":escape", "=>", "should_escape", "end" ]
Analyse the content using a shell command @param opts [Hash] passing :escape => false doesn't shell-escape each word @example content.shell_eval do |path| "file --mime-type #{path}" end # ===> "beach.jpg: image/jpeg"
[ "Analyse", "the", "content", "using", "a", "shell", "command" ]
2516f24557dc32c4ab147db7c878c5be3f5e57f0
https://github.com/markevans/dragonfly/blob/2516f24557dc32c4ab147db7c878c5be3f5e57f0/lib/dragonfly/content.rb#L138-L142
train
markevans/dragonfly
lib/dragonfly/content.rb
Dragonfly.Content.shell_generate
def shell_generate(opts={}) ext = opts[:ext] || self.ext should_escape = opts[:escape] != false tempfile = Utils.new_tempfile(ext) new_path = should_escape ? shell.escape(tempfile.path) : tempfile.path command = yield(new_path) run(command, :escape => should_escape) update(tempfile) end
ruby
def shell_generate(opts={}) ext = opts[:ext] || self.ext should_escape = opts[:escape] != false tempfile = Utils.new_tempfile(ext) new_path = should_escape ? shell.escape(tempfile.path) : tempfile.path command = yield(new_path) run(command, :escape => should_escape) update(tempfile) end
[ "def", "shell_generate", "(", "opts", "=", "{", "}", ")", "ext", "=", "opts", "[", ":ext", "]", "||", "self", ".", "ext", "should_escape", "=", "opts", "[", ":escape", "]", "!=", "false", "tempfile", "=", "Utils", ".", "new_tempfile", "(", "ext", ")", "new_path", "=", "should_escape", "?", "shell", ".", "escape", "(", "tempfile", ".", "path", ")", ":", "tempfile", ".", "path", "command", "=", "yield", "(", "new_path", ")", "run", "(", "command", ",", ":escape", "=>", "should_escape", ")", "update", "(", "tempfile", ")", "end" ]
Set the content using a shell command @param opts [Hash] :ext sets the file extension of the new path and :escape => false doesn't shell-escape each word @example content.shell_generate do |path| "/usr/local/bin/generate_text gumfry -o #{path}" end @return [Content] self
[ "Set", "the", "content", "using", "a", "shell", "command" ]
2516f24557dc32c4ab147db7c878c5be3f5e57f0
https://github.com/markevans/dragonfly/blob/2516f24557dc32c4ab147db7c878c5be3f5e57f0/lib/dragonfly/content.rb#L151-L159
train
dwbutler/logstash-logger
lib/logstash-logger/multi_logger.rb
LogStashLogger.MultiLogger.method_missing
def method_missing(name, *args, &block) @loggers.each do |logger| if logger.respond_to?(name) logger.send(name, args, &block) end end end
ruby
def method_missing(name, *args, &block) @loggers.each do |logger| if logger.respond_to?(name) logger.send(name, args, &block) end end end
[ "def", "method_missing", "(", "name", ",", "*", "args", ",", "&", "block", ")", "@loggers", ".", "each", "do", "|", "logger", "|", "if", "logger", ".", "respond_to?", "(", "name", ")", "logger", ".", "send", "(", "name", ",", "args", ",", "block", ")", "end", "end", "end" ]
Any method not defined on standard Logger class, just send it on to anyone who will listen
[ "Any", "method", "not", "defined", "on", "standard", "Logger", "class", "just", "send", "it", "on", "to", "anyone", "who", "will", "listen" ]
b8f5403c44150f10d15b01133f8b6d1e9eb31806
https://github.com/dwbutler/logstash-logger/blob/b8f5403c44150f10d15b01133f8b6d1e9eb31806/lib/logstash-logger/multi_logger.rb#L70-L76
train
dwbutler/logstash-logger
lib/logstash-logger/buffer.rb
LogStashLogger.Buffer.buffer_initialize
def buffer_initialize(options={}) if ! self.class.method_defined?(:flush) raise ArgumentError, "Any class including Stud::Buffer must define a flush() method." end @buffer_config = { :max_items => options[:max_items] || 50, :max_interval => options[:max_interval] || 5, :logger => options[:logger] || nil, :autoflush => options.fetch(:autoflush, true), :has_on_flush_error => self.class.method_defined?(:on_flush_error), :has_on_full_buffer_receive => self.class.method_defined?(:on_full_buffer_receive), :drop_messages_on_flush_error => options.fetch(:drop_messages_on_flush_error, false), :drop_messages_on_full_buffer => options.fetch(:drop_messages_on_full_buffer, false), :flush_at_exit => options.fetch(:flush_at_exit, false) } if @buffer_config[:flush_at_exit] at_exit { buffer_flush(final: true) } end reset_buffer end
ruby
def buffer_initialize(options={}) if ! self.class.method_defined?(:flush) raise ArgumentError, "Any class including Stud::Buffer must define a flush() method." end @buffer_config = { :max_items => options[:max_items] || 50, :max_interval => options[:max_interval] || 5, :logger => options[:logger] || nil, :autoflush => options.fetch(:autoflush, true), :has_on_flush_error => self.class.method_defined?(:on_flush_error), :has_on_full_buffer_receive => self.class.method_defined?(:on_full_buffer_receive), :drop_messages_on_flush_error => options.fetch(:drop_messages_on_flush_error, false), :drop_messages_on_full_buffer => options.fetch(:drop_messages_on_full_buffer, false), :flush_at_exit => options.fetch(:flush_at_exit, false) } if @buffer_config[:flush_at_exit] at_exit { buffer_flush(final: true) } end reset_buffer end
[ "def", "buffer_initialize", "(", "options", "=", "{", "}", ")", "if", "!", "self", ".", "class", ".", "method_defined?", "(", ":flush", ")", "raise", "ArgumentError", ",", "\"Any class including Stud::Buffer must define a flush() method.\"", "end", "@buffer_config", "=", "{", ":max_items", "=>", "options", "[", ":max_items", "]", "||", "50", ",", ":max_interval", "=>", "options", "[", ":max_interval", "]", "||", "5", ",", ":logger", "=>", "options", "[", ":logger", "]", "||", "nil", ",", ":autoflush", "=>", "options", ".", "fetch", "(", ":autoflush", ",", "true", ")", ",", ":has_on_flush_error", "=>", "self", ".", "class", ".", "method_defined?", "(", ":on_flush_error", ")", ",", ":has_on_full_buffer_receive", "=>", "self", ".", "class", ".", "method_defined?", "(", ":on_full_buffer_receive", ")", ",", ":drop_messages_on_flush_error", "=>", "options", ".", "fetch", "(", ":drop_messages_on_flush_error", ",", "false", ")", ",", ":drop_messages_on_full_buffer", "=>", "options", ".", "fetch", "(", ":drop_messages_on_full_buffer", ",", "false", ")", ",", ":flush_at_exit", "=>", "options", ".", "fetch", "(", ":flush_at_exit", ",", "false", ")", "}", "if", "@buffer_config", "[", ":flush_at_exit", "]", "at_exit", "{", "buffer_flush", "(", "final", ":", "true", ")", "}", "end", "reset_buffer", "end" ]
Initialize the buffer. Call directly from your constructor if you wish to set some non-default options. Otherwise buffer_initialize will be called automatically during the first buffer_receive call. Options: * :max_items, Max number of items to buffer before flushing. Default 50. * :max_interval, Max number of seconds to wait between flushes. Default 5. * :logger, A logger to write log messages to. No default. Optional. * :autoflush, Whether to immediately flush all inbound messages. Default true. * :drop_messages_on_flush_error, Whether to drop messages when there is a flush error. Default false. * :drop_messages_on_full_buffer, Whether to drop messages when the buffer is full. Default false. @param [Hash] options
[ "Initialize", "the", "buffer", "." ]
b8f5403c44150f10d15b01133f8b6d1e9eb31806
https://github.com/dwbutler/logstash-logger/blob/b8f5403c44150f10d15b01133f8b6d1e9eb31806/lib/logstash-logger/buffer.rb#L85-L107
train
dwbutler/logstash-logger
lib/logstash-logger/buffer.rb
LogStashLogger.Buffer.buffer_receive
def buffer_receive(event, group=nil) buffer_initialize if ! @buffer_state # block if we've accumulated too many events while buffer_full? do on_full_buffer_receive( :pending => @buffer_state[:pending_count], :outgoing => @buffer_state[:outgoing_count] ) if @buffer_config[:has_on_full_buffer_receive] if @buffer_config[:drop_messages_on_full_buffer] reset_buffer else sleep 0.1 end end @buffer_state[:pending_mutex].synchronize do @buffer_state[:pending_items][group] << event @buffer_state[:pending_count] += 1 end if @buffer_config[:autoflush] buffer_flush(force: true) end end
ruby
def buffer_receive(event, group=nil) buffer_initialize if ! @buffer_state # block if we've accumulated too many events while buffer_full? do on_full_buffer_receive( :pending => @buffer_state[:pending_count], :outgoing => @buffer_state[:outgoing_count] ) if @buffer_config[:has_on_full_buffer_receive] if @buffer_config[:drop_messages_on_full_buffer] reset_buffer else sleep 0.1 end end @buffer_state[:pending_mutex].synchronize do @buffer_state[:pending_items][group] << event @buffer_state[:pending_count] += 1 end if @buffer_config[:autoflush] buffer_flush(force: true) end end
[ "def", "buffer_receive", "(", "event", ",", "group", "=", "nil", ")", "buffer_initialize", "if", "!", "@buffer_state", "# block if we've accumulated too many events", "while", "buffer_full?", "do", "on_full_buffer_receive", "(", ":pending", "=>", "@buffer_state", "[", ":pending_count", "]", ",", ":outgoing", "=>", "@buffer_state", "[", ":outgoing_count", "]", ")", "if", "@buffer_config", "[", ":has_on_full_buffer_receive", "]", "if", "@buffer_config", "[", ":drop_messages_on_full_buffer", "]", "reset_buffer", "else", "sleep", "0.1", "end", "end", "@buffer_state", "[", ":pending_mutex", "]", ".", "synchronize", "do", "@buffer_state", "[", ":pending_items", "]", "[", "group", "]", "<<", "event", "@buffer_state", "[", ":pending_count", "]", "+=", "1", "end", "if", "@buffer_config", "[", ":autoflush", "]", "buffer_flush", "(", "force", ":", "true", ")", "end", "end" ]
Save an event for later delivery Events are grouped by the (optional) group parameter you provide. Groups of events, plus the group name, are later passed to +flush+. This call will block if +:max_items+ has been reached. @see Stud::Buffer The overview has more information on grouping and flushing. @param event An item to buffer for flushing later. @param group Optional grouping key. All events with the same key will be passed to +flush+ together, along with the grouping key itself.
[ "Save", "an", "event", "for", "later", "delivery" ]
b8f5403c44150f10d15b01133f8b6d1e9eb31806
https://github.com/dwbutler/logstash-logger/blob/b8f5403c44150f10d15b01133f8b6d1e9eb31806/lib/logstash-logger/buffer.rb#L157-L182
train
dwbutler/logstash-logger
lib/logstash-logger/buffer.rb
LogStashLogger.Buffer.buffer_flush
def buffer_flush(options={}) force = options[:force] || options[:final] final = options[:final] # final flush will wait for lock, so we are sure to flush out all buffered events if options[:final] @buffer_state[:flush_mutex].lock elsif ! @buffer_state[:flush_mutex].try_lock # failed to get lock, another flush already in progress return 0 end items_flushed = 0 begin time_since_last_flush = (Time.now - @buffer_state[:last_flush]) return 0 if @buffer_state[:pending_count] == 0 return 0 if (!force) && (@buffer_state[:pending_count] < @buffer_config[:max_items]) && (time_since_last_flush < @buffer_config[:max_interval]) @buffer_state[:pending_mutex].synchronize do @buffer_state[:outgoing_items] = @buffer_state[:pending_items] @buffer_state[:outgoing_count] = @buffer_state[:pending_count] buffer_clear_pending end @buffer_config[:logger].debug do debug_output = { :outgoing_count => @buffer_state[:outgoing_count], :time_since_last_flush => time_since_last_flush, :outgoing_events => @buffer_state[:outgoing_items], :batch_timeout => @buffer_config[:max_interval], :force => force, :final => final } "Flushing output: #{debug_output}" end if @buffer_config[:logger] @buffer_state[:outgoing_items].each do |group, events| begin if group.nil? flush(events,final) else flush(events, group, final) end @buffer_state[:outgoing_items].delete(group) events_size = events.size @buffer_state[:outgoing_count] -= events_size items_flushed += events_size @buffer_state[:last_flush] = Time.now rescue => e @buffer_config[:logger].warn do warn_output = { :outgoing_count => @buffer_state[:outgoing_count], :exception => e.class.name, :backtrace => e.backtrace } "Failed to flush outgoing items: #{warn_output}" end if @buffer_config[:logger] if @buffer_config[:has_on_flush_error] on_flush_error e end if @buffer_config[:drop_messages_on_flush_error] reset_buffer else cancel_flush end end end ensure @buffer_state[:flush_mutex].unlock end return items_flushed end
ruby
def buffer_flush(options={}) force = options[:force] || options[:final] final = options[:final] # final flush will wait for lock, so we are sure to flush out all buffered events if options[:final] @buffer_state[:flush_mutex].lock elsif ! @buffer_state[:flush_mutex].try_lock # failed to get lock, another flush already in progress return 0 end items_flushed = 0 begin time_since_last_flush = (Time.now - @buffer_state[:last_flush]) return 0 if @buffer_state[:pending_count] == 0 return 0 if (!force) && (@buffer_state[:pending_count] < @buffer_config[:max_items]) && (time_since_last_flush < @buffer_config[:max_interval]) @buffer_state[:pending_mutex].synchronize do @buffer_state[:outgoing_items] = @buffer_state[:pending_items] @buffer_state[:outgoing_count] = @buffer_state[:pending_count] buffer_clear_pending end @buffer_config[:logger].debug do debug_output = { :outgoing_count => @buffer_state[:outgoing_count], :time_since_last_flush => time_since_last_flush, :outgoing_events => @buffer_state[:outgoing_items], :batch_timeout => @buffer_config[:max_interval], :force => force, :final => final } "Flushing output: #{debug_output}" end if @buffer_config[:logger] @buffer_state[:outgoing_items].each do |group, events| begin if group.nil? flush(events,final) else flush(events, group, final) end @buffer_state[:outgoing_items].delete(group) events_size = events.size @buffer_state[:outgoing_count] -= events_size items_flushed += events_size @buffer_state[:last_flush] = Time.now rescue => e @buffer_config[:logger].warn do warn_output = { :outgoing_count => @buffer_state[:outgoing_count], :exception => e.class.name, :backtrace => e.backtrace } "Failed to flush outgoing items: #{warn_output}" end if @buffer_config[:logger] if @buffer_config[:has_on_flush_error] on_flush_error e end if @buffer_config[:drop_messages_on_flush_error] reset_buffer else cancel_flush end end end ensure @buffer_state[:flush_mutex].unlock end return items_flushed end
[ "def", "buffer_flush", "(", "options", "=", "{", "}", ")", "force", "=", "options", "[", ":force", "]", "||", "options", "[", ":final", "]", "final", "=", "options", "[", ":final", "]", "# final flush will wait for lock, so we are sure to flush out all buffered events", "if", "options", "[", ":final", "]", "@buffer_state", "[", ":flush_mutex", "]", ".", "lock", "elsif", "!", "@buffer_state", "[", ":flush_mutex", "]", ".", "try_lock", "# failed to get lock, another flush already in progress", "return", "0", "end", "items_flushed", "=", "0", "begin", "time_since_last_flush", "=", "(", "Time", ".", "now", "-", "@buffer_state", "[", ":last_flush", "]", ")", "return", "0", "if", "@buffer_state", "[", ":pending_count", "]", "==", "0", "return", "0", "if", "(", "!", "force", ")", "&&", "(", "@buffer_state", "[", ":pending_count", "]", "<", "@buffer_config", "[", ":max_items", "]", ")", "&&", "(", "time_since_last_flush", "<", "@buffer_config", "[", ":max_interval", "]", ")", "@buffer_state", "[", ":pending_mutex", "]", ".", "synchronize", "do", "@buffer_state", "[", ":outgoing_items", "]", "=", "@buffer_state", "[", ":pending_items", "]", "@buffer_state", "[", ":outgoing_count", "]", "=", "@buffer_state", "[", ":pending_count", "]", "buffer_clear_pending", "end", "@buffer_config", "[", ":logger", "]", ".", "debug", "do", "debug_output", "=", "{", ":outgoing_count", "=>", "@buffer_state", "[", ":outgoing_count", "]", ",", ":time_since_last_flush", "=>", "time_since_last_flush", ",", ":outgoing_events", "=>", "@buffer_state", "[", ":outgoing_items", "]", ",", ":batch_timeout", "=>", "@buffer_config", "[", ":max_interval", "]", ",", ":force", "=>", "force", ",", ":final", "=>", "final", "}", "\"Flushing output: #{debug_output}\"", "end", "if", "@buffer_config", "[", ":logger", "]", "@buffer_state", "[", ":outgoing_items", "]", ".", "each", "do", "|", "group", ",", "events", "|", "begin", "if", "group", ".", "nil?", "flush", "(", "events", ",", "final", ")", "else", "flush", "(", "events", ",", "group", ",", "final", ")", "end", "@buffer_state", "[", ":outgoing_items", "]", ".", "delete", "(", "group", ")", "events_size", "=", "events", ".", "size", "@buffer_state", "[", ":outgoing_count", "]", "-=", "events_size", "items_flushed", "+=", "events_size", "@buffer_state", "[", ":last_flush", "]", "=", "Time", ".", "now", "rescue", "=>", "e", "@buffer_config", "[", ":logger", "]", ".", "warn", "do", "warn_output", "=", "{", ":outgoing_count", "=>", "@buffer_state", "[", ":outgoing_count", "]", ",", ":exception", "=>", "e", ".", "class", ".", "name", ",", ":backtrace", "=>", "e", ".", "backtrace", "}", "\"Failed to flush outgoing items: #{warn_output}\"", "end", "if", "@buffer_config", "[", ":logger", "]", "if", "@buffer_config", "[", ":has_on_flush_error", "]", "on_flush_error", "e", "end", "if", "@buffer_config", "[", ":drop_messages_on_flush_error", "]", "reset_buffer", "else", "cancel_flush", "end", "end", "end", "ensure", "@buffer_state", "[", ":flush_mutex", "]", ".", "unlock", "end", "return", "items_flushed", "end" ]
Try to flush events. Returns immediately if flushing is not necessary/possible at the moment: * :max_items have not been accumulated * :max_interval seconds have not elapased since the last flush * another flush is in progress <code>buffer_flush(:force => true)</code> will cause a flush to occur even if +:max_items+ or +:max_interval+ have not been reached. A forced flush will still return immediately (without flushing) if another flush is currently in progress. <code>buffer_flush(:final => true)</code> is identical to <code>buffer_flush(:force => true)</code>, except that if another flush is already in progress, <code>buffer_flush(:final => true)</code> will block/wait for the other flush to finish before proceeding. @param [Hash] options Optional. May be <code>{:force => true}</code> or <code>{:final => true}</code>. @return [Fixnum] The number of items successfully passed to +flush+.
[ "Try", "to", "flush", "events", "." ]
b8f5403c44150f10d15b01133f8b6d1e9eb31806
https://github.com/dwbutler/logstash-logger/blob/b8f5403c44150f10d15b01133f8b6d1e9eb31806/lib/logstash-logger/buffer.rb#L202-L284
train
dkubb/axiom
lib/axiom/relation.rb
Axiom.Relation.each
def each return to_enum unless block_given? seen = {} tuples.each do |tuple| tuple = Tuple.coerce(header, tuple) yield seen[tuple] = tuple unless seen.key?(tuple) end self end
ruby
def each return to_enum unless block_given? seen = {} tuples.each do |tuple| tuple = Tuple.coerce(header, tuple) yield seen[tuple] = tuple unless seen.key?(tuple) end self end
[ "def", "each", "return", "to_enum", "unless", "block_given?", "seen", "=", "{", "}", "tuples", ".", "each", "do", "|", "tuple", "|", "tuple", "=", "Tuple", ".", "coerce", "(", "header", ",", "tuple", ")", "yield", "seen", "[", "tuple", "]", "=", "tuple", "unless", "seen", ".", "key?", "(", "tuple", ")", "end", "self", "end" ]
Iterate over each tuple in the set @example relation = Relation.new(header, tuples) relation.each { |tuple| ... } @yield [tuple] @yieldparam [Tuple] tuple each tuple in the set @return [self] @api public
[ "Iterate", "over", "each", "tuple", "in", "the", "set" ]
2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc
https://github.com/dkubb/axiom/blob/2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc/lib/axiom/relation.rb#L120-L128
train
dkubb/axiom
lib/axiom/relation.rb
Axiom.Relation.replace
def replace(other) other = coerce(other) delete(difference(other)).insert(other.difference(self)) end
ruby
def replace(other) other = coerce(other) delete(difference(other)).insert(other.difference(self)) end
[ "def", "replace", "(", "other", ")", "other", "=", "coerce", "(", "other", ")", "delete", "(", "difference", "(", "other", ")", ")", ".", "insert", "(", "other", ".", "difference", "(", "self", ")", ")", "end" ]
Return a relation that represents a replacement of a relation Delete the tuples from the relation that are not in the other relation, then insert only new tuples. @example replacement = relation.delete(other) @param [Enumerable] other @return [Relation::Operation::Insertion] @api public
[ "Return", "a", "relation", "that", "represents", "a", "replacement", "of", "a", "relation" ]
2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc
https://github.com/dkubb/axiom/blob/2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc/lib/axiom/relation.rb#L143-L146
train
dkubb/axiom
lib/axiom/support/aliasable.rb
Axiom.Aliasable.define_inheritable_alias_method
def define_inheritable_alias_method(new_method, original_method) define_method(new_method) do |*args, &block| public_send(original_method, *args, &block) end end
ruby
def define_inheritable_alias_method(new_method, original_method) define_method(new_method) do |*args, &block| public_send(original_method, *args, &block) end end
[ "def", "define_inheritable_alias_method", "(", "new_method", ",", "original_method", ")", "define_method", "(", "new_method", ")", "do", "|", "*", "args", ",", "&", "block", "|", "public_send", "(", "original_method", ",", "args", ",", "block", ")", "end", "end" ]
Create a new method alias for the original method @param [Symbol] new_method @param [Symbol] original_method @return [undefined] @api private
[ "Create", "a", "new", "method", "alias", "for", "the", "original", "method" ]
2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc
https://github.com/dkubb/axiom/blob/2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc/lib/axiom/support/aliasable.rb#L35-L39
train
dkubb/axiom
lib/axiom/tuple.rb
Axiom.Tuple.extend
def extend(header, extensions) join( header, extensions.map { |extension| Function.extract_value(extension, self) } ) end
ruby
def extend(header, extensions) join( header, extensions.map { |extension| Function.extract_value(extension, self) } ) end
[ "def", "extend", "(", "header", ",", "extensions", ")", "join", "(", "header", ",", "extensions", ".", "map", "{", "|", "extension", "|", "Function", ".", "extract_value", "(", "extension", ",", "self", ")", "}", ")", "end" ]
Extend a tuple with function results @example new_tuple = tuple.extend(header, [func1, func2]) @param [Header] header the attributes to include in the tuple @param [Array<Object>] extensions the functions to extend the tuple with @return [Tuple] @api public
[ "Extend", "a", "tuple", "with", "function", "results" ]
2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc
https://github.com/dkubb/axiom/blob/2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc/lib/axiom/tuple.rb#L94-L99
train
dkubb/axiom
lib/axiom/tuple.rb
Axiom.Tuple.predicate
def predicate header.reduce(Function::Proposition::Tautology.instance) do |predicate, attribute| predicate.and(attribute.eq(attribute.call(self))) end end
ruby
def predicate header.reduce(Function::Proposition::Tautology.instance) do |predicate, attribute| predicate.and(attribute.eq(attribute.call(self))) end end
[ "def", "predicate", "header", ".", "reduce", "(", "Function", "::", "Proposition", "::", "Tautology", ".", "instance", ")", "do", "|", "predicate", ",", "attribute", "|", "predicate", ".", "and", "(", "attribute", ".", "eq", "(", "attribute", ".", "call", "(", "self", ")", ")", ")", "end", "end" ]
Return the predicate matching the tuple @return [Function] @api private
[ "Return", "the", "predicate", "matching", "the", "tuple" ]
2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc
https://github.com/dkubb/axiom/blob/2476a75ed04d8a86d7a4dd30b306bac7fe2e8edc/lib/axiom/tuple.rb#L137-L141
train
jasonlong/geo_pattern
lib/geo_pattern/geo_pattern_task.rb
GeoPattern.GeoPatternTask.run_task
def run_task(_verbose) data.each do |path, string| opts = {} path = File.expand_path(path) if string.is_a?(Hash) input = string[:input] opts[:patterns] = string[:patterns] if string.key? :patterns opts[:color] = string[:color] if string.key? :color opts[:base_color] = string[:base_color] if string.key? :base_color else raise 'Invalid data structure for Rake Task' end pattern = GeoPattern.generate(input, opts) logger.info "Creating pattern at \"#{path}\"." FileUtils.mkdir_p File.dirname(path) File.write(path, pattern.to_svg) end end
ruby
def run_task(_verbose) data.each do |path, string| opts = {} path = File.expand_path(path) if string.is_a?(Hash) input = string[:input] opts[:patterns] = string[:patterns] if string.key? :patterns opts[:color] = string[:color] if string.key? :color opts[:base_color] = string[:base_color] if string.key? :base_color else raise 'Invalid data structure for Rake Task' end pattern = GeoPattern.generate(input, opts) logger.info "Creating pattern at \"#{path}\"." FileUtils.mkdir_p File.dirname(path) File.write(path, pattern.to_svg) end end
[ "def", "run_task", "(", "_verbose", ")", "data", ".", "each", "do", "|", "path", ",", "string", "|", "opts", "=", "{", "}", "path", "=", "File", ".", "expand_path", "(", "path", ")", "if", "string", ".", "is_a?", "(", "Hash", ")", "input", "=", "string", "[", ":input", "]", "opts", "[", ":patterns", "]", "=", "string", "[", ":patterns", "]", "if", "string", ".", "key?", ":patterns", "opts", "[", ":color", "]", "=", "string", "[", ":color", "]", "if", "string", ".", "key?", ":color", "opts", "[", ":base_color", "]", "=", "string", "[", ":base_color", "]", "if", "string", ".", "key?", ":base_color", "else", "raise", "'Invalid data structure for Rake Task'", "end", "pattern", "=", "GeoPattern", ".", "generate", "(", "input", ",", "opts", ")", "logger", ".", "info", "\"Creating pattern at \\\"#{path}\\\".\"", "FileUtils", ".", "mkdir_p", "File", ".", "dirname", "(", "path", ")", "File", ".", "write", "(", "path", ",", "pattern", ".", "to_svg", ")", "end", "end" ]
Create a new geo pattern task @param [Hash] data The data which should be used to generate patterns @param [Array] allowed_patterns The allowed_patterns @see RakeTask For other arguments accepted @private
[ "Create", "a", "new", "geo", "pattern", "task" ]
62d3222c7394f0f02ab7f4705219d616c5a72b7e
https://github.com/jasonlong/geo_pattern/blob/62d3222c7394f0f02ab7f4705219d616c5a72b7e/lib/geo_pattern/geo_pattern_task.rb#L37-L57
train
jasonlong/geo_pattern
lib/geo_pattern/rake_task.rb
GeoPattern.RakeTask.include
def include(modules) modules = Array(modules) modules.each { |m| self.class.include m } end
ruby
def include(modules) modules = Array(modules) modules.each { |m| self.class.include m } end
[ "def", "include", "(", "modules", ")", "modules", "=", "Array", "(", "modules", ")", "modules", ".", "each", "{", "|", "m", "|", "self", ".", "class", ".", "include", "m", "}", "end" ]
Include module in instance
[ "Include", "module", "in", "instance" ]
62d3222c7394f0f02ab7f4705219d616c5a72b7e
https://github.com/jasonlong/geo_pattern/blob/62d3222c7394f0f02ab7f4705219d616c5a72b7e/lib/geo_pattern/rake_task.rb#L101-L105
train
kontena/kontena
cli/lib/kontena/cli/master/login_command.rb
Kontena::Cli::Master.LoginCommand.authentication_path
def authentication_path(local_port: nil, invite_code: nil, expires_in: nil, remote: false) auth_url_params = {} if remote auth_url_params[:redirect_uri] = "/code" elsif local_port auth_url_params[:redirect_uri] = "http://localhost:#{local_port}/cb" else raise ArgumentError, "Local port not defined and not performing remote login" end auth_url_params[:invite_code] = invite_code if invite_code auth_url_params[:expires_in] = expires_in if expires_in "/authenticate?#{URI.encode_www_form(auth_url_params)}" end
ruby
def authentication_path(local_port: nil, invite_code: nil, expires_in: nil, remote: false) auth_url_params = {} if remote auth_url_params[:redirect_uri] = "/code" elsif local_port auth_url_params[:redirect_uri] = "http://localhost:#{local_port}/cb" else raise ArgumentError, "Local port not defined and not performing remote login" end auth_url_params[:invite_code] = invite_code if invite_code auth_url_params[:expires_in] = expires_in if expires_in "/authenticate?#{URI.encode_www_form(auth_url_params)}" end
[ "def", "authentication_path", "(", "local_port", ":", "nil", ",", "invite_code", ":", "nil", ",", "expires_in", ":", "nil", ",", "remote", ":", "false", ")", "auth_url_params", "=", "{", "}", "if", "remote", "auth_url_params", "[", ":redirect_uri", "]", "=", "\"/code\"", "elsif", "local_port", "auth_url_params", "[", ":redirect_uri", "]", "=", "\"http://localhost:#{local_port}/cb\"", "else", "raise", "ArgumentError", ",", "\"Local port not defined and not performing remote login\"", "end", "auth_url_params", "[", ":invite_code", "]", "=", "invite_code", "if", "invite_code", "auth_url_params", "[", ":expires_in", "]", "=", "expires_in", "if", "expires_in", "\"/authenticate?#{URI.encode_www_form(auth_url_params)}\"", "end" ]
Build a path for master authentication @param local_port [Fixnum] tcp port where localhost webserver is listening @param invite_code [String] an invitation code generated when user was invited @param expires_in [Fixnum] expiration time for the requested access token @param remote [Boolean] true when performing a login where the code is displayed on the web page @return [String]
[ "Build", "a", "path", "for", "master", "authentication" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/cli/lib/kontena/cli/master/login_command.rb#L126-L138
train
kontena/kontena
cli/lib/kontena/cli/master/login_command.rb
Kontena::Cli::Master.LoginCommand.authentication_url_from_master
def authentication_url_from_master(master_url, auth_params) client = Kontena::Client.new(master_url) vspinner "Sending authentication request to receive an authorization URL" do response = client.request( http_method: :get, path: authentication_path(auth_params), expects: [501, 400, 302, 403], auth: false ) if client.last_response.status == 302 client.last_response.headers['Location'] elsif response.kind_of?(Hash) exit_with_error [response['error'], response['error_description']].compact.join(' : ') elsif response.kind_of?(String) && response.length > 1 exit_with_error response else exit_with_error "Invalid response to authentication request : HTTP#{client.last_response.status} #{client.last_response.body if debug?}" end end end
ruby
def authentication_url_from_master(master_url, auth_params) client = Kontena::Client.new(master_url) vspinner "Sending authentication request to receive an authorization URL" do response = client.request( http_method: :get, path: authentication_path(auth_params), expects: [501, 400, 302, 403], auth: false ) if client.last_response.status == 302 client.last_response.headers['Location'] elsif response.kind_of?(Hash) exit_with_error [response['error'], response['error_description']].compact.join(' : ') elsif response.kind_of?(String) && response.length > 1 exit_with_error response else exit_with_error "Invalid response to authentication request : HTTP#{client.last_response.status} #{client.last_response.body if debug?}" end end end
[ "def", "authentication_url_from_master", "(", "master_url", ",", "auth_params", ")", "client", "=", "Kontena", "::", "Client", ".", "new", "(", "master_url", ")", "vspinner", "\"Sending authentication request to receive an authorization URL\"", "do", "response", "=", "client", ".", "request", "(", "http_method", ":", ":get", ",", "path", ":", "authentication_path", "(", "auth_params", ")", ",", "expects", ":", "[", "501", ",", "400", ",", "302", ",", "403", "]", ",", "auth", ":", "false", ")", "if", "client", ".", "last_response", ".", "status", "==", "302", "client", ".", "last_response", ".", "headers", "[", "'Location'", "]", "elsif", "response", ".", "kind_of?", "(", "Hash", ")", "exit_with_error", "[", "response", "[", "'error'", "]", ",", "response", "[", "'error_description'", "]", "]", ".", "compact", ".", "join", "(", "' : '", ")", "elsif", "response", ".", "kind_of?", "(", "String", ")", "&&", "response", ".", "length", ">", "1", "exit_with_error", "response", "else", "exit_with_error", "\"Invalid response to authentication request : HTTP#{client.last_response.status} #{client.last_response.body if debug?}\"", "end", "end", "end" ]
Request a redirect to the authentication url from master @param master_url [String] master root url @param auth_params [Hash] auth parameters (keyword arguments of #authentication_path) @return [String] url to begin authentication web flow
[ "Request", "a", "redirect", "to", "the", "authentication", "url", "from", "master" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/cli/lib/kontena/cli/master/login_command.rb#L145-L165
train
kontena/kontena
cli/lib/kontena/cli/master/login_command.rb
Kontena::Cli::Master.LoginCommand.select_a_server
def select_a_server(name, url) # no url, no name, try to use current master if url.nil? && name.nil? if config.current_master return config.current_master else exit_with_error 'URL not specified and current master not selected' end end if name && url exact_match = config.find_server_by(url: url, name: name) return exact_match if exact_match # found an exact match, going to use that one. name_match = config.find_server(name) if name_match #found a server with the provided name, set the provided url to it and return name_match.url = url return name_match else # nothing found, create new. return Kontena::Cli::Config::Server.new(name: name, url: url) end elsif name # only --name provided, try to find a server with that name name_match = config.find_server(name) if name_match && name_match.url return name_match else exit_with_error "Master #{name} was found from config, but it does not have an URL and no URL was provided on command line" end elsif url # only url provided if url =~ /^https?:\/\// # url is actually an url url_match = config.find_server_by(url: url) if url_match return url_match else return Kontena::Cli::Config::Server.new(url: url, name: nil) end else name_match = config.find_server(url) if name_match unless name_match.url exit_with_error "Master #{url} was found from config, but it does not have an URL and no URL was provided on command line" end return name_match else exit_with_error "Can't find a master with name #{name} from configuration" end end end end
ruby
def select_a_server(name, url) # no url, no name, try to use current master if url.nil? && name.nil? if config.current_master return config.current_master else exit_with_error 'URL not specified and current master not selected' end end if name && url exact_match = config.find_server_by(url: url, name: name) return exact_match if exact_match # found an exact match, going to use that one. name_match = config.find_server(name) if name_match #found a server with the provided name, set the provided url to it and return name_match.url = url return name_match else # nothing found, create new. return Kontena::Cli::Config::Server.new(name: name, url: url) end elsif name # only --name provided, try to find a server with that name name_match = config.find_server(name) if name_match && name_match.url return name_match else exit_with_error "Master #{name} was found from config, but it does not have an URL and no URL was provided on command line" end elsif url # only url provided if url =~ /^https?:\/\// # url is actually an url url_match = config.find_server_by(url: url) if url_match return url_match else return Kontena::Cli::Config::Server.new(url: url, name: nil) end else name_match = config.find_server(url) if name_match unless name_match.url exit_with_error "Master #{url} was found from config, but it does not have an URL and no URL was provided on command line" end return name_match else exit_with_error "Can't find a master with name #{name} from configuration" end end end end
[ "def", "select_a_server", "(", "name", ",", "url", ")", "# no url, no name, try to use current master", "if", "url", ".", "nil?", "&&", "name", ".", "nil?", "if", "config", ".", "current_master", "return", "config", ".", "current_master", "else", "exit_with_error", "'URL not specified and current master not selected'", "end", "end", "if", "name", "&&", "url", "exact_match", "=", "config", ".", "find_server_by", "(", "url", ":", "url", ",", "name", ":", "name", ")", "return", "exact_match", "if", "exact_match", "# found an exact match, going to use that one.", "name_match", "=", "config", ".", "find_server", "(", "name", ")", "if", "name_match", "#found a server with the provided name, set the provided url to it and return", "name_match", ".", "url", "=", "url", "return", "name_match", "else", "# nothing found, create new.", "return", "Kontena", "::", "Cli", "::", "Config", "::", "Server", ".", "new", "(", "name", ":", "name", ",", "url", ":", "url", ")", "end", "elsif", "name", "# only --name provided, try to find a server with that name", "name_match", "=", "config", ".", "find_server", "(", "name", ")", "if", "name_match", "&&", "name_match", ".", "url", "return", "name_match", "else", "exit_with_error", "\"Master #{name} was found from config, but it does not have an URL and no URL was provided on command line\"", "end", "elsif", "url", "# only url provided", "if", "url", "=~", "/", "\\/", "\\/", "/", "# url is actually an url", "url_match", "=", "config", ".", "find_server_by", "(", "url", ":", "url", ")", "if", "url_match", "return", "url_match", "else", "return", "Kontena", "::", "Cli", "::", "Config", "::", "Server", ".", "new", "(", "url", ":", "url", ",", "name", ":", "nil", ")", "end", "else", "name_match", "=", "config", ".", "find_server", "(", "url", ")", "if", "name_match", "unless", "name_match", ".", "url", "exit_with_error", "\"Master #{url} was found from config, but it does not have an URL and no URL was provided on command line\"", "end", "return", "name_match", "else", "exit_with_error", "\"Can't find a master with name #{name} from configuration\"", "end", "end", "end", "end" ]
Figure out or create a server based on url or name. No name or url provided: try to use current_master A name provided with --name but no url defined: try to find a server by name from config An URL starting with 'http' provided: try to find a server by url from config An URL not starting with 'http' provided: try to find a server by name An URL and a name provided - If a server is found by name: use entry and update URL to the provided url - Else create a new entry with the url and name @param name [String] master name @param url [String] master url or name @return [Kontena::Cli::Config::Server]
[ "Figure", "out", "or", "create", "a", "server", "based", "on", "url", "or", "name", "." ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/cli/lib/kontena/cli/master/login_command.rb#L273-L328
train
kontena/kontena
agent/lib/kontena/network_adapters/weave.rb
Kontena::NetworkAdapters.Weave.ensure_exposed
def ensure_exposed(cidr) # configure new address # these will be added alongside any existing addresses if @executor_pool.expose(cidr) info "Exposed host node at cidr=#{cidr}" else error "Failed to expose host node at cidr=#{cidr}" end # cleanup any old addresses @executor_pool.ps('weave:expose') do |name, mac, *cidrs| cidrs.each do |exposed_cidr| if exposed_cidr != cidr warn "Migrating host node from cidr=#{exposed_cidr}" @executor_pool.hide(exposed_cidr) end end end end
ruby
def ensure_exposed(cidr) # configure new address # these will be added alongside any existing addresses if @executor_pool.expose(cidr) info "Exposed host node at cidr=#{cidr}" else error "Failed to expose host node at cidr=#{cidr}" end # cleanup any old addresses @executor_pool.ps('weave:expose') do |name, mac, *cidrs| cidrs.each do |exposed_cidr| if exposed_cidr != cidr warn "Migrating host node from cidr=#{exposed_cidr}" @executor_pool.hide(exposed_cidr) end end end end
[ "def", "ensure_exposed", "(", "cidr", ")", "# configure new address", "# these will be added alongside any existing addresses", "if", "@executor_pool", ".", "expose", "(", "cidr", ")", "info", "\"Exposed host node at cidr=#{cidr}\"", "else", "error", "\"Failed to expose host node at cidr=#{cidr}\"", "end", "# cleanup any old addresses", "@executor_pool", ".", "ps", "(", "'weave:expose'", ")", "do", "|", "name", ",", "mac", ",", "*", "cidrs", "|", "cidrs", ".", "each", "do", "|", "exposed_cidr", "|", "if", "exposed_cidr", "!=", "cidr", "warn", "\"Migrating host node from cidr=#{exposed_cidr}\"", "@executor_pool", ".", "hide", "(", "exposed_cidr", ")", "end", "end", "end", "end" ]
Ensure that the host weave bridge is exposed using the given CIDR address, and only the given CIDR address @param [String] cidr '10.81.0.X/16'
[ "Ensure", "that", "the", "host", "weave", "bridge", "is", "exposed", "using", "the", "given", "CIDR", "address", "and", "only", "the", "given", "CIDR", "address" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/network_adapters/weave.rb#L162-L180
train
kontena/kontena
agent/lib/kontena/network_adapters/weave.rb
Kontena::NetworkAdapters.Weave.get_containers
def get_containers containers = { } @executor_pool.ps() do |id, mac, *cidrs| next if id == 'weave:expose' containers[id] = cidrs end containers end
ruby
def get_containers containers = { } @executor_pool.ps() do |id, mac, *cidrs| next if id == 'weave:expose' containers[id] = cidrs end containers end
[ "def", "get_containers", "containers", "=", "{", "}", "@executor_pool", ".", "ps", "(", ")", "do", "|", "id", ",", "mac", ",", "*", "cidrs", "|", "next", "if", "id", "==", "'weave:expose'", "containers", "[", "id", "]", "=", "cidrs", "end", "containers", "end" ]
Inspect current state of attached containers @return [Hash<String, String>] container_id[0..12] => [overlay_cidr]
[ "Inspect", "current", "state", "of", "attached", "containers" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/network_adapters/weave.rb#L285-L295
train
kontena/kontena
agent/lib/kontena/network_adapters/weave.rb
Kontena::NetworkAdapters.Weave.migrate_container
def migrate_container(container_id, cidr, attached_cidrs) # first remove any existing addresses # this is required, since weave will not attach if the address already exists, but with a different netmask attached_cidrs.each do |attached_cidr| if cidr != attached_cidr warn "Migrate container=#{container_id} from cidr=#{attached_cidr}" @executor_pool.detach(container_id, attached_cidr) end end # attach with the correct address self.attach_container(container_id, cidr) end
ruby
def migrate_container(container_id, cidr, attached_cidrs) # first remove any existing addresses # this is required, since weave will not attach if the address already exists, but with a different netmask attached_cidrs.each do |attached_cidr| if cidr != attached_cidr warn "Migrate container=#{container_id} from cidr=#{attached_cidr}" @executor_pool.detach(container_id, attached_cidr) end end # attach with the correct address self.attach_container(container_id, cidr) end
[ "def", "migrate_container", "(", "container_id", ",", "cidr", ",", "attached_cidrs", ")", "# first remove any existing addresses", "# this is required, since weave will not attach if the address already exists, but with a different netmask", "attached_cidrs", ".", "each", "do", "|", "attached_cidr", "|", "if", "cidr", "!=", "attached_cidr", "warn", "\"Migrate container=#{container_id} from cidr=#{attached_cidr}\"", "@executor_pool", ".", "detach", "(", "container_id", ",", "attached_cidr", ")", "end", "end", "# attach with the correct address", "self", ".", "attach_container", "(", "container_id", ",", "cidr", ")", "end" ]
Attach container to weave with given CIDR address, first detaching any existing mismatching addresses @param [String] container_id @param [String] overlay_cidr '10.81.X.Y/16' @param [Array<String>] migrate_cidrs ['10.81.X.Y/19']
[ "Attach", "container", "to", "weave", "with", "given", "CIDR", "address", "first", "detaching", "any", "existing", "mismatching", "addresses" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/network_adapters/weave.rb#L312-L324
train
kontena/kontena
agent/lib/kontena/network_adapters/weave.rb
Kontena::NetworkAdapters.Weave.remove_container
def remove_container(container_id, overlay_network, overlay_cidr) info "Remove container=#{container_id} from network=#{overlay_network} at cidr=#{overlay_cidr}" @ipam_client.release_address(overlay_network, overlay_cidr) rescue IpamError => error # Cleanup will take care of these later on warn "Failed to release container=#{container_id} from network=#{overlay_network} at cidr=#{overlay_cidr}: #{error}" end
ruby
def remove_container(container_id, overlay_network, overlay_cidr) info "Remove container=#{container_id} from network=#{overlay_network} at cidr=#{overlay_cidr}" @ipam_client.release_address(overlay_network, overlay_cidr) rescue IpamError => error # Cleanup will take care of these later on warn "Failed to release container=#{container_id} from network=#{overlay_network} at cidr=#{overlay_cidr}: #{error}" end
[ "def", "remove_container", "(", "container_id", ",", "overlay_network", ",", "overlay_cidr", ")", "info", "\"Remove container=#{container_id} from network=#{overlay_network} at cidr=#{overlay_cidr}\"", "@ipam_client", ".", "release_address", "(", "overlay_network", ",", "overlay_cidr", ")", "rescue", "IpamError", "=>", "error", "# Cleanup will take care of these later on", "warn", "\"Failed to release container=#{container_id} from network=#{overlay_network} at cidr=#{overlay_cidr}: #{error}\"", "end" ]
Remove container from weave network @param [String] container_id may not exist anymore @param [Hash] labels Docker container labels
[ "Remove", "container", "from", "weave", "network" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/network_adapters/weave.rb#L330-L337
train
kontena/kontena
agent/lib/kontena/workers/weave_worker.rb
Kontena::Workers.WeaveWorker.start_container
def start_container(container) overlay_cidr = container.overlay_cidr if overlay_cidr wait_weave_running? register_container_dns(container) if container.service_container? attach_overlay(container) else debug "skip start for container=#{container.name} without overlay_cidr" end rescue Docker::Error::NotFoundError debug "skip start for missing container=#{container.id}" rescue => exc error "failed to start container: #{exc.class.name}: #{exc.message}" error exc.backtrace.join("\n") end
ruby
def start_container(container) overlay_cidr = container.overlay_cidr if overlay_cidr wait_weave_running? register_container_dns(container) if container.service_container? attach_overlay(container) else debug "skip start for container=#{container.name} without overlay_cidr" end rescue Docker::Error::NotFoundError debug "skip start for missing container=#{container.id}" rescue => exc error "failed to start container: #{exc.class.name}: #{exc.message}" error exc.backtrace.join("\n") end
[ "def", "start_container", "(", "container", ")", "overlay_cidr", "=", "container", ".", "overlay_cidr", "if", "overlay_cidr", "wait_weave_running?", "register_container_dns", "(", "container", ")", "if", "container", ".", "service_container?", "attach_overlay", "(", "container", ")", "else", "debug", "\"skip start for container=#{container.name} without overlay_cidr\"", "end", "rescue", "Docker", "::", "Error", "::", "NotFoundError", "debug", "\"skip start for missing container=#{container.id}\"", "rescue", "=>", "exc", "error", "\"failed to start container: #{exc.class.name}: #{exc.message}\"", "error", "exc", ".", "backtrace", ".", "join", "(", "\"\\n\"", ")", "end" ]
Ensure weave network for container @param [Docker::Container] container
[ "Ensure", "weave", "network", "for", "container" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/workers/weave_worker.rb#L86-L102
train
kontena/kontena
cli/lib/kontena/plugin_manager.rb
Kontena.PluginManager.init
def init ENV["GEM_HOME"] = Common.install_dir Gem.paths = ENV Common.use_dummy_ui unless Kontena.debug? plugins true end
ruby
def init ENV["GEM_HOME"] = Common.install_dir Gem.paths = ENV Common.use_dummy_ui unless Kontena.debug? plugins true end
[ "def", "init", "ENV", "[", "\"GEM_HOME\"", "]", "=", "Common", ".", "install_dir", "Gem", ".", "paths", "=", "ENV", "Common", ".", "use_dummy_ui", "unless", "Kontena", ".", "debug?", "plugins", "true", "end" ]
Initialize plugin manager
[ "Initialize", "plugin", "manager" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/cli/lib/kontena/plugin_manager.rb#L11-L17
train
kontena/kontena
agent/lib/kontena/logging.rb
Kontena.Logging.debug
def debug(message = nil, &block) logger.add(Logger::DEBUG, message, self.logging_prefix, &block) end
ruby
def debug(message = nil, &block) logger.add(Logger::DEBUG, message, self.logging_prefix, &block) end
[ "def", "debug", "(", "message", "=", "nil", ",", "&", "block", ")", "logger", ".", "add", "(", "Logger", "::", "DEBUG", ",", "message", ",", "self", ".", "logging_prefix", ",", "block", ")", "end" ]
Send a debug message @param message [String] @yield optionally set the message using a block
[ "Send", "a", "debug", "message" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/logging.rb#L32-L34
train
kontena/kontena
agent/lib/kontena/logging.rb
Kontena.Logging.info
def info(message = nil, &block) logger.add(Logger::INFO, message, self.logging_prefix, &block) end
ruby
def info(message = nil, &block) logger.add(Logger::INFO, message, self.logging_prefix, &block) end
[ "def", "info", "(", "message", "=", "nil", ",", "&", "block", ")", "logger", ".", "add", "(", "Logger", "::", "INFO", ",", "message", ",", "self", ".", "logging_prefix", ",", "block", ")", "end" ]
Send a info message @param message [String] @yield optionally set the message using a block
[ "Send", "a", "info", "message" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/logging.rb#L39-L41
train
kontena/kontena
agent/lib/kontena/logging.rb
Kontena.Logging.warn
def warn(message = nil, &block) logger.add(Logger::WARN, message, self.logging_prefix, &block) end
ruby
def warn(message = nil, &block) logger.add(Logger::WARN, message, self.logging_prefix, &block) end
[ "def", "warn", "(", "message", "=", "nil", ",", "&", "block", ")", "logger", ".", "add", "(", "Logger", "::", "WARN", ",", "message", ",", "self", ".", "logging_prefix", ",", "block", ")", "end" ]
Send a warning message @param message [String] @yield optionally set the message using a block
[ "Send", "a", "warning", "message" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/logging.rb#L46-L48
train
kontena/kontena
agent/lib/kontena/logging.rb
Kontena.Logging.error
def error(message = nil, &block) logger.add(Logger::ERROR, message, self.logging_prefix, &block) end
ruby
def error(message = nil, &block) logger.add(Logger::ERROR, message, self.logging_prefix, &block) end
[ "def", "error", "(", "message", "=", "nil", ",", "&", "block", ")", "logger", ".", "add", "(", "Logger", "::", "ERROR", ",", "message", ",", "self", ".", "logging_prefix", ",", "block", ")", "end" ]
Send an error message @param message [String] @yield optionally set the message using a block
[ "Send", "an", "error", "message" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/agent/lib/kontena/logging.rb#L53-L55
train
kontena/kontena
server/lib/mutations/command_errors.rb
Mutations.Command.add_error
def add_error(key, error, message = nil) if error.is_a? Symbol error = ErrorAtom.new(key, error, message: message) elsif error.is_a?(Mutations::ErrorAtom) || error.is_a?(Mutations::ErrorArray) || error.is_a?(Mutations::ErrorHash) else raise ArgumentError.new("Invalid error of kind #{error.class}") end @errors ||= ErrorHash.new @errors.tap do |errs| path = key.to_s.split(".") last = path.pop inner = path.inject(errs) do |cur_errors,part| cur_errors[part.to_sym] ||= ErrorHash.new end inner[last] = error end end
ruby
def add_error(key, error, message = nil) if error.is_a? Symbol error = ErrorAtom.new(key, error, message: message) elsif error.is_a?(Mutations::ErrorAtom) || error.is_a?(Mutations::ErrorArray) || error.is_a?(Mutations::ErrorHash) else raise ArgumentError.new("Invalid error of kind #{error.class}") end @errors ||= ErrorHash.new @errors.tap do |errs| path = key.to_s.split(".") last = path.pop inner = path.inject(errs) do |cur_errors,part| cur_errors[part.to_sym] ||= ErrorHash.new end inner[last] = error end end
[ "def", "add_error", "(", "key", ",", "error", ",", "message", "=", "nil", ")", "if", "error", ".", "is_a?", "Symbol", "error", "=", "ErrorAtom", ".", "new", "(", "key", ",", "error", ",", "message", ":", "message", ")", "elsif", "error", ".", "is_a?", "(", "Mutations", "::", "ErrorAtom", ")", "||", "error", ".", "is_a?", "(", "Mutations", "::", "ErrorArray", ")", "||", "error", ".", "is_a?", "(", "Mutations", "::", "ErrorHash", ")", "else", "raise", "ArgumentError", ".", "new", "(", "\"Invalid error of kind #{error.class}\"", ")", "end", "@errors", "||=", "ErrorHash", ".", "new", "@errors", ".", "tap", "do", "|", "errs", "|", "path", "=", "key", ".", "to_s", ".", "split", "(", "\".\"", ")", "last", "=", "path", ".", "pop", "inner", "=", "path", ".", "inject", "(", "errs", ")", "do", "|", "cur_errors", ",", "part", "|", "cur_errors", "[", "part", ".", "to_sym", "]", "||=", "ErrorHash", ".", "new", "end", "inner", "[", "last", "]", "=", "error", "end", "end" ]
Add error for a key @param key [Symbol] :foo @param key [String] 'foo.bar' @param error [Symbol] :not_found @param error [Mutations:ErrorAtom, Mutations::ErrorArray, Mutations::ErrorHash]
[ "Add", "error", "for", "a", "key" ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/server/lib/mutations/command_errors.rb#L13-L31
train
kontena/kontena
cli/lib/kontena/cli/helpers/exec_helper.rb
Kontena::Cli::Helpers.ExecHelper.websocket_exec_write_thread
def websocket_exec_write_thread(ws, tty: nil) Thread.new do begin if tty console_height, console_width = TTY::Screen.size websocket_exec_write(ws, 'tty_size' => { width: console_width, height: console_height }) end read_stdin(tty: tty) do |stdin| logger.debug "websocket exec stdin with encoding=#{stdin.encoding}: #{stdin.inspect}" websocket_exec_write(ws, 'stdin' => stdin) end websocket_exec_write(ws, 'stdin' => nil) # EOF rescue => exc logger.error exc ws.close(1001, "stdin read #{exc.class}: #{exc}") end end end
ruby
def websocket_exec_write_thread(ws, tty: nil) Thread.new do begin if tty console_height, console_width = TTY::Screen.size websocket_exec_write(ws, 'tty_size' => { width: console_width, height: console_height }) end read_stdin(tty: tty) do |stdin| logger.debug "websocket exec stdin with encoding=#{stdin.encoding}: #{stdin.inspect}" websocket_exec_write(ws, 'stdin' => stdin) end websocket_exec_write(ws, 'stdin' => nil) # EOF rescue => exc logger.error exc ws.close(1001, "stdin read #{exc.class}: #{exc}") end end end
[ "def", "websocket_exec_write_thread", "(", "ws", ",", "tty", ":", "nil", ")", "Thread", ".", "new", "do", "begin", "if", "tty", "console_height", ",", "console_width", "=", "TTY", "::", "Screen", ".", "size", "websocket_exec_write", "(", "ws", ",", "'tty_size'", "=>", "{", "width", ":", "console_width", ",", "height", ":", "console_height", "}", ")", "end", "read_stdin", "(", "tty", ":", "tty", ")", "do", "|", "stdin", "|", "logger", ".", "debug", "\"websocket exec stdin with encoding=#{stdin.encoding}: #{stdin.inspect}\"", "websocket_exec_write", "(", "ws", ",", "'stdin'", "=>", "stdin", ")", "end", "websocket_exec_write", "(", "ws", ",", "'stdin'", "=>", "nil", ")", "# EOF", "rescue", "=>", "exc", "logger", ".", "error", "exc", "ws", ".", "close", "(", "1001", ",", "\"stdin read #{exc.class}: #{exc}\"", ")", "end", "end", "end" ]
Start thread to read from stdin, and write to websocket. Closes websocket on stdin read errors. @param ws [Kontena::Websocket::Client] @param tty [Boolean] @return [Thread]
[ "Start", "thread", "to", "read", "from", "stdin", "and", "write", "to", "websocket", ".", "Closes", "websocket", "on", "stdin", "read", "errors", "." ]
5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7
https://github.com/kontena/kontena/blob/5cb5b4457895985231ac88e78c8cbc5a8ffb5ec7/cli/lib/kontena/cli/helpers/exec_helper.rb#L107-L126
train