_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q11000
Kafka.Connection.write_request
train
def write_request(request, notification) message = Kafka::Protocol::RequestMessage.new( api_key: request.api_key, api_version: request.respond_to?(:api_version) ? request.api_version : 0, correlation_id: @correlation_id, client_id: @client_id, request: request, ) ...
ruby
{ "resource": "" }
q11001
Kafka.Connection.read_response
train
def read_response(response_class, notification) @logger.debug "Waiting for response #{@correlation_id} from #{to_s}" data = @decoder.bytes notification[:response_size] = data.bytesize buffer = StringIO.new(data) response_decoder = Kafka::Protocol::Decoder.new(buffer) correlation_i...
ruby
{ "resource": "" }
q11002
Kafka.Producer.deliver_messages
train
def deliver_messages # There's no need to do anything if the buffer is empty. return if buffer_size == 0 @instrumenter.instrument("deliver_messages.producer") do |notification| message_count = buffer_size notification[:message_count] = message_count notification[:attempts] = ...
ruby
{ "resource": "" }
q11003
Kafka.Producer.send_offsets_to_transaction
train
def send_offsets_to_transaction(batch:, group_id:) @transaction_manager.send_offsets_to_txn(offsets: { batch.topic => { batch.partition => { offset: batch.last_offset + 1, leader_epoch: batch.leader_epoch } } }, group_id: group_id) end
ruby
{ "resource": "" }
q11004
Kafka.Producer.transaction
train
def transaction raise 'This method requires a block' unless block_given? begin_transaction yield commit_transaction rescue Kafka::Producer::AbortTransaction abort_transaction rescue abort_transaction raise end
ruby
{ "resource": "" }
q11005
Capybara.Session.open_new_window
train
def open_new_window(kind = :tab) window_opened_by do if driver.method(:open_new_window).arity.zero? driver.open_new_window else driver.open_new_window(kind) end end end
ruby
{ "resource": "" }
q11006
Faraday.AutoloadHelper.autoload_all
train
def autoload_all(prefix, options) if prefix =~ %r{^faraday(/|$)}i prefix = File.join(Faraday.root_path, prefix) end options.each do |const_name, path| autoload const_name, File.join(prefix, path) end end
ruby
{ "resource": "" }
q11007
Faraday.AutoloadHelper.all_loaded_constants
train
def all_loaded_constants constants .map { |c| const_get(c) } .select { |a| a.respond_to?(:loaded?) && a.loaded? } end
ruby
{ "resource": "" }
q11008
Faraday.HelperMethods.parse_multipart
train
def parse_multipart(boundary, body) reader = MultipartParser::Reader.new(boundary) result = { errors: [], parts: [] } def result.part(name) hash = self[:parts].detect { |h| h[:part].name == name } [hash[:part], hash[:body].join] end reader.on_part do |part| result[...
ruby
{ "resource": "" }
q11009
Faraday.DependencyLoader.dependency
train
def dependency(lib = nil) lib ? require(lib) : yield rescue LoadError, NameError => e self.load_error = e end
ruby
{ "resource": "" }
q11010
Faraday.Connection.default_parallel_manager
train
def default_parallel_manager @default_parallel_manager ||= begin adapter = @builder.adapter.klass if @builder.adapter if support_parallel?(adapter) adapter.setup_parallel_manager elsif block_given? yield end end end
ruby
{ "resource": "" }
q11011
Faraday.Connection.url_prefix=
train
def url_prefix=(url, encoder = nil) uri = @url_prefix = Utils.URI(url) self.path_prefix = uri.path params.merge_query(uri.query, encoder) uri.query = nil with_uri_credentials(uri) do |user, password| basic_auth user, password uri.user = uri.password = nil end en...
ruby
{ "resource": "" }
q11012
Faraday.Connection.build_url
train
def build_url(url = nil, extra_params = nil) uri = build_exclusive_url(url) query_values = params.dup.merge_query(uri.query, options.params_encoder) query_values.update(extra_params) if extra_params uri.query = if query_values.empty? nil else query_values.to_...
ruby
{ "resource": "" }
q11013
Faraday.Connection.build_request
train
def build_request(method) Request.create(method) do |req| req.params = params.dup req.headers = headers.dup req.options = options yield(req) if block_given? end end
ruby
{ "resource": "" }
q11014
Faraday.Connection.build_exclusive_url
train
def build_exclusive_url(url = nil, params = nil, params_encoder = nil) url = nil if url.respond_to?(:empty?) && url.empty? base = url_prefix if url && base.path && base.path !~ %r{/$} base = base.dup base.path = base.path + '/' # ensure trailing slash end uri = url ? base +...
ruby
{ "resource": "" }
q11015
Faraday.Utils.normalize_path
train
def normalize_path(url) url = URI(url) (url.path.start_with?('/') ? url.path : '/' + url.path) + (url.query ? "?#{sort_query_params(url.query)}" : '') end
ruby
{ "resource": "" }
q11016
Faraday.Utils.deep_merge!
train
def deep_merge!(target, hash) hash.each do |key, value| target[key] = if value.is_a?(Hash) && target[key].is_a?(Hash) deep_merge(target[key], value) else value end end target end
ruby
{ "resource": "" }
q11017
Faraday.Request.url
train
def url(path, params = nil) if path.respond_to? :query if (query = path.query) path = path.dup path.query = nil end else anchor_index = path.index('#') path = path.slice(0, anchor_index) unless anchor_index.nil? path, query = path.split('?', 2) ...
ruby
{ "resource": "" }
q11018
Faraday.Request.marshal_dump
train
def marshal_dump { method: method, body: body, headers: headers, path: path, params: params, options: options } end
ruby
{ "resource": "" }
q11019
Faraday.Request.marshal_load
train
def marshal_load(serialised) self.method = serialised[:method] self.body = serialised[:body] self.headers = serialised[:headers] self.path = serialised[:path] self.params = serialised[:params] self.options = serialised[:options] end
ruby
{ "resource": "" }
q11020
Aws::S3.Client.get_bucket_policy
train
def get_bucket_policy(params = {}, options = {}, &block) req = build_request(:get_bucket_policy, params) req.send_request(options, &block) end
ruby
{ "resource": "" }
q11021
Aws::S3.Client.get_object
train
def get_object(params = {}, options = {}, &block) req = build_request(:get_object, params) req.send_request(options, &block) end
ruby
{ "resource": "" }
q11022
Aws::S3.Client.get_object_torrent
train
def get_object_torrent(params = {}, options = {}, &block) req = build_request(:get_object_torrent, params) req.send_request(options, &block) end
ruby
{ "resource": "" }
q11023
Aws::S3.Client.wait_until
train
def wait_until(waiter_name, params = {}, options = {}) w = waiter(waiter_name, options) yield(w.waiter) if block_given? # deprecated w.wait(params) end
ruby
{ "resource": "" }
q11024
Aws.SharedConfig.fresh
train
def fresh(options = {}) @profile_name = nil @credentials_path = nil @config_path = nil @parsed_credentials = {} @parsed_config = nil @config_enabled = options[:config_enabled] ? true : false @profile_name = determine_profile(options) @credentials_path = options[:credentia...
ruby
{ "resource": "" }
q11025
Aws.SharedConfig.assume_role_credentials_from_config
train
def assume_role_credentials_from_config(opts = {}) p = opts.delete(:profile) || @profile_name chain_config = opts.delete(:chain_config) credentials = assume_role_from_profile(@parsed_credentials, p, opts, chain_config) if @parsed_config credentials ||= assume_role_from_profile(@parsed_co...
ruby
{ "resource": "" }
q11026
Aws.Structure.to_h
train
def to_h(obj = self) case obj when Struct obj.members.each.with_object({}) do |member, hash| value = obj[member] hash[member] = to_hash(value) unless value.nil? end when Hash obj.each.with_object({}) do |(key, value), hash| hash[key] = to_hash(valu...
ruby
{ "resource": "" }
q11027
Aws.ClientStubs.api_requests
train
def api_requests(options = {}) if config.stub_responses if options[:exclude_presign] @api_requests.reject {|req| req[:context][:presigned_url] } else @api_requests end else msg = 'This method is only implemented for stubbed clients, and is ' msg <<...
ruby
{ "resource": "" }
q11028
Aws.ClientStubs.stub_data
train
def stub_data(operation_name, data = {}) Stubbing::StubData.new(config.api.operation(operation_name)).stub(data) end
ruby
{ "resource": "" }
q11029
Aws.PageableResponse.each
train
def each(&block) return enum_for(:each_page) unless block_given? response = self yield(response) until response.last_page? response = response.next_page yield(response) end end
ruby
{ "resource": "" }
q11030
Aws::Glacier.Client.get_job_output
train
def get_job_output(params = {}, options = {}, &block) req = build_request(:get_job_output, params) req.send_request(options, &block) end
ruby
{ "resource": "" }
q11031
Aws.EndpointCache.key?
train
def key?(key) if @entries.key?(key) && (@entries[key].nil? || @entries[key].expired?) self.delete(key) end @entries.key?(key) end
ruby
{ "resource": "" }
q11032
Aws.EndpointCache.extract_key
train
def extract_key(ctx) parts = [] # fetching from cred provider directly gives warnings parts << ctx.config.credentials.credentials.access_key_id if _endpoint_operation_identifier(ctx) parts << ctx.operation_name ctx.operation.input.shape.members.inject(parts) do |p, (name, ref)| ...
ruby
{ "resource": "" }
q11033
Jekyll.Octicons.string_to_hash
train
def string_to_hash(markup) options = {} if match = markup.match(Syntax) markup.scan(TagAttributes) do |key, value| options[key.to_sym] = value.gsub(/\A"|"\z/, "") end end options end
ruby
{ "resource": "" }
q11034
Resque.Plugin.lint
train
def lint(plugin) hooks = before_hooks(plugin) + around_hooks(plugin) + after_hooks(plugin) hooks.each do |hook| if hook.to_s.end_with?("perform") raise LintError, "#{plugin}.#{hook} is not namespaced" end end failure_hooks(plugin).each do |hook| if hook.to_s.e...
ruby
{ "resource": "" }
q11035
Resque.Worker.process
train
def process(job = nil, &block) return unless job ||= reserve job.worker = self working_on job perform(job, &block) ensure done_working end
ruby
{ "resource": "" }
q11036
Resque.Worker.report_failed_job
train
def report_failed_job(job,exception) log_with_severity :error, "#{job.inspect} failed: #{exception.inspect}" begin job.fail(exception) rescue Object => exception log_with_severity :error, "Received exception when reporting failure: #{exception.inspect}" end begin fa...
ruby
{ "resource": "" }
q11037
Resque.Worker.perform
train
def perform(job) begin if fork_per_job? reconnect run_hook :after_fork, job end job.perform rescue Object => e report_failed_job(job,e) else log_with_severity :info, "done: #{job.inspect}" ensure yield job if block_given? ...
ruby
{ "resource": "" }
q11038
Resque.Worker.reserve
train
def reserve queues.each do |queue| log_with_severity :debug, "Checking #{queue}" if job = Resque.reserve(queue) log_with_severity :debug, "Found job on #{queue}" return job end end nil rescue Exception => e log_with_severity :error, "Error reservi...
ruby
{ "resource": "" }
q11039
Resque.Worker.reconnect
train
def reconnect tries = 0 begin data_store.reconnect rescue Redis::BaseConnectionError if (tries += 1) <= 3 log_with_severity :error, "Error reconnecting to Redis; retrying" sleep(tries) retry else log_with_severity :error, "Error reconnect...
ruby
{ "resource": "" }
q11040
Resque.Worker.shutdown!
train
def shutdown! shutdown if term_child if fork_per_job? new_kill_child else # Raise TermException in the same process trap('TERM') do # ignore subsequent terms end raise TermException.new("SIGTERM") end else ki...
ruby
{ "resource": "" }
q11041
Resque.Worker.run_hook
train
def run_hook(name, *args) hooks = Resque.send(name) return if hooks.empty? return if name == :before_first_fork && @before_first_fork_hook_ran msg = "Running #{name} hooks" msg << " with #{args.inspect}" if args.any? log_with_severity :info, msg hooks.each do |hook| ar...
ruby
{ "resource": "" }
q11042
Resque.Worker.unregister_worker
train
def unregister_worker(exception = nil) # If we're still processing a job, make sure it gets logged as a # failure. if (hash = processing) && !hash.empty? job = Job.new(hash['queue'], hash['payload']) # Ensure the proper worker is attached to this job, even if # it's not the pre...
ruby
{ "resource": "" }
q11043
Resque.Worker.working_on
train
def working_on(job) data = encode \ :queue => job.queue, :run_at => Time.now.utc.iso8601, :payload => job.payload data_store.set_worker_payload(self,data) end
ruby
{ "resource": "" }
q11044
Resque.Worker.windows_worker_pids
train
def windows_worker_pids tasklist_output = `tasklist /FI "IMAGENAME eq ruby.exe" /FO list`.encode("UTF-8", Encoding.locale_charmap) tasklist_output.split($/).select { |line| line =~ /^PID:/ }.collect { |line| line.gsub(/PID:\s+/, '') } end
ruby
{ "resource": "" }
q11045
Resque.Job.fail
train
def fail(exception) begin run_failure_hooks(exception) rescue Exception => e raise e ensure Failure.create \ :payload => payload, :exception => exception, :worker => worker, :queue => queue end end
ruby
{ "resource": "" }
q11046
Grape.Endpoint.inherit_settings
train
def inherit_settings(namespace_stackable) inheritable_setting.route[:saved_validations] += namespace_stackable[:validations] parent_declared_params = namespace_stackable[:declared_params] if parent_declared_params inheritable_setting.route[:declared_params] ||= [] inheritable_setting....
ruby
{ "resource": "" }
q11047
Blazer.BaseHelper.blazer_json_escape
train
def blazer_json_escape(s) if Rails::VERSION::STRING < "4.1" result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE) s.html_safe? ? result.html_safe : result else json_escape(s) end end
ruby
{ "resource": "" }
q11048
ActiveAdmin.Namespace.register
train
def register(resource_class, options = {}, &block) config = find_or_build_resource(resource_class, options) # Register the resource register_resource_controller(config) parse_registration_block(config, &block) if block_given? reset_menu! # Dispatch a registration event Active...
ruby
{ "resource": "" }
q11049
ActiveAdmin.Namespace.build_menu
train
def build_menu(name = DEFAULT_MENU) @menus.before_build do |menus| menus.menu name do |menu| yield menu end end end
ruby
{ "resource": "" }
q11050
ActiveAdmin.Namespace.add_logout_button_to_menu
train
def add_logout_button_to_menu(menu, priority = 20, html_options = {}) if logout_link_path html_options = html_options.reverse_merge(method: logout_link_method || :get) menu.add id: 'logout', priority: priority, html_options: html_options, label: -> { I18n.t 'active_admin.logout' }, ...
ruby
{ "resource": "" }
q11051
ActiveAdmin.Namespace.add_current_user_to_menu
train
def add_current_user_to_menu(menu, priority = 10, html_options = {}) if current_user_method menu.add id: 'current_user', priority: priority, html_options: html_options, label: -> { display_name current_active_admin_user }, url: -> { auto_url_for(current_active_admin_user) }, ...
ruby
{ "resource": "" }
q11052
ActiveAdmin.PageDSL.content
train
def content(options = {}, &block) config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
ruby
{ "resource": "" }
q11053
ActiveAdmin.ResourceCollection.find_resource
train
def find_resource(obj) resources.detect do |r| r.resource_name.to_s == obj.to_s end || resources.detect do |r| r.resource_class.to_s == obj.to_s end || if obj.respond_to? :base_class resources.detect { |r| r.resource_class.to_s == obj.base_class.to_s } end end
ruby
{ "resource": "" }
q11054
ActiveAdmin.Application.register
train
def register(resource, options = {}, &block) ns = options.fetch(:namespace) { default_namespace } namespace(ns).register resource, options, &block end
ruby
{ "resource": "" }
q11055
ActiveAdmin.Application.namespace
train
def namespace(name) name ||= :root namespace = namespaces[name] ||= begin namespace = Namespace.new(self, name) ActiveSupport::Notifications.publish ActiveAdmin::Namespace::RegisterEvent, namespace namespace end yield(namespace) if block_given? namespace end
ruby
{ "resource": "" }
q11056
ActiveAdmin.Application.register_page
train
def register_page(name, options = {}, &block) ns = options.fetch(:namespace) { default_namespace } namespace(ns).register_page name, options, &block end
ruby
{ "resource": "" }
q11057
ActiveAdmin.Application.load!
train
def load! unless loaded? ActiveSupport::Notifications.publish BeforeLoadEvent, self # before_load hook files.each { |file| load file } # load files namespace(default_namespace) # init AA resources ActiveSupport::Notifications...
ruby
{ "resource": "" }
q11058
ActiveAdmin.Application.routes
train
def routes(rails_router) load! Router.new(router: rails_router, namespaces: namespaces).apply end
ruby
{ "resource": "" }
q11059
ActiveAdmin.Application.attach_reloader
train
def attach_reloader Rails.application.config.after_initialize do |app| ActiveSupport::Reloader.after_class_unload do ActiveAdmin.application.unload! end admin_dirs = {} load_paths.each do |path| admin_dirs[path] = [:rb] end routes_reloader = a...
ruby
{ "resource": "" }
q11060
ActiveAdmin.HasManyBuilder.extract_custom_settings!
train
def extract_custom_settings!(options) @heading = options.key?(:heading) ? options.delete(:heading) : default_heading @sortable_column = options.delete(:sortable) @sortable_start = options.delete(:sortable_start) || 0 @new_record = options.key?(:new_record) ? options.delete(:new_record) : true ...
ruby
{ "resource": "" }
q11061
ActiveAdmin.HasManyBuilder.render_has_many_form
train
def render_has_many_form(form_builder, parent, &block) index = parent && form_builder.send(:parent_child_index, parent) template.concat template.capture { yield(form_builder, index) } template.concat has_many_actions(form_builder, "".html_safe) end
ruby
{ "resource": "" }
q11062
ActiveAdmin.HasManyBuilder.js_for_has_many
train
def js_for_has_many(class_string, &form_block) assoc_name = assoc_klass.model_name placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(/\//, '_')}_RECORD" opts = { for: [assoc, assoc_klass.new], class: class_string, for_options: { child_index: placeholder } ...
ruby
{ "resource": "" }
q11063
ActiveAdmin.Router.define_resources_routes
train
def define_resources_routes resources = namespaces.flat_map { |n| n.resources.values } resources.each do |config| define_resource_routes(config) end end
ruby
{ "resource": "" }
q11064
ActiveAdmin.Router.define_actions
train
def define_actions(config) router.member do config.member_actions.each { |action| build_action(action) } end router.collection do config.collection_actions.each { |action| build_action(action) } router.post :batch_action if config.batch_actions_enabled? end end
ruby
{ "resource": "" }
q11065
ActiveAdmin.Callbacks.run_callback
train
def run_callback(method, *args) case method when Symbol send(method, *args) when Proc instance_exec(*args, &method) else raise "Please register with callbacks using a symbol or a block/proc." end end
ruby
{ "resource": "" }
q11066
ActiveAdmin.ResourceDSL.permit_params
train
def permit_params(*args, &block) param_key = config.param_key.to_sym belongs_to_param = config.belongs_to_param create_another_param = :create_another if config.create_another controller do define_method :permitted_params do permitted_params = active_admin_namespac...
ruby
{ "resource": "" }
q11067
ActiveAdmin.ResourceDSL.index
train
def index(options = {}, &block) options[:as] ||= :table config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
ruby
{ "resource": "" }
q11068
ActiveAdmin.ResourceDSL.show
train
def show(options = {}, &block) config.set_page_presenter :show, ActiveAdmin::PagePresenter.new(options, &block) end
ruby
{ "resource": "" }
q11069
ActiveAdmin.ResourceDSL.csv
train
def csv(options = {}, &block) options[:resource] = config config.csv_builder = CSVBuilder.new(options, &block) end
ruby
{ "resource": "" }
q11070
ActiveAdmin.ResourceDSL.action
train
def action(set, name, options = {}, &block) warn "Warning: method `#{name}` already defined" if controller.method_defined?(name) set << ControllerAction.new(name, options) title = options.delete(:title) controller do before_action(only: [name]) { @page_title = title } if title ...
ruby
{ "resource": "" }
q11071
ShopifyAPI.Product.price_range
train
def price_range prices = variants.collect(&:price).collect(&:to_f) format = "%0.2f" if prices.min != prices.max "#{format % prices.min} - #{format % prices.max}" else format % prices.min end end
ruby
{ "resource": "" }
q11072
Overcommit.ConfigurationLoader.load_file
train
def load_file(file) config = self.class.load_from_file(file, default: false, logger: @log) config = self.class.default_configuration.merge(config) if @options.fetch(:verify) { config.verify_signatures? } verify_signatures(config) end config rescue Overcommit::Exceptions::Conf...
ruby
{ "resource": "" }
q11073
Overcommit::HookContext.Base.filter_directories
train
def filter_directories(modified_files) modified_files.reject do |file| File.directory?(file) && !Overcommit::Utils::FileUtils.symlink?(file) end end
ruby
{ "resource": "" }
q11074
Overcommit::Hook::PreCommit.YardCoverage.check_yard_coverage
train
def check_yard_coverage(stat_lines) if config['min_coverage_percentage'] match = stat_lines.last.match(/^\s*([\d.]+)%\s+documented\s*$/) unless match return :warn end yard_coverage = match.captures[0].to_f if yard_coverage >= config['min_coverage_percentage'].to_...
ruby
{ "resource": "" }
q11075
Overcommit::Hook::PreCommit.YardCoverage.error_messages
train
def error_messages(yard_coverage, error_text) first_message = "You have a #{yard_coverage}% yard documentation coverage. "\ "#{config['min_coverage_percentage']}% is the minimum required." # Add the undocumented objects text as error messages messages = [Overcommit::Hook::Messag...
ruby
{ "resource": "" }
q11076
Overcommit::HookContext.PostMerge.modified_files
train
def modified_files staged = squash? refs = 'HEAD^ HEAD' if merge_commit? @modified_files ||= Overcommit::GitRepo.modified_files(staged: staged, refs: refs) end
ruby
{ "resource": "" }
q11077
Overcommit::HookContext.PostRewrite.modified_files
train
def modified_files @modified_files ||= begin @modified_files = [] rewritten_commits.each do |rewritten_commit| refs = "#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}" @modified_files |= Overcommit::GitRepo.modified_files(refs: refs) end filter_modif...
ruby
{ "resource": "" }
q11078
Overcommit.MessageProcessor.basic_status_and_output
train
def basic_status_and_output(messages) status = if messages.any? { |message| message.type == :error } :fail elsif messages.any? { |message| message.type == :warning } :warn else :pass end output = '' if messages.any? output += messa...
ruby
{ "resource": "" }
q11079
Overcommit::Hook.Base.run_and_transform
train
def run_and_transform if output = check_for_requirements status = :fail else result = Overcommit::Utils.with_environment(@config.fetch('env') { {} }) { run } status, output = process_hook_return_value(result) end [transform_status(status), output] end
ruby
{ "resource": "" }
q11080
Overcommit::Hook.Base.check_for_libraries
train
def check_for_libraries output = [] required_libraries.each do |library| begin require library rescue LoadError install_command = @config['install_command'] install_command = " -- install via #{install_command}" if install_command output << "Unable t...
ruby
{ "resource": "" }
q11081
Overcommit::HookContext.PreCommit.setup_environment
train
def setup_environment store_modified_times Overcommit::GitRepo.store_merge_state Overcommit::GitRepo.store_cherry_pick_state if !initial_commit? && any_changes? @stash_attempted = true stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}" resu...
ruby
{ "resource": "" }
q11082
Overcommit::HookContext.PreCommit.cleanup_environment
train
def cleanup_environment unless initial_commit? || (@stash_attempted && !@changes_stashed) clear_working_tree # Ensure working tree is clean before restoring it restore_modified_times end if @changes_stashed restore_working_tree restore_modified_times end O...
ruby
{ "resource": "" }
q11083
Overcommit::HookContext.PreCommit.modified_files
train
def modified_files unless @modified_files currently_staged = Overcommit::GitRepo.modified_files(staged: true) @modified_files = currently_staged # Include files modified in last commit if amending if amendment? subcmd = 'show --format=%n' previously_modified = ...
ruby
{ "resource": "" }
q11084
Overcommit::HookContext.PreCommit.clear_working_tree
train
def clear_working_tree removed_submodules = Overcommit::GitRepo.staged_submodule_removals result = Overcommit::Utils.execute(%w[git reset --hard]) unless result.success? raise Overcommit::Exceptions::HookCleanupFailed, "Unable to cleanup working tree after #{hook_script_name} ho...
ruby
{ "resource": "" }
q11085
Overcommit::HookContext.PreCommit.restore_working_tree
train
def restore_working_tree result = Overcommit::Utils.execute(%w[git stash pop --index --quiet]) unless result.success? raise Overcommit::Exceptions::HookCleanupFailed, "Unable to restore working tree after #{hook_script_name} hooks run:" \ "\nSTDOUT:#{result.stdout}\nSTDER...
ruby
{ "resource": "" }
q11086
Overcommit::HookContext.PreCommit.store_modified_times
train
def store_modified_times @modified_times = {} staged_files = modified_files unstaged_files = Overcommit::GitRepo.modified_files(staged: false) (staged_files + unstaged_files).each do |file| next if Overcommit::Utils.broken_symlink?(file) next unless File.exist?(file) # Ignore r...
ruby
{ "resource": "" }
q11087
Overcommit::HookContext.PreCommit.restore_modified_times
train
def restore_modified_times @modified_times.each do |file, time| next if Overcommit::Utils.broken_symlink?(file) next unless File.exist?(file) File.utime(time, time, file) end end
ruby
{ "resource": "" }
q11088
Overcommit.ConfigurationValidator.validate
train
def validate(config, hash, options) @options = options.dup @log = options[:logger] hash = convert_nils_to_empty_hashes(hash) ensure_hook_type_sections_exist(hash) check_hook_name_format(hash) check_hook_env(hash) check_for_missing_enabled_option(hash) unless @options[:default]...
ruby
{ "resource": "" }
q11089
Overcommit.ConfigurationValidator.convert_nils_to_empty_hashes
train
def convert_nils_to_empty_hashes(hash) hash.each_with_object({}) do |(key, value), h| h[key] = case value when nil then {} when Hash then convert_nils_to_empty_hashes(value) else value end end end
ruby
{ "resource": "" }
q11090
Overcommit.ConfigurationValidator.check_hook_name_format
train
def check_hook_name_format(hash) errors = [] Overcommit::Utils.supported_hook_type_classes.each do |hook_type| hash.fetch(hook_type) { {} }.each_key do |hook_name| next if hook_name == 'ALL' unless hook_name.match?(/\A[A-Za-z0-9]+\z/) errors << "#{hook_type}::#{hook...
ruby
{ "resource": "" }
q11091
Overcommit.ConfigurationValidator.check_for_missing_enabled_option
train
def check_for_missing_enabled_option(hash) return unless @log any_warnings = false Overcommit::Utils.supported_hook_type_classes.each do |hook_type| hash.fetch(hook_type) { {} }.each do |hook_name, hook_config| next if hook_name == 'ALL' if hook_config['enabled'].nil? ...
ruby
{ "resource": "" }
q11092
Overcommit.ConfigurationValidator.check_for_too_many_processors
train
def check_for_too_many_processors(config, hash) concurrency = config.concurrency errors = [] Overcommit::Utils.supported_hook_type_classes.each do |hook_type| hash.fetch(hook_type) { {} }.each do |hook_name, hook_config| processors = hook_config.fetch('processors') { 1 } i...
ruby
{ "resource": "" }
q11093
Overcommit.Configuration.all_builtin_hook_configs
train
def all_builtin_hook_configs hook_configs = {} Overcommit::Utils.supported_hook_type_classes.each do |hook_type| hook_names = @hash[hook_type].keys.reject { |name| name == 'ALL' } hook_configs[hook_type] = Hash[ hook_names.map do |hook_name| [hook_name, for_hook(hook_...
ruby
{ "resource": "" }
q11094
Overcommit.Configuration.all_plugin_hook_configs
train
def all_plugin_hook_configs hook_configs = {} Overcommit::Utils.supported_hook_types.each do |hook_type| hook_type_class_name = Overcommit::Utils.camel_case(hook_type) directory = File.join(plugin_directory, hook_type.tr('-', '_')) plugin_paths = Dir[File.join(directory, '*.rb')].s...
ruby
{ "resource": "" }
q11095
Overcommit.Configuration.enabled_builtin_hooks
train
def enabled_builtin_hooks(hook_context) @hash[hook_context.hook_class_name].keys. reject { |hook_name| hook_name == 'ALL' }. select { |hook_name| built_in_hook?(hook_context, hook_name) }. select { |hook_name| hook_enabled?(hook_context, hook_name) } end
ruby
{ "resource": "" }
q11096
Overcommit.Configuration.enabled_ad_hoc_hooks
train
def enabled_ad_hoc_hooks(hook_context) @hash[hook_context.hook_class_name].keys. reject { |hook_name| hook_name == 'ALL' }. select { |hook_name| ad_hoc_hook?(hook_context, hook_name) }. select { |hook_name| hook_enabled?(hook_context, hook_name) } end
ruby
{ "resource": "" }
q11097
Overcommit.Configuration.for_hook
train
def for_hook(hook, hook_type = nil) unless hook_type components = hook.class.name.split('::') hook = components.last hook_type = components[-2] end # Merge hook configuration with special 'ALL' config hook_config = smart_merge(@hash[hook_type]['ALL'], @hash[hook_type][ho...
ruby
{ "resource": "" }
q11098
Overcommit.Configuration.apply_environment!
train
def apply_environment!(hook_context, env) skipped_hooks = "#{env['SKIP']} #{env['SKIP_CHECKS']} #{env['SKIP_HOOKS']}".split(/[:, ]/) only_hooks = env.fetch('ONLY') { '' }.split(/[:, ]/) hook_type = hook_context.hook_class_name if only_hooks.any? || skipped_hooks.include?('all') || skipped_hooks...
ruby
{ "resource": "" }
q11099
Overcommit.Configuration.stored_signature
train
def stored_signature result = Overcommit::Utils.execute( %w[git config --local --get] + [signature_config_key] ) if result.status == 1 # Key doesn't exist return '' elsif result.status != 0 raise Overcommit::Exceptions::GitConfigError, "Unable to read from ...
ruby
{ "resource": "" }