idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
2,200 | def unlock! ( token = nil ) token ||= jid Scripts . call ( :unlock , redis_pool , keys : [ exists_key , grabbed_key , available_key , version_key , UNIQUE_SET , unique_digest ] , argv : [ token , ttl , lock_type ] , ) end | Removes the lock keys from Redis |
2,201 | def redis ( redis_pool = nil ) if redis_pool redis_pool . with { | conn | yield conn } else Sidekiq . redis { | conn | yield conn } end end | Creates a connection to redis |
2,202 | def all ( pattern : SCAN_PATTERN , count : DEFAULT_COUNT ) redis { | conn | conn . sscan_each ( UNIQUE_SET , match : pattern , count : count ) . to_a } end | Return unique digests matching pattern |
2,203 | def page ( pattern : SCAN_PATTERN , cursor : 0 , page_size : 100 ) redis do | conn | total_size , digests = conn . multi do conn . scard ( UNIQUE_SET ) conn . sscan ( UNIQUE_SET , cursor , match : pattern , count : page_size ) end [ total_size , digests [ 0 ] , digests [ 1 ] ] end end | Paginate unique digests |
2,204 | def del ( digest : nil , pattern : nil , count : DEFAULT_COUNT ) return delete_by_pattern ( pattern , count : count ) if pattern return delete_by_digest ( digest ) if digest raise ArgumentError , "either digest or pattern need to be provided" end | Deletes unique digest either by a digest or pattern |
2,205 | def delete_by_pattern ( pattern , count : DEFAULT_COUNT ) result , elapsed = timed do digests = all ( pattern : pattern , count : count ) batch_delete ( digests ) digests . size end log_info ( "#{__method__}(#{pattern}, count: #{count}) completed in #{elapsed}ms" ) result end | Deletes unique digests by pattern |
2,206 | def delete_by_digest ( digest ) result , elapsed = timed do Scripts . call ( :delete_by_digest , nil , keys : [ UNIQUE_SET , digest ] ) count end log_info ( "#{__method__}(#{digest}) completed in #{elapsed}ms" ) result end | Get a total count of unique digests |
2,207 | def worker_class_constantize ( klazz = @worker_class ) return klazz unless klazz . is_a? ( String ) Object . const_get ( klazz ) rescue NameError => ex case ex . message when / / klazz else raise end end | Attempt to constantize a string worker_class argument always failing back to the original argument when the constant can t be found |
2,208 | def add_lock ( name , klass ) raise ArgumentError , "Lock #{name} already defined, please use another name" if locks . key? ( name . to_sym ) new_locks = locks . dup . merge ( name . to_sym => klass ) . freeze self . locks = new_locks end | Adds a lock type to the configuration . It will raise if the lock exists already |
2,209 | def add_strategy ( name , klass ) raise ArgumentError , "strategy #{name} already defined, please use another name" if strategies . key? ( name . to_sym ) new_strategies = strategies . dup . merge ( name . to_sym => klass ) . freeze self . strategies = new_strategies end | Adds an on_conflict strategy to the configuration . It will raise if the strategy exists already |
2,210 | def digestable_hash @item . slice ( CLASS_KEY , QUEUE_KEY , UNIQUE_ARGS_KEY ) . tap do | hash | hash . delete ( QUEUE_KEY ) if unique_across_queues? hash . delete ( CLASS_KEY ) if unique_across_workers? end end | Filter a hash to use for digest |
2,211 | def filtered_args ( args ) return args if args . empty? json_args = Normalizer . jsonify ( args ) case unique_args_method when Proc filter_by_proc ( json_args ) when Symbol filter_by_symbol ( json_args ) else log_debug ( "#{__method__} arguments not filtered (using all arguments for uniqueness)" ) json_args end end | Filters unique arguments by proc or symbol |
2,212 | def filter_by_symbol ( args ) return args unless worker_method_defined? ( unique_args_method ) worker_class . send ( unique_args_method , args ) rescue ArgumentError => ex log_fatal ( ex ) args end | Filters unique arguments by method configured in the sidekiq worker |
2,213 | def method_missing ( m , * args , & block ) begin results = client . send ( m , * args , & block ) rescue Exception => e raise unless e . class . to_s == symbol . to_s && backoff < backoff_limit @backoff = backoff + ( iteration * iteration * 0.5 ) @iteration += 1 sleep backoff results = self . send ( m , * args , & block ) end reset_backoff results end | used to capture only the RequestLimitExceeded error from an aws client api call . In the case of matching it we want to try again backing off successively each time until the backoff_limit is reached or exceeded in which case the error will be re - raised and it should fail as expected . |
2,214 | def changes_to ( time : nil , version : nil , data : { } , from : 0 ) raise ArgumentError , "Time or version must be specified" if time . nil? && version . nil? filter = time . nil? ? method ( :version_filter ) : method ( :time_filter ) versions . each_with_object ( data . dup ) do | v , acc | next if v . version < from break acc if filter . call ( v , version , time ) acc . merge! ( v . changes ) end end | Return diff from the initial state to specified time or version . Optional data paramater can be used as initial diff state . |
2,215 | def diff_from ( time : nil , version : nil ) raise ArgumentError , "Time or version must be specified" if time . nil? && version . nil? from_version = version . nil? ? find_by_time ( time ) : find_by_version ( version ) from_version ||= versions . first base = changes_to ( version : from_version . version ) diff = changes_to ( version : self . version , data : base , from : from_version . version + 1 ) build_changes ( base , diff ) end | Return diff object representing changes since specified time or version . |
2,216 | def current_ts? ( time ) ( current_version . time <= time ) && ( next_version . nil? || ( next_version . time < time ) ) end | Return true iff time corresponds to current version |
2,217 | def at_version ( version ) return self if log_data . version == version log_entry = log_data . find_by_version ( version ) return nil unless log_entry build_dup ( log_entry ) end | Return a dirty copy of specified version of record |
2,218 | def diff_from ( ts = nil , version : nil , time : nil ) Deprecations . show_ts_deprecation_for ( "#diff_from" ) if ts time ||= ts time = parse_time ( time ) if time changes = log_data . diff_from ( time : time , version : version ) . tap do | v | deserialize_changes! ( v ) end changes . delete_if { | k , _v | deleted_column? ( k ) } { "id" => id , "changes" => changes } end | Return diff object representing changes since specified time . |
2,219 | def undo! ( append : Logidze . append_on_undo ) version = log_data . previous_version return false if version . nil? switch_to! ( version . version , append : append ) end | Restore record to the previous version . Return false if no previous version found otherwise return updated record . |
2,220 | def switch_to! ( version , append : Logidze . append_on_undo ) return false unless at_version ( version ) if append && version < log_version update! ( log_data . changes_to ( version : version ) ) else at_version! ( version ) self . class . without_logging { save! } end end | Restore record to the specified version . Return false if version is unknown . |
2,221 | def find_type ( type , nested = true ) find_type_elements ( type , nested ) . map { | e | e . options } end | Find all elements of a given type returning their options hash . The options hash has most of the useful data about an element and often you can just use this in your rules . |
2,222 | def find_type_elements ( type , nested = true , elements = @elements ) results = [ ] if type . class == Symbol type = [ type ] end elements . each do | e | results . push ( e ) if type . include? ( e . type ) if nested and not e . children . empty? results . concat ( find_type_elements ( type , nested , e . children ) ) end end results end | Find all elements of a given type returning a list of the element objects themselves . |
2,223 | def find_type_elements_except ( type , nested_except = [ ] , elements = @elements ) results = [ ] if type . class == Symbol type = [ type ] end if nested_except . class == Symbol nested_except = [ nested_except ] end elements . each do | e | results . push ( e ) if type . include? ( e . type ) unless nested_except . include? ( e . type ) or e . children . empty? results . concat ( find_type_elements_except ( type , nested_except , e . children ) ) end end results end | A variation on find_type_elements that allows you to skip drilling down into children of specific element types . |
2,224 | def element_linenumber ( element ) element = element . options if element . is_a? ( Kramdown :: Element ) element [ :location ] end | Returns the line number a given element is located on in the source file . You can pass in either an element object or an options hash here . |
2,225 | def matching_lines ( re ) @lines . each_with_index . select { | text , linenum | re . match ( text ) } . map { | i | i [ 1 ] + 1 } end | Returns line numbers for lines that match the given regular expression |
2,226 | def extract_text ( element , prefix = "" , restore_whitespace = true ) quotes = { :rdquo => '"' , :ldquo => '"' , :lsquo => "'" , :rsquo => "'" } lines = element . children . map { | e | if e . type == :text e . value elsif [ :strong , :em , :p , :codespan ] . include? ( e . type ) extract_text ( e , prefix , restore_whitespace ) . join ( "\n" ) elsif e . type == :smart_quote quotes [ e . value ] end } . join . split ( "\n" ) if restore_whitespace lines [ 0 ] = element_line ( element ) . sub ( prefix , "" ) end lines end | Extracts the text from an element whose children consist of text elements and other things |
2,227 | def add_levels ( elements , level = 1 ) elements . each do | e | e . options [ :element_level ] = level add_levels ( e . children , level + 1 ) end end | Adds a level option to all elements to show how nested they are |
2,228 | def guess ( span , mode = :middle ) return span if not mode return span . begin + span . width / 2 if span . width > 1 and ( mode == true or mode == :middle ) return span . end if mode == :end span . begin end | Guess a specific time within the given span . |
2,229 | def definitions defined_items . each_with_object ( { } ) do | word , defs | word_type = "#{word.capitalize.to_s + 'Definitions'}" defs [ word ] = Chronic . const_get ( word_type ) . new ( options ) . definitions end end | returns a hash of each word s Definitions |
2,230 | def handle_od_rm ( tokens , options ) day = tokens [ 0 ] . get_tag ( OrdinalDay ) . type month = tokens [ 2 ] . get_tag ( RepeaterMonth ) handle_m_d ( month , day , tokens [ 3 .. tokens . size ] , options ) end | Handle ordinal this month |
2,231 | def handle_r ( tokens , options ) dd_tokens = dealias_and_disambiguate_times ( tokens , options ) get_anchor ( dd_tokens , options ) end | anchors Handle repeaters |
2,232 | def handle_orr ( tokens , outer_span , options ) repeater = tokens [ 1 ] . get_tag ( Repeater ) repeater . start = outer_span . begin - 1 ordinal = tokens [ 0 ] . get_tag ( Ordinal ) . type span = nil ordinal . times do span = repeater . next ( :future ) if span . begin >= outer_span . end span = nil break end end span end | narrows Handle oridinal repeaters |
2,233 | def find_within ( tags , span , pointer ) puts "--#{span}" if Chronic . debug return span if tags . empty? head = tags . shift head . start = ( pointer == :future ? span . begin : span . end ) h = head . this ( :none ) if span . cover? ( h . begin ) || span . cover? ( h . end ) find_within ( tags , h , pointer ) end end | Recursively finds repeaters within other repeaters . Returns a Span representing the innermost time span or nil if no repeater union could be found |
2,234 | def match ( tokens , definitions ) token_index = 0 @pattern . each do | elements | was_optional = false elements = [ elements ] unless elements . is_a? ( Array ) elements . each_index do | i | name = elements [ i ] . to_s optional = name [ - 1 , 1 ] == '?' name = name . chop if optional case elements [ i ] when Symbol if tags_match? ( name , tokens , token_index ) token_index += 1 break else if optional was_optional = true next elsif i + 1 < elements . count next else return false unless was_optional end end when String return true if optional && token_index == tokens . size if definitions . key? ( name . to_sym ) sub_handlers = definitions [ name . to_sym ] else raise "Invalid subset #{name} specified" end sub_handlers . each do | sub_handler | return true if sub_handler . match ( tokens [ token_index .. tokens . size ] , definitions ) end else raise "Invalid match type: #{elements[i].class}" end end end return false if token_index != tokens . size return true end | pattern - An Array of patterns to match tokens against . handler_method - A Symbol representing the method to be invoked when a pattern matches . tokens - An Array of tokens to process . definitions - A Hash of definitions to check against . |
2,235 | def create ( * args ) arguments ( args ) do assert_required %w[ name ] end params = arguments . params if ( org = params . delete ( 'org' ) || org ) post_request ( "/orgs/#{org}/repos" , params ) else post_request ( "/user/repos" , params ) end end | Create a new repository for the authenticated user . |
2,236 | def get ( * args ) params = arguments ( args ) . params if user_name = params . delete ( 'user' ) get_request ( "/users/#{user_name}" , params ) else get_request ( "/user" , params ) end end | Get a single unauthenticated user |
2,237 | def create ( * args ) arguments ( args , required : [ :user , :repo , :number ] ) params = arguments . params params [ "accept" ] ||= PREVIEW_MEDIA post_request ( "/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews" , params ) end | Create a pull request review |
2,238 | def update ( * args ) arguments ( args , required : [ :user , :repo , :number , :id ] ) params = arguments . params params [ "accept" ] ||= PREVIEW_MEDIA post_request ( "/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews/#{arguments.id}/events" , params ) end | Update a pull request review |
2,239 | def get ( * args ) arguments ( args , required : [ :name ] ) name = arguments . name response = list . body . _links [ name ] if response params = arguments . params params [ 'accept' ] = response . type get_request ( response . href , params ) end end | Get all the items for a named timeline |
2,240 | def list ( * args ) arguments ( args , required : [ :column_id ] ) params = arguments . params params [ "accept" ] ||= :: Github :: Client :: Projects :: PREVIEW_MEDIA response = get_request ( "/projects/columns/#{arguments.column_id}/cards" , params ) return response unless block_given? response . each { | el | yield el } end | List project cards for a column |
2,241 | def create ( * args ) arguments ( args , required : [ :column_id ] ) params = arguments . params params [ "accept" ] ||= :: Github :: Client :: Projects :: PREVIEW_MEDIA post_request ( "/projects/columns/#{arguments.column_id}/cards" , params ) end | Create a project card for a column |
2,242 | def update ( * args ) arguments ( args , required : [ :card_id ] ) params = arguments . params params [ "accept" ] ||= :: Github :: Client :: Projects :: PREVIEW_MEDIA patch_request ( "/projects/columns/cards/#{arguments.card_id}" , params ) end | Update a project card |
2,243 | def delete ( * args ) arguments ( args , required : [ :card_id ] ) params = arguments . params params [ "accept" ] ||= :: Github :: Client :: Projects :: PREVIEW_MEDIA delete_request ( "/projects/columns/cards/#{arguments.card_id}" , params ) end | Delete a project card |
2,244 | def move ( * args ) arguments ( args , required : [ :card_id ] ) do assert_required REQUIRED_MOVE_CARD_PARAMS end params = arguments . params params [ "accept" ] ||= :: Github :: Client :: Projects :: PREVIEW_MEDIA post_request ( "/projects/columns/cards/#{arguments.card_id}/moves" , params ) end | Move a project card |
2,245 | def list ( * args ) params = arguments ( args ) do assert_values VALID_ISSUE_PARAM_VALUES end . params response = if ( org = params . delete ( 'org' ) ) get_request ( "/orgs/#{org}/issues" , params ) elsif ( user_name = params . delete ( 'user' ) ) && ( repo_name = params . delete ( 'repo' ) ) list_repo user_name , repo_name elsif args . include? :user get_request ( "/user/issues" , params ) else get_request ( "/issues" , params ) end return response unless block_given? response . each { | el | yield el } end | List your issues |
2,246 | def upload ( * args ) arguments ( args , required : [ :owner , :repo , :id , :filepath ] ) do permit VALID_ASSET_PARAM_NAMES end params = arguments . params unless type = params [ 'content_type' ] type = infer_media ( arguments . filepath ) end file = Faraday :: UploadIO . new ( arguments . filepath , type ) options = { headers : { content_type : type } , endpoint : upload_endpoint , query : { 'name' => params [ 'name' ] } } params [ 'data' ] = file . read params [ 'options' ] = options post_request ( "/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}/assets" , params ) ensure file . close if file end | Upload a release asset |
2,247 | def infer_media ( filepath ) require 'mime/types' types = MIME :: Types . type_for ( filepath ) types . empty? ? 'application/octet-stream' : types . first rescue LoadError raise Github :: Error :: UnknownMedia . new ( filepath ) end | Infer media type of the asset |
2,248 | def edit ( * args ) arguments ( args , required : [ :owner , :repo , :id ] ) do permit VALID_ASSET_PARAM_NAMES end patch_request ( "/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}" , arguments . params ) end | Edit a release asset |
2,249 | def render ( * args ) arguments ( args ) do assert_required [ 'text' ] end params = arguments . params params [ 'raw' ] = true post_request ( "markdown" , arguments . params ) end | Render an arbitrary Markdown document |
2,250 | def render_raw ( * args ) params = arguments ( args ) . params params [ 'data' ] = args . shift params [ 'raw' ] = true params [ 'accept' ] = params . fetch ( 'accept' ) { 'text/plain' } post_request ( "markdown/raw" , params ) end | Render a Markdown document in raw mode |
2,251 | def create ( * args ) arguments ( args , required : [ :user , :repo , :sha ] ) do permit VALID_STATUS_PARAM_NAMES , recursive : false assert_required REQUIRED_PARAMS end post_request ( "/repos/#{arguments.user}/#{arguments.repo}/statuses/#{arguments.sha}" , arguments . params ) end | Create a status |
2,252 | def starring? ( * args ) arguments ( args , required : [ :user , :repo ] ) get_request ( "/user/starred/#{arguments.user}/#{arguments.repo}" , arguments . params ) true rescue Github :: Error :: NotFound false end | Check if you are starring a repository |
2,253 | def list ( * args ) arguments ( args ) response = get_request ( "/gitignore/templates" , arguments . params ) return response unless block_given? response . each { | el | yield el } end | List all templates available to pass as an option when creating a repository . |
2,254 | def get ( * args ) arguments ( args , required : [ :name ] ) params = arguments . params if ( media = params . delete ( 'accept' ) ) params [ 'accept' ] = media params [ 'raw' ] = true end get_request ( "/gitignore/templates/#{arguments.name}" , params ) end | Get a single template |
2,255 | def get ( * args ) arguments ( args , required : [ :user , :repo , :label_name ] ) params = arguments . params get_request ( "/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}" , params ) end | Get a single label |
2,256 | def create ( * args ) arguments ( args , required : [ :user , :repo ] ) do permit VALID_LABEL_INPUTS assert_required VALID_LABEL_INPUTS end post_request ( "/repos/#{arguments.user}/#{arguments.repo}/labels" , arguments . params ) end | Create a label |
2,257 | def update ( * args ) arguments ( args , required : [ :user , :repo , :label_name ] ) do permit VALID_LABEL_INPUTS assert_required VALID_LABEL_INPUTS end patch_request ( "/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}" , arguments . params ) end | Update a label |
2,258 | def remove ( * args ) arguments ( args , required : [ :user , :repo , :number ] ) params = arguments . params user = arguments . user repo = arguments . repo number = arguments . number if ( label_name = params . delete ( 'label_name' ) ) delete_request ( "/repos/#{user}/#{repo}/issues/#{number}/labels/#{label_name}" , params ) else delete_request ( "/repos/#{user}/#{repo}/issues/#{number}/labels" , params ) end end | Remove a label from an issue |
2,259 | def replace ( * args ) arguments ( args , required : [ :user , :repo , :number ] ) params = arguments . params params [ 'data' ] = arguments . remaining unless arguments . remaining . empty? put_request ( "/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/labels" , params ) end | Replace all labels for an issue |
2,260 | def parse_page_params ( uri , attr ) return - 1 if uri . nil? || uri . empty? parsed = nil begin parsed = URI . parse ( uri ) rescue URI :: Error return - 1 end param = parse_query_for_param ( parsed . query , attr ) return - 1 if param . nil? || param . empty? begin return param . to_i rescue ArgumentError return - 1 end end | Extracts query string parameter for given name |
2,261 | def list ( * args ) arguments ( args ) params = arguments . params token = args . shift if token . is_a? ( Hash ) && ! params [ 'token' ] . nil? token = params . delete ( 'token' ) elsif token . nil? token = oauth_token end if token . nil? raise ArgumentError , 'Access token required' end headers = { 'Authorization' => "token #{token}" } params [ 'headers' ] = headers response = get_request ( "/user" , params ) response . headers . oauth_scopes . split ( ',' ) . map ( & :strip ) end | Check what OAuth scopes you have . |
2,262 | def received ( * args ) arguments ( args , required : [ :user ] ) params = arguments . params public_events = if params [ 'public' ] params . delete ( 'public' ) '/public' end response = get_request ( "/users/#{arguments.user}/received_events#{public_events}" , params ) return response unless block_given? response . each { | el | yield el } end | List all events that a user has received |
2,263 | def auto_paginate ( auto = false ) if ( current_api . auto_pagination? || auto ) && self . body . is_a? ( Array ) resources_bodies = [ ] each_page { | resource | resources_bodies += resource . body } self . body = resources_bodies end self end | Iterate over results set pages by automatically calling next_page until all pages are exhausted . Caution needs to be exercised when using this feature - 100 pages iteration will perform 100 API calls . By default this is off . You can set it on the client individual API instances or just per given request . |
2,264 | def get ( * args ) arguments ( args , required : [ :column_id ] ) params = arguments . params params [ "accept" ] ||= :: Github :: Client :: Projects :: PREVIEW_MEDIA get_request ( "/projects/columns/#{arguments.column_id}" , params ) end | Get a project columns |
2,265 | def get ( * args ) arguments ( args , required : [ :user , :repo , :sha ] ) user = arguments . user repo = arguments . repo sha = arguments . sha params = arguments . params response = if params [ 'recursive' ] params [ 'recursive' ] = 1 get_request ( "/repos/#{user}/#{repo}/git/trees/#{sha}" , params ) else get_request ( "/repos/#{user}/#{repo}/git/trees/#{sha.to_s}" , params ) end return response unless block_given? response . tree . each { | el | yield el } end | Get a tree |
2,266 | def create ( * args ) arguments ( args , required : [ :user , :repo ] ) do assert_required %w[ tree ] permit VALID_TREE_PARAM_NAMES , 'tree' , { recursive : true } assert_values VALID_TREE_PARAM_VALUES , 'tree' end post_request ( "/repos/#{arguments.user}/#{arguments.repo}/git/trees" , arguments . params ) end | Create a tree |
2,267 | def create ( * args ) arguments ( args , required : [ :user , :repo ] ) do permit VALID_COMMIT_PARAM_NAMES assert_required REQUIRED_COMMIT_PARAMS end post_request ( "/repos/#{arguments.user}/#{arguments.repo}/git/commits" , arguments . params ) end | Create a commit |
2,268 | def remove ( * args ) arguments ( args , required : [ :user , :repo , :number ] ) params = arguments . params params [ 'data' ] = { 'assignees' => arguments . remaining } unless arguments . remaining . empty? delete_request ( "/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/assignees" , params ) end | Remove a assignees from an issue |
2,269 | def filter_callbacks ( kind , action_name ) self . class . send ( "#{kind}_callbacks" ) . select do | callback | callback [ :only ] . nil? || callback [ :only ] . include? ( action_name ) end end | Filter callbacks based on kind |
2,270 | def run_callbacks ( action_name , & block ) filter_callbacks ( :before , action_name ) . each { | hook | send hook [ :callback ] } yield if block_given? filter_callbacks ( :after , action_name ) . each { | hook | send hook [ :callback ] } end | Run all callbacks associated with this action |
2,271 | def set ( option , value = ( not_set = true ) , ignore_setter = false , & block ) raise ArgumentError , 'value not set' if block and ! not_set return self if ! not_set and value . nil? if not_set set_options option return self end if respond_to? ( "#{option}=" ) and not ignore_setter return __send__ ( "#{option}=" , value ) end define_accessors option , value self end | Set a configuration option for a given namespace |
2,272 | def set_options ( options ) unless options . respond_to? ( :each ) raise ArgumentError , 'cannot iterate over value' end options . each { | key , value | set ( key , value ) } end | Set multiple options |
2,273 | def define_accessors ( option , value ) setter = proc { | val | set option , val , true } getter = proc { value } define_singleton_method ( "#{option}=" , setter ) if setter define_singleton_method ( option , getter ) if getter end | Define setters and getters |
2,274 | def define_singleton_method ( method_name , content = Proc . new ) ( class << self ; self ; end ) . class_eval do undef_method ( method_name ) if method_defined? ( method_name ) if String === content class_eval ( "def #{method_name}() #{content}; end" ) else define_method ( method_name , & content ) end end end | Dynamically define a method for setting request option |
2,275 | def create ( * args ) arguments ( args , required : [ :user , :repo ] ) do permit VALID_TAG_PARAM_NAMES assert_values VALID_TAG_PARAM_VALUES end post_request ( "/repos/#{arguments.user}/#{arguments.repo}/git/tags" , arguments . params ) end | Create a tag object |
2,276 | def list ( * args ) params = arguments ( args ) . params response = if user_name = arguments . remaining . first get_request ( "/users/#{user_name}/followers" , params ) else get_request ( "/user/followers" , params ) end return response unless block_given? response . each { | el | yield el } end | List a user s followers |
2,277 | def following? ( * args ) arguments ( args , required : [ :username ] ) params = arguments . params if target_user = params . delete ( 'target_user' ) get_request ( "/users/#{arguments.username}/following/#{target_user}" , params ) else get_request ( "/user/following/#{arguments.username}" , params ) end true rescue Github :: Error :: NotFound false end | Check if you are following a user |
2,278 | def watched ( * args ) arguments ( args ) params = arguments . params response = if ( user_name = params . delete ( 'user' ) ) get_request ( "/users/#{user_name}/subscriptions" , params ) else get_request ( '/user/subscriptions' , params ) end return response unless block_given? response . each { | el | yield el } end | List repos being watched by a user |
2,279 | def member? ( * args ) params = arguments ( args , required : [ :org_name , :user ] ) . params org_name = arguments . org_name user = arguments . user response = if params . delete ( 'public' ) get_request ( "/orgs/#{org_name}/public_members/#{user}" , params ) else get_request ( "/orgs/#{org_name}/members/#{user}" , params ) end response . status == 204 rescue Github :: Error :: NotFound false end | Check if user is publicly or privately a member of an organization |
2,280 | def edit ( * args ) arguments ( args , required : [ :user , :repo , :branch ] ) do permit VALID_PROTECTION_PARAM_NAMES end put_request ( "/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection" , arguments . params ) end | Edit a branch protection |
2,281 | def filter! ( keys , params , options = { :recursive => true } ) case params when Hash , ParamsHash params . keys . each do | k , v | unless ( keys . include? ( k ) or Github :: Validations :: VALID_API_KEYS . include? ( k ) ) params . delete ( k ) else filter! ( keys , params [ k ] ) if options [ :recursive ] end end when Array params . map! do | el | filter! ( keys , el ) if options [ :recursive ] end else params end return params end | Removes any keys from nested hashes that don t match predefiend keys |
2,282 | def team_repo? ( * args ) arguments ( args , required : [ :id , :user , :repo ] ) response = get_request ( "/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}" , arguments . params ) response . status == 204 rescue Github :: Error :: NotFound false end | Check if a repository belongs to a team |
2,283 | def on_complete ( env ) status_code = env [ :status ] . to_i service_error = Github :: Error :: ServiceError error_class = service_error . error_mapping [ status_code ] if ! error_class and ( 400 ... 600 ) === status_code error_class = service_error end raise error_class . new ( env ) if error_class end | Check if status code requires raising a ServiceError |
2,284 | def create ( * args ) arguments ( args , required : [ :user , :repo ] ) do permit VALID_DEPLOYMENTS_OPTIONS assert_required %w[ ref ] end params = arguments . params params [ 'accept' ] ||= PREVIEW_MEDIA post_request ( "repos/#{arguments.user}/#{arguments.repo}/deployments" , arguments . params ) end | Create a deployment |
2,285 | def statuses ( * args ) arguments ( args , required : [ :user , :repo , :id ] ) params = arguments . params params [ 'accept' ] ||= PREVIEW_MEDIA statuses = get_request ( "repos/#{arguments.user}/#{arguments.repo}/deployments/#{arguments.id}/statuses" , params ) return statuses unless block_given? statuses . each { | status | yield status } end | List the statuses of a deployment . |
2,286 | def create_status ( * args ) arguments ( args , required : [ :user , :repo , :id ] ) do assert_required %w[ state ] permit VALID_STATUS_OPTIONS end params = arguments . params params [ 'accept' ] ||= PREVIEW_MEDIA post_request ( "repos/#{arguments.user}/#{arguments.repo}/deployments/#{arguments.id}/statuses" , params ) end | Create a deployment status |
2,287 | def options opts = fetch ( 'options' , { } ) headers = fetch ( 'headers' , { } ) if value = accept headers [ :accept ] = value end opts [ :raw ] = key? ( 'raw' ) ? self [ 'raw' ] : false opts [ :headers ] = headers unless headers . empty? opts end | Configuration options from request |
2,288 | def merge_default ( defaults ) if defaults && ! defaults . empty? defaults . each do | key , value | self [ key ] = value unless self . key? ( key ) end end self end | Update hash with default parameters for non existing keys |
2,289 | def strict_encode64 ( key ) value = self [ key ] encoded = if Base64 . respond_to? ( :strict_encode64 ) Base64 . strict_encode64 ( value ) else [ value ] . pack ( 'm0' ) end self [ key ] = encoded . delete ( "\n\r" ) end | Base64 encode string removing newline characters |
2,290 | def create ( * args ) arguments ( args , required : [ :user , :repo , :sha ] ) do assert_required REQUIRED_COMMENT_OPTIONS end post_request ( "/repos/#{arguments.user}/#{arguments.repo}/commits/#{arguments.sha}/comments" , arguments . params ) end | Creates a commit comment |
2,291 | def update ( * args ) arguments ( args , required : [ :user , :repo , :id ] ) do assert_required REQUIRED_COMMENT_OPTIONS end patch_request ( "/repos/#{arguments.user}/#{arguments.repo}/comments/#{arguments.id}" , arguments . params ) end | Update a commit comment |
2,292 | def create ( * args ) arguments ( args , required : [ :user , :repo , :path ] ) do assert_required REQUIRED_CONTENT_OPTIONS end params = arguments . params params . strict_encode64 ( 'content' ) put_request ( "/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}" , params ) end | Create a file |
2,293 | def delete ( * args ) arguments ( args , required : [ :user , :repo , :path ] ) do assert_required %w[ path message sha ] end delete_request ( "/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}" , arguments . params ) end | Delete a file |
2,294 | def archive ( * args ) arguments ( args , required : [ :user , :repo ] ) params = arguments . params archive_format = params . delete ( 'archive_format' ) || 'tarball' ref = params . delete ( 'ref' ) || 'master' disable_redirects do response = get_request ( "/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}" , params ) response . headers . location end end | Get archive link |
2,295 | def normalize! ( params ) case params when Hash params . keys . each do | k | params [ k . to_s ] = params . delete ( k ) normalize! ( params [ k . to_s ] ) end when Array params . map! do | el | normalize! ( el ) end end params end | Turns any keys from nested hashes including nested arrays into strings |
2,296 | def create ( * args ) raise_authentication_error unless authenticated? arguments ( args , required : [ :client_id ] ) if arguments . client_id put_request ( "/authorizations/clients/#{arguments.client_id}" , arguments . params ) else raise raise_app_authentication_error end end | Get - or - create an authorization for a specific app |
2,297 | def check ( * args ) raise_authentication_error unless authenticated? params = arguments ( args , required : [ :client_id , :access_token ] ) . params if arguments . client_id begin get_request ( "/applications/#{arguments.client_id}/tokens/#{arguments.access_token}" , params ) rescue Github :: Error :: NotFound nil end else raise raise_app_authentication_error end end | Check if an access token is a valid authorization for an application |
2,298 | def delete ( * args ) raise_authentication_error unless authenticated? params = arguments ( args , required : [ :client_id ] ) . params if arguments . client_id if access_token = ( params . delete ( 'access_token' ) || args [ 1 ] ) delete_request ( "/applications/#{arguments.client_id}/tokens/#{access_token}" , params ) else delete_request ( "/applications/#{arguments.client_id}/tokens" , params ) end else raise raise_app_authentication_error end end | Revoke all authorizations for an application |
2,299 | def edit ( * args ) arguments ( args , required : [ :id ] ) params = arguments . params params [ "accept" ] ||= PREVIEW_MEDIA patch_request ( "/projects/#{arguments.id}" , params ) end | Edit a project |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.