_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q15500 | Strings.Pad.pad_around | train | def pad_around(text, padding, fill: SPACE)
fill * padding.left + text + fill * padding.right
end | ruby | {
"resource": ""
} |
q15501 | Strings.Align.align_left | train | def align_left(text, width, fill: SPACE, separator: NEWLINE)
return if width.nil?
each_line(text, separator) do |line|
width_diff = width - display_width(line)
if width_diff > 0
line + fill * width_diff
else
line
end
end
end | ruby | {
"resource": ""
} |
q15502 | Strings.Align.align_center | train | def align_center(text, width, fill: SPACE, separator: NEWLINE)
return text if width.nil?
each_line(text, separator) do |line|
width_diff = width - display_width(line)
if width_diff > 0
right_count = (width_diff.to_f / 2).ceil
left_count = width_diff - right_count
... | ruby | {
"resource": ""
} |
q15503 | Strings.Align.each_line | train | def each_line(text, separator)
lines = text.split(separator)
return yield(text) if text.empty?
lines.reduce([]) do |aligned, line|
aligned << yield(line)
end.join(separator)
end | ruby | {
"resource": ""
} |
q15504 | Nylas.HttpClient.execute | train | def execute(method:, path: nil, headers: {}, query: {}, payload: nil)
timeout = ENDPOINT_TIMEOUTS.fetch(path, 230)
request = build_request(
method: method,
path: path,
headers: headers,
query: query,
payload: payload,
timeout: timeout
)
rest_client... | ruby | {
"resource": ""
} |
q15505 | Nylas.HttpClient.get | train | def get(path: nil, headers: {}, query: {})
execute(method: :get, path: path, query: query, headers: headers)
end | ruby | {
"resource": ""
} |
q15506 | Nylas.HttpClient.post | train | def post(path: nil, payload: nil, headers: {}, query: {})
execute(method: :post, path: path, headers: headers, query: query, payload: payload)
end | ruby | {
"resource": ""
} |
q15507 | Nylas.HttpClient.put | train | def put(path: nil, payload:, headers: {}, query: {})
execute(method: :put, path: path, headers: headers, query: query, payload: payload)
end | ruby | {
"resource": ""
} |
q15508 | Nylas.HttpClient.delete | train | def delete(path: nil, payload: nil, headers: {}, query: {})
execute(method: :delete, path: path, headers: headers, query: query, payload: payload)
end | ruby | {
"resource": ""
} |
q15509 | Nylas.Collection.where | train | def where(filters)
raise ModelNotFilterableError, model unless model.filterable?
self.class.new(model: model, api: api, constraints: constraints.merge(where: filters))
end | ruby | {
"resource": ""
} |
q15510 | Nylas.Collection.raw | train | def raw
raise ModelNotAvailableAsRawError, model unless model.exposable_as_raw?
self.class.new(model: model, api: api, constraints: constraints.merge(accept: model.raw_mime_type))
end | ruby | {
"resource": ""
} |
q15511 | Nylas.Collection.each | train | def each
return enum_for(:each) unless block_given?
execute.each do |result|
yield(model.new(result.merge(api: api)))
end
end | ruby | {
"resource": ""
} |
q15512 | Nylas.Collection.find_each | train | def find_each
return enum_for(:find_each) unless block_given?
query = self
accumulated = 0
while query
results = query.each do |instance|
yield(instance)
end
accumulated += results.length
query = query.next_page(accumulated: accumulated, current_page:... | ruby | {
"resource": ""
} |
q15513 | Nylas.File.download! | train | def download!
return download if file.nil?
file.close
file.unlink
self.file = nil
download
end | ruby | {
"resource": ""
} |
q15514 | Nylas.API.revoke | train | def revoke(access_token)
response = client.as(access_token).post(path: "/oauth/revoke")
response.code == 200 && response.empty?
end | ruby | {
"resource": ""
} |
q15515 | FoodCritic.CommandLine.valid_paths? | train | def valid_paths?
paths = options[:cookbook_paths] + options[:role_paths] +
options[:environment_paths]
paths.any? && paths.all? { |path| File.exist?(path) }
end | ruby | {
"resource": ""
} |
q15516 | FoodCritic.CommandLine.valid_grammar? | train | def valid_grammar?
return true unless options.key?(:search_grammar)
return false unless File.exist?(options[:search_grammar])
search = FoodCritic::Chef::Search.new
search.create_parser([options[:search_grammar]])
search.parser?
end | ruby | {
"resource": ""
} |
q15517 | FoodCritic.Linter.list | train | def list(options = {})
options = setup_defaults(options)
@options = options
load_rules
if options[:tags].any?
@rules = active_rules(options[:tags])
end
RuleList.new(@rules)
end | ruby | {
"resource": ""
} |
q15518 | FoodCritic.Linter.check | train | def check(options = {})
options = setup_defaults(options)
@options = options
@chef_version = options[:chef_version] || DEFAULT_CHEF_VERSION
warnings = []; last_dir = nil; matched_rule_tags = Set.new
load_rules
paths = specified_paths!(options)
# Loop through each file to be p... | ruby | {
"resource": ""
} |
q15519 | FoodCritic.Linter.applies_to_version? | train | def applies_to_version?(rule, version)
return true unless version
rule.applies_to.yield(Gem::Version.create(version))
end | ruby | {
"resource": ""
} |
q15520 | FoodCritic.Linter.rule_file_tags | train | def rule_file_tags(file)
cookbook = cookbook_dir(file)
@tag_cache ||= {}
# lookup the tags in the cache has and return that if we find something
cb_tags = @tag_cache[cookbook]
return cb_tags unless cb_tags.nil?
# if a rule file has been specified use that. Otherwise use the .foodcr... | ruby | {
"resource": ""
} |
q15521 | FoodCritic.Linter.parse_rule_file | train | def parse_rule_file(file)
tags = []
begin
tag_text = File.read file
tags = tag_text.split(/\s/)
rescue
raise "ERROR: Could not read or parse the specified rule file at #{file}"
end
tags
end | ruby | {
"resource": ""
} |
q15522 | FoodCritic.Linter.cookbook_dir | train | def cookbook_dir(file)
@dir_cache ||= {}
abs_file = File.absolute_path(file)
# lookup the file in the cache has and return that if we find something
cook_val = @dir_cache[abs_file]
return cook_val unless cook_val.nil?
if file =~ /\.erb$/
# split each directory into an item ... | ruby | {
"resource": ""
} |
q15523 | FoodCritic.Linter.files_to_process | train | def files_to_process(paths)
paths.reject { |type, _| type == :exclude }.map do |path_type, dirs|
dirs.map do |dir|
exclusions = []
unless paths[:exclude].empty?
exclusions = Dir.glob(paths[:exclude].map do |p|
File.join(dir, p, "**/**")
end)
... | ruby | {
"resource": ""
} |
q15524 | FoodCritic.Linter.matches | train | def matches(match_method, *params)
return [] unless match_method.respond_to?(:yield)
matches = match_method.yield(*params)
return [] unless matches.respond_to?(:each)
# We convert Nokogiri nodes to matches transparently
matches.map do |m|
if m.respond_to?(:node_name)
mat... | ruby | {
"resource": ""
} |
q15525 | FoodCritic.Chef.valid_query? | train | def valid_query?(query)
raise ArgumentError, "Query cannot be nil or empty" if query.to_s.empty?
# Attempt to create a search query parser
search = FoodCritic::Chef::Search.new
search.create_parser(search.chef_search_grammars)
if search.parser?
search.parser.parse(query.to_s)
... | ruby | {
"resource": ""
} |
q15526 | FoodCritic.Chef.load_metadata | train | def load_metadata
version = if respond_to?(:chef_version)
chef_version
else
Linter::DEFAULT_CHEF_VERSION
end
metadata_path = [version, version.sub(/\.[a-z].*/, ""),
Linter::DEFAULT_CHEF_VERSION].map do |ver|
metadata_path(... | ruby | {
"resource": ""
} |
q15527 | FoodCritic.ContextOutput.output | train | def output(review)
unless review.respond_to?(:warnings)
puts review; return
end
context = 3
print_fn = lambda { |fn| ansi_print(fn, :red, nil, :bold) }
print_rule = lambda { |warn| ansi_print(warn, :cyan, nil, :bold) }
print_line = lambda { |line| ansi_print(line, nil, :red... | ruby | {
"resource": ""
} |
q15528 | FoodCritic.ContextOutput.key_by_file_and_line | train | def key_by_file_and_line(review)
warn_hash = {}
review.warnings.each do |warning|
filename = Pathname.new(warning.match[:filename]).cleanpath.to_s
line_num = warning.match[:line].to_i
warn_hash[filename] = {} unless warn_hash.key?(filename)
unless warn_hash[filename].key?(lin... | ruby | {
"resource": ""
} |
q15529 | FoodCritic.Api.ensure_file_exists | train | def ensure_file_exists(basepath, filepath)
path = File.join(basepath, filepath)
[file_match(path)] unless File.exist?(path)
end | ruby | {
"resource": ""
} |
q15530 | FoodCritic.Api.attribute_access | train | def attribute_access(ast, options = {})
options = { type: :any, ignore_calls: false }.merge!(options)
return [] unless ast.respond_to?(:xpath)
unless [:any, :string, :symbol, :vivified].include?(options[:type])
raise ArgumentError, "Node type not recognised"
end
case options[:typ... | ruby | {
"resource": ""
} |
q15531 | FoodCritic.Api.cookbook_base_path | train | def cookbook_base_path(file)
file = File.expand_path(file) # make sure we get an absolute path
file = File.dirname(file) unless File.directory?(file) # get the dir only
# get list of items in the dir and intersect with metadata array.
# until we get an interfact (we have a metadata) walk up the... | ruby | {
"resource": ""
} |
q15532 | FoodCritic.Api.metadata_field | train | def metadata_field(file, field)
until (file.split(File::SEPARATOR) & standard_cookbook_subdirs).empty?
file = File.absolute_path(File.dirname(file.to_s))
end
file = File.dirname(file) unless File.extname(file).empty?
md_path = File.join(file, "metadata.rb")
if File.exist?(md_path)... | ruby | {
"resource": ""
} |
q15533 | FoodCritic.Api.cookbook_name | train | def cookbook_name(file)
raise ArgumentError, "File cannot be nil or empty" if file.to_s.empty?
# Name is a special case as we want to fallback to the cookbook directory
# name if metadata_field fails
begin
metadata_field(file, "name")
rescue RuntimeError
until (file.split(... | ruby | {
"resource": ""
} |
q15534 | FoodCritic.Api.declared_dependencies | train | def declared_dependencies(ast)
raise_unless_xpath!(ast)
deps = []
# String literals.
#
# depends 'foo'
deps += field(ast, "depends").xpath("descendant::args_add/descendant::tstring_content[1]")
# Quoted word arrays are also common.
#
# %w{foo bar baz}.each... | ruby | {
"resource": ""
} |
q15535 | FoodCritic.Api.field | train | def field(ast, field_name)
if field_name.nil? || field_name.to_s.empty?
raise ArgumentError, "Field name cannot be nil or empty"
end
ast.xpath("(.//command[ident/@value='#{field_name}']|.//fcall[ident/@value='#{field_name}']/..)")
end | ruby | {
"resource": ""
} |
q15536 | FoodCritic.Api.field_value | train | def field_value(ast, field_name)
field(ast, field_name).xpath('.//args_add_block//tstring_content
[count(ancestor::args_add) = 1][count(ancestor::string_add) = 1]
/@value').map { |a| a.to_s }.last
end | ruby | {
"resource": ""
} |
q15537 | FoodCritic.Api.file_match | train | def file_match(file)
raise ArgumentError, "Filename cannot be nil" if file.nil?
{ filename: file, matched: file, line: 1, column: 1 }
end | ruby | {
"resource": ""
} |
q15538 | FoodCritic.Api.included_recipes | train | def included_recipes(ast, options = { with_partial_names: true })
raise_unless_xpath!(ast)
filter = ["[count(descendant::args_add) = 1]"]
# If `:with_partial_names` is false then we won't include the string
# literal portions of any string that has an embedded expression.
unless options[... | ruby | {
"resource": ""
} |
q15539 | FoodCritic.Api.match | train | def match(node)
raise_unless_xpath!(node)
pos = node.xpath("descendant::pos").first
return nil if pos.nil?
{ matched: node.respond_to?(:name) ? node.name : "",
line: pos["line"].to_i, column: pos["column"].to_i }
end | ruby | {
"resource": ""
} |
q15540 | FoodCritic.Api.read_ast | train | def read_ast(file)
@ast_cache ||= Rufus::Lru::Hash.new(5)
if @ast_cache.include?(file)
@ast_cache[file]
else
@ast_cache[file] = uncached_read_ast(file)
end
end | ruby | {
"resource": ""
} |
q15541 | FoodCritic.Api.resource_attribute | train | def resource_attribute(resource, name)
raise ArgumentError, "Attribute name cannot be empty" if name.empty?
resource_attributes(resource)[name.to_s]
end | ruby | {
"resource": ""
} |
q15542 | FoodCritic.Api.resource_attributes | train | def resource_attributes(resource, options = {})
atts = {}
name = resource_name(resource, options)
atts[:name] = name unless name.empty?
atts.merge!(normal_attributes(resource, options))
atts.merge!(block_attributes(resource))
atts
end | ruby | {
"resource": ""
} |
q15543 | FoodCritic.Api.resource_attributes_by_type | train | def resource_attributes_by_type(ast)
result = {}
resources_by_type(ast).each do |type, resources|
result[type] = resources.map do |resource|
resource_attributes(resource)
end
end
result
end | ruby | {
"resource": ""
} |
q15544 | FoodCritic.Api.resource_name | train | def resource_name(resource, options = {})
raise_unless_xpath!(resource)
options = { return_expressions: false }.merge(options)
if options[:return_expressions]
name = resource.xpath("command/args_add_block")
if name.xpath("descendant::string_add").size == 1 &&
name.xpath("de... | ruby | {
"resource": ""
} |
q15545 | FoodCritic.Api.resources_by_type | train | def resources_by_type(ast)
raise_unless_xpath!(ast)
result = Hash.new { |hash, key| hash[key] = Array.new }
find_resources(ast).each do |resource|
result[resource_type(resource)] << resource
end
result
end | ruby | {
"resource": ""
} |
q15546 | FoodCritic.Api.ruby_code? | train | def ruby_code?(str)
str = str.to_s
return false if str.empty?
checker = FoodCritic::ErrorChecker.new(str)
checker.parse
!checker.error?
end | ruby | {
"resource": ""
} |
q15547 | FoodCritic.Api.supported_platforms | train | def supported_platforms(ast)
# Find the supports() method call.
platforms_ast = field(ast, "supports")
# Look for the first argument (the node next to the top args_new) and
# filter out anything with a string_embexpr since that can't be parsed
# statically. Then grab the static value for b... | ruby | {
"resource": ""
} |
q15548 | FoodCritic.Api.template_paths | train | def template_paths(recipe_path)
Dir.glob(Pathname.new(recipe_path).dirname.dirname + "templates" +
"**/*", File::FNM_DOTMATCH).select do |path|
File.file?(path)
end.reject do |path|
File.basename(path) == ".DS_Store" || File.extname(path) == ".swp"
end
end | ruby | {
"resource": ""
} |
q15549 | FoodCritic.Api.json_file_to_hash | train | def json_file_to_hash(filename)
raise "File #{filename} not found" unless File.exist?(filename)
file = File.read(filename)
begin
FFI_Yajl::Parser.parse(file)
rescue FFI_Yajl::ParseError
raise "File #{filename} does not appear to contain valid JSON"
end
end | ruby | {
"resource": ""
} |
q15550 | FoodCritic.Api.build_xml | train | def build_xml(node, doc = nil, xml_node = nil)
doc, xml_node = xml_document(doc, xml_node)
if node.respond_to?(:each)
node.each do |child|
if position_node?(child)
xml_position_node(doc, xml_node, child)
else
if ast_node_has_children?(child)
... | ruby | {
"resource": ""
} |
q15551 | FoodCritic.Api.node_method? | train | def node_method?(meth, cookbook_dir)
chef_dsl_methods.include?(meth) || meth == :set || meth == :set_unless ||
patched_node_method?(meth, cookbook_dir)
end | ruby | {
"resource": ""
} |
q15552 | FoodCritic.CommandHelpers.expect_warning | train | def expect_warning(code, options = {})
if options.has_key?(:file_type)
options[:file] = { :attributes => "attributes/default.rb", :definition => "definitions/apache_site.rb",
:metadata => "metadata.rb", :provider => "providers/site.rb",
:resource => "r... | ruby | {
"resource": ""
} |
q15553 | FoodCritic.CommandHelpers.usage_displayed | train | def usage_displayed(is_exit_zero)
expect_output "foodcritic [cookbook_paths]"
usage_options.each do |option|
expect_usage_option(option[:short], option[:long], option[:description])
end
if is_exit_zero
assert_no_error_occurred
else
assert_error_occurred
end
... | ruby | {
"resource": ""
} |
q15554 | FoodCritic.InProcessHelpers.run_lint | train | def run_lint(cmd_args)
cd "." do
show_context = cmd_args.include?("-C")
review, @status = FoodCritic::Linter.run(CommandLine.new(cmd_args))
@review =
if review.nil? || (review.respond_to?(:warnings) && review.warnings.empty?)
""
elsif show_context
... | ruby | {
"resource": ""
} |
q15555 | FoodCritic.BuildHelpers.assert_build_result | train | def assert_build_result(success, warnings)
success ? assert_no_error_occurred : assert_error_occurred
warnings.each do |code|
expect_warning(code, :warning_only => true)
end
end | ruby | {
"resource": ""
} |
q15556 | FoodCritic.BuildHelpers.build_tasks | train | def build_tasks
all_output.split("\n").map do |task|
next unless task.start_with? "rake"
task.split("#").map { |t| t.strip.sub(/^rake /, "") }
end.compact
end | ruby | {
"resource": ""
} |
q15557 | FoodCritic.ArubaHelpers.expect_output | train | def expect_output(output)
if output.respond_to?(:~)
assert_matching_output(output.to_s, all_output)
else
assert_partial_output(output, all_output)
end
end | ruby | {
"resource": ""
} |
q15558 | FoodCritic.Notifications.notifications | train | def notifications(ast)
# Sanity check the AST provided.
return [] unless ast.respond_to?(:xpath)
# We are mapping each `notifies` or `subscribes` line in the provided
# AST to a Hash with the extracted details.
notification_nodes(ast).map do |notify|
# Chef supports two styles of... | ruby | {
"resource": ""
} |
q15559 | FoodCritic.Notifications.notification_action | train | def notification_action(notify)
is_variable = true unless notify.xpath("args_add_block/args_add//args_add[aref or vcall or call or var_ref]").empty?
string_val = notify.xpath("descendant::args_add/string_literal/string_add/tstring_content/@value").first
symbol_val = notify.xpath('descendant::args_add/... | ruby | {
"resource": ""
} |
q15560 | FoodCritic.CookbookHelpers.cookbook_that_matches_rules | train | def cookbook_that_matches_rules(codes)
recipe = ""
codes.each do |code|
if code == "FC002"
recipe += %q{
directory "#{node['base_dir']}" do
action :create
end
}
elsif code == "FC004"
recipe += %q{
execute "stop-j... | ruby | {
"resource": ""
} |
q15561 | FoodCritic.CookbookHelpers.cookbook_with_lwrp | train | def cookbook_with_lwrp(lwrp)
lwrp = { :default_action => false, :notifies => :does_not_notify,
:use_inline_resources => false }.merge!(lwrp)
ruby_default_action = %q{
def initialize(*args)
super
@action = :create
end
}.strip
write_resource("site... | ruby | {
"resource": ""
} |
q15562 | FoodCritic.CookbookHelpers.cookbook_with_maintainer | train | def cookbook_with_maintainer(name, email)
write_recipe %q{
#
# Cookbook Name:: example
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
}
fields = {}
fields["maintainer"] = na... | ruby | {
"resource": ""
} |
q15563 | FoodCritic.CookbookHelpers.rakefile | train | def rakefile(task, options)
rakefile_content = "task :default => []"
task_def = case task
when :no_block then "FoodCritic::Rake::LintTask.new"
else %Q{
FoodCritic::Rake::LintTask.new do |t|
#{"t.name = '#{options[:name]}'" if options[:name]}
#{"t.files = #{o... | ruby | {
"resource": ""
} |
q15564 | FoodCritic.CookbookHelpers.recipe_installs_gem | train | def recipe_installs_gem(type, action = :install)
case type
when :simple
write_recipe %Q{
gem_package "bluepill" do
action :#{action}
end
}.strip
when :compile_time
write_recipe %Q{
r = gem_package "mysql" do
... | ruby | {
"resource": ""
} |
q15565 | FoodCritic.CookbookHelpers.recipe_with_dependency | train | def recipe_with_dependency(dep)
dep = { :is_scoped => true, :is_declared => true,
:parentheses => false }.merge!(dep)
recipe = "foo#{dep[:is_scoped] ? '::default' : ''}"
write_recipe(if dep[:parentheses]
"include_recipe('#{recipe}')"
else
... | ruby | {
"resource": ""
} |
q15566 | FoodCritic.CookbookHelpers.recipe_with_ruby_block | train | def recipe_with_ruby_block(length)
recipe = ""
if length == :short || length == :both
recipe << %q{
ruby_block "subexpressions" do
block do
rc = Chef::Util::FileEdit.new("/foo/bar.conf")
rc.search_file_replace_line(/^search/, "search #{node["foo"]["bar"]} compute-... | ruby | {
"resource": ""
} |
q15567 | FoodCritic.CookbookHelpers.role | train | def role(options = {})
options = { :format => :ruby, :dir => "roles" }.merge(options)
content = if options[:format] == :json
%Q{
{
"chef_type": "role",
"json_class": "Chef::Role",
#{Array(options[:role_na... | ruby | {
"resource": ""
} |
q15568 | FoodCritic.Review.to_s | train | def to_s
# Sorted by filename and line number.
#
# FC123: My rule name: foo/recipes/default.rb
@warnings.map do |w|
["#{w.rule.code}: #{w.rule.name}: #{w.match[:filename]}",
w.match[:line].to_i]
end.sort do |x, y|
x.first == y.first ? x[1] <=> y[1] : x.first <=... | ruby | {
"resource": ""
} |
q15569 | JenkinsApi.Client.get_artifact | train | def get_artifact(job_name,filename)
@artifact = job.find_artifact(job_name)
response = make_http_request(Net::HTTP::Get.new(@artifact))
if response.code == "200"
File.write(File.expand_path(filename), response.body)
else
raise "Couldn't get the artifact"
end
end | ruby | {
"resource": ""
} |
q15570 | JenkinsApi.Client.get_artifacts | train | def get_artifacts(job_name, dldir, build_number = nil)
@artifacts = job.find_artifacts(job_name,build_number)
results = []
@artifacts.each do |artifact|
uri = URI.parse(artifact)
http = Net::HTTP.new(uri.host, uri.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.... | ruby | {
"resource": ""
} |
q15571 | JenkinsApi.Client.make_http_request | train | def make_http_request(request, follow_redirect = @follow_redirects)
request.basic_auth @username, @password if @username
request['Cookie'] = @cookies if @cookies
if @proxy_ip
case @proxy_protocol
when 'http'
http = Net::HTTP::Proxy(@proxy_ip, @proxy_port).new(@server_ip, @se... | ruby | {
"resource": ""
} |
q15572 | JenkinsApi.Client.api_get_request | train | def api_get_request(url_prefix, tree = nil, url_suffix ="/api/json",
raw_response = false)
url_prefix = "#{@jenkins_path}#{url_prefix}"
to_get = ""
if tree
to_get = "#{url_prefix}#{url_suffix}?#{tree}"
else
to_get = "#{url_prefix}#{url_suffix}"
end
... | ruby | {
"resource": ""
} |
q15573 | JenkinsApi.Client.api_post_request | train | def api_post_request(url_prefix, form_data = {}, raw_response = false)
retries = @crumb_max_retries
begin
refresh_crumbs
# Added form_data default {} instead of nil to help with proxies
# that barf with empty post
request = Net::HTTP::Post.new("#{@jenkins_path}#{url_prefix}"... | ruby | {
"resource": ""
} |
q15574 | JenkinsApi.Client.get_config | train | def get_config(url_prefix)
request = Net::HTTP::Get.new("#{@jenkins_path}#{url_prefix}/config.xml")
@logger.debug "GET #{url_prefix}/config.xml"
response = make_http_request(request)
handle_exception(response, "body")
end | ruby | {
"resource": ""
} |
q15575 | JenkinsApi.Client.exec_cli | train | def exec_cli(command, args = [])
base_dir = File.dirname(__FILE__)
server_url = "http://#{@server_ip}:#{@server_port}/#{@jenkins_path}"
cmd = "java -jar #{base_dir}/../../java_deps/jenkins-cli.jar -s #{server_url}"
cmd << " -i #{@identity_file}" if @identity_file && !@identity_file.empty?
... | ruby | {
"resource": ""
} |
q15576 | JenkinsApi.Client.symbolize_keys | train | def symbolize_keys(hash)
hash.inject({}){|result, (key, value)|
new_key = case key
when String then key.to_sym
else key
end
new_value = case value
when Hash then symbolize_keys(value)
else value
end
result[new_key] = new_value
... | ruby | {
"resource": ""
} |
q15577 | JenkinsApi.Client.handle_exception | train | def handle_exception(response, to_send = "code", send_json = false)
msg = "HTTP Code: #{response.code}, Response Body: #{response.body}"
@logger.debug msg
case response.code.to_i
# As of Jenkins version 1.519, the job builds return a 201 status code
# with a Location HTTP header with the p... | ruby | {
"resource": ""
} |
q15578 | Bugsnag.Report.add_tab | train | def add_tab(name, value)
return if name.nil?
if value.is_a? Hash
meta_data[name] ||= {}
meta_data[name].merge! value
else
meta_data["custom"] = {} unless meta_data["custom"]
meta_data["custom"][name.to_s] = value
end
end | ruby | {
"resource": ""
} |
q15579 | Bugsnag.Report.as_json | train | def as_json
# Build the payload's exception event
payload_event = {
app: {
version: app_version,
releaseStage: release_stage,
type: app_type
},
context: context,
device: {
hostname: hostname
},
exceptions: exceptions,
... | ruby | {
"resource": ""
} |
q15580 | Bugsnag.Report.summary | train | def summary
# Guard against the exceptions array being removed/changed or emptied here
if exceptions.respond_to?(:first) && exceptions.first
{
:error_class => exceptions.first[:errorClass],
:message => exceptions.first[:message],
:severity => severity
}
el... | ruby | {
"resource": ""
} |
q15581 | Bugsnag::Breadcrumbs.Validator.valid_meta_data_type? | train | def valid_meta_data_type?(value)
value.nil? || value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(FalseClass) || value.is_a?(TrueClass)
end | ruby | {
"resource": ""
} |
q15582 | Bugsnag.Rack.call | train | def call(env)
# Set the request data for bugsnag middleware to use
Bugsnag.configuration.set_request_data(:rack_env, env)
if Bugsnag.configuration.auto_capture_sessions
Bugsnag.start_session
end
begin
response = @app.call(env)
rescue Exception => raised
# Not... | ruby | {
"resource": ""
} |
q15583 | Bugsnag.SessionTracker.start_session | train | def start_session
return unless Bugsnag.configuration.enable_sessions
start_delivery_thread
start_time = Time.now().utc().strftime('%Y-%m-%dT%H:%M:00')
new_session = {
:id => SecureRandom.uuid,
:startedAt => start_time,
:events => {
:handled => 0,
:unh... | ruby | {
"resource": ""
} |
q15584 | Bugsnag.SessionTracker.send_sessions | train | def send_sessions
sessions = []
counts = @session_counts
@session_counts = Concurrent::Hash.new(0)
counts.each do |min, count|
sessions << {
:startedAt => min,
:sessionsStarted => count
}
end
deliver(sessions)
end | ruby | {
"resource": ""
} |
q15585 | Bugsnag.Railtie.event_subscription | train | def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id
if event[:id] == "sql.active_record"
binds... | ruby | {
"resource": ""
} |
q15586 | Bugsnag.Resque.save | train | def save
Bugsnag.notify(exception, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
:attributes => FRAMEWORK_ATTRIBUTES
}
context = "#{payload['class']}@#{queue}"
report.met... | ruby | {
"resource": ""
} |
q15587 | Bugsnag.MiddlewareStack.insert_after | train | def insert_after(after, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if after.is_a? Array
index = @middlewares.rindex {|el| after.include?(el)}
else
index = @middle... | ruby | {
"resource": ""
} |
q15588 | Bugsnag.MiddlewareStack.insert_before | train | def insert_before(before, new_middleware)
@mutex.synchronize do
return if @disabled_middleware.include?(new_middleware)
return if @middlewares.include?(new_middleware)
if before.is_a? Array
index = @middlewares.index {|el| before.include?(el)}
else
index = @mid... | ruby | {
"resource": ""
} |
q15589 | Bugsnag.MiddlewareStack.run | train | def run(report)
# The final lambda is the termination of the middleware stack. It calls deliver on the notification
lambda_has_run = false
notify_lambda = lambda do |notif|
lambda_has_run = true
yield if block_given?
end
begin
# We reverse them, so we can call "cal... | ruby | {
"resource": ""
} |
q15590 | Bugsnag.MongoBreadcrumbSubscriber.leave_mongo_breadcrumb | train | def leave_mongo_breadcrumb(event_name, event)
message = MONGO_MESSAGE_PREFIX + event_name
meta_data = {
:event_name => MONGO_EVENT_PREFIX + event_name,
:command_name => event.command_name,
:database_name => event.database_name,
:operation_id => event.operation_id,
:re... | ruby | {
"resource": ""
} |
q15591 | Bugsnag.MongoBreadcrumbSubscriber.sanitize_filter_hash | train | def sanitize_filter_hash(filter_hash, depth = 0)
filter_hash.each_with_object({}) do |(key, value), output|
output[key] = sanitize_filter_value(value, depth)
end
end | ruby | {
"resource": ""
} |
q15592 | Bugsnag.MongoBreadcrumbSubscriber.sanitize_filter_value | train | def sanitize_filter_value(value, depth)
depth += 1
if depth >= MAX_FILTER_DEPTH
'[MAX_FILTER_DEPTH_REACHED]'
elsif value.is_a?(Array)
value.map { |array_value| sanitize_filter_value(array_value, depth) }
elsif value.is_a?(Hash)
sanitize_filter_hash(value, depth)
els... | ruby | {
"resource": ""
} |
q15593 | Bugsnag.Configuration.parse_proxy | train | def parse_proxy(uri)
proxy = URI.parse(uri)
self.proxy_host = proxy.host
self.proxy_port = proxy.port
self.proxy_user = proxy.user
self.proxy_password = proxy.password
end | ruby | {
"resource": ""
} |
q15594 | Bugsnag.Mailman.call | train | def call(mail)
begin
Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s
yield
rescue Exception => ex
Bugsnag.notify(ex, true) do |report|
report.severity = "error"
report.severity_reason = {
:type => Bugsnag::Report::UNHANDLED_EXCEPTION_MID... | ruby | {
"resource": ""
} |
q15595 | SimpleNavigation.Helpers.render_navigation | train | def render_navigation(options = {}, &block)
container = active_navigation_item_container(options, &block)
container && container.render(options)
end | ruby | {
"resource": ""
} |
q15596 | SimpleNavigation.Helpers.active_navigation_item | train | def active_navigation_item(options = {}, value_for_nil = nil)
if options[:level].nil? || options[:level] == :all
options[:level] = :leaves
end
container = active_navigation_item_container(options)
if container && (item = container.selected_item)
block_given? ? yield(item) : item
... | ruby | {
"resource": ""
} |
q15597 | SimpleNavigation.Helpers.active_navigation_item_container | train | def active_navigation_item_container(options = {}, &block)
options = SimpleNavigation::Helpers.apply_defaults(options)
SimpleNavigation::Helpers.load_config(options, self, &block)
SimpleNavigation.active_item_container_for(options[:level])
end | ruby | {
"resource": ""
} |
q15598 | SimpleNavigation.Item.html_options | train | def html_options
html_opts = options.fetch(:html) { Hash.new }
html_opts[:id] ||= autogenerated_item_id
classes = [html_opts[:class], selected_class, active_leaf_class]
classes = classes.flatten.compact.join(' ')
html_opts[:class] = classes if classes && !classes.empty?
html_opts
... | ruby | {
"resource": ""
} |
q15599 | SimpleNavigation.ItemContainer.item | train | def item(key, name, url = nil, options = {}, &block)
return unless should_add_item?(options)
item = Item.new(self, key, name, url, options, &block)
add_item item, options
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.