_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q11600
HamlLint.Utils.with_environment
train
def with_environment(env) old_env = {} env.each do |var, value| old_env[var] = ENV[var.to_s]
ruby
{ "resource": "" }
q11601
HamlLint.RakeTask.run_cli
train
def run_cli(task_args) cli_args = parse_args logger = quiet ? HamlLint::Logger.silent : HamlLint::Logger.new(STDOUT) result = HamlLint::CLI.new(logger).run(Array(cli_args)
ruby
{ "resource": "" }
q11602
HamlLint.RakeTask.files_to_lint
train
def files_to_lint(task_args) # Note: we're abusing Rake's argument handling a bit here. We call the # first argument `files` but it's actually only the first file--we pull # the rest out of the `extras` from the task arguments. This is so we # can specify an arbitrary list of files separated by ...
ruby
{ "resource": "" }
q11603
Sensu.Daemon.log_notices
train
def log_notices(notices=[], level=:warn) notices.each do |concern| message = concern.delete(:message)
ruby
{ "resource": "" }
q11604
Sensu.Daemon.setup_spawn
train
def setup_spawn @logger.info("configuring sensu spawn", :settings => @settings[:sensu][:spawn]) threadpool_size = @settings[:sensu][:spawn][:limit] + 10 @logger.debug("setting
ruby
{ "resource": "" }
q11605
Sensu.Utilities.retry_until_true
train
def retry_until_true(wait=0.5, &block) EM::Timer.new(wait) do unless block.call
ruby
{ "resource": "" }
q11606
Sensu.Utilities.deep_merge
train
def deep_merge(hash_one, hash_two) merged = hash_one.dup hash_two.each do |key, value| merged[key] = case when hash_one[key].is_a?(Hash) && value.is_a?(Hash) deep_merge(hash_one[key], value)
ruby
{ "resource": "" }
q11607
Sensu.Utilities.deep_dup
train
def deep_dup(obj) if obj.class == Hash new_obj = obj.dup new_obj.each do |key, value| new_obj[deep_dup(key)] = deep_dup(value) end new_obj elsif obj.class == Array arr = []
ruby
{ "resource": "" }
q11608
Sensu.Utilities.system_address
train
def system_address ::Socket.ip_address_list.find { |address| address.ipv4?
ruby
{ "resource": "" }
q11609
Sensu.Utilities.find_attribute_value
train
def find_attribute_value(tree, path, default) attribute = tree[path.shift] if attribute.is_a?(Hash) find_attribute_value(attribute,
ruby
{ "resource": "" }
q11610
Sensu.Utilities.determine_check_cron_time
train
def determine_check_cron_time(check) cron_parser = CronParser.new(check[:cron])
ruby
{ "resource": "" }
q11611
ActiveRecord.LockingExtensions.with_restart_on_deadlock
train
def with_restart_on_deadlock yield rescue ActiveRecord::StatementInvalid => exception if exception.message =~ /deadlock/i || exception.message =~ /database is locked/i
ruby
{ "resource": "" }
q11612
DoubleEntry.BalanceCalculator.calculate
train
def calculate(account, args = {}) options = Options.new(account, args) relations = RelationBuilder.new(options) lines = relations.build if options.between? || options.code? # from and to or code lookups have to be done via sum Money.new(lines.sum(:amount), account.currency) ...
ruby
{ "resource": "" }
q11613
PageObject.PagePopulator.populate_page_with
train
def populate_page_with(data) data.to_h.each do |key, value| populate_section(key, value) if value.respond_to?(:to_h)
ruby
{ "resource": "" }
q11614
PageObject.Accessors.page_url
train
def page_url(url) define_method("goto") do platform.navigate_to self.page_url_value end define_method('page_url_value') do lookup = url.kind_of?(Symbol) ? self.send(url) : url erb = ERB.new(%Q{#{lookup}})
ruby
{ "resource": "" }
q11615
PageObject.Accessors.in_frame
train
def in_frame(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup
ruby
{ "resource": "" }
q11616
PageObject.Accessors.in_iframe
train
def in_iframe(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup
ruby
{ "resource": "" }
q11617
PageObject.Accessors.text_field
train
def text_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_field_for', &block) define_method(name) do return platform.text_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do...
ruby
{ "resource": "" }
q11618
PageObject.Accessors.hidden_field
train
def hidden_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'hidden_field_for', &block) define_method(name) do return platform.hidden_field_value_for
ruby
{ "resource": "" }
q11619
PageObject.Accessors.text_area
train
def text_area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_area_for', &block) define_method(name) do return platform.text_area_value_for identifier.clone unless block_given?
ruby
{ "resource": "" }
q11620
PageObject.Accessors.select_list
train
def select_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'select_list_for', &block) define_method(name) do return platform.select_list_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=")...
ruby
{ "resource": "" }
q11621
PageObject.Accessors.button
train
def button(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'button_for', &block) define_method(name) do return platform.click_button_for
ruby
{ "resource": "" }
q11622
PageObject.Accessors.div
train
def div(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'div_for', &block)
ruby
{ "resource": "" }
q11623
PageObject.Accessors.span
train
def span(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'span_for', &block) define_method(name) do return platform.span_text_for
ruby
{ "resource": "" }
q11624
PageObject.Accessors.table
train
def table(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'table_for', &block) define_method(name) do return platform.table_text_for
ruby
{ "resource": "" }
q11625
PageObject.Accessors.cell
train
def cell(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'cell_for', &block)
ruby
{ "resource": "" }
q11626
PageObject.Accessors.row
train
def row(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'row_for', &block)
ruby
{ "resource": "" }
q11627
PageObject.Accessors.image
train
def image(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'image_for', &block) define_method("#{name}_loaded?") do
ruby
{ "resource": "" }
q11628
PageObject.Accessors.list_item
train
def list_item(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'list_item_for', &block) define_method(name) do return platform.list_item_text_for
ruby
{ "resource": "" }
q11629
PageObject.Accessors.unordered_list
train
def unordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'unordered_list_for', &block) define_method(name) do return
ruby
{ "resource": "" }
q11630
PageObject.Accessors.ordered_list
train
def ordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'ordered_list_for', &block) define_method(name) do return platform.ordered_list_text_for
ruby
{ "resource": "" }
q11631
PageObject.Accessors.h1
train
def h1(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'h1_for', &block)
ruby
{ "resource": "" }
q11632
PageObject.Accessors.h2
train
def h2(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h2_for', &block)
ruby
{ "resource": "" }
q11633
PageObject.Accessors.h3
train
def h3(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h3_for', &block)
ruby
{ "resource": "" }
q11634
PageObject.Accessors.h4
train
def h4(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h4_for', &block)
ruby
{ "resource": "" }
q11635
PageObject.Accessors.h5
train
def h5(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h5_for', &block)
ruby
{ "resource": "" }
q11636
PageObject.Accessors.h6
train
def h6(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h6_for', &block)
ruby
{ "resource": "" }
q11637
PageObject.Accessors.paragraph
train
def paragraph(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'paragraph_for', &block) define_method(name) do return platform.paragraph_text_for
ruby
{ "resource": "" }
q11638
PageObject.Accessors.file_field
train
def file_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'file_field_for', &block) define_method("#{name}=") do |value|
ruby
{ "resource": "" }
q11639
PageObject.Accessors.label
train
def label(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'label_for', &block) define_method(name) do return platform.label_text_for
ruby
{ "resource": "" }
q11640
PageObject.Accessors.area
train
def area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'area_for', &block)
ruby
{ "resource": "" }
q11641
PageObject.Accessors.b
train
def b(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'b_for', &block)
ruby
{ "resource": "" }
q11642
PageObject.Accessors.i
train
def i(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'i_for', &block)
ruby
{ "resource": "" }
q11643
PageObject.Accessors.element
train
def element(name, tag=:element, identifier={ :index => 0 }, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end standard_methods(name, identifier, 'element_for', &block) define_method("#{name}") do ...
ruby
{ "resource": "" }
q11644
PageObject.Accessors.elements
train
def elements(name, tag=:element, identifier={:index => 0}, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end
ruby
{ "resource": "" }
q11645
PageObject.Accessors.page_section
train
def page_section(name, section_class, identifier) define_method(name) do
ruby
{ "resource": "" }
q11646
PageObject.Accessors.page_sections
train
def page_sections(name, section_class, identifier) define_method(name) do
ruby
{ "resource": "" }
q11647
PageObject.PageFactory.on_page
train
def on_page(page_class, params={:using_params => {}}, visit=false, &block) page_class = class_from_string(page_class) if page_class.is_a? String return super(page_class, params, visit, &block) unless page_class.ancestors.include?
ruby
{ "resource": "" }
q11648
PageObject.PageFactory.if_page
train
def if_page(page_class, params={:using_params => {}},&block) page_class = class_from_string(page_class) if page_class.is_a? String
ruby
{ "resource": "" }
q11649
Oj.EasyHash.method_missing
train
def method_missing(m, *args, &block) if m.to_s.end_with?('=') raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length m = m[0..-2] return store(m.to_s, args[0]) if has_key?(m.to_s) return store(m.to_sym, ar...
ruby
{ "resource": "" }
q11650
AutoprefixerRails.Processor.process
train
def process(css, opts = {}) opts = convert_options(opts) apply_wrapper = "(function(opts, pluginOpts) {" \ "return eval(process.apply(this, opts, pluginOpts));" \ "})" plugin_opts = params_with_browsers(opts[:from]).merge(opts) process_opts = { from: plugin_opts...
ruby
{ "resource": "" }
q11651
AutoprefixerRails.Processor.parse_config
train
def parse_config(config) sections = {"defaults" => []} current = "defaults" config.gsub(/#[^\n]*/, "") .split(/\n/) .map(&:strip) .reject(&:empty?) .each do |line| if IS_SECTION =~ line
ruby
{ "resource": "" }
q11652
AutoprefixerRails.Processor.convert_options
train
def convert_options(opts) converted = {} opts.each_pair do |name, value| if /_/ =~ name name = name.to_s.gsub(/_\w/) { |i| i.delete("_").upcase }.to_sym end
ruby
{ "resource": "" }
q11653
AutoprefixerRails.Processor.find_config
train
def find_config(file) path = Pathname(file).expand_path while path.parent != path config1 = path.join("browserslist") return config1.read if config1.exist? && !config1.directory? config2 = path.join(".browserslistrc")
ruby
{ "resource": "" }
q11654
AutoprefixerRails.Processor.runtime
train
def runtime @runtime ||= begin if ExecJS.eval("typeof Uint8Array") != "function" if ExecJS.runtime.name.start_with?("therubyracer") raise "ExecJS::RubyRacerRuntime is not supported. " \ "Please replace therubyracer with mini_racer " \ "in your Gemfile or u...
ruby
{ "resource": "" }
q11655
AutoprefixerRails.Processor.read_js
train
def read_js @@js ||= begin root = Pathname(File.dirname(__FILE__)) path
ruby
{ "resource": "" }
q11656
Licensed.DependencyRecord.save
train
def save(filename) data_to_save = @metadata.merge({ "licenses" => licenses, "notices" => notices })
ruby
{ "resource": "" }
q11657
Licensed.Dependency.license_contents
train
def license_contents matched_files.reject { |f| f == package_file } .group_by(&:content)
ruby
{ "resource": "" }
q11658
Licensed.Dependency.notice_contents
train
def notice_contents Dir.glob(dir_path.join("*")) .grep(LEGAL_FILES_PATTERN) .select { |path| File.file?(path) } .sort # sorted by the path .map { |path| {
ruby
{ "resource": "" }
q11659
Licensed.Dependency.license_content_sources
train
def license_content_sources(files) paths = Array(files).map do |file| next file[:uri] if file[:uri] path = dir_path.join(file[:dir], file[:name])
ruby
{ "resource": "" }
q11660
Licensed.AppConfiguration.sources
train
def sources @sources ||= Licensed::Sources::Source.sources .select { |source_class| enabled?(source_class.type) }
ruby
{ "resource": "" }
q11661
Licensed.AppConfiguration.enabled?
train
def enabled?(source_type) # the default is false if any sources are set to true, true otherwise default =
ruby
{ "resource": "" }
q11662
Passwordless.ControllerHelpers.authenticate_by_cookie
train
def authenticate_by_cookie(authenticatable_class) key = cookie_name(authenticatable_class) authenticatable_id = cookies.encrypted[key]
ruby
{ "resource": "" }
q11663
Passwordless.ControllerHelpers.sign_in
train
def sign_in(authenticatable) key = cookie_name(authenticatable.class)
ruby
{ "resource": "" }
q11664
Passwordless.ControllerHelpers.sign_out
train
def sign_out(authenticatable_class) key = cookie_name(authenticatable_class)
ruby
{ "resource": "" }
q11665
Datadog.Statsd.count
train
def count(stat, count, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric
ruby
{ "resource": "" }
q11666
Datadog.Statsd.gauge
train
def gauge(stat, value, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric
ruby
{ "resource": "" }
q11667
Datadog.Statsd.histogram
train
def histogram(stat, value, opts=EMPTY_OPTIONS)
ruby
{ "resource": "" }
q11668
Datadog.Statsd.set
train
def set(stat, value, opts=EMPTY_OPTIONS) opts = {:sample_rate => opts} if opts.is_a? Numeric
ruby
{ "resource": "" }
q11669
Datadog.Statsd.service_check
train
def service_check(name, status, opts=EMPTY_OPTIONS)
ruby
{ "resource": "" }
q11670
Datadog.Statsd.event
train
def event(title, text, opts=EMPTY_OPTIONS)
ruby
{ "resource": "" }
q11671
JekyllRedirectFrom.Generator.generate_redirect_from
train
def generate_redirect_from(doc) doc.redirect_from.each do |path| page = RedirectPage.redirect_from(doc, path) doc.site.pages << page
ruby
{ "resource": "" }
q11672
JekyllRedirectFrom.RedirectPage.set_paths
train
def set_paths(from, to) @context ||= context from = ensure_leading_slash(from) data.merge!( "permalink" => from, "redirect" => { "from" => from,
ruby
{ "resource": "" }
q11673
Opal.Compiler.compile
train
def compile parse @fragments = re_raise_with_location { process(@sexp).flatten }
ruby
{ "resource": "" }
q11674
Opal.Compiler.unique_temp
train
def unique_temp(name) name = name.to_s if name && !name.empty? name = name .to_s .gsub('<=>', '$lt_eq_gt') .gsub('===', '$eq_eq_eq') .gsub('==', '$eq_eq') .gsub('=~', '$eq_tilde') .gsub('!~', '$excl_tilde') ...
ruby
{ "resource": "" }
q11675
Opal.Compiler.process
train
def process(sexp, level = :expr) return fragment('', scope) if sexp.nil? if handler = handlers[sexp.type] return
ruby
{ "resource": "" }
q11676
Opal.Compiler.returns
train
def returns(sexp) return returns s(:nil) unless sexp case sexp.type when :undef # undef :method_name always returns nil returns s(:begin, sexp, s(:nil)) when :break, :next, :redo sexp when :yield sexp.updated(:returnable_yield, nil) when :when ...
ruby
{ "resource": "" }
q11677
Racc.Parser.on_error
train
def on_error(t, val, vstack) raise ParseError, sprintf("\nparse error on value %s (%s)",
ruby
{ "resource": "" }
q11678
Racc.Parser.racc_read_token
train
def racc_read_token(t, tok, val) @racc_debug_out.print 'read ' @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
ruby
{ "resource": "" }
q11679
Benchmark.Tms.memberwise
train
def memberwise(op, x) case x when Benchmark::Tms Benchmark::Tms.new(utime.__send__(op, x.utime), stime.__send__(op, x.stime), cutime.__send__(op, x.cutime), cstime.__send__(op, x.cstime), real...
ruby
{ "resource": "" }
q11680
Opal.Config.config_option
train
def config_option(name, default_value, options = {}) compiler = options.fetch(:compiler_option, nil) valid_values = options.fetch(:valid_values, [true, false]) config_options[name] = { default: default_value, compiler: compiler } define_singleton_method(name) { conf...
ruby
{ "resource": "" }
q11681
Marshal.ReadBuffer.read_float
train
def read_float s = read_string(cache: false) result = if s == 'nan' 0.0 / 0 elsif s == 'inf'
ruby
{ "resource": "" }
q11682
Marshal.ReadBuffer.read_bignum
train
def read_bignum sign = read_char == '-' ? -1 : 1 size = read_fixnum * 2 result = 0 (0...size).each do |exp| result += read_char.ord * 2**(exp * 8)
ruby
{ "resource": "" }
q11683
Marshal.ReadBuffer.read_regexp
train
def read_regexp string = read_string(cache: false) options = read_byte
ruby
{ "resource": "" }
q11684
Marshal.ReadBuffer.read_struct
train
def read_struct klass_name = read(cache: false) klass = safe_const_get(klass_name) attributes = read_hash(cache: false)
ruby
{ "resource": "" }
q11685
Marshal.ReadBuffer.read_class
train
def read_class klass_name = read_string(cache: false) result = safe_const_get(klass_name) unless
ruby
{ "resource": "" }
q11686
Marshal.ReadBuffer.read_module
train
def read_module mod_name = read_string(cache: false) result = safe_const_get(mod_name) unless result.class
ruby
{ "resource": "" }
q11687
Marshal.ReadBuffer.read_object
train
def read_object klass_name = read(cache: false) klass = safe_const_get(klass_name) object = klass.allocate @object_cache << object ivars = read_hash(cache: false) ivars.each do |name, value|
ruby
{ "resource": "" }
q11688
Marshal.ReadBuffer.read_extended_object
train
def read_extended_object mod = safe_const_get(read)
ruby
{ "resource": "" }
q11689
MemoryProfiler.Reporter.run
train
def run(&block) start begin yield rescue Exception ObjectSpace.trace_object_allocations_stop
ruby
{ "resource": "" }
q11690
MemoryProfiler.Reporter.object_list
train
def object_list(generation) rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] helper = Helpers.new result = StatHash.new.compare_by_identity ObjectSpace.each_object do |obj| next unless ObjectSpace.allocation_generation(obj) == generation file = ObjectSpace.allocation_source...
ruby
{ "resource": "" }
q11691
MemoryProfiler.Results.pretty_print
train
def pretty_print(io = $stdout, **options) # Handle the special case that Ruby PrettyPrint expects `pretty_print` # to be a customized pretty printing function for a class return io.pp_object(self) if defined?(PP) && io.is_a?(PP) io = File.open(options[:to_file], "w") if options[:to_file] ...
ruby
{ "resource": "" }
q11692
Lhm.Chunker.execute
train
def execute return unless @start && @limit @next_to_insert = @start while @next_to_insert <= @limit stride = @throttler.stride affected_rows = @connection.update(copy(bottom, top(stride))) if @throttler && affected_rows > 0 @throttler.run end
ruby
{ "resource": "" }
q11693
Lhm.Migrator.rename_column
train
def rename_column(old, nu) col = @origin.columns[old.to_s] definition = col[:type] definition += ' NOT NULL' unless col[:is_nullable] definition += " DEFAULT #{@connection.quote(col[:column_default])}" if col[:column_default]
ruby
{ "resource": "" }
q11694
Lhm.Migrator.remove_index
train
def remove_index(columns, index_name = nil) columns = [columns].flatten.map(&:to_sym) from_origin = @origin.indices.find { |_, cols| cols.map(&:to_sym) == columns } index_name ||= from_origin[0] unless from_origin.nil?
ruby
{ "resource": "" }
q11695
Hutch.Worker.setup_queues
train
def setup_queues logger.info 'setting up queues' vetted = @consumers.reject { |c| group_configured? && group_restricted?(c) }
ruby
{ "resource": "" }
q11696
Hutch.Worker.setup_queue
train
def setup_queue(consumer) logger.info "setting up queue: #{consumer.get_queue_name}" queue = @broker.queue(consumer.get_queue_name, consumer.get_arguments) @broker.bind_queue(queue, consumer.routing_keys) queue.subscribe(consumer_tag: unique_consumer_tag, manual_ack: true) do |*args|
ruby
{ "resource": "" }
q11697
Hutch.Worker.handle_message
train
def handle_message(consumer, delivery_info, properties, payload) serializer = consumer.get_serializer || Hutch::Config[:serializer] logger.debug { spec = serializer.binary? ? "#{payload.bytesize} bytes" : "#{payload}" "message(#{properties.message_id || '-'}): " + "routing key: #{d...
ruby
{ "resource": "" }
q11698
Hutch.Broker.set_up_api_connection
train
def set_up_api_connection logger.info "connecting to rabbitmq HTTP API (#{api_config.sanitized_uri})" with_authentication_error_handler do with_connection_error_handler do @api_client = CarrotTop.new(host: api_config.host, port: api_config.port,
ruby
{ "resource": "" }
q11699
Hutch.Broker.bindings
train
def bindings results = Hash.new { |hash, key| hash[key] = [] } api_client.bindings.each do |binding| next if binding['destination'] == binding['routing_key'] next unless binding['source'] == @config[:mq_exchange]
ruby
{ "resource": "" }