_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q14400 | Mailgun.Client.put | train | def put(resource_path, data)
response = @http_client[resource_path].put(data)
Response.new(response)
rescue => err
raise communication_error err
end | ruby | {
"resource": ""
} |
q14401 | Mailgun.Client.delete | train | def delete(resource_path)
response = @http_client[resource_path].delete
Response.new(response)
rescue => err
raise communication_error err
end | ruby | {
"resource": ""
} |
q14402 | Mailgun.Client.convert_string_to_file | train | def convert_string_to_file(string)
file = Tempfile.new('MG_TMP_MIME')
file.write(string)
file.rewind
file
end | ruby | {
"resource": ""
} |
q14403 | Mailgun.Client.communication_error | train | def communication_error(e)
return CommunicationError.new(e.message, e.response) if e.respond_to? :response
CommunicationError.new(e.message)
end | ruby | {
"resource": ""
} |
q14404 | ForemanAnsible.FactParser.get_interfaces | train | def get_interfaces # rubocop:disable Naming/AccessorMethodName
pref = facts[:ansible_default_ipv4] &&
facts[:ansible_default_ipv4]['interface']
if pref.present?
(facts[:ansible_interfaces] - [pref]).unshift(pref)
else
ansible_interfaces
end
end | ruby | {
"resource": ""
} |
q14405 | BrowseEverything.Retriever.download | train | def download(spec, target = nil)
if target.nil?
ext = File.extname(spec['file_name'])
base = File.basename(spec['file_name'], ext)
target = Dir::Tmpname.create([base, ext]) {}
end
File.open(target, 'wb') do |output|
retrieve(spec) do |chunk, retrieved, total|
... | ruby | {
"resource": ""
} |
q14406 | BrowseEverything.Retriever.retrieve | train | def retrieve(options, &block)
expiry_time_value = options.fetch('expires', nil)
if expiry_time_value
expiry_time = Time.parse(expiry_time_value)
raise ArgumentError, "Download expired at #{expiry_time}" if expiry_time < Time.now
end
download_options = extract_download_options(op... | ruby | {
"resource": ""
} |
q14407 | BrowseEverything.Retriever.extract_download_options | train | def extract_download_options(options)
url = options.fetch('url')
# This avoids the potential for a KeyError
headers = options.fetch('headers', {}) || {}
file_size_value = options.fetch('file_size', 0)
file_size = file_size_value.to_i
output = {
url: ::Address... | ruby | {
"resource": ""
} |
q14408 | BrowseEverything.Retriever.retrieve_file | train | def retrieve_file(options)
file_uri = options.fetch(:url)
file_size = options.fetch(:file_size)
retrieved = 0
File.open(file_uri.path, 'rb') do |f|
until f.eof?
chunk = f.read(chunk_size)
retrieved += chunk.length
yield(chunk, retrieved, fil... | ruby | {
"resource": ""
} |
q14409 | BrowseEverything.Retriever.retrieve_http | train | def retrieve_http(options)
file_size = options.fetch(:file_size)
headers = options.fetch(:headers)
url = options.fetch(:url)
retrieved = 0
request = Typhoeus::Request.new(url.to_s, method: :get, headers: headers)
request.on_headers do |response|
raise DownloadE... | ruby | {
"resource": ""
} |
q14410 | BrowseEverything.Retriever.get_file_size | train | def get_file_size(options)
url = options.fetch(:url)
headers = options.fetch(:headers)
file_size = options.fetch(:file_size)
case url.scheme
when 'file'
File.size(url.path)
when /https?/
response = Typhoeus.head(url.to_s, headers: headers)
l... | ruby | {
"resource": ""
} |
q14411 | MQTT.Packet.update_attributes | train | def update_attributes(attr = {})
attr.each_pair do |k, v|
if v.is_a?(Array) || v.is_a?(Hash)
send("#{k}=", v.dup)
else
send("#{k}=", v)
end
end
end | ruby | {
"resource": ""
} |
q14412 | MQTT.Packet.to_s | train | def to_s
# Encode the fixed header
header = [
((type_id.to_i & 0x0F) << 4) |
(flags[3] ? 0x8 : 0x0) |
(flags[2] ? 0x4 : 0x0) |
(flags[1] ? 0x2 : 0x0) |
(flags[0] ? 0x1 : 0x0)
]
# Get the packet's variable header and payload
body = encode_bod... | ruby | {
"resource": ""
} |
q14413 | MQTT.Packet.shift_bits | train | def shift_bits(buffer)
buffer.slice!(0...1).unpack('b8').first.split('').map { |b| b == '1' }
end | ruby | {
"resource": ""
} |
q14414 | MQTT.Packet.shift_string | train | def shift_string(buffer)
len = shift_short(buffer)
str = shift_data(buffer, len)
# Strings in MQTT v3.1 are all UTF-8
str.force_encoding('UTF-8')
end | ruby | {
"resource": ""
} |
q14415 | MQTT.Client.key_file= | train | def key_file=(*args)
path, passphrase = args.flatten
ssl_context.key = OpenSSL::PKey::RSA.new(File.open(path), passphrase)
end | ruby | {
"resource": ""
} |
q14416 | MQTT.Client.key= | train | def key=(*args)
cert, passphrase = args.flatten
ssl_context.key = OpenSSL::PKey::RSA.new(cert, passphrase)
end | ruby | {
"resource": ""
} |
q14417 | MQTT.Client.ca_file= | train | def ca_file=(path)
ssl_context.ca_file = path
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER unless path.nil?
end | ruby | {
"resource": ""
} |
q14418 | MQTT.Client.set_will | train | def set_will(topic, payload, retain = false, qos = 0)
self.will_topic = topic
self.will_payload = payload
self.will_retain = retain
self.will_qos = qos
end | ruby | {
"resource": ""
} |
q14419 | MQTT.Client.connect | train | def connect(clientid = nil)
@client_id = clientid unless clientid.nil?
if @client_id.nil? || @client_id.empty?
raise 'Must provide a client_id if clean_session is set to false' unless @clean_session
# Empty client id is not allowed for version 3.1.0
@client_id = MQTT::Client.genera... | ruby | {
"resource": ""
} |
q14420 | MQTT.Client.disconnect | train | def disconnect(send_msg = true)
# Stop reading packets from the socket first
@read_thread.kill if @read_thread && @read_thread.alive?
@read_thread = nil
return unless connected?
# Close the socket if it is open
if send_msg
packet = MQTT::Packet::Disconnect.new
send_... | ruby | {
"resource": ""
} |
q14421 | MQTT.Client.publish | train | def publish(topic, payload = '', retain = false, qos = 0)
raise ArgumentError, 'Topic name cannot be nil' if topic.nil?
raise ArgumentError, 'Topic name cannot be empty' if topic.empty?
packet = MQTT::Packet::Publish.new(
:id => next_packet_id,
:qos => qos,
:retain => retain,
... | ruby | {
"resource": ""
} |
q14422 | MQTT.Client.get | train | def get(topic = nil, options = {})
if block_given?
get_packet(topic) do |packet|
yield(packet.topic, packet.payload) unless packet.retain && options[:omit_retained]
end
else
loop do
# Wait for one packet to be available
packet = get_packet(topic)
... | ruby | {
"resource": ""
} |
q14423 | MQTT.Client.get_packet | train | def get_packet(topic = nil)
# Subscribe to a topic, if an argument is given
subscribe(topic) unless topic.nil?
if block_given?
# Loop forever!
loop do
packet = @read_queue.pop
yield(packet)
puback_packet(packet) if packet.qos > 0
end
else
... | ruby | {
"resource": ""
} |
q14424 | MQTT.Client.unsubscribe | train | def unsubscribe(*topics)
topics = topics.first if topics.is_a?(Enumerable) && topics.count == 1
packet = MQTT::Packet::Unsubscribe.new(
:topics => topics,
:id => next_packet_id
)
send_packet(packet)
end | ruby | {
"resource": ""
} |
q14425 | MQTT.Client.receive_packet | train | def receive_packet
# Poll socket - is there data waiting?
result = IO.select([@socket], [], [], SELECT_TIMEOUT)
unless result.nil?
# Yes - read in the packet
packet = MQTT::Packet.read(@socket)
handle_packet packet
end
keep_alive!
# Pass exceptions up to parent ... | ruby | {
"resource": ""
} |
q14426 | MQTT.Client.receive_connack | train | def receive_connack
Timeout.timeout(@ack_timeout) do
packet = MQTT::Packet.read(@socket)
if packet.class != MQTT::Packet::Connack
raise MQTT::ProtocolException, "Response wasn't a connection acknowledgement: #{packet.class}"
end
# Check the return code
if packet.... | ruby | {
"resource": ""
} |
q14427 | MQTT.Client.send_packet | train | def send_packet(data)
# Raise exception if we aren't connected
raise MQTT::NotConnectedException unless connected?
# Only allow one thread to write to socket at a time
@write_semaphore.synchronize do
@socket.write(data.to_s)
end
end | ruby | {
"resource": ""
} |
q14428 | MQTT.Proxy.run | train | def run
loop do
# Wait for a client to connect and then create a thread for it
Thread.new(@server.accept) do |client_socket|
logger.info "Accepted client: #{client_socket.peeraddr.join(':')}"
server_socket = TCPSocket.new(@server_host, @server_port)
begin
... | ruby | {
"resource": ""
} |
q14429 | InfluxDB.Config.configure_hosts! | train | def configure_hosts!(hosts)
@hosts_queue = Queue.new
Array(hosts).each do |host|
@hosts_queue.push(host)
end
end | ruby | {
"resource": ""
} |
q14430 | InfluxDB.Config.opts_from_url | train | def opts_from_url(url)
url = URI.parse(url) unless url.is_a?(URI)
opts_from_non_params(url).merge opts_from_params(url.query)
rescue URI::InvalidURIError
{}
end | ruby | {
"resource": ""
} |
q14431 | Fear.Future.on_complete_match | train | def on_complete_match
promise.add_observer do |_time, try, _error|
Fear::Try.matcher { |m| yield(m) }.call_or_else(try, &:itself)
end
self
end | ruby | {
"resource": ""
} |
q14432 | Fear.Future.transform | train | def transform(success, failure)
promise = Promise.new(@options)
on_complete_match do |m|
m.success { |value| promise.success(success.call(value)) }
m.failure { |error| promise.failure(failure.call(error)) }
end
promise.to_future
end | ruby | {
"resource": ""
} |
q14433 | Fear.Future.map | train | def map(&block)
promise = Promise.new(@options)
on_complete do |try|
promise.complete!(try.map(&block))
end
promise.to_future
end | ruby | {
"resource": ""
} |
q14434 | Fear.Future.flat_map | train | def flat_map # rubocop: disable Metrics/MethodLength
promise = Promise.new(@options)
on_complete_match do |m|
m.case(Fear::Failure) { |failure| promise.complete!(failure) }
m.success do |value|
begin
yield(value).on_complete { |callback_result| promise.complete!(callbac... | ruby | {
"resource": ""
} |
q14435 | Fear.Future.zip | train | def zip(other) # rubocop: disable Metrics/MethodLength
promise = Promise.new(@options)
on_complete_match do |m|
m.success do |value|
other.on_complete do |other_try|
promise.complete!(other_try.map { |other_value| [value, other_value] })
end
end
m.fail... | ruby | {
"resource": ""
} |
q14436 | Fear.Future.fallback_to | train | def fallback_to(fallback)
promise = Promise.new(@options)
on_complete_match do |m|
m.success { |value| promise.complete!(value) }
m.failure do |error|
fallback.on_complete_match do |m2|
m2.success { |value| promise.complete!(value) }
m2.failure { promise.fai... | ruby | {
"resource": ""
} |
q14437 | Fear.OptionPatternMatch.some | train | def some(*conditions, &effect)
branch = Fear.case(Fear::Some, &GET_METHOD).and_then(Fear.case(*conditions, &effect))
or_else(branch)
end | ruby | {
"resource": ""
} |
q14438 | Lines.Article.used_images | train | def used_images
result = content.scan(/!\[.*\]\(.*\/image\/(\d.*)\/.*\)/)
image_ids = result.nil? ? nil : result.map{ |i| i[0].to_i }.uniq
image_ids
end | ruby | {
"resource": ""
} |
q14439 | Lines.Article.update_used_images | train | def update_used_images
ActionController::Base.new.expire_fragment(self)
image_ids = self.used_images
if !image_ids.nil?
Picture.where(id: image_ids).each do |picture|
picture.update_attributes(article_id: self.id)
end
end
end | ruby | {
"resource": ""
} |
q14440 | Lines.Article.refresh_sitemap | train | def refresh_sitemap
if self.published
if Rails.env == 'production' && ENV["CONFIG_FILE"]
SitemapGenerator::Interpreter.run(config_file: ENV["CONFIG_FILE"])
SitemapGenerator::Sitemap.ping_search_engines
end
end
end | ruby | {
"resource": ""
} |
q14441 | Lines.ArticlesController.index | train | def index
respond_to do |format|
format.html {
@first_page = (params[:page] and params[:page].to_i > 0) ? false : true
if params[:tag]
@articles = Lines::Article.published.tagged_with(params[:tag]).page(params[:page].to_i)
else
@articles = Lines::Artic... | ruby | {
"resource": ""
} |
q14442 | Lines.ArticlesController.show | train | def show
@first_page = true
@article = Lines::Article.published.find(params[:id])
@article.teaser = nil unless @article.teaser.present?
meta_tags = { title: @article.title,
type: 'article',
url: url_for(@article),
site_name: SITE_TITLE,
}
meta_tags[:image] = C... | ruby | {
"resource": ""
} |
q14443 | Lines.ApplicationHelper.render_teaser | train | def render_teaser(article, article_counter=0)
if article_counter < 0
teaser = article.teaser && article.teaser.present? ? markdown(article.teaser) : nil
else
teaser = article.teaser && article.teaser.present? ? format_code(article.teaser) : format_code(article.content)
end
teaser... | ruby | {
"resource": ""
} |
q14444 | Lines.ApplicationHelper.markdown | train | def markdown(text)
renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: false, with_toc_data: false)
options = {
autolink: true,
no_intra_emphasis: true,
fenced_code_blocks: true,
lax_html_blocks: true,
tables: true,
strikethrough: true,
super... | ruby | {
"resource": ""
} |
q14445 | Lines.ApplicationHelper.nav_link | train | def nav_link(link_text, link_path)
recognized = Rails.application.routes.recognize_path(link_path)
class_name = recognized[:controller] == params[:controller] ? 'active' : ''
content_tag(:li, class: class_name) do
link_to link_text, link_path
end
end | ruby | {
"resource": ""
} |
q14446 | Lines.ApplicationHelper.display_article_authors | train | def display_article_authors(article, with_info=false)
authors = article.authors.map{|author| author.gplus_profile.blank? ? author.name : link_to(author.name, author.gplus_profile)}.to_sentence(two_words_connector: " & ", last_word_connector: " & ").html_safe
if with_info
authors += (" — " + article.... | ruby | {
"resource": ""
} |
q14447 | Lines.ApplicationHelper.render_navbar | train | def render_navbar(&block)
action_link = get_action_link
if !action_link
action_link = CONFIG[:title_short]
end
html = content_tag(:div, id: 'navbar') do
content_tag(:div, class: 'navbar-inner') do
if current_lines_user
content_tag(:span, class: 'buttons', &b... | ruby | {
"resource": ""
} |
q14448 | Lines.ApplicationHelper.get_action_link | train | def get_action_link
if controller_path == 'admin/articles'
case action_name
when 'index' then t('lines/buttons/all_articles').html_safe
when 'new' then t('lines/buttons/new_article').html_safe
when 'edit' then t('lines/buttons/edit_article').html_safe
when 'show' th... | ruby | {
"resource": ""
} |
q14449 | Lines.User.create_reset_digest | train | def create_reset_digest
self.reset_token = Lines::User.generate_token
update_attribute(:reset_digest, Lines::User.digest(reset_token))
update_attribute(:reset_sent_at, Time.zone.now)
end | ruby | {
"resource": ""
} |
q14450 | Lines.SessionsController.create | train | def create
user = Lines::User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to admin_root_url
else
flash.now[:error] = t('lines.login_error')
render "new"
end
end | ruby | {
"resource": ""
} |
q14451 | Net.VNC.type | train | def type text, options={}
packet = 0.chr * 8
packet[0] = 4.chr
text.split(//).each do |char|
packet[7] = char[0]
packet[1] = 1.chr
socket.write packet
packet[1] = 0.chr
socket.write packet
end
wait options
end | ruby | {
"resource": ""
} |
q14452 | Net.VNC.type_string | train | def type_string text, options={}
shift_key_down = nil
text.each_char do |char|
key_to_press = KEY_PRESS_CHARS[char]
unless key_to_press.nil?
key_press key_to_press
else
key_needs_shift = SHIFTED_CHARS.include? char
if shift_key_down.nil? || shift_key_d... | ruby | {
"resource": ""
} |
q14453 | Veewee.Templates.valid_paths | train | def valid_paths(paths)
paths = GemContent.get_gem_paths("veewee-templates")
valid_paths = paths.collect { |path|
if File.exists?(path) && File.directory?(path)
env.logger.info "Path #{path} exists"
File.expand_path(path)
else
env.logger.info "Path #{path} does n... | ruby | {
"resource": ""
} |
q14454 | Veewee.Config.load_veewee_config | train | def load_veewee_config()
veewee_configurator = self
begin
filename = @env.config_filepath
if File.exists?(filename)
env.logger.info("Loading config file: #{filename}")
veeweefile = File.read(filename)
veeweefile["Veewee::Config.run"] = "veewee_configurator.defin... | ruby | {
"resource": ""
} |
q14455 | Veewee.Definition.declare | train | def declare(options)
options.each do |key, value|
instance_variable_set("@#{key}".to_sym, options[key])
env.logger.info("definition") { " - #{key} : #{options[key]}" }
end
end | ruby | {
"resource": ""
} |
q14456 | Fission.VM.mac_address | train | def mac_address
raise ::Fission::Error,"VM #{@name} does not exist" unless self.exists?
line=File.new(vmx_path).grep(/^ethernet0.generatedAddress =/)
if line.nil?
#Fission.ui.output "Hmm, the vmx file #{vmx_path} does not contain a generated mac address "
return nil
end
ad... | ruby | {
"resource": ""
} |
q14457 | Fission.VM.ip_address | train | def ip_address
raise ::Fission::Error,"VM #{@name} does not exist" unless self.exists?
unless mac_address.nil?
lease=LeasesFile.new("/var/db/vmware/vmnet-dhcpd-vmnet8.leases").find_lease_by_mac(mac_address)
if lease.nil?
return nil
else
return lease.ip
en... | ruby | {
"resource": ""
} |
q14458 | Veewee.Definitions.each | train | def each(&block)
definitions = Hash.new
env.logger.debug("[Definition] Searching #{env.definition_dir} for definitions:")
subdirs = Dir.glob("#{env.definition_dir}/*")
subdirs.each do |sub|
name = File.basename(sub)
env.logger.debug("[Definition] possible definition '#{name}' f... | ruby | {
"resource": ""
} |
q14459 | CF::UAA.SpecHelper.frequest | train | def frequest(on_fiber, &blk)
return capture_exception(&blk) unless on_fiber
result, cthred = nil, Thread.current
EM.schedule { Fiber.new { result = capture_exception(&blk); cthred.run }.resume }
Thread.stop
result
end | ruby | {
"resource": ""
} |
q14460 | CF::UAA.StubUAAConn.bad_params? | train | def bad_params?(params, required, optional = nil)
required.each {|r|
next if params[r]
reply.json(400, error: 'invalid_request', error_description: "no #{r} in request")
return true
}
return false unless optional
params.each {|k, v|
next if required.include?(k) || optional.includ... | ruby | {
"resource": ""
} |
q14461 | Stub.Request.completed? | train | def completed?(str)
str, @prelude = @prelude + str, "" unless @prelude.empty?
add_lines(str)
return unless @state == :body && @body.bytesize >= @content_length
@prelude = bslice(@body, @content_length..-1)
@body = bslice(@body, 0..@content_length)
@state = :init
end | ruby | {
"resource": ""
} |
q14462 | ArJdbc.Derby.type_to_sql | train | def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless NO_LIMIT_TYPES.include?(t = type.to_s.downcase.to_sym)
native_type = NATIVE_DATABASE_TYPES[t]
native_type.is_a?(Hash) ? native_type[:name] : native_type
end | ruby | {
"resource": ""
} |
q14463 | ArJdbc.Oracle.default_owner | train | def default_owner
unless defined? @default_owner
username = config[:username] ? config[:username].to_s : jdbc_connection.meta_data.user_name
@default_owner = username.nil? ? nil : username.upcase
end
@default_owner
end | ruby | {
"resource": ""
} |
q14464 | ArJdbc.AS400.execute_and_auto_confirm | train | def execute_and_auto_confirm(sql, name = nil)
begin
@connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)',0000000031.00000)"
@connection.execute_update "call qsys.qcmdexc('ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY(''I'')',0000000045.00000)"
rescue Exception => e
... | ruby | {
"resource": ""
} |
q14465 | ArJdbc.AS400.table_exists? | train | def table_exists?(name)
return false unless name
schema ? @connection.table_exists?(name, schema) : @connection.table_exists?(name)
end | ruby | {
"resource": ""
} |
q14466 | ArJdbc.MSSQL.exec_proc | train | def exec_proc(proc_name, *variables)
vars =
if variables.any? && variables.first.is_a?(Hash)
variables.first.map { |k, v| "@#{k} = #{quote(v)}" }
else
variables.map { |v| quote(v) }
end.join(', ')
sql = "EXEC #{proc_name} #{vars}".strip
log(sql, 'Execute Pro... | ruby | {
"resource": ""
} |
q14467 | ArJdbc.MSSQL.exec_query | train | def exec_query(sql, name = 'SQL', binds = [])
# NOTE: we allow to execute SQL as requested returning a results.
# e.g. this allows to use SQLServer's EXEC with a result set ...
sql = to_sql(sql, binds) if sql.respond_to?(:to_sql)
sql = repair_special_columns(sql)
if prepared_statements?
... | ruby | {
"resource": ""
} |
q14468 | ArJdbc.PostgreSQL.configure_connection | train | def configure_connection
#if encoding = config[:encoding]
# The client_encoding setting is set by the driver and should not be altered.
# If the driver detects a change it will abort the connection.
# see http://jdbc.postgresql.org/documentation/91/connect.html
# self.set_client_en... | ruby | {
"resource": ""
} |
q14469 | DelayedJob.NextMigrationVersion.next_migration_number | train | def next_migration_number(dirname)
next_migration_number = current_migration_number(dirname) + 1
if ActiveRecord::Base.timestamped_migrations
[Time.now.utc.strftime("%Y%m%d%H%M%S"), format("%.14d", next_migration_number)].max
else
format("%.3d", next_migration_number)
end
end | ruby | {
"resource": ""
} |
q14470 | Diplomat.Maintenance.enabled | train | def enabled(n, options = {})
health = Diplomat::Health.new(@conn)
result = health.node(n, options)
.select { |check| check['CheckID'] == '_node_maintenance' }
if result.empty?
{ enabled: false, reason: nil }
else
{ enabled: true, reason: result.first['Notes'... | ruby | {
"resource": ""
} |
q14471 | Diplomat.Maintenance.enable | train | def enable(enable = true, reason = nil, options = {})
custom_params = []
custom_params << use_named_parameter('enable', enable.to_s)
custom_params << use_named_parameter('reason', reason) if reason
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
raw = send_put_requ... | ruby | {
"resource": ""
} |
q14472 | Diplomat.Session.create | train | def create(value = nil, options = {})
# TODO: only certain keys are recognised in a session create request,
# should raise an error on others.
custom_params = []
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
data = value.is_a?(String) ? value : JSON.generate(valu... | ruby | {
"resource": ""
} |
q14473 | Diplomat.Session.destroy | train | def destroy(id, options = {})
custom_params = []
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
raw = send_put_request(@conn, ["/v1/session/destroy/#{id}"], options, nil, custom_params)
raw.body
end | ruby | {
"resource": ""
} |
q14474 | Diplomat.Query.create | train | def create(definition, options = {})
custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
@raw = send_post_request(@conn, ['/v1/query'], options, definition, custom_params)
parse_body
rescue Faraday::ClientError
raise Diplomat::QueryAlreadyExists
end | ruby | {
"resource": ""
} |
q14475 | Diplomat.Query.delete | train | def delete(key, options = {})
custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
ret = send_delete_request(@conn, ["/v1/query/#{key}"], options, custom_params)
ret.status == 200
end | ruby | {
"resource": ""
} |
q14476 | Diplomat.Query.update | train | def update(key, definition, options = {})
custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
ret = send_put_request(@conn, ["/v1/query/#{key}"], options, definition, custom_params)
ret.status == 200
end | ruby | {
"resource": ""
} |
q14477 | Diplomat.Query.execute | train | def execute(key, options = {})
custom_params = []
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
custom_params << use_named_parameter('near', options[:near]) if options[:near]
custom_params << use_named_parameter('limit', options[:limit]) if options[:limit]
ret = ... | ruby | {
"resource": ""
} |
q14478 | Diplomat.Check.register_script | train | def register_script(check_id, name, notes, args, interval, options = {})
unless args.is_a?(Array)
raise(Diplomat::DeprecatedArgument, 'Script usage is deprecated, replace by an array of args')
end
definition = JSON.generate(
'ID' => check_id,
'Name' => name,
'Notes' =>... | ruby | {
"resource": ""
} |
q14479 | Diplomat.Check.update_ttl | train | def update_ttl(check_id, status, output = nil, options = {})
definition = JSON.generate(
'Status' => status,
'Output' => output
)
ret = send_put_request(@conn, ["/v1/agent/check/update/#{check_id}"], options, definition)
ret.status == 200
end | ruby | {
"resource": ""
} |
q14480 | Diplomat.Kv.get | train | def get(key, options = {}, not_found = :reject, found = :return)
key_subst = if key.start_with? '/'
key[1..-1]
else
key.freeze
end
@key = key_subst
@options = options
custom_params = []
custom_params << recurse_get... | ruby | {
"resource": ""
} |
q14481 | Diplomat.Kv.delete | train | def delete(key, options = {})
@key = key
@options = options
custom_params = []
custom_params << recurse_get(@options)
custom_params << dc(@options)
@raw = send_delete_request(@conn, ["/v1/kv/#{@key}"], options, custom_params)
end | ruby | {
"resource": ""
} |
q14482 | Diplomat.Event.fire | train | def fire(name, value = nil, service = nil, node = nil, tag = nil, dc = nil, options = {})
custom_params = []
custom_params << use_named_parameter('service', service) if service
custom_params << use_named_parameter('node', node) if node
custom_params << use_named_parameter('tag', tag) if tag
... | ruby | {
"resource": ""
} |
q14483 | Diplomat.Event.get | train | def get(name = nil, token = :last, not_found = :wait, found = :return, options = {})
@raw = send_get_request(@conn, ['/v1/event/list'], options, use_named_parameter('name', name))
body = JSON.parse(@raw.body)
# TODO: deal with unknown symbols, invalid indices (find_index will return nil)
idx = c... | ruby | {
"resource": ""
} |
q14484 | Diplomat.Service.get | train | def get(key, scope = :first, options = {}, meta = nil)
custom_params = []
custom_params << use_named_parameter('wait', options[:wait]) if options[:wait]
custom_params << use_named_parameter('index', options[:index]) if options[:index]
custom_params << use_named_parameter('dc', options[:dc]) if o... | ruby | {
"resource": ""
} |
q14485 | Diplomat.Service.register | train | def register(definition, options = {})
url = options[:path] || ['/v1/agent/service/register']
register = send_put_request(@conn, url, options, definition)
register.status == 200
end | ruby | {
"resource": ""
} |
q14486 | Diplomat.Service.maintenance | train | def maintenance(service_id, options = { enable: true })
custom_params = []
custom_params << ["enable=#{options[:enable]}"]
custom_params << ["reason=#{options[:reason].split(' ').join('+')}"] if options[:reason]
maintenance = send_put_request(@conn, ["/v1/agent/service/maintenance/#{service_id}"... | ruby | {
"resource": ""
} |
q14487 | Diplomat.Health.node | train | def node(n, options = {})
custom_params = []
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
ret = send_get_request(@conn, ["/v1/health/node/#{n}"], options, custom_params)
JSON.parse(ret.body).map { |node| OpenStruct.new node }
end | ruby | {
"resource": ""
} |
q14488 | Diplomat.Health.checks | train | def checks(s, options = {})
custom_params = []
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
ret = send_get_request(@conn, ["/v1/health/checks/#{s}"], options, custom_params)
JSON.parse(ret.body).map { |check| OpenStruct.new check }
end | ruby | {
"resource": ""
} |
q14489 | Diplomat.Health.service | train | def service(s, options = {})
custom_params = []
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
custom_params << ['passing'] if options[:passing]
custom_params << use_named_parameter('tag', options[:tag]) if options[:tag]
custom_params << use_named_parameter('near'... | ruby | {
"resource": ""
} |
q14490 | Diplomat.Lock.acquire | train | def acquire(key, session, value = nil, options = {})
custom_params = []
custom_params << use_named_parameter('acquire', session)
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
custom_params << use_named_parameter('flags', options[:flags]) if options && options[:flags]
... | ruby | {
"resource": ""
} |
q14491 | Diplomat.Lock.wait_to_acquire | train | def wait_to_acquire(key, session, value = nil, check_interval = 10, options = {})
acquired = false
until acquired
acquired = acquire(key, session, value, options)
sleep(check_interval) unless acquired
return true if acquired
end
end | ruby | {
"resource": ""
} |
q14492 | Diplomat.Lock.release | train | def release(key, session, options = {})
custom_params = []
custom_params << use_named_parameter('release', session)
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
custom_params << use_named_parameter('flags', options[:flags]) if options && options[:flags]
raw = se... | ruby | {
"resource": ""
} |
q14493 | Diplomat.RestClient.concat_url | train | def concat_url(parts)
parts.reject!(&:empty?)
if parts.length > 1
parts.first + '?' + parts.drop(1).join('&')
else
parts.first
end
end | ruby | {
"resource": ""
} |
q14494 | Diplomat.Acl.info | train | def info(id, options = {}, not_found = :reject, found = :return)
@id = id
@options = options
custom_params = []
custom_params << use_consistency(options)
raw = send_get_request(@conn_no_err, ["/v1/acl/info/#{id}"], options, custom_params)
if raw.status == 200 && raw.body.chomp != '... | ruby | {
"resource": ""
} |
q14495 | Diplomat.Acl.update | train | def update(value, options = {})
raise Diplomat::IdParameterRequired unless value['ID'] || value[:ID]
custom_params = use_cas(@options)
@raw = send_put_request(@conn, ['/v1/acl/update'], options, value, custom_params)
parse_body
end | ruby | {
"resource": ""
} |
q14496 | Diplomat.Acl.create | train | def create(value, options = {})
custom_params = use_cas(@options)
@raw = send_put_request(@conn, ['/v1/acl/create'], options, value, custom_params)
parse_body
end | ruby | {
"resource": ""
} |
q14497 | Diplomat.Datacenter.get | train | def get(meta = nil, options = {})
ret = send_get_request(@conn, ['/v1/catalog/datacenters'], options)
if meta && ret.headers
meta[:index] = ret.headers['x-consul-index'] if ret.headers['x-consul-index']
meta[:knownleader] = ret.headers['x-consul-knownleader'] if ret.headers['x-consul-knownl... | ruby | {
"resource": ""
} |
q14498 | Gemstash.Resource.update_properties | train | def update_properties(props)
load_properties(true)
deep_merge = proc do |_, old_value, new_value|
if old_value.is_a?(Hash) && new_value.is_a?(Hash)
old_value.merge(new_value, &deep_merge)
else
new_value
end
end
props = properties.merge(props || {}, &... | ruby | {
"resource": ""
} |
q14499 | Gemstash.Resource.property? | train | def property?(*keys)
keys.inject(node: properties, result: true) do |memo, key|
if memo[:result]
memo[:result] = memo[:node].is_a?(Hash) && memo[:node].include?(key)
memo[:node] = memo[:node][key] if memo[:result]
end
memo
end[:result]
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.