_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q14300 | Azure::GraphRbac::V1_6.Applications.list_owners | train | def list_owners(application_object_id, custom_headers:nil)
response = list_owners_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14301 | Azure::GraphRbac::V1_6.Applications.list_key_credentials | train | def list_key_credentials(application_object_id, custom_headers:nil)
response = list_key_credentials_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14302 | Azure::GraphRbac::V1_6.Applications.update_key_credentials | train | def update_key_credentials(application_object_id, parameters, custom_headers:nil)
response = update_key_credentials_async(application_object_id, parameters, custom_headers:custom_headers).value!
nil
end | ruby | {
"resource": ""
} |
q14303 | Azure::GraphRbac::V1_6.Applications.list_password_credentials | train | def list_password_credentials(application_object_id, custom_headers:nil)
response = list_password_credentials_async(application_object_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14304 | Azure::GraphRbac::V1_6.Applications.update_password_credentials | train | def update_password_credentials(application_object_id, parameters, custom_headers:nil)
response = update_password_credentials_async(application_object_id, parameters, custom_headers:custom_headers).value!
nil
end | ruby | {
"resource": ""
} |
q14305 | Azure::Authorization::Mgmt::V2018_07_01_preview.DenyAssignments.get_by_id | train | def get_by_id(deny_assignment_id, custom_headers:nil)
response = get_by_id_async(deny_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14306 | Azure::IotCentral::Mgmt::V2018_09_01.Apps.check_subdomain_availability | train | def check_subdomain_availability(operation_inputs, custom_headers:nil)
response = check_subdomain_availability_async(operation_inputs, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14307 | Azure::ApiManagement::Mgmt::V2018_01_01.NotificationRecipientEmail.check_entity_exists_with_http_info | train | def check_entity_exists_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
check_entity_exists_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14308 | Azure::ApiManagement::Mgmt::V2018_01_01.NotificationRecipientEmail.create_or_update_with_http_info | train | def create_or_update_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
create_or_update_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14309 | Azure::ApiManagement::Mgmt::V2018_01_01.NotificationRecipientEmail.delete_with_http_info | train | def delete_with_http_info(resource_group_name, service_name, notification_name, email, custom_headers:nil)
delete_async(resource_group_name, service_name, notification_name, email, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14310 | Azure::Network::Mgmt::V2018_07_01.NetworkInterfaces.begin_update_tags_with_http_info | train | def begin_update_tags_with_http_info(resource_group_name, network_interface_name, parameters, custom_headers:nil)
begin_update_tags_async(resource_group_name, network_interface_name, parameters, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14311 | Azure::Resources::Mgmt::V2016_02_01.Providers.unregister | train | def unregister(resource_provider_namespace, custom_headers:nil)
response = unregister_async(resource_provider_namespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14312 | Azure::Resources::Mgmt::V2016_02_01.Providers.register | train | def register(resource_provider_namespace, custom_headers:nil)
response = register_async(resource_provider_namespace, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14313 | Azure::Resources::Mgmt::V2016_02_01.Providers.get_with_http_info | train | def get_with_http_info(resource_provider_namespace, expand:nil, custom_headers:nil)
get_async(resource_provider_namespace, expand:expand, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14314 | Azure::Logic::Mgmt::V2016_06_01.Certificates.get_with_http_info | train | def get_with_http_info(resource_group_name, integration_account_name, certificate_name, custom_headers:nil)
get_async(resource_group_name, integration_account_name, certificate_name, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14315 | Azure::Logic::Mgmt::V2016_06_01.Certificates.delete_with_http_info | train | def delete_with_http_info(resource_group_name, integration_account_name, certificate_name, custom_headers:nil)
delete_async(resource_group_name, integration_account_name, certificate_name, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14316 | Azure::Network::Mgmt::V2019_02_01.LoadBalancerOutboundRules.get_with_http_info | train | def get_with_http_info(resource_group_name, load_balancer_name, outbound_rule_name, custom_headers:nil)
get_async(resource_group_name, load_balancer_name, outbound_rule_name, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14317 | Azure::Policy::Mgmt::V2015_10_01_preview.PolicyAssignments.create_with_http_info | train | def create_with_http_info(scope, policy_assignment_name, parameters, custom_headers:nil)
create_async(scope, policy_assignment_name, parameters, custom_headers:custom_headers).value!
end | ruby | {
"resource": ""
} |
q14318 | Azure::Policy::Mgmt::V2015_10_01_preview.PolicyAssignments.delete_by_id | train | def delete_by_id(policy_assignment_id, custom_headers:nil)
response = delete_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14319 | Azure::Policy::Mgmt::V2015_10_01_preview.PolicyAssignments.get_by_id | train | def get_by_id(policy_assignment_id, custom_headers:nil)
response = get_by_id_async(policy_assignment_id, custom_headers:custom_headers).value!
response.body unless response.nil?
end | ruby | {
"resource": ""
} |
q14320 | RequestLogAnalyzer::Tracker.NumericValue.prepare | train | def prepare
fail "No value field set up for numeric tracker #{inspect}" unless options[:value]
fail "No categorizer set up for numeric tracker #{inspect}" unless options[:category]
unless options[:multiple]
@categorizer = create_lambda(options[:category])
@valueizer = create_lambda(options[:value])
end
@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 0.000001
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000
# precalculate the bucket size
@bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
@categories = {}
end | ruby | {
"resource": ""
} |
q14321 | RequestLogAnalyzer::Tracker.NumericValue.update | train | def update(request)
if options[:multiple]
found_categories = request.every(options[:category])
found_values = request.every(options[:value])
fail 'Capture mismatch for multiple values in a request' unless found_categories.length == found_values.length
found_categories.each_with_index do |cat, index|
update_statistics(cat, found_values[index]) if cat && found_values[index].is_a?(Numeric)
end
else
category = @categorizer.call(request)
value = @valueizer.call(request)
update_statistics(category, value) if (value.is_a?(Numeric) || value.is_a?(Array)) && category
end
end | ruby | {
"resource": ""
} |
q14322 | RequestLogAnalyzer::Tracker.NumericValue.display_value | train | def display_value(value)
return '- ' if value.nil?
return '0 ' if value.zero?
case [Math.log10(value.abs).floor, 0].max
when 0...4 then '%d ' % value
when 4...7 then '%dk' % (value / 1000)
when 7...10 then '%dM' % (value / 1_000_000)
when 10...13 then '%dG' % (value / 1_000_000_000)
when 13...16 then '%dT' % (value / 1_000_000_000_000)
else '%dP' % (value / 1_000_000_000_000_000)
end
end | ruby | {
"resource": ""
} |
q14323 | RequestLogAnalyzer::Tracker.NumericValue.title | train | def title
@title ||= begin
if options[:title]
options[:title]
else
title_builder = ''
title_builder << "#{options[:value]} " if options[:value].is_a?(Symbol)
title_builder << (options[:category].is_a?(Symbol) ? "per #{options[:category]}" : 'per request')
title_builder
end
end
end | ruby | {
"resource": ""
} |
q14324 | RequestLogAnalyzer::Tracker.NumericValue.to_yaml_object | train | def to_yaml_object
return nil if @categories.empty?
@categories.each do |cat, info|
info[:stddev] = stddev(cat)
info[:median] = median(cat) if info[:buckets]
info[:interval_95_percent] = percentile_interval(cat, 95) if info[:buckets]
end
@categories
end | ruby | {
"resource": ""
} |
q14325 | RequestLogAnalyzer::Tracker.NumericValue.bucket_index | train | def bucket_index(value)
return 0 if value < @min_bucket_value
return @number_of_buckets - 1 if value >= @max_bucket_value
((Math.log(value) - Math.log(@min_bucket_value)) / @bucket_size).floor
end | ruby | {
"resource": ""
} |
q14326 | RequestLogAnalyzer::Tracker.NumericValue.bucket_value | train | def bucket_value(index, type = nil)
case type
when :begin, :start, :lower, :lower_bound then bucket_lower_bound(index)
when :end, :finish, :upper, :upper_bound then bucket_upper_bound(index)
else bucket_average_value(index)
end
end | ruby | {
"resource": ""
} |
q14327 | RequestLogAnalyzer::Tracker.NumericValue.percentile_index | train | def percentile_index(category, x, inclusive = false)
total_encountered = 0
@categories[category][:buckets].each_with_index do |count, index|
total_encountered += count
percentage = ((total_encountered.to_f / hits(category).to_f) * 100).floor
return index if (inclusive && percentage >= x) || (!inclusive && percentage > x)
end
end | ruby | {
"resource": ""
} |
q14328 | RequestLogAnalyzer::Tracker.NumericValue.percentile_interval | train | def percentile_interval(category, x)
case x
when Range
lower, upper = percentile_indices(category, x.begin, x.end)
Range.new(bucket_lower_bound(lower), bucket_upper_bound(upper))
when Numeric
percentile_interval(category, Range.new((100 - x) / 2, (100 - (100 - x) / 2)))
else
fail 'What does it mean?'
end
end | ruby | {
"resource": ""
} |
q14329 | RequestLogAnalyzer::Tracker.NumericValue.statistics_header | train | def statistics_header(options)
[
{ title: options[:title], width: :rest },
{ title: 'Hits', align: :right, highlight: (options[:highlight] == :hits), min_width: 4 },
{ title: 'Sum', align: :right, highlight: (options[:highlight] == :sum), min_width: 6 },
{ title: 'Mean', align: :right, highlight: (options[:highlight] == :mean), min_width: 6 },
{ title: 'StdDev', align: :right, highlight: (options[:highlight] == :stddev), min_width: 6 },
{ title: 'Min', align: :right, highlight: (options[:highlight] == :min), min_width: 6 },
{ title: 'Max', align: :right, highlight: (options[:highlight] == :max), min_width: 6 },
{ title: '95 %tile', align: :right, highlight: (options[:highlight] == :percentile_interval), min_width: 11 }
]
end | ruby | {
"resource": ""
} |
q14330 | RequestLogAnalyzer::Tracker.NumericValue.statistics_row | train | def statistics_row(cat)
[cat, hits(cat), display_value(sum(cat)), display_value(mean(cat)), display_value(stddev(cat)),
display_value(min(cat)), display_value(max(cat)),
display_value(percentile_interval(cat, 95).begin) + '-' + display_value(percentile_interval(cat, 95).end)]
end | ruby | {
"resource": ""
} |
q14331 | RequestLogAnalyzer::Source.LogParser.decompress_file? | train | def decompress_file?(filename)
nice_command = 'nice -n 5'
return "#{nice_command} gunzip -c -d #{filename}" if filename.match(/\.tar.gz$/) || filename.match(/\.tgz$/) || filename.match(/\.gz$/)
return "#{nice_command} bunzip2 -c -d #{filename}" if filename.match(/\.bz2$/)
return "#{nice_command} unzip -p #{filename}" if filename.match(/\.zip$/)
''
end | ruby | {
"resource": ""
} |
q14332 | RequestLogAnalyzer::Source.LogParser.parse_file | train | def parse_file(file, options = {}, &block)
if File.directory?(file)
parse_files(Dir["#{ file }/*"], options, &block)
return
end
@current_source = File.expand_path(file)
@source_changes_handler.call(:started, @current_source) if @source_changes_handler
if decompress_file?(file).empty?
@progress_handler = @dormant_progress_handler
@progress_handler.call(:started, file) if @progress_handler
File.open(file, 'rb') { |f| parse_io(f, options, &block) }
@progress_handler.call(:finished, file) if @progress_handler
@progress_handler = nil
@processed_files.push(@current_source.dup)
else
IO.popen(decompress_file?(file), 'rb') { |f| parse_io(f, options, &block) }
end
@source_changes_handler.call(:finished, @current_source) if @source_changes_handler
@current_source = nil
end | ruby | {
"resource": ""
} |
q14333 | RequestLogAnalyzer::Source.LogParser.update_current_request | train | def update_current_request(request_data, &block) # :yields: request
if alternative_header_line?(request_data)
if @current_request
@current_request << request_data
else
@current_request = @file_format.request(request_data)
end
elsif header_line?(request_data)
if @current_request
case options[:parse_strategy]
when 'assume-correct'
handle_request(@current_request, &block)
@current_request = @file_format.request(request_data)
when 'cautious'
@skipped_lines += 1
warn(:unclosed_request, "Encountered header line (#{request_data[:line_definition].name.inspect}), but previous request was not closed!")
@current_request = nil # remove all data that was parsed, skip next request as well.
end
elsif footer_line?(request_data)
handle_request(@file_format.request(request_data), &block)
else
@current_request = @file_format.request(request_data)
end
else
if @current_request
@current_request << request_data
if footer_line?(request_data)
handle_request(@current_request, &block) # yield @current_request
@current_request = nil
end
else
@skipped_lines += 1
warn(:no_current_request, "Parseable line (#{request_data[:line_definition].name.inspect}) found outside of a request!")
end
end
end | ruby | {
"resource": ""
} |
q14334 | RequestLogAnalyzer::Source.LogParser.handle_request | train | def handle_request(request, &_block) # :yields: :request, request
@parsed_requests += 1
request.validate
accepted = block_given? ? yield(request) : true
@skipped_requests += 1 unless accepted
end | ruby | {
"resource": ""
} |
q14335 | RequestLogAnalyzer::FileFormat.CommonRegularExpressions.hostname_or_ip_address | train | def hostname_or_ip_address(blank = false)
regexp = Regexp.union(hostname, ip_address)
add_blank_option(regexp, blank)
end | ruby | {
"resource": ""
} |
q14336 | RequestLogAnalyzer::FileFormat.CommonRegularExpressions.timestamp | train | def timestamp(format_string, blank = false)
regexp = ''
format_string.scan(/([^%]*)(?:%([A-Za-z%]))?/) do |literal, variable|
regexp << Regexp.quote(literal)
if variable
if TIMESTAMP_PARTS.key?(variable)
regexp << TIMESTAMP_PARTS[variable]
else
fail "Unknown variable: %#{variable}"
end
end
end
add_blank_option(Regexp.new(regexp), blank)
end | ruby | {
"resource": ""
} |
q14337 | RequestLogAnalyzer::FileFormat.CommonRegularExpressions.add_blank_option | train | def add_blank_option(regexp, blank)
case blank
when String then Regexp.union(regexp, Regexp.new(Regexp.quote(blank)))
when true then Regexp.union(regexp, //)
else regexp
end
end | ruby | {
"resource": ""
} |
q14338 | RequestLogAnalyzer::FileFormat.Base.valid_line_definitions? | train | def valid_line_definitions?
line_definitions.any? { |(_, ld)| ld.header } && line_definitions.any? { |(_, ld)| ld.footer }
end | ruby | {
"resource": ""
} |
q14339 | RequestLogAnalyzer::FileFormat.Base.parse_line | train | def parse_line(line, &warning_handler)
line_definitions.each do |_lt, definition|
match = definition.matches(line, &warning_handler)
return match if match
end
nil
end | ruby | {
"resource": ""
} |
q14340 | RequestLogAnalyzer::Aggregator.Summarizer.to_yaml | train | def to_yaml
require 'yaml'
trackers_export = @trackers.reduce({}) do |export, tracker|
export[tracker.title] = tracker.to_yaml_object; export
end
YAML.dump(trackers_export)
end | ruby | {
"resource": ""
} |
q14341 | RequestLogAnalyzer::Tracker.Frequency.prepare | train | def prepare
options[:category] = options[:value] if options[:value] && !options[:category]
fail "No categorizer set up for category tracker #{inspect}" unless options[:category]
@categorizer = create_lambda(options[:category]) unless options[:multiple]
# Initialize the categories. Use the list of category names to
@categories = {}
options[:all_categories].each { |cat| @categories[cat] = 0 } if options[:all_categories].is_a?(Enumerable)
end | ruby | {
"resource": ""
} |
q14342 | RequestLogAnalyzer::Tracker.Base.setup_should_update_checks! | train | def setup_should_update_checks!
@should_update_checks = []
@should_update_checks.push(lambda { |request| request.has_line_type?(options[:line_type]) }) if options[:line_type]
@should_update_checks.push(options[:if]) if options[:if].respond_to?(:call)
@should_update_checks.push(lambda { |request| request[options[:if]] }) if options[:if].is_a?(Symbol)
@should_update_checks.push(lambda { |request| !options[:unless].call(request) }) if options[:unless].respond_to?(:call)
@should_update_checks.push(lambda { |request| !request[options[:unless]] }) if options[:unless].is_a?(Symbol)
end | ruby | {
"resource": ""
} |
q14343 | RequestLogAnalyzer::Tracker.Base.create_lambda | train | def create_lambda(arg)
case arg
when Proc then arg
when Symbol then lambda { |request| request[arg] }
else fail "Canot create a lambda expression from this argument: #{arg.inspect}!"
end
end | ruby | {
"resource": ""
} |
q14344 | RequestLogAnalyzer.LineDefinition.match_for | train | def match_for(line, request, &warning_handler)
if match_info = matches(line, &warning_handler)
convert_captured_values(match_info[:captures], request)
else
false
end
end | ruby | {
"resource": ""
} |
q14345 | RequestLogAnalyzer.Request.add_parsed_line | train | def add_parsed_line(parsed_line)
value_hash = parsed_line[:line_definition].convert_captured_values(parsed_line[:captures], self)
value_hash[:line_type] = parsed_line[:line_definition].name
value_hash[:lineno] = parsed_line[:lineno]
value_hash[:source] = parsed_line[:source]
value_hash[:compound] = parsed_line[:line_definition].compound
add_line_hash(value_hash)
end | ruby | {
"resource": ""
} |
q14346 | RequestLogAnalyzer.Request.add_line_hash | train | def add_line_hash(value_hash)
@lines << value_hash
if value_hash[:compound]
value_hash.each do |key, value|
if value_hash[:compound].include?(key)
@attributes[key] = [] if @attributes[key].nil?
@attributes[key] = [@attributes[key]] unless @attributes[key].is_a?(Array)
@attributes[key] << value
else
@attributes[key] = value unless key == :compound || @attributes[key]
end
end
else
@attributes = value_hash.merge(@attributes)
end
end | ruby | {
"resource": ""
} |
q14347 | RequestLogAnalyzer.Request.has_line_type? | train | def has_line_type?(line_type)
return true if @lines.length == 1 && @lines[0][:line_type] == line_type.to_sym
@lines.find { |l| l[:line_type] == line_type.to_sym }
end | ruby | {
"resource": ""
} |
q14348 | RequestLogAnalyzer.Request.every | train | def every(field)
@lines.reduce([]) { |result, fields| result << fields[field] if fields.key?(field); result }
end | ruby | {
"resource": ""
} |
q14349 | RequestLogAnalyzer.Request.completed? | train | def completed?
header_found, footer_found = false, false
@lines.each do |line|
line_def = file_format.line_definitions[line[:line_type]]
header_found = true if line_def.header
footer_found = true if line_def.footer
end
header_found && footer_found
end | ruby | {
"resource": ""
} |
q14350 | RequestLogAnalyzer::Tracker.Traffic.prepare | train | def prepare
options[:value] = options[:traffic] if options[:traffic]
options[:total] = true
super
@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 1
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1_000_000_000_000
# precalculate the bucket size
@bucket_size = (Math.log(@max_bucket_value) - Math.log(@min_bucket_value)) / @number_of_buckets.to_f
end | ruby | {
"resource": ""
} |
q14351 | RequestLogAnalyzer::Filter.Field.filter | train | def filter(request)
found_field = request.every(@field).any? { |value| @value === value.to_s }
return nil if !found_field && @mode == :select
return nil if found_field && @mode == :reject
request
end | ruby | {
"resource": ""
} |
q14352 | RequestLogAnalyzer::Output.HTML.header | train | def header
@io.content_type = content_type if @io.respond_to?(:content_type)
@io << '<html>'
@io << tag(:head) do |headers|
headers << tag(:title, 'Request-log-analyzer report')
headers << tag(:style, '
body {
font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
background: #E6EAE9;
padding-left:20px;
padding-top:20px;
padding-bottom:20px;
}
a {
color: #c75f3e;
}
.color_bar {
border: 1px solid;
height:10px;
background: #CAE8EA;
}
.rla-report-table {
width: 700px;
padding: 0;
margin: 0;
padding-bottom:10px;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}
td {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
', type: 'text/css')
end
@io << '<body>'
@io << tag(:h1, 'Request-log-analyzer summary report')
@io << tag(:p, "Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke")
end | ruby | {
"resource": ""
} |
q14353 | RequestLogAnalyzer.Controller.handle_source_change | train | def handle_source_change(change, filename)
@aggregators.each { |agg| agg.source_change(change, File.expand_path(filename, Dir.pwd)) }
end | ruby | {
"resource": ""
} |
q14354 | RequestLogAnalyzer.Controller.add_filter | train | def add_filter(filter, filter_options = {})
filter = RequestLogAnalyzer::Filter.const_get(RequestLogAnalyzer.to_camelcase(filter)) if filter.is_a?(Symbol)
@filters << filter.new(source.file_format, @options.merge(filter_options))
end | ruby | {
"resource": ""
} |
q14355 | RequestLogAnalyzer.Controller.filter_request | train | def filter_request(request)
@filters.each do |filter|
request = filter.filter(request)
return nil if request.nil?
end
request
end | ruby | {
"resource": ""
} |
q14356 | RequestLogAnalyzer.Controller.aggregate_request | train | def aggregate_request(request)
return false unless request
@aggregators.each { |agg| agg.aggregate(request) }
true
end | ruby | {
"resource": ""
} |
q14357 | RequestLogAnalyzer.Controller.run! | train | def run!
# @aggregators.each{|agg| p agg}
@aggregators.each { |agg| agg.prepare }
install_signal_handlers
@source.each_request do |request|
break if @interrupted
aggregate_request(filter_request(request))
end
@aggregators.each { |agg| agg.finalize }
@output.header
@aggregators.each { |agg| agg.report(@output) }
@output.footer
@source.finalize
if @output.io.is_a?(File)
unless @options[:silent]
puts
puts 'Report written to: ' + File.expand_path(@output.io.path)
puts 'Need an expert to analyze your application?'
puts 'Mail to contact@railsdoctors.com or visit us at http://railsdoctors.com'
puts 'Thanks for using request-log-analyzer!'
end
@output.io.close
elsif @output.io.is_a?(RequestLogAnalyzer::Mailer)
@output.io.mail
end
end | ruby | {
"resource": ""
} |
q14358 | RequestLogAnalyzer::Tracker.Duration.display_value | train | def display_value(time)
case time
when nil then '-'
when 0...1 then '%0ims' % (time * 1000)
when 1...60 then '%0.02fs' % time
when 60...3600 then '%dm%02ds' % [time / 60, (time % 60).round]
else '%dh%02dm%02ds' % [time / 3600, (time % 3600) / 60, (time % 60).round]
end
end | ruby | {
"resource": ""
} |
q14359 | RequestLogAnalyzer::Aggregator.DatabaseInserter.prepare | train | def prepare
require 'request_log_analyzer/database'
@sources = {}
@database = RequestLogAnalyzer::Database.new(options[:database])
@database.file_format = source.file_format
database.drop_database_schema! if options[:reset_database]
database.create_database_schema!
end | ruby | {
"resource": ""
} |
q14360 | RequestLogAnalyzer::Aggregator.DatabaseInserter.aggregate | train | def aggregate(request)
@request_object = RequestLogAnalyzer::Database::Request.new(first_lineno: request.first_lineno, last_lineno: request.last_lineno)
request.lines.each do |line|
class_columns = database.get_class(line[:line_type]).column_names.reject { |column| %w(id source_id request_id).include?(column) }
attributes = Hash[*line.select { |(key, _)| class_columns.include?(key.to_s) }.flatten]
# Fix encoding patch for 1.9.2
attributes.each do |k, v|
attributes[k] = v.force_encoding('UTF-8') if v.is_a?(String)
end
@request_object.send("#{line[:line_type]}_lines").build(attributes)
end
@request_object.save!
rescue SQLite3::SQLException => e
raise Interrupt, e.message
end | ruby | {
"resource": ""
} |
q14361 | RequestLogAnalyzer::Aggregator.DatabaseInserter.warning | train | def warning(type, message, lineno)
RequestLogAnalyzer::Database::Warning.create!(warning_type: type.to_s, message: message, lineno: lineno)
end | ruby | {
"resource": ""
} |
q14362 | RequestLogAnalyzer::Aggregator.DatabaseInserter.source_change | train | def source_change(change, filename)
if File.exist?(filename)
case change
when :started
@sources[filename] = RequestLogAnalyzer::Database::Source.create!(filename: filename)
when :finished
@sources[filename].update_attributes!(filesize: File.size(filename), mtime: File.mtime(filename))
end
end
end | ruby | {
"resource": ""
} |
q14363 | RequestLogAnalyzer::Aggregator.DatabaseInserter.report | train | def report(output)
output.title('Request database created')
output << "A database file has been created with all parsed request information.\n"
output << "#{@request_count} requests have been added to the database.\n"
output << "\n"
output << "To open a Ruby console to inspect the database, run the following command.\n"
output << output.colorize(" $ request-log-analyzer console -d #{options[:database]}\n", :bold)
output << "\n"
end | ruby | {
"resource": ""
} |
q14364 | ActiveScaffold::DataStructures.Set.add | train | def add(*args)
args.flatten! # allow [] as a param
args.each do |arg|
arg = arg.to_sym if arg.is_a? String
@set << arg unless @set.include? arg # avoid duplicates
end
end | ruby | {
"resource": ""
} |
q14365 | ActiveScaffold::DataStructures.Set.exclude | train | def exclude(*args)
args.flatten! # allow [] as a param
args.collect!(&:to_sym) # symbolize the args
# check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
@set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified
end | ruby | {
"resource": ""
} |
q14366 | ActiveScaffold.AttributeParams.attributes_hash_is_empty? | train | def attributes_hash_is_empty?(hash, klass)
hash.all? do |key, value|
# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'
column_name = key.to_s.split('(', 2)[0]
# datetimes will always have a value. so we ignore them when checking whether the hash is empty.
# this could be a bad idea. but the current situation (excess record entry) seems worse.
next true if mulitpart_ignored?(key, klass)
# defaults are pre-filled on the form. we can't use them to determine if the user intends a new row.
# booleans always have value, so they are ignored if not changed from default
next true if default_value?(column_name, klass, value)
if params_hash? value
attributes_hash_is_empty?(value, klass)
elsif value.is_a?(Array)
value.all?(&:blank?)
else
value.respond_to?(:empty?) ? value.empty? : false
end
end
end | ruby | {
"resource": ""
} |
q14367 | ActiveScaffold::Actions::Nested.ChildMethods.do_add_existing | train | def do_add_existing
parent_record = nested_parent_record(:update)
@record = active_scaffold_config.model.find(params[:associated_id])
if parent_record && @record
parent_record.send(nested.association.name) << @record
parent_record.save
else
false
end
end | ruby | {
"resource": ""
} |
q14368 | ActiveScaffold.RenderingHelper.render | train | def render(*args, &block)
if args.first.is_a?(Hash) && args.first[:active_scaffold]
render_embedded args.first
elsif args.first == :super
@_view_paths ||= lookup_context.view_paths.clone
@_last_template ||= lookup_context.last_template
parts = @virtual_path.split('/')
template = parts.pop
prefix = parts.join('/')
options = args[1] || {}
options[:locals] ||= {}
if view_stack.last
options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals]
options[:object] ||= view_stack.last[:object] if view_stack.last[:object]
end
options[:template] = template
# if prefix is active_scaffold_overrides we must try to render with this prefix in following paths
if prefix != 'active_scaffold_overrides'
options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1)
else
options[:prefixes] = ['active_scaffold_overrides']
last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
lookup_context.view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
end
result = super options
lookup_context.view_paths = @_view_paths if @_view_paths
lookup_context.last_template = @_last_template if @_last_template
result
else
@_view_paths ||= lookup_context.view_paths.clone
last_template = lookup_context.last_template
current_view = if args[0].is_a?(Hash)
{:locals => args[0][:locals], :object => args[0][:object]}
else # call is render 'partial', locals_hash
{:locals => args[1]}
end
view_stack << current_view if current_view
lookup_context.view_paths = @_view_paths # reset view_paths in case a view render :super, and then render :partial
result = super
view_stack.pop if current_view.present?
lookup_context.last_template = last_template
result
end
end | ruby | {
"resource": ""
} |
q14369 | ActiveScaffold::DataStructures.ActionLink.initialize_copy | train | def initialize_copy(action_link)
self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters)
self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options)
end | ruby | {
"resource": ""
} |
q14370 | ActiveScaffold::Config.Nested.add_link | train | def add_link(attribute, options = {})
column = @core.columns[attribute.to_sym]
raise ArgumentError, "unknown column #{attribute}" if column.nil?
raise ArgumentError, "column #{attribute} is not an association" if column.association.nil?
label =
if column.association.polymorphic?
column.label
else
column.association.klass.model_name.human(:count => column.association.singular? ? 1 : 2, :default => column.association.klass.name.pluralize)
end
options.reverse_merge! :security_method => :nested_authorized?, :label => label
action_group = options.delete(:action_group) || self.action_group
action_link = @core.link_for_association(column, options)
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
action_link
end | ruby | {
"resource": ""
} |
q14371 | ActiveScaffold::Actions.Create.do_create | train | def do_create(options = {})
attributes = options[:attributes] || params[:record]
active_scaffold_config.model.transaction do
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, attributes)
apply_constraints_to_record(@record, :allow_autosave => true)
create_association_with_parent(@record) if nested?
before_create_save(@record)
# errors to @record can be added by update_record_from_params when association fails to set and ActiveRecord::RecordNotSaved is raised
self.successful = [@record.keeping_errors { @record.valid? }, @record.associated_valid?].all? # this syntax avoids a short-circuit
create_save(@record) unless options[:skip_save]
end
rescue ActiveRecord::ActiveRecordError => ex
flash[:error] = ex.message
self.successful = false
@record ||= new_model # ensure @record exists or display form will fail
end | ruby | {
"resource": ""
} |
q14372 | ActiveScaffold::Config.Core._configure_sti | train | def _configure_sti
column = model.inheritance_column
if sti_create_links
columns[column].form_ui ||= :hidden
else
columns[column].form_ui ||= :select
columns[column].options ||= {}
columns[column].options[:options] = sti_children.collect do |model_name|
[model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize]
end
end
end | ruby | {
"resource": ""
} |
q14373 | ActiveScaffold::DataStructures.Sorting.add | train | def add(column_name, direction = nil)
direction ||= 'ASC'
direction = direction.to_s.upcase
column = get_column(column_name)
raise ArgumentError, "Could not find column #{column_name}" if column.nil?
raise ArgumentError, 'Sorting direction unknown' unless %i[ASC DESC].include? direction.to_sym
@clauses << [column, direction.untaint] if column.sortable?
raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting?
end | ruby | {
"resource": ""
} |
q14374 | ActiveScaffold::DataStructures.Sorting.clause | train | def clause(grouped_columns_calculations = nil)
return nil if sorts_by_method? || default_sorting?
# unless the sorting is by method, create the sql string
order = []
each do |sort_column, sort_direction|
next if constraint_columns.include? sort_column.name
sql = grouped_columns_calculations&.dig(sort_column.name) || sort_column.sort[:sql]
next if sql.blank?
sql = sql.to_sql if sql.respond_to?(:to_sql)
parts = Array(sql).map do |column|
mongoid? ? [column, sort_direction] : "#{column} #{sort_direction}"
end
order << parts
end
order << @primary_key_order_clause if @sorting_by_primary_key
order.flatten!(1)
order unless order.empty?
end | ruby | {
"resource": ""
} |
q14375 | ActiveScaffold::DataStructures.Sorting.get_column | train | def get_column(name_or_column)
# it's a column
return name_or_column if name_or_column.is_a? ActiveScaffold::DataStructures::Column
# it's a name
name_or_column = name_or_column.to_s.split('.').last if name_or_column.to_s.include? '.'
@columns[name_or_column]
end | ruby | {
"resource": ""
} |
q14376 | ActiveScaffold::DataStructures.Columns.add | train | def add(*args)
args.flatten! # allow [] as a param
args = args.collect(&:to_sym)
# make the columns inheritable
@_inheritable.concat(args)
# then add columns to @set (unless they already exist)
args.each { |a| @set << ActiveScaffold::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
end | ruby | {
"resource": ""
} |
q14377 | ActiveScaffold::DataStructures.Column.set_link | train | def set_link(action, options = {})
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc)
@link = action
else
options[:label] ||= label
options[:position] ||= :after unless options.key?(:position)
options[:type] ||= :member
@link = ActiveScaffold::DataStructures::ActionLink.new(action, options)
end
end | ruby | {
"resource": ""
} |
q14378 | ActiveScaffold::DataStructures.ActionLinks.add | train | def add(action, options = {})
link =
if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
action
else
options[:type] ||= default_type if default_type
ActiveScaffold::DataStructures::ActionLink.new(action, options)
end
# NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure
existing = find_duplicate(link)
if existing
existing
else
# That s for backwards compatibility if we are in root of action_links
# we have to move actionlink into members or collection subgroup
group = (name == :root ? subgroup(link.type, link.type) : self)
group.add_to_set(link)
link
end
end | ruby | {
"resource": ""
} |
q14379 | ActiveScaffold::DataStructures.ActionLinks.add_to_group | train | def add_to_group(link, group_name = nil)
add_to = root
add_to = group_name.split('.').inject(root) { |group, name| group.send(name) } if group_name
add_to << link unless link.nil?
end | ruby | {
"resource": ""
} |
q14380 | ActiveScaffold::DataStructures.ActionLinks.[] | train | def [](val)
links = []
@set.each do |item|
if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
collected = item[val]
links << collected unless collected.nil?
elsif item.action.to_s == val.to_s
links << item
end
end
links.first
end | ruby | {
"resource": ""
} |
q14381 | ActiveScaffold::DataStructures.ActionLinks.each | train | def each(options = {}, &block)
method = options[:reverse] ? :reverse_each : :each
@set.sort_by(&:weight).send(method) do |item|
if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) && !options[:groups]
item.each(options, &block)
elsif options[:include_set]
yield item, @set
else
yield item
end
end
end | ruby | {
"resource": ""
} |
q14382 | ActiveScaffold::DataStructures.ActionColumns.add_subgroup | train | def add_subgroup(label, &proc)
columns = ActiveScaffold::DataStructures::ActionColumns.new
columns.label = label
columns.action = action
columns.configure(&proc)
exclude columns.collect_columns
add columns
end | ruby | {
"resource": ""
} |
q14383 | ActiveScaffold::Actions.Delete.do_destroy | train | def do_destroy(record)
record ||= destroy_find_record
begin
self.successful = record.destroy
rescue StandardError => exception
flash[:warning] = as_(:cant_destroy_record, :record => ERB::Util.h(record.to_label))
self.successful = false
logger.warn do
"\n\n#{exception.class} (#{exception.message}):\n " +
Rails.backtrace_cleaner.clean(exception.backtrace).join("\n ") +
"\n\n"
end
end
end | ruby | {
"resource": ""
} |
q14384 | ActiveScaffold.Constraints.conditions_from_constraints | train | def conditions_from_constraints
hash_conditions = {}
conditions = [hash_conditions]
active_scaffold_constraints.each do |k, v|
column = active_scaffold_config.columns[k]
if column
# Assume this is a multi-level association constraint.
# example:
# data model: Park -> Den -> Bear
# constraint: :den => {:park => 5}
if params_hash? v
far_association = column.association.klass.reflect_on_association(v.keys.first)
field = far_association.klass.primary_key
table = far_association.table_name
active_scaffold_references.concat([{k => far_association.name}]) # e.g. {:den => :park}
hash_conditions.deep_merge!(table => {field => v.values.first})
# association column constraint
elsif column.association
join_from_association_constraint(column)
hash_conditions.deep_merge!(condition_from_association_constraint(column.association, v))
# regular column constraints
elsif column.searchable? && params[column.name] != v
active_scaffold_references.concat column.references if column.includes.present?
conditions << [column.search_sql.collect { |search_sql| "#{search_sql} = ?" }.join(' OR '), *([v] * column.search_sql.size)]
end
# unknown-to-activescaffold-but-real-database-column constraint
elsif active_scaffold_config.model.columns_hash[k.to_s] && params[column.name] != v
hash_conditions.deep_merge!(k => v)
else
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
end
end
conditions.reject(&:blank?)
end | ruby | {
"resource": ""
} |
q14385 | ActiveScaffold.Constraints.condition_from_association_constraint | train | def condition_from_association_constraint(association, value)
# when the reverse association is a :belongs_to, the id for the associated object only exists as
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
# we have to use the other model's primary_key.
#
# please see the relevant tests for concrete examples.
field =
if association.belongs_to?
association.foreign_key
else
association.klass.primary_key
end
table = association.belongs_to? ? active_scaffold_config.model.table_name : association.table_name
value = association.klass.find(value).send(association.primary_key) if association.primary_key
if association.polymorphic?
unless value.is_a?(Array) && value.size == 2
raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(association), caller
end
condition = {table => {association.foreign_type => value[0], field => value[1]}}
else
condition = {table => {field.to_s => value}}
end
condition
end | ruby | {
"resource": ""
} |
q14386 | ActiveScaffold.Constraints.apply_constraints_to_record | train | def apply_constraints_to_record(record, options = {})
options[:allow_autosave] = false if options[:allow_autosave].nil?
constraints = options[:constraints] || active_scaffold_constraints
config = record.is_a?(active_scaffold_config.model) ? active_scaffold_config : active_scaffold_config_for(record.class)
constraints.each do |k, v|
column = config.columns[k]
if column&.association
if column.association.collection?
record.send(k.to_s).send(:<<, column.association.klass.find(v))
elsif column.association.polymorphic?
unless v.is_a?(Array) && v.size == 2
raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(column.association), caller
end
record.send("#{k}=", v[0].constantize.find(v[1]))
else # regular singular association
record.send("#{k}=", column.association.klass.find(v))
# setting the belongs_to side of a has_one isn't safe. if the has_one was already
# specified, rails won't automatically clear out the previous associated record.
#
# note that we can't take the extra step to correct this unless we're permitted to
# run operations where activerecord auto-saves the object.
reverse = column.association.reverse_association
if reverse.singular? && !reverse.belongs_to? && options[:allow_autosave]
record.send(k).send("#{reverse.name}=", record)
end
end
else
record.send("#{k}=", v)
end
end
end | ruby | {
"resource": ""
} |
q14387 | Montrose.Schedule.events | train | def events(opts = {})
enums = @rules.map { |r| r.merge(opts).events }
Enumerator.new do |y|
loop do
enum = active_enums(enums).min_by(&:peek) or break
y << enum.next
end
end
end | ruby | {
"resource": ""
} |
q14388 | Montrose.Stack.advance | train | def advance(time)
yes, no = @stack.partition { |rule| rule.include?(time) }
if no.empty?
yes.all? { |rule| rule.advance!(time) } or return false
puts time if ENV["DEBUG"]
yield time if block_given?
true
else
no.any? { |rule| rule.continue?(time) }
end
end | ruby | {
"resource": ""
} |
q14389 | Mailgun.MessageBuilder.add_campaign_id | train | def add_campaign_id(campaign_id)
fail(Mailgun::ParameterError, 'Too many campaigns added to message.', campaign_id) if @counters[:attributes][:campaign_id] >= Mailgun::Chains::MAX_CAMPAIGN_IDS
set_multi_complex('o:campaign', campaign_id)
@counters[:attributes][:campaign_id] += 1
end | ruby | {
"resource": ""
} |
q14390 | Mailgun.MessageBuilder.add_tag | train | def add_tag(tag)
if @counters[:attributes][:tag] >= Mailgun::Chains::MAX_TAGS
fail Mailgun::ParameterError, 'Too many tags added to message.', tag
end
set_multi_complex('o:tag', tag)
@counters[:attributes][:tag] += 1
end | ruby | {
"resource": ""
} |
q14391 | Mailgun.MessageBuilder.header | train | def header(name, data)
fail(Mailgun::ParameterError, 'Header name for message must be specified') if name.to_s.empty?
begin
jsondata = make_json data
set_single("h:#{name}", jsondata)
rescue Mailgun::ParameterError
set_single("h:#{name}", data)
end
end | ruby | {
"resource": ""
} |
q14392 | Mailgun.MessageBuilder.bool_lookup | train | def bool_lookup(value)
return 'yes' if %w(true yes yep).include? value.to_s.downcase
return 'no' if %w(false no nope).include? value.to_s.downcase
value
end | ruby | {
"resource": ""
} |
q14393 | Mailgun.BatchMessage.send_message | train | def send_message
rkey = 'recipient-variables'
set_multi_simple rkey, JSON.generate(@recipient_variables)
@message[rkey] = @message[rkey].first if @message.key?(rkey)
response = @client.send_message(@domain, @message).to_h!
message_id = response['id'].gsub(/\>|\</, '')
@message_ids[message_id] = count_recipients
reset_message
end | ruby | {
"resource": ""
} |
q14394 | Mailgun.BatchMessage.store_recipient_variables | train | def store_recipient_variables(recipient_type, address, variables)
variables = { id: @counters[:recipients][recipient_type] } unless variables
@recipient_variables[address] = variables
end | ruby | {
"resource": ""
} |
q14395 | Mailgun.Response.to_yaml | train | def to_yaml
YAML.dump(to_h)
rescue => err
raise ParseError.new(err), err
end | ruby | {
"resource": ""
} |
q14396 | Railgun.Mailer.deliver! | train | def deliver!(mail)
mg_message = Railgun.transform_for_mailgun(mail)
response = @mg_client.send_message(@domain, mg_message)
if response.code == 200 then
mg_id = response.to_h['id']
mail.message_id = mg_id
end
response
end | ruby | {
"resource": ""
} |
q14397 | Mailgun.Client.send_message | train | def send_message(working_domain, data)
if test_mode? then
Mailgun::Client.deliveries << data
return Response.from_hash(
{
:body => '{"id": "test-mode-mail@localhost", "message": "Queued. Thank you."}',
:code => 200,
}
)
end
case data
when Hash
# Remove nil values from the data hash
# Submitting nils to the API will likely cause an error.
# See also: https://github.com/mailgun/mailgun-ruby/issues/32
data = data.select { |k, v| v != nil }
if data.key?(:message)
if data[:message].is_a?(String)
data[:message] = convert_string_to_file(data[:message])
end
return post("#{working_domain}/messages.mime", data)
end
post("#{working_domain}/messages", data)
when MessageBuilder
post("#{working_domain}/messages", data.message)
else
fail ParameterError.new('Unknown data type for data parameter.', data)
end
end | ruby | {
"resource": ""
} |
q14398 | Mailgun.Client.post | train | def post(resource_path, data, headers = {})
response = @http_client[resource_path].post(data, headers)
Response.new(response)
rescue => err
raise communication_error err
end | ruby | {
"resource": ""
} |
q14399 | Mailgun.Client.get | train | def get(resource_path, params = nil, accept = '*/*')
if params
response = @http_client[resource_path].get(params: params, accept: accept)
else
response = @http_client[resource_path].get(accept: accept)
end
Response.new(response)
rescue => err
raise communication_error err
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.