_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q19600 | Kms.PageFetcher.fetch_templatable_page! | train | def fetch_templatable_page!
parent_page_path = File.dirname(@path)
parent_page_path = Kms::Page::INDEX_FULLPATH if parent_page_path == "."
parent_page = Kms::Page.published.find_by_fullpath!(parent_page_path)
templatable_pages = parent_page.children.where(templatable: true)
templatable_pag... | ruby | {
"resource": ""
} |
q19601 | Kms.Permalinkable.permalink | train | def permalink
templatable_page = Kms::Page.where(templatable_type: self.class.name).first
if templatable_page
Pathname.new(templatable_page.parent.fullpath).join(slug.to_s).to_s
end
end | ruby | {
"resource": ""
} |
q19602 | Yell.Level.set | train | def set( *severities )
@severities = Yell::Severities.map { true }
severity = severities.length > 1 ? severities : severities.first
case severity
when Array then at(*severity)
when Range then gte(severity.first).lte(severity.last)
when String then interpret(severity)
when Inte... | ruby | {
"resource": ""
} |
q19603 | ShowFor.Helper.show_for | train | def show_for(object, html_options={}, &block)
html_options = html_options.dup
tag = html_options.delete(:show_for_tag) || ShowFor.show_for_tag
html_options[:id] ||= dom_id(object)
html_options[:class] = show_for_html_class(object, html_options)
builder = html_options.delete(:builder) |... | ruby | {
"resource": ""
} |
q19604 | ScormCloud.Base.execute_call_xml | train | def execute_call_xml(url)
doc = REXML::Document.new(execute_call_plain(url))
raise create_error(doc) unless doc.elements["rsp"].attributes["stat"] == "ok"
doc
end | ruby | {
"resource": ""
} |
q19605 | ScormCloud.Base.execute_call_plain | train | def execute_call_plain(url)
res = Net::HTTP.get_response(URI.parse(url))
case res
when Net::HTTPRedirection
# Return the new URL
res['location']
when Net::HTTPSuccess
res.body
else
raise "HTTP Error connecting to scorm cloud: #{res.inspect}"
end
end | ruby | {
"resource": ""
} |
q19606 | ScormCloud.Base.prepare_url | train | def prepare_url(method, params = {})
timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
params[:method] = method
params[:appid] = @appid
params[:ts] = timestamp
html_params = params.map { |k,v| "#{k.to_s}=#{v}" }.join("&")
raw = @secret + params.keys.
sort{ |a,b| a.to_s.downcase <=> b.to_s.downca... | ruby | {
"resource": ""
} |
q19607 | ScormCloud.Base.create_error | train | def create_error(doc, url)
err = doc.elements["rsp"].elements["err"]
code = err.attributes["code"]
msg = err.attributes["msg"]
"Error In Scorm Cloud: Error=#{code} Message=#{msg} URL=#{url}"
end | ruby | {
"resource": ""
} |
q19608 | Twee2.StoryFormat.compile | train | def compile
@source.gsub('{{STORY_NAME}}', Twee2::build_config.story_name).gsub('{{STORY_DATA}}', Twee2::build_config.story_file.xmldata).gsub('{{STORY_FORMAT}}', @name)
end | ruby | {
"resource": ""
} |
q19609 | Twee2.StoryFile.run_preprocessors | train | def run_preprocessors
@passages.each_key do |k|
# HAML
if @passages[k][:tags].include? 'haml'
@passages[k][:content] = Haml::Engine.new(@passages[k][:content], HAML_OPTIONS).render
@passages[k][:tags].delete 'haml'
end
# Coffeescript
if @passages... | ruby | {
"resource": ""
} |
q19610 | HammerCLIKatello.IdNameOptionsValidator.validate_id_or_name | train | def validate_id_or_name(record_name = nil)
child_options = IdNameOptionsValidator.build_child_options(record_name)
validate_options do
any(*child_options).required
end
end | ruby | {
"resource": ""
} |
q19611 | Bowline.Watcher.call | train | def call(event, *args)
return unless @listeners[event]
@listeners[event].each do |callback|
callback.call(*args)
end
end | ruby | {
"resource": ""
} |
q19612 | Bowline.Watcher.remove | train | def remove(event, value=nil)
return unless @listeners[event]
if value
@listeners[event].delete(value)
if @listeners[event].empty?
@listeners.delete(event)
end
else
@listeners.delete(event)
end
end | ruby | {
"resource": ""
} |
q19613 | Bowline.Initializer.set_autoload_paths | train | def set_autoload_paths
# Rails 3 master support
if ActiveSupport::Dependencies.respond_to?(:autoload_paths)
ActiveSupport::Dependencies.autoload_paths = configuration.autoload_paths.uniq
ActiveSupport::Dependencies.autoload_once_paths = configuration.autoload_once_paths.uniq
else
... | ruby | {
"resource": ""
} |
q19614 | Bowline.Configuration.set_root_path! | train | def set_root_path!
raise 'APP_ROOT is not set' unless defined?(::APP_ROOT)
raise 'APP_ROOT is not a directory' unless File.directory?(::APP_ROOT)
@root_path =
# Pathname is incompatible with Windows, but Windows doesn't have
# real symlinks so File.expand_path is safe.
i... | ruby | {
"resource": ""
} |
q19615 | CocoaPodsStats.TargetMapper.pods_from_project | train | def pods_from_project(context, master_pods)
context.umbrella_targets.flat_map do |target|
root_specs = target.specs.map(&:root).uniq
# As it's hard to look up the source of a pod, we
# can check if the pod exists in the master specs repo though
pods = root_specs.
s... | ruby | {
"resource": ""
} |
q19616 | JekyllAssetPipeline.Pipeline.collect | train | def collect
@assets = YAML.safe_load(@manifest).map! do |path|
full_path = File.join(@source, path)
File.open(File.join(@source, path)) do |file|
::JekyllAssetPipeline::Asset.new(file.read, File.basename(path),
File.dirname(full_path))
e... | ruby | {
"resource": ""
} |
q19617 | JekyllAssetPipeline.Pipeline.convert_asset | train | def convert_asset(klass, asset)
# Convert asset content
converter = klass.new(asset)
# Replace asset content and filename
asset.content = converter.converted
asset.filename = File.basename(asset.filename, '.*')
# Add back the output extension if no extension left
if File.extn... | ruby | {
"resource": ""
} |
q19618 | JekyllAssetPipeline.Pipeline.compress | train | def compress
@assets.each do |asset|
# Find a compressor to use
klass = ::JekyllAssetPipeline::Compressor.subclasses.select do |c|
c.filetype == @type
end.last
break unless klass
begin
asset.content = klass.new(asset.content).compressed
rescue ... | ruby | {
"resource": ""
} |
q19619 | JekyllAssetPipeline.Pipeline.gzip | train | def gzip
@assets.map! do |asset|
gzip_content = Zlib::Deflate.deflate(asset.content)
[
asset,
::JekyllAssetPipeline::Asset
.new(gzip_content, "#{asset.filename}.gz", asset.dirname)
]
end.flatten!
end | ruby | {
"resource": ""
} |
q19620 | JekyllAssetPipeline.Pipeline.save | train | def save
output_path = @options['output_path']
staging_path = @options['staging_path']
@assets.each do |asset|
directory = File.join(@source, staging_path, output_path)
write_asset_file(directory, asset)
# Store output path of saved file
asset.output_path = output_pat... | ruby | {
"resource": ""
} |
q19621 | StarlingServer.QueueCollection.put | train | def put(key, data)
queue = queues(key)
return nil unless queue
@stats[:current_bytes] += data.size
@stats[:total_items] += 1
queue.push(data)
return true
end | ruby | {
"resource": ""
} |
q19622 | StarlingServer.QueueCollection.take | train | def take(key)
queue = queues(key)
if queue.nil? || queue.length == 0
@stats[:get_misses] += 1
return nil
else
@stats[:get_hits] += 1
end
result = queue.pop
@stats[:current_bytes] -= result.size
result
end | ruby | {
"resource": ""
} |
q19623 | StarlingServer.QueueCollection.queues | train | def queues(key=nil)
return nil if @shutdown_mutex.locked?
return @queues if key.nil?
# First try to return the queue named 'key' if it's available.
return @queues[key] if @queues[key]
# If the queue wasn't available, create or get the mutex that will
# wrap creation of the Queue.
... | ruby | {
"resource": ""
} |
q19624 | StarlingServer.PersistentQueue.pop | train | def pop(log_trx = true)
raise NoTransactionLog if log_trx && !@trx
begin
rv = super(!log_trx)
rescue ThreadError
puts "WARNING: The queue was empty when trying to pop(). Technically this shouldn't ever happen. Probably a bug in the transactional underpinnings. Or maybe shutdown didn't... | ruby | {
"resource": ""
} |
q19625 | StarlingServer.Base.run | train | def run
@stats[:start_time] = Time.now
if @opts[:syslog_channel]
begin
require 'syslog_logger'
@@logger = SyslogLogger.new(@opts[:syslog_channel])
rescue LoadError
# SyslogLogger isn't available, so we're just going to use Logger
end
end
@@... | ruby | {
"resource": ""
} |
q19626 | StarlingServer.Handler.post_init | train | def post_init
@stash = []
@data = ""
@data_buf = ""
@server = @opts[:server]
@logger = StarlingServer::Base.logger
@expiry_stats = Hash.new(0)
@expected_length = nil
@server.stats[:total_connections] += 1
set_comm_inactivity_timeout @opts[:timeout]
@queue_coll... | ruby | {
"resource": ""
} |
q19627 | Attach.Attachment.child | train | def child(role)
@cached_children ||= {}
@cached_children[role.to_sym] ||= self.children.where(:role => role).first || :nil
@cached_children[role.to_sym] == :nil ? nil : @cached_children[role.to_sym]
end | ruby | {
"resource": ""
} |
q19628 | Attach.Attachment.add_child | train | def add_child(role, &block)
attachment = self.children.build
attachment.role = role
attachment.owner = self.owner
attachment.file_name = self.file_name
attachment.file_type = self.file_type
attachment.disposition = self.disposition
attachment.cache_type = self.cache_type
... | ruby | {
"resource": ""
} |
q19629 | LinuxAdmin.NetworkInterface.netmask6 | train | def netmask6(scope = :global)
if [:global, :link].include?(scope)
@network_conf["mask6_#{scope}".to_sym] ||= IPAddr.new('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff').mask(prefix6(scope)).to_s if prefix6(scope)
else
raise ArgumentError, "Unrecognized address scope #{scope}"
end
end | ruby | {
"resource": ""
} |
q19630 | LinuxAdmin.NetworkInterfaceRH.apply_static | train | def apply_static(ip, mask, gw, dns, search = nil)
self.address = ip
self.netmask = mask
self.gateway = gw
self.dns = dns
self.search_order = search if search
save
end | ruby | {
"resource": ""
} |
q19631 | LinuxAdmin.NetworkInterfaceRH.apply_static6 | train | def apply_static6(ip, prefix, gw, dns, search = nil)
self.address6 = "#{ip}/#{prefix}"
self.gateway6 = gw
self.dns = dns
self.search_order = search if search
save
end | ruby | {
"resource": ""
} |
q19632 | CustomFields.Source.klass_with_custom_fields | train | def klass_with_custom_fields(name)
# Rails.logger.debug "[CustomFields] klass_with_custom_fields #{self.send(name).metadata.klass} / #{self.send(name).metadata[:old_klass]}" if defined?(Rails) # DEBUG
recipe = self.custom_fields_recipe_for(name)
_metadata = self.send(name).relation_metadata
t... | ruby | {
"resource": ""
} |
q19633 | CustomFields.Source.collect_custom_fields_diff | train | def collect_custom_fields_diff(name, fields)
# puts "==> collect_custom_fields_diff for #{name}, #{fields.size}" # DEBUG
memo = self.initialize_custom_fields_diff(name)
fields.map do |field|
field.collect_diff(memo)
end
# collect fields with a modified localized field
fiel... | ruby | {
"resource": ""
} |
q19634 | CustomFields.Source.apply_custom_fields_diff | train | def apply_custom_fields_diff(name)
# puts "==> apply_custom_fields_recipes for #{name}, #{self._custom_fields_diff[name].inspect}" # DEBUG
operations = self._custom_fields_diff[name]
operations['$set'].merge!({ 'custom_fields_recipe.version' => self.custom_fields_version(name) })
collection, se... | ruby | {
"resource": ""
} |
q19635 | CustomFields.Source.apply_custom_fields_localize_diff | train | def apply_custom_fields_localize_diff(name)
return if self._custom_field_localize_diff[name].empty?
self.send(name).all.each do |record|
updates = {}
# puts "[apply_custom_fields_localize_diff] processing: record #{record._id} / #{self._custom_field_localize_diff[name].inspect}" # DEBUG
... | ruby | {
"resource": ""
} |
q19636 | CustomFields.TargetHelpers.custom_fields_methods | train | def custom_fields_methods(&filter)
self.custom_fields_recipe['rules'].map do |rule|
method = self.custom_fields_getters_for rule['name'], rule['type']
if block_given?
filter.call(rule) ? method : nil
else
method
end
end.compact.flatten
end | ruby | {
"resource": ""
} |
q19637 | CustomFields.TargetHelpers.custom_fields_safe_setters | train | def custom_fields_safe_setters
self.custom_fields_recipe['rules'].map do |rule|
case rule['type'].to_sym
when :date, :date_time, :money then "formatted_#{rule['name']}"
when :file then [rule['name'], "remove_#{rule['name']}", "remote_#{rule['name']}_url"]
when... | ruby | {
"resource": ""
} |
q19638 | CustomFields.TargetHelpers.custom_fields_basic_attributes | train | def custom_fields_basic_attributes
{}.tap do |hash|
self.non_relationship_custom_fields.each do |rule|
name, type = rule['name'], rule['type'].to_sym
# method of the custom getter
method_name = "#{type}_attribute_get"
hash.merge!(self.class.send(method_name, self,... | ruby | {
"resource": ""
} |
q19639 | CustomFields.TargetHelpers.is_a_custom_field_many_relationship? | train | def is_a_custom_field_many_relationship?(name)
rule = self.custom_fields_recipe['rules'].detect do |rule|
rule['name'] == name && _custom_field_many_relationship?(rule['type'])
end
end | ruby | {
"resource": ""
} |
q19640 | Instrumental.Agent.gauge | train | def gauge(metric, value, time = Time.now, count = 1)
if valid?(metric, value, time, count) &&
send_command("gauge", metric, value, time.to_i, count.to_i)
value
else
nil
end
rescue Exception => e
report_exception(e)
nil
end | ruby | {
"resource": ""
} |
q19641 | Instrumental.Agent.time | train | def time(metric, multiplier = 1)
start = Time.now
begin
result = yield
ensure
finish = Time.now
duration = finish - start
gauge(metric, duration * multiplier, start)
end
result
end | ruby | {
"resource": ""
} |
q19642 | Instrumental.Agent.cleanup | train | def cleanup
if running?
logger.info "Cleaning up agent, queue size: #{@queue.size}, thread running: #{@thread.alive?}"
@allow_reconnect = false
if @queue.size > 0
queue_message('exit')
begin
with_timeout(EXIT_FLUSH_TIMEOUT) { @thread.join }
rescue ... | ruby | {
"resource": ""
} |
q19643 | Secp256k1.ECDSA.ecdsa_signature_normalize | train | def ecdsa_signature_normalize(raw_sig, check_only: false)
sigout = check_only ? nil : C::ECDSASignature.new.pointer
res = C.secp256k1_ecdsa_signature_normalize(@ctx, sigout, raw_sig)
[res == 1, sigout]
end | ruby | {
"resource": ""
} |
q19644 | Secp256k1.PublicKey.combine | train | def combine(pubkeys)
raise ArgumentError, 'must give at least 1 pubkey' if pubkeys.empty?
outpub = FFI::Pubkey.new.pointer
#pubkeys.each {|item| }
res = C.secp256k1_ec_pubkey_combine(@ctx, outpub, pubkeys, pubkeys.size)
raise AssertError, 'failed to combine public keys' unless res == 1
... | ruby | {
"resource": ""
} |
q19645 | HipChat.Room.get_room | train | def get_room
response = self.class.get(@api.get_room_config[:url],
:query => {:auth_token => @token }.merge(@api.get_room_config[:query_params]),
:headers => @api.headers
)
ErrorHandler.response_code_to_exception_for :room, room_id, response
response.parsed_response
end | ruby | {
"resource": ""
} |
q19646 | HipChat.Room.update_room | train | def update_room(options = {})
merged_options = {
:privacy => 'public',
:is_archived => false,
:is_guest_accessible => false
}.merge symbolize(options)
response = self.class.send(@api.topic_config[:method], @api.update_room_config[:url],
:query => { :auth_token => @toke... | ruby | {
"resource": ""
} |
q19647 | HipChat.Room.delete_room | train | def delete_room
response = self.class.send(@api.delete_room_config[:method], @api.delete_room_config[:url],
:query => {:auth_token => @token }.merge(@api.get_room_config[:query_params]),
:headers => @api.headers)
ErrorHandler.response_code_to_exception_for :room, room_id, response
true... | ruby | {
"resource": ""
} |
q19648 | HipChat.Room.invite | train | def invite(user, reason='')
response = self.class.post(@api.invite_config[:url]+"/#{user}",
:query => { :auth_token => @token },
:body => {
:reason => reason
}.to_json,
:headers => @api.headers)
ErrorHandler.response_code_to_exception_for :room, room_id, response
... | ruby | {
"resource": ""
} |
q19649 | HipChat.Room.add_member | train | def add_member(user, room_roles=['room_member'])
response = self.class.put(@api.member_config[:url]+"/#{user}",
:query => { :auth_token => @token },
:body => {
:room_roles => room_roles
}.to_json,
:headers => @api.headers)
ErrorHandler.response_code_to_exception_fo... | ruby | {
"resource": ""
} |
q19650 | HipChat.Room.members | train | def members(options = {})
response = self.class.get(@api.member_config[:url],
:query => { :auth_token => @token }.merge(options),
:headers => @api.headers)
ErrorHandler.response_code_to_exception_for :room, room_id, response
wrap_users(response)
end | ruby | {
"resource": ""
} |
q19651 | HipChat.Room.participants | train | def participants(options = {})
response = self.class.get(@api.participant_config[:url],
:query => { :auth_token => @token }.merge(options),
:headers => @api.headers)
ErrorHandler.response_code_to_exception_for :room, room_id, response
wrap_users(response)
end | ruby | {
"resource": ""
} |
q19652 | HipChat.Room.send_message | train | def send_message(message)
response = self.class.post(@api.send_message_config[:url],
:query => { :auth_token => @token },
:body => {
:room_id => room_id,
:message => message,
}.send(@api.send_config[:body_format]),
:headers => @api.headers
)
ErrorH... | ruby | {
"resource": ""
} |
q19653 | HipChat.Room.send | train | def send(from, message, options_or_notify = {})
if from.length > 20
raise UsernameTooLong, "Username #{from} is `#{from.length} characters long. Limit is 20'"
end
if options_or_notify == true or options_or_notify == false
warn 'DEPRECATED: Specify notify flag as an option (e.g., :notif... | ruby | {
"resource": ""
} |
q19654 | HipChat.Room.send_file | train | def send_file(from, message, file)
if from.length > 20
raise UsernameTooLong, "Username #{from} is `#{from.length} characters long. Limit is 20'"
end
response = self.class.post(@api.send_file_config[:url],
:query => { :auth_token => @token },
:body => file_body(
{
... | ruby | {
"resource": ""
} |
q19655 | HipChat.Room.topic | train | def topic(new_topic, options = {})
merged_options = { :from => 'API' }.merge options
response = self.class.send(@api.topic_config[:method], @api.topic_config[:url],
:query => { :auth_token => @token },
:body => {
:room_id => room_id,
:from => merged_op... | ruby | {
"resource": ""
} |
q19656 | HipChat.Room.history | train | def history(options = {})
merged_options = {
:date => 'recent',
:timezone => 'UTC',
:format => 'JSON',
:'max-results' => 100,
:'start-index' => 0,
:'end-date' => nil
}.merge options
response = self.class.get(@api.history_config[:url],
:query =>... | ruby | {
"resource": ""
} |
q19657 | HipChat.Room.statistics | train | def statistics(options = {})
response = self.class.get(@api.statistics_config[:url],
:query => {
:room_id => room_id,
:date => options[:date],
:timezone => options[:timezone],
:format => options[:format],
:auth_token => @token,
}.re... | ruby | {
"resource": ""
} |
q19658 | HipChat.Room.create_webhook | train | def create_webhook(url, event, options = {})
raise InvalidEvent.new("Invalid event: #{event}") unless %w(room_message room_notification room_exit room_enter room_topic_change room_archived room_deleted room_unarchived).include? event
begin
u = URI::parse(url)
raise InvalidUrl.new("Invalid S... | ruby | {
"resource": ""
} |
q19659 | HipChat.Room.delete_webhook | train | def delete_webhook(webhook_id)
response = self.class.delete("#{@api.webhook_config[:url]}/#{URI::escape(webhook_id)}",
:query => {
:auth_token => @token
},
:headers => @api.headers... | ruby | {
"resource": ""
} |
q19660 | HipChat.Room.get_all_webhooks | train | def get_all_webhooks(options = {})
merged_options = {:'start-index' => 0, :'max-results' => 100}.merge(options)
response = self.class.get(@api.webhook_config[:url],
:query => {
:auth_token => @token,
... | ruby | {
"resource": ""
} |
q19661 | HipChat.Room.get_webhook | train | def get_webhook(webhook_id)
response = self.class.get("#{@api.webhook_config[:url]}/#{URI::escape(webhook_id)}",
:query => {
:auth_token => @token
},
:headers => @api.headers
)
... | ruby | {
"resource": ""
} |
q19662 | Soulmate.Loader.add | train | def add(item, opts = {})
opts = { :skip_duplicate_check => false }.merge(opts)
raise ArgumentError, "Items must specify both an id and a term" unless item["id"] && item["term"]
# kill any old items with this id
remove("id" => item["id"]) unless opts[:skip_duplicate_check]
Sou... | ruby | {
"resource": ""
} |
q19663 | Soulmate.Loader.remove | train | def remove(item)
prev_item = Soulmate.redis.hget(database, item["id"])
if prev_item
prev_item = MultiJson.decode(prev_item)
# undo the operations done in add
Soulmate.redis.pipelined do
Soulmate.redis.hdel(database, prev_item["id"])
phrase = ([prev_item["term"]] +... | ruby | {
"resource": ""
} |
q19664 | HipChat.User.send | train | def send(message, options = {})
message_format = options[:message_format] ? options[:message_format] : 'text'
notify = options[:notify] ? options[:notify] : false
response = self.class.post(@api.send_config[:url],
:query => { :auth_token => @to... | ruby | {
"resource": ""
} |
q19665 | HipChat.User.send_file | train | def send_file(message, file)
response = self.class.post(@api.send_file_config[:url],
:query => { :auth_token => @token },
:body => file_body({ :message => message }.send(@api.send_config[:body_format]), file),
:headers => file_body_headers(@api.headers)
)
ErrorHandler.response... | ruby | {
"resource": ""
} |
q19666 | HipChat.User.view | train | def view
response = self.class.get(@api.view_config[:url],
:query => { :auth_token => @token }.merge(@api.view_config[:query_params]),
:headers => @api.headers
)
ErrorHandler.response_code_to_exception_for :user, user_id, response
... | ruby | {
"resource": ""
} |
q19667 | HipChat.User.rooms | train | def rooms
response = self.class.get(@api.user_joined_rooms_config[:url],
:query => { :auth_token => @token }.merge(@api.user_joined_rooms_config[:query_params]),
:headers => @api.headers
)
ErrorHandler.response_code_to_exception_for :user... | ruby | {
"resource": ""
} |
q19668 | HipChat.FileHelper.file_body | train | def file_body(message, file)
file_name = File.basename(file.path)
mime_type = MimeMagic.by_path(file_name)
file_content = Base64.encode64(file.read)
body = ["--#{BOUNDARY}"]
body << 'Content-Type: application/json; charset=UTF-8'
body << 'Content-Disposition: attachment; name="meta... | ruby | {
"resource": ""
} |
q19669 | HipChat.Client.scopes | train | def scopes(room: nil)
path = "#{@api.scopes_config[:url]}/#{URI::escape(@token)}"
response = self.class.get(path,
:query => { :auth_token => @token },
:headers => @api.headers
)
ErrorHandler.response_code_to_exception_for :room, 'scopes', response
return response['scopes'] ... | ruby | {
"resource": ""
} |
q19670 | Instana.Span.add_stack | train | def add_stack(limit: nil, stack: Kernel.caller)
frame_count = 0
@data[:stack] = []
stack.each do |i|
# If the stack has the full instana gem version in it's path
# then don't include that frame. Also don't exclude the Rack module.
if !i.match(/instana\/instrumentation\/rack.rb... | ruby | {
"resource": ""
} |
q19671 | Instana.Span.add_error | train | def add_error(e)
@data[:error] = true
if @data.key?(:ec)
@data[:ec] = @data[:ec] + 1
else
@data[:ec] = 1
end
# If a valid exception has been passed in, log the information about it
# In case of just logging an error for things such as HTTP client 5xx
# respons... | ruby | {
"resource": ""
} |
q19672 | Instana.Span.set_tags | train | def set_tags(tags)
return unless tags.is_a?(Hash)
tags.each do |k,v|
set_tag(k, v)
end
self
end | ruby | {
"resource": ""
} |
q19673 | Instana.Span.tags | train | def tags(key = nil)
if custom?
tags = @data[:data][:sdk][:custom][:tags]
else
tags = @data[:data][key]
end
key ? tags[key] : tags
end | ruby | {
"resource": ""
} |
q19674 | Riiif.Resize.reduce? | train | def reduce?
case size
when IIIF::Image::Size::Full, IIIF::Image::Size::Max
false
when IIIF::Image::Size::Absolute
aspect_ratio = width.to_f / height
in_delta?(image_info.aspect, aspect_ratio, 0.001)
else
true
end
end | ruby | {
"resource": ""
} |
q19675 | Riiif.KakaduTransformer.post_process | train | def post_process(intermediate_file, reduction_factor)
# Calculate a new set of transforms with respect to reduction_factor
transformation = if reduction_factor
reduce(without_crop, reduction_factor)
else
without_crop
... | ruby | {
"resource": ""
} |
q19676 | Riiif.KakaduTransformer.without_crop | train | def without_crop
IIIF::Image::Transformation.new(region: IIIF::Image::Region::Full.new,
size: transformation.size.dup,
quality: transformation.quality,
rotation: transformation.rotation,
... | ruby | {
"resource": ""
} |
q19677 | Riiif.KakaduTransformer.reduce | train | def reduce(transformation, factor)
resize = Resize.new(transformation.size, image_info)
IIIF::Image::Transformation.new(region: transformation.region.dup,
size: resize.reduce(factor),
quality: transformation.quality,
... | ruby | {
"resource": ""
} |
q19678 | Instana.Agent.setup | train | def setup
# The announce timer
# We attempt to announce this ruby sensor to the host agent.
# In case of failure, we try again in 30 seconds.
@announce_timer = @timers.every(30) do
if @state == :unannounced
if host_agent_available? && announce_sensor
transition_to(:... | ruby | {
"resource": ""
} |
q19679 | Instana.Agent.start | train | def start
if !host_agent_available?
if !ENV.key?("INSTANA_QUIET")
::Instana.logger.warn "Host agent not available. Will retry periodically. (Set env INSTANA_QUIET=1 to shut these messages off)"
end
end
loop do
if @state == :unannounced
@collect_timer.pause... | ruby | {
"resource": ""
} |
q19680 | Instana.Agent.announce_sensor | train | def announce_sensor
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
# Always re-collect process info before announce in case the process name has been
# re-written (looking at you puma!)
@process = ::Instana:... | ruby | {
"resource": ""
} |
q19681 | Instana.Agent.report_metrics | train | def report_metrics(payload)
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
path = "com.instana.plugin.ruby.#{@process[:report_pid]}"
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/... | ruby | {
"resource": ""
} |
q19682 | Instana.Agent.report_spans | train | def report_spans(spans)
return unless @state == :announced
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
path = "com.instana.plugin.ruby/traces.#{@process[:report_pid]}"
uri = URI.parse("http://#{@discover... | ruby | {
"resource": ""
} |
q19683 | Instana.Agent.host_agent_available? | train | def host_agent_available?
@discovered ||= run_discovery
if @discovered
# Try default location or manually configured (if so)
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/")
req = Net::HTTP::Get.new(uri)
response = make_host_agent_request(r... | ruby | {
"resource": ""
} |
q19684 | Instana.Tracer.start_or_continue_trace | train | def start_or_continue_trace(name, kvs = {}, incoming_context = {}, &block)
log_start_or_continue(name, kvs, incoming_context)
block.call
rescue Exception => e
log_error(e)
raise
ensure
log_end(name)
end | ruby | {
"resource": ""
} |
q19685 | Instana.Tracer.trace | train | def trace(name, kvs = {}, &block)
log_entry(name, kvs)
result = block.call
result
rescue Exception => e
log_error(e)
raise
ensure
log_exit(name)
end | ruby | {
"resource": ""
} |
q19686 | Instana.Tracer.log_start_or_continue | train | def log_start_or_continue(name, kvs = {}, incoming_context = {})
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]
::Instana.logger.debug "#{__method__} passed a block. Use `start_or_continue` instead!" if block_given?
self.current_trace = ::Instana::Trace.new(name, kvs, inco... | ruby | {
"resource": ""
} |
q19687 | Instana.Tracer.log_exit | train | def log_exit(name, kvs = {})
return unless tracing?
if ::Instana.debug? || ::Instana.test?
unless current_span_name?(name)
::Instana.logger.debug "Span mismatch: Attempt to exit #{name} span but #{current_span.name} is active."
end
end
self.current_trace.end_span(kvs)... | ruby | {
"resource": ""
} |
q19688 | Instana.Tracer.log_end | train | def log_end(name, kvs = {}, end_time = ::Instana::Util.now_in_ms)
return unless tracing?
if ::Instana.debug? || ::Instana.test?
unless current_span_name?(name)
::Instana.logger.debug "Span mismatch: Attempt to end #{name} span but #{current_span.name} is active."
end
end
... | ruby | {
"resource": ""
} |
q19689 | Instana.Tracer.log_async_info | train | def log_async_info(kvs, span)
# Asynchronous spans can persist longer than the parent
# trace. With the trace ID, we check the current trace
# but otherwise, we search staged traces.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.add_async_info(kvs, sp... | ruby | {
"resource": ""
} |
q19690 | Instana.Tracer.log_async_error | train | def log_async_error(e, span)
# Asynchronous spans can persist longer than the parent
# trace. With the trace ID, we check the current trace
# but otherwise, we search staged traces.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.add_async_error(e, span... | ruby | {
"resource": ""
} |
q19691 | Instana.Tracer.log_async_exit | train | def log_async_exit(_name, kvs, span)
# An asynchronous span can end after the current trace has
# already completed so we make sure that we end the span
# on the right trace.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.end_async_span(kvs, span)
... | ruby | {
"resource": ""
} |
q19692 | Instana.Tracer.inject | train | def inject(span_context, format, carrier)
case format
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
::Instana.logger.debug 'Unsupported inject format'
when OpenTracing::FORMAT_RACK
carrier['X-Instana-T'] = ::Instana::Util.id_to_header(span_context.trace_id)
carr... | ruby | {
"resource": ""
} |
q19693 | Instana.Tracer.extract | train | def extract(format, carrier)
case format
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
::Instana.logger.debug 'Unsupported extract format'
when OpenTracing::FORMAT_RACK
::Instana::SpanContext.new(::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_T']),
... | ruby | {
"resource": ""
} |
q19694 | Instana.Processor.add | train | def add(trace)
# Do a quick checkup on our background thread.
if ::Instana.agent.collect_thread.nil? || !::Instana.agent.collect_thread.alive?
::Instana.agent.spawn_background_thread
end
# ::Instana.logger.debug("Queuing completed trace id: #{trace.id}")
@queue.push(trace)
end | ruby | {
"resource": ""
} |
q19695 | Instana.Processor.staged_trace | train | def staged_trace(trace_id)
candidate = nil
@staging_lock.synchronize {
@staging_queue.each do |trace|
if trace.id == trace_id
candidate = trace
break
end
end
}
unless candidate
::Instana.logger.debug("Couldn't find staged trace ... | ruby | {
"resource": ""
} |
q19696 | Instana.Trace.new_span | train | def new_span(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
return unless @current_span
if child_of && child_of.is_a?(::Instana::Span)
new_span = Span.new(name, @id, parent_id: child_of.id, start_time: start_time)
new_span.parent = child_of
new_span.baggage... | ruby | {
"resource": ""
} |
q19697 | Instana.Trace.add_error | train | def add_error(e, span = nil)
# Return if we've already logged this exception and it
# is just propogating up the spans.
return if e && e.instance_variable_get(:@instana_logged) || @current_span.nil?
span ||= @current_span
span.add_error(e)
end | ruby | {
"resource": ""
} |
q19698 | Instana.Trace.end_span | train | def end_span(kvs = {}, end_time = ::Instana::Util.now_in_ms)
return unless @current_span
@current_span.close(end_time)
add_info(kvs) if kvs && !kvs.empty?
@current_span = @current_span.parent unless @current_span.is_root?
end | ruby | {
"resource": ""
} |
q19699 | Instana.Trace.end_async_span | train | def end_async_span(kvs = {}, span)
span.set_tags(kvs) unless kvs.empty?
span.close
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.