_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(... | 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_wit... | 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' % (val... | 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')
... | 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 >... | 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)))
e... | 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', ... | 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... | 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?(... | 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)
... | 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
fai... | 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... | 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|... | 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[:co... | 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?(Arra... | 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_v... | 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, Hel... | 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.... | 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 % 6... | 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).includ... | 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.m... | 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 data... | 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 has... | 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('/')
... | 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?
... | 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)
... | 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... | 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... | 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_... | 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_reco... | 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 = ActiveSc... | 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(act... | 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 ite... | 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#{ex... | 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 m... | 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 prima... | 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.c... | 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
... | 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[m... | 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... | 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 e... | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.