idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
2,700
def onmessage ( msg ) msg = Oj . strict_load ( msg ) msg [ 'data' ] = Oj . strict_load ( msg [ 'data' ] ) if msg [ 'data' ] . is_a? String event = msg [ 'event' ] . gsub ( / \A / , 'pusher_' ) if event =~ / \A / msg [ 'socket_id' ] = connection . socket_id Channel . send_client_message msg elsif respond_to? event , tru...
Dispatches message handling to method with same name as the event name
2,701
def dispatch ( message , channel ) if channel =~ / \A / update_subscribers message else push Oj . dump ( message , mode : :compat ) end end
Send an event received from Redis to the EventMachine channel
2,702
def add ( name , options ) @properties [ name . to_sym ] = Property . new ( name . to_sym , options [ :type ] , options [ :default ] ) end
Add a property to the schema
2,703
def use ( middleware , * args , & block ) return if faraday . builder . locked? faraday . builder . insert_before ( Middleware :: ParseJson , middleware , * args , & block ) end
insert middleware before ParseJson - middleware executed in reverse order - inserted middleware will run after json parsed
2,704
def destroy self . last_result_set = self . class . requestor . destroy ( self ) if last_result_set . has_errors? fill_errors false else mark_as_destroyed! self . relationships . last_result_set = nil _clear_cached_relationships _clear_belongs_to_params true end end
Try to destroy this resource
2,705
def new_url_query_values? ( uri , paths_with_queries ) queries = uri . query_values . keys . join ( '-' ) domain_path = extract_domain_path ( uri ) if paths_with_queries [ domain_path ] . nil? paths_with_queries [ domain_path ] = [ queries ] true elsif ! paths_with_queries [ domain_path ] . include? ( queries ) paths_w...
remember queries we ve seen ignore future ones
2,706
def external_link_checker ( external_urls ) external_urls = Hash [ external_urls . sort ] count = external_urls . length check_text = pluralize ( count , 'external link' , 'external links' ) @logger . log :info , "Checking #{check_text}..." Ethon . logger = @logger establish_queue ( external_urls ) @hydra . run end
Proofer runs faster if we pull out all the external URLs and run the checks at the end . Otherwise we re halting the consuming process for every file during process_files .
2,707
def check_hash_in_2xx_response ( href , effective_url , response , filenames ) return false if @options [ :only_4xx ] return false unless @options [ :check_external_hash ] return false unless ( hash = hash? ( href ) ) body_doc = create_nokogiri ( response . body ) unencoded_hash = Addressable :: URI . unescape ( hash )...
Even though the response was a success we may have been asked to check if the hash on the URL exists on the page
2,708
def check_files @external_urls = { } process_files . each do | item | @external_urls . merge! ( item [ :external_urls ] ) @failures . concat ( item [ :failures ] ) end if @options [ :external_only ] @failures = [ ] validate_urls elsif ! @options [ :disable_external ] validate_urls end end
Collects any external URLs found in a directory of files . Also collectes every failed test from process_files . Sends the external URLs to Typhoeus for batch processing .
2,709
def process_files if @options [ :parallel ] . empty? files . map { | path | check_path ( path ) } else Parallel . map ( files , @options [ :parallel ] ) { | path | check_path ( path ) } end end
Walks over each implemented check and runs them on the files in parallel .
2,710
def set_request_body! ( request ) case @request_format when :json then request . body = ( camelize_keys! @body ) . to_json when :form then request . set_form_data @body when :file then request . body_stream = @body end if @body end
Adds the request body to the request in the appropriate format . if the request body is a JSON Object transform its keys into camel - case since this is the common format for JSON APIs .
2,711
def parse_response! response . body = case @response_format when :xml then Hash . from_xml response . body when :json then JSON response . body end if response . body end
Replaces the body of the response with the parsed version of the body according to the format specified in the Request .
2,712
def server_errors [ OpenSSL :: SSL :: SSLError , Errno :: ETIMEDOUT , Errno :: EHOSTUNREACH , Errno :: ENETUNREACH , Errno :: ECONNRESET , Net :: OpenTimeout , SocketError , Net :: HTTPServerError ] + extra_server_errors end
Returns the list of server errors worth retrying the request once .
2,713
def perform ( action , options = { } ) return unless %i[ backtrace down finish frame next step up ] . include? ( action ) send ( "perform_#{action}" , options ) end
Set up a number of navigational commands to be performed by Byebug .
2,714
def resume_pry new_binding = frame . _binding run do if defined? ( @pry ) && @pry @pry . repl ( new_binding ) else @pry = Pry . start_without_pry_byebug ( new_binding ) end end end
Resume an existing Pry REPL at the paused point .
2,715
def render ( scope = Object . new , locals = { } , & block ) parent = scope . instance_variable_defined? ( :@haml_buffer ) ? scope . instance_variable_get ( :@haml_buffer ) : nil buffer = Haml :: Buffer . new ( parent , @options . for_buffer ) if scope . is_a? ( Binding ) scope_object = eval ( "self" , scope ) scope = ...
Processes the template and returns the result as a string .
2,716
def render_proc ( scope = Object . new , * local_names ) if scope . is_a? ( Binding ) scope_object = eval ( "self" , scope ) else scope_object = scope scope = scope_object . instance_eval { binding } end begin str = @temple_engine . precompiled_with_ambles ( local_names ) eval ( "Proc.new { |*_haml_locals| _haml_locals...
Returns a proc that when called renders the template and returns the result as a string .
2,717
def def_method ( object , name , * local_names ) method = object . is_a? ( Module ) ? :module_eval : :instance_eval object . send ( method , "def #{name}(_haml_locals = {}); #{@temple_engine.precompiled_with_ambles(local_names)}; end" , @options . filename , @options . line ) end
Defines a method on object with the given name that renders the template and returns the result as a string .
2,718
def compile_attribute_values ( values ) if values . map ( & :key ) . uniq . size == 1 compile_attribute ( values . first . key , values ) else runtime_build ( values ) end end
Compiles attribute values with the similar key to Temple expression .
2,719
def static_build ( values ) hash_content = values . group_by ( & :key ) . map do | key , values_for_key | "#{frozen_string(key)} => #{merged_value(key, values_for_key)}" end . join ( ', ' ) arguments = [ @is_html , @attr_wrapper , @escape_attrs , @hyphenate_data_attrs ] code = "::Haml::AttributeBuilder.build_attributes...
Renders attribute values statically .
2,720
def compile_attribute ( key , values ) if values . all? { | v | Temple :: StaticAnalyzer . static? ( v . to_literal ) } return static_build ( values ) end case key when 'id' , 'class' compile_id_or_class_attribute ( key , values ) else compile_common_attribute ( key , values ) end end
Compiles attribute values for one key to Temple expression that generates key = value .
2,721
def parse_haml_magic_comment ( str ) scanner = StringScanner . new ( str . dup . force_encoding ( Encoding :: ASCII_8BIT ) ) bom = scanner . scan ( / \xEF \xBB \xBF /n ) return bom unless scanner . scan ( / \s \s /n ) if coding = try_parse_haml_emacs_magic_comment ( scanner ) return bom , coding end return bom unless s...
Parses a magic comment at the beginning of a Haml file . The parsing rules are basically the same as Ruby s .
2,722
def rstrip! if capture_position . nil? buffer . rstrip! return end buffer << buffer . slice! ( capture_position .. - 1 ) . rstrip end
Remove the whitespace from the right side of the buffer string . Doesn t do anything if we re at the beginning of a capture_haml block .
2,723
def preserve ( input = nil , & block ) return preserve ( capture_haml ( & block ) ) if block s = input . to_s . chomp ( "\n" ) s . gsub! ( / \n / , '&#x000A;' ) s . delete! ( "\r" ) s end
Takes any string finds all the newlines and converts them to HTML entities so they ll render correctly in whitespace - sensitive tags without screwing up the indentation .
2,724
def capture_haml ( * args , & block ) buffer = eval ( 'if defined? _hamlout then _hamlout else nil end' , block . binding ) || haml_buffer with_haml_buffer ( buffer ) do position = haml_buffer . buffer . length haml_buffer . capture_position = position value = block . call ( * args ) captured = haml_buffer . buffer . s...
Captures the result of a block of Haml code gets rid of the excess indentation and returns it as a string . For example after the following
2,725
def haml_internal_concat ( text = "" , newline = true , indent = true ) if haml_buffer . tabulation == 0 haml_buffer . buffer << "#{text}#{"\n" if newline}" else haml_buffer . buffer << %[#{haml_indent if indent}#{text.to_s.gsub("\n", "\n#{haml_indent}")}#{"\n" if newline}] end end
Internal method to write directly to the buffer with control of whether the first line should be indented and if there should be a final newline .
2,726
def with_haml_buffer ( buffer ) @haml_buffer , old_buffer = buffer , @haml_buffer old_buffer . active , old_was_active = false , old_buffer . active? if old_buffer @haml_buffer . active , was_active = true , @haml_buffer . active? yield ensure @haml_buffer . active = was_active old_buffer . active = old_was_active if o...
Runs a block of code with the given buffer as the currently active buffer .
2,727
def haml_bind_proc ( & proc ) _hamlout = haml_buffer _erbout = _erbout = _hamlout . buffer proc { | * args | proc . call ( * args ) } end
Gives a proc the same local _hamlout and _erbout variables that the current template has .
2,728
def process_indent ( line ) return unless line . tabs <= @template_tabs && @template_tabs > 0 to_close = @template_tabs - line . tabs to_close . times { | i | close unless to_close - 1 - i == 0 && continuation_script? ( line . text ) } end
Processes and deals with lowering indentation .
2,729
def process_line ( line ) case line . text [ 0 ] when DIV_CLASS ; push div ( line ) when DIV_ID return push plain ( line ) if %w[ { @ $ ] . include? ( line . text [ 1 ] ) push div ( line ) when ELEMENT ; push tag ( line ) when COMMENT ; push comment ( line . text [ 1 .. - 1 ] . lstrip ) when SANITIZE return push plain ...
Processes a single line of Haml .
2,730
def comment ( text ) if text [ 0 .. 1 ] == '![' revealed = true text = text [ 1 .. - 1 ] else revealed = false end conditional , text = balance ( text , ?[ , ?] ) if text [ 0 ] == ?[ text . strip! if contains_interpolation? ( text ) parse = true text = unescape_interpolation ( text ) else parse = false end if block_ope...
Renders an XHTML comment .
2,731
def doctype ( text ) raise SyntaxError . new ( Error . message ( :illegal_nesting_header ) , @next_line . index ) if block_opened? version , type , encoding = text [ 3 .. - 1 ] . strip . downcase . scan ( DOCTYPE_REGEX ) [ 0 ] ParseNode . new ( :doctype , @line . index + 1 , :version => version , :type => type , :encod...
Renders an XHTML doctype or XML shebang .
2,732
def parse_tag ( text ) match = text . scan ( / \w \w \@ / ) [ 0 ] raise SyntaxError . new ( Error . message ( :invalid_tag , text ) ) unless match tag_name , attributes , rest = match if ! attributes . empty? && ( attributes =~ / \. \z / ) raise SyntaxError . new ( Error . message ( :illegal_element ) ) end new_attribu...
Parses a line into tag_name attributes attributes_hash object_ref action value
2,733
def is_multiline? ( text ) text && text . length > 1 && text [ - 1 ] == MULTILINE_CHAR_VALUE && text [ - 2 ] == ?\s && text !~ BLOCK_WITH_SPACES end
Checks whether or not line is in a multiline sequence .
2,734
def push_silent ( text , can_suppress = false ) flush_merged_text return if can_suppress && @options . suppress_eval? newline = ( text == "end" ) ? ";" : "\n" @temple << [ :code , "#{resolve_newlines}#{text}#{newline}" ] @output_line = @output_line + text . count ( "\n" ) + newline . count ( "\n" ) end
Evaluates text in the context of the scope object but does not output the result .
2,735
def rstrip_buffer! ( index = - 1 ) last = @to_merge [ index ] if last . nil? push_silent ( "_hamlout.rstrip!" , false ) return end case last . first when :text last [ 1 ] = last [ 1 ] . rstrip if last [ 1 ] . empty? @to_merge . slice! index rstrip_buffer! index end when :script last [ 1 ] . gsub! ( / \( \) / , '(haml_t...
Get rid of and whitespace at the end of the buffer or the merged text
2,736
def remove_filter ( name ) defined . delete name . to_s . downcase if constants . map ( & :to_s ) . include? ( name . to_s ) remove_const name . to_sym end end
Removes a filter from Haml . If the filter was removed it returns the Module that was removed upon success or nil on failure . If you try to redefine a filter Haml will raise an error . Use this method first to explicitly remove the filter before redefining it .
2,737
def wait_until ( depr_timeout = nil , depr_message = nil , timeout : nil , message : nil , interval : nil , ** opt , & blk ) if depr_message || depr_timeout Watir . logger . deprecate 'Using arguments for #wait_until' , 'keywords' , ids : [ :timeout_arguments ] timeout = depr_timeout message = depr_message end message ...
Waits until the condition is true .
2,738
def wait_until_present ( depr_timeout = nil , timeout : nil , interval : nil , message : nil ) timeout = depr_timeout if depr_timeout Watir . logger . deprecate "#{self.class}#wait_until_present" , "#{self.class}#wait_until(&:present?)" , ids : [ :wait_until_present ] message ||= proc { | obj | "waiting for #{obj.inspe...
Waits until the element is present . Element is always relocated so this can be used in the case of an element going away and returning
2,739
def wait_while_present ( depr_timeout = nil , timeout : nil , interval : nil , message : nil ) timeout = depr_timeout if depr_timeout Watir . logger . deprecate "#{self.class}#wait_while_present" , "#{self.class}#wait_while(&:present?)" , ids : [ :wait_while_present ] message ||= proc { | obj | "waiting for #{obj.inspe...
Waits while the element is present . Element is always relocated so this can be used in the case of the element changing attributes
2,740
def set! ( * args ) msg = '#set! does not support special keys, use #set instead' raise ArgumentError , msg if args . any? { | v | v . is_a? ( :: Symbol ) } input_value = args . join set input_value [ 0 ] return content_editable_set! ( * args ) if @content_editable element_call { execute_js ( :setValue , @element , inp...
Uses JavaScript to enter most of the given value . Selenium is used to enter the first and last characters
2,741
def execute_script ( script , * args ) args . map! do | e | e . is_a? ( Element ) ? e . wait_until ( & :exists? ) . wd : e end returned = driver . execute_script ( script , * args ) browser . wrap_elements_in ( self , returned ) end
Executes JavaScript snippet in context of frame .
2,742
def fire_event ( event_name ) event_name = event_name . to_s . sub ( / / , '' ) . downcase element_call { execute_js :fireEvent , @element , event_name } end
Simulates JavaScript events on element . Note that you may omit on from event name .
2,743
def include? ( str_or_rx ) option ( text : str_or_rx ) . exist? || option ( label : str_or_rx ) . exist? end
Returns true if the select list has one or more options where text or label matches the given value .
2,744
def select ( * str_or_rx ) results = str_or_rx . flatten . map { | v | select_by v } results . first end
Select the option whose text or label matches the given string .
2,745
def select_all ( * str_or_rx ) results = str_or_rx . flatten . map { | v | select_all_by v } results . first end
Select all options whose text or label matches the given string .
2,746
def select! ( * str_or_rx ) results = str_or_rx . flatten . map { | v | select_by! ( v , :single ) } results . first end
Uses JavaScript to select the option whose text matches the given string .
2,747
def select_all! ( * str_or_rx ) results = str_or_rx . flatten . map { | v | select_by! ( v , :multiple ) } results . first end
Uses JavaScript to select all options whose text matches the given string .
2,748
def value = ( path ) path = path . gsub ( File :: SEPARATOR , File :: ALT_SEPARATOR ) if File :: ALT_SEPARATOR element_call { @element . send_keys path } end
Sets the file field to the given path
2,749
def goto ( uri ) uri = "http://#{uri}" unless uri =~ URI :: DEFAULT_PARSER . make_regexp @driver . navigate . to uri @after_hooks . run uri end
Goes to the given URL .
2,750
def warn ( message , ids : [ ] , & block ) msg = ids . empty? ? '' : "[#{ids.map!(&:to_s).map(&:inspect).join(', ')}] " msg += message @logger . warn ( msg , & block ) unless ( @ignored & ids ) . any? end
Only log a warn message if it is not set to be ignored .
2,751
def deprecate ( old , new , reference : '' , ids : [ ] ) return if @ignored . include? ( 'deprecations' ) || ( @ignored & ids . map! ( & :to_s ) ) . any? msg = ids . empty? ? '' : "[#{ids.map(&:inspect).join(', ')}] " ref_msg = reference . empty? ? '.' : "; see explanation for this deprecation: #{reference}." warn "[DE...
Marks code as deprecated with replacement .
2,752
def attribute ( type , method , attr ) typed_attributes [ type ] << [ method , attr ] define_attribute ( type , method , attr ) end
YARD macro to generated friendly documentation for attributes .
2,753
def execute_script ( script , * args ) args . map! do | e | e . is_a? ( Element ) ? e . wait_until ( & :exists? ) . wd : e end wrap_elements_in ( self , @driver . execute_script ( script , * args ) ) end
Executes JavaScript snippet .
2,754
def resize_to ( width , height ) Selenium :: WebDriver :: Dimension . new ( Integer ( width ) , Integer ( height ) ) . tap do | dimension | use { @driver . manage . window . size = dimension } end end
Resizes window to given width and height .
2,755
def move_to ( x_coord , y_coord ) Selenium :: WebDriver :: Point . new ( Integer ( x_coord ) , Integer ( y_coord ) ) . tap do | point | use { @driver . manage . window . position = point } end end
Moves window to given x and y coordinates .
2,756
def to_a @control . all_cookies . map do | e | e . merge ( expires : e [ :expires ] ? e [ :expires ] . to_time : nil ) end end
Returns array of cookies .
2,757
def add ( name , value , opts = { } ) cookie = { name : name , value : value } cookie [ :secure ] = opts [ :secure ] if opts . key? ( :secure ) cookie [ :path ] = opts [ :path ] if opts . key? ( :path ) expires = opts [ :expires ] if expires cookie [ :expires ] = expires . is_a? ( String ) ? :: Time . parse ( expires )...
Adds new cookie .
2,758
def load ( file = '.cookies' ) YAML . safe_load ( IO . read ( file ) , [ :: Symbol , :: Time ] ) . each do | c | add ( c . delete ( :name ) , c . delete ( :value ) , c ) end end
Load cookies from file
2,759
def headers ( row = nil ) row ||= rows . first header_type = row . th . exist? ? 'th' : 'td' row . send ( "#{header_type}s" ) end
Returns first row of Table with proper subtype
2,760
def select ( str_or_rx ) %i[ value label ] . each do | key | radio = radio ( key => str_or_rx ) next unless radio . exist? radio . click unless radio . selected? return key == :value ? radio . value : radio . text end raise UnknownObjectException , "Unable to locate radio matching #{str_or_rx.inspect}" end
Select the radio button whose value or label matches the given string .
2,761
def selected? ( str_or_rx ) found = frame . radio ( label : str_or_rx ) return found . selected? if found . exist? raise UnknownObjectException , "Unable to locate radio matching #{str_or_rx.inspect}" end
Returns true if any of the radio button label matches the given value .
2,762
def windows ( * args ) all = @driver . window_handles . map { | handle | Window . new ( self , handle : handle ) } if args . empty? all else filter_windows extract_selector ( args ) , all end end
Returns browser windows array .
2,763
def window ( * args , & blk ) win = Window . new self , extract_selector ( args ) win . use ( & blk ) if block_given? win end
Returns browser window .
2,764
def to ( param = :top ) args = @object . is_a? ( Watir :: Element ) ? element_scroll ( param ) : browser_scroll ( param ) raise ArgumentError , "Don't know how to scroll #{@object} to: #{param}!" if args . nil? @object . browser . execute_script ( * args ) self end
Scrolls to specified location .
2,765
def children ( opt = { } ) raise ArgumentError , '#children can not take an index value' if opt [ :index ] xpath_adjacent ( opt . merge ( adjacent : :child , plural : true ) ) end
Returns collection of elements of direct children of current element .
2,766
def when_present ( timeout = nil ) msg = '#when_present' repl_msg = '#wait_until_present if a wait is still needed' Watir . logger . deprecate msg , repl_msg , ids : [ :when_present ] timeout ||= Watir . default_timeout message = "waiting for #{selector_string} to become present" if block_given? Wait . until ( timeout ...
Waits until the element is present .
2,767
def when_enabled ( timeout = nil ) msg = '#when_enabled' repl_msg = 'wait_until(&:enabled?)' Watir . logger . deprecate msg , repl_msg , ids : [ :when_enabled ] timeout ||= Watir . default_timeout message = "waiting for #{selector_string} to become enabled" if block_given? Wait . until ( timeout , message ) { enabled? ...
Waits until the element is enabled .
2,768
def add ( after_hook = nil , & block ) if block_given? @after_hooks << block elsif after_hook . respond_to? :call @after_hooks << after_hook else raise ArgumentError , 'expected block or object responding to #call' end end
Adds new after hook .
2,769
def run return unless @after_hooks . any? && ! @browser . alert . exists? each { | after_hook | after_hook . call ( @browser ) } rescue Selenium :: WebDriver :: Error :: NoSuchWindowError => ex Watir . logger . info "Could not execute After Hooks because browser window was closed #{ex}" end
Runs after hooks .
2,770
def exists? if located? && stale? Watir . logger . deprecate 'Checking `#exists? == false` to determine a stale element' , '`#stale? == true`' , reference : 'http://watir.com/staleness-changes' , ids : [ :stale_exists ] return false end assert_exists true rescue UnknownObjectException , UnknownFrameException false end
Returns true if element exists . Checking for staleness is deprecated
2,771
def click ( * modifiers ) element_call ( :wait_for_enabled ) do if modifiers . any? action = driver . action modifiers . each { | mod | action . key_down mod } action . click @element modifiers . each { | mod | action . key_up mod } action . perform else @element . click end end browser . after_hooks . run end
Clicks the element optionally while pressing the given modifier keys . Note that support for holding a modifier key is currently experimental and may not work at all .
2,772
def drag_and_drop_on ( other ) assert_is_element other value = element_call ( :wait_for_present ) do driver . action . drag_and_drop ( @element , other . wd ) . perform end browser . after_hooks . run value end
Drag and drop this element on to another element instance . Note that browser support may vary .
2,773
def drag_and_drop_by ( right_by , down_by ) element_call ( :wait_for_present ) do driver . action . drag_and_drop_by ( @element , right_by , down_by ) . perform end end
Drag and drop this element by the given offsets . Note that browser support may vary .
2,774
def attribute_value ( attribute_name ) attribute_name = attribute_name . to_s . tr ( '_' , '-' ) if attribute_name . is_a? ( :: Symbol ) element_call { @element . attribute attribute_name } end
Returns given attribute value of element .
2,775
def attribute_values result = element_call { execute_js ( :attributeValues , @element ) } result . keys . each do | key | next unless key == key [ / \- / ] result [ key . tr ( '-' , '_' ) . to_sym ] = result . delete ( key ) end result end
Returns all attribute values . Attributes with special characters are returned as String rest are returned as a Symbol .
2,776
def center point = location dimensions = size Selenium :: WebDriver :: Point . new ( point . x + ( dimensions [ 'width' ] / 2 ) , point . y + ( dimensions [ 'height' ] / 2 ) ) end
Get centre coordinates of element
2,777
def visible? msg = '#visible? behavior will be changing slightly, consider switching to #present? ' '(more details: http://watir.com/element-existentialism/)' Watir . logger . warn msg , ids : [ :visible_element ] displayed = display_check if displayed . nil? && display_check Watir . logger . deprecate 'Checking `#visi...
Returns true if this element is visible on the page . Raises exception if element does not exist
2,778
def present? displayed = display_check if displayed . nil? && display_check Watir . logger . deprecate 'Checking `#present? == false` to determine a stale element' , '`#stale? == true`' , reference : 'http://watir.com/staleness-changes' , ids : [ :stale_present ] end displayed rescue UnknownObjectException , UnknownFra...
Returns true if the element exists and is visible on the page . Returns false if element does not exist or exists but is not visible
2,779
def [] ( value ) if value . is_a? ( Range ) to_a [ value ] elsif @selector . key? :adjacent to_a [ value ] || element_class . new ( @query_scope , invalid_locator : true ) elsif @to_a && @to_a [ value ] @to_a [ value ] else element_class . new ( @query_scope , @selector . merge ( index : value ) ) end end
Get the element at the given index or range .
2,780
def to_a hash = { } @to_a ||= elements_with_tags . map . with_index do | ( el , tag_name ) , idx | selector = @selector . dup selector [ :index ] = idx unless idx . zero? element = element_class . new ( @query_scope , selector ) if [ HTMLElement , Input ] . include? element . class construct_subtype ( element , hash , ...
This collection as an Array .
2,781
def diff ( * args ) args . unshift ( parents . first ) if args . size == 1 && args . first . is_a? ( Hash ) self . tree . diff ( * args ) end
Return a diff between this commit and its first parent or another commit or tree .
2,782
def checkout ( target , options = { } ) options [ :strategy ] ||= :safe options . delete ( :paths ) return checkout_head ( options ) if target == "HEAD" if target . kind_of? ( Rugged :: Branch ) branch = target else branch = branches [ target ] end if branch self . checkout_tree ( branch . target , options ) if branch ...
Checkout the specified branch reference or commit .
2,783
def create_branch ( name , sha_or_ref = "HEAD" ) case sha_or_ref when Rugged :: Object target = sha_or_ref . oid else target = rev_parse_oid ( sha_or_ref ) end branches . create ( name , target ) end
Create a new branch in the repository
2,784
def blob_at ( revision , path ) tree = Rugged :: Commit . lookup ( self , revision ) . tree begin blob_data = tree . path ( path ) rescue Rugged :: TreeError return nil end blob = Rugged :: Blob . lookup ( self , blob_data [ :oid ] ) ( blob . type == :blob ) ? blob : nil end
Get the blob at a path for a specific revision .
2,785
def push ( remote_or_url , * args ) unless remote_or_url . kind_of? Remote remote_or_url = remotes [ remote_or_url ] || remotes . create_anonymous ( remote_or_url ) end remote_or_url . push ( * args ) end
Push a list of refspecs to the given remote .
2,786
def clone_submodule ( repo , fetch_options ) repo . remotes [ 'origin' ] . fetch ( fetch_options ) repo . branches . create ( 'master' , 'origin/master' ) repo . branches [ 'master' ] . upstream = repo . branches [ 'origin/master' ] repo . checkout_head ( strategy : :force ) end
currently libgit2 s git_submodule_add_setup initializes a repo with a workdir for the submodule . libgit2 s git_clone however requires the target for the clone to be an empty dir .
2,787
def build_access_token ( response , access_token_opts , access_token_class ) access_token_class . from_hash ( self , response . parsed . merge ( access_token_opts ) ) . tap do | access_token | access_token . response = response if access_token . respond_to? ( :response= ) end end
Builds the access token from the response of the HTTP call
2,788
def apply ( params ) case mode . to_sym when :basic_auth apply_basic_auth ( params ) when :request_body apply_params_auth ( params ) else raise NotImplementedError end end
Apply the request credentials used to authenticate to the Authorization Server
2,789
def apply_basic_auth ( params ) headers = params . fetch ( :headers , { } ) headers = basic_auth_header . merge ( headers ) params . merge ( :headers => headers ) end
Adds an Authorization header with Basic Auth credentials if and only if it is not already set in the params .
2,790
def content_type return nil unless response . headers ( ( response . headers . values_at ( 'content-type' , 'Content-Type' ) . compact . first || '' ) . split ( ';' ) . first || '' ) . strip end
Attempts to determine the content type of the response .
2,791
def request ( verb , path , opts = { } , & block ) url = client . connection . build_url ( path , opts [ :params ] ) . to_s opts [ :headers ] ||= { } opts [ :headers ] [ 'Authorization' ] = header ( verb , url ) @client . request ( verb , path , opts , & block ) end
Initalize a MACToken
2,792
def header ( verb , url ) timestamp = Time . now . utc . to_i nonce = Digest :: MD5 . hexdigest ( [ timestamp , SecureRandom . hex ] . join ( ':' ) ) uri = URI . parse ( url ) raise ( ArgumentError , "could not parse \"#{url}\" into URI" ) unless uri . is_a? ( URI :: HTTP ) mac = signature ( timestamp , nonce , verb , ...
Generate the MAC header
2,793
def signature ( timestamp , nonce , verb , uri ) signature = [ timestamp , nonce , verb . to_s . upcase , uri . request_uri , uri . host , uri . port , '' , nil ] . join ( "\n" ) Base64 . strict_encode64 ( OpenSSL :: HMAC . digest ( @algorithm , secret , signature ) ) end
Generate the Base64 - encoded HMAC digest signature
2,794
def algorithm = ( alg ) @algorithm = begin case alg . to_s when 'hmac-sha-1' OpenSSL :: Digest :: SHA1 . new when 'hmac-sha-256' OpenSSL :: Digest :: SHA256 . new else raise ( ArgumentError , 'Unsupported algorithm' ) end end end
Set the HMAC algorithm
2,795
def refresh ( params = { } , access_token_opts = { } , access_token_class = self . class ) raise ( 'A refresh_token is not available' ) unless refresh_token params [ :grant_type ] = 'refresh_token' params [ :refresh_token ] = refresh_token new_token = @client . get_token ( params , access_token_opts , access_token_clas...
Refreshes the current Access Token
2,796
def request ( verb , path , opts = { } , & block ) configure_authentication! ( opts ) @client . request ( verb , path , opts , & block ) end
Make a request with the Access Token
2,797
def run_log log = @base . lib . full_log_commits ( :count => @count , :object => @object , :path_limiter => @path , :since => @since , :author => @author , :grep => @grep , :skip => @skip , :until => @until , :between => @between ) @commits = log . map { | c | Git :: Object :: Commit . new ( @base , c [ 'sha' ] , c ) }...
actually run the git log command
2,798
def [] ( branch_name ) @branches . values . inject ( @branches ) do | branches , branch | branches [ branch . full ] ||= branch branches [ branch . full . sub ( 'remotes/' , '' ) ] ||= branch if branch . full =~ / \/ / branches end [ branch_name . to_s ] end
Returns the target branch
2,799
def describe ( committish = nil , opts = { } ) arr_opts = [ ] arr_opts << '--all' if opts [ :all ] arr_opts << '--tags' if opts [ :tags ] arr_opts << '--contains' if opts [ :contains ] arr_opts << '--debug' if opts [ :debug ] arr_opts << '--long' if opts [ :long ] arr_opts << '--always' if opts [ :always ] arr_opts << ...
tries to clone the given repo