idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
16,500 | def delete deregister fullpath = File . join ( self . class . bindir , filename ) FileUtils . rm ( fullpath ) if File . exists? ( fullpath ) end | Delete the executable double . |
16,501 | def []= ( index , filter ) raise TypeError , 'must provide a filter' unless filter . respond_to? ( :call ) synchronize do id = index_at ( index ) unless id && ( 0 .. @filters . size ) . cover? ( id ) raise ArgumentError , "Cannot insert at index #{index.inspect}" end @filters [ id ] = filter end end | Set the new filter at the given index . You can specify any existing filter or an index one above the highest index . |
16,502 | def call ( event ) each do | filter | result = filter . call ( event ) return false if result == false end event end | Filter the given event by calling each defined filter with it . Each filter will be called with the current event and can manipulate it in any way . |
16,503 | def insert_before ( index , * filter_spec , & block ) filter = build_filter ( filter_spec , & block ) synchronize do id = index_at ( index ) unless id && ( 0 ... @filters . size ) . cover? ( id ) raise ArgumentError , "No such filter to insert before: #{index.inspect}" end @filters . insert ( id , filter ) end self end | Insert a new filter before an existing filter in the filter chain . |
16,504 | def build_filter ( filter_spec , & block ) if filter_spec . empty? return Rackstash :: Filter . build ( block ) if block_given? raise ArgumentError , 'Need to specify a filter' else Rackstash :: Filter . build ( * filter_spec , & block ) end end | Build a new filter instance from the given specification . |
16,505 | def start! wait logger . warn 'Tasks list is empty' if tasks . empty? tasks . each do | task | run_task ( task ) sleep post_task_sleep_time end scheduler . join rescue SystemExit , Interrupt logger . info 'Shutting down' scheduler . shutdown end | Start the service |
16,506 | def fetch ( spec , default = UNDEFINED ) case spec when Class spec when String , Symbol , -> ( s ) { s . respond_to? ( :to_sym ) } @registry . fetch ( spec . to_sym ) do | key | next yield ( key ) if block_given? next default unless UNDEFINED . equal? default raise KeyError , "No #{@object_type} was registered for #{sp... | Retrieve the registered class for a given name . If the argument is already a class we return it unchanged . |
16,507 | def []= ( name , registered_class ) unless registered_class . is_a? ( Class ) raise TypeError , 'Can only register class objects' end case name when String , Symbol @registry [ name . to_sym ] = registered_class else raise TypeError , "Can not use #{name.inspect} to register a #{@object_type} class" end registered_clas... | Register a class for the given name . |
16,508 | def emit name , * args EM . defer { notify_scripts name , * args } matching_callbacks = callbacks [ name ] return false unless matching_callbacks &. any? EM . defer do matching_callbacks . each { | callback | callback . call * args } end end | Emit a new event with given arguments . |
16,509 | def export ( options = nil ) self . class . attributes . reduce ( { } ) do | result , name | value = attributes [ name ] if self . class . association? ( name , :many ) result [ name ] = export_values ( value , options ) elsif self . class . association? ( name , :one ) result [ name ] = export_value ( value , options ... | Two models are equal if their attributes are equal . Recursively convert all attributes to hash pairs . |
16,510 | def extract_attributes ( model ) self . class . attributes . reduce ( { } ) do | result , name | if model . respond_to? ( name ) result [ name ] = model . public_send ( name ) elsif model . respond_to? ( :[] ) && model . respond_to? ( :key? ) && model . key? ( name ) result [ name ] = model [ name ] end result end end | Extract model attributes into a hash . |
16,511 | def validate_associations_many self . class . associations ( :many ) . each do | name | values = attributes [ name ] || [ ] values . each . with_index do | value , index | import_errors ( "#{name}[#{index}]" , value ) end end end | Validate many associations and import errors . |
16,512 | def import_errors ( name , model ) return unless model . respond_to? ( :validate ) return if model . validate ( validation_context ) model . errors . each do | field , error | errors . add ( "#{name}[#{field}]" , error ) end end | Merge associated errors using the current validation context . |
16,513 | def export_values ( values , options = nil ) return if values . nil? values . map { | v | export_value ( v , options ) } end | Export each value with the provided options . |
16,514 | def export_value ( value , options = nil ) return if value . nil? value . respond_to? ( :export ) ? value . export ( options ) : value end | Export the value with the provided options . |
16,515 | def contender_key ( value = 'none' ) if value . nil? || value . empty? raise ArgumentError , 'Value cannot be empty or nil' end key = "#{prefix}/#{session.id}" :: DaemonRunner :: RetryErrors . retry do @contender_key = Diplomat :: Lock . acquire ( key , session . id , value ) end @contender_key end | Create a contender key |
16,516 | def semaphore_state options = { decode_values : true , recurse : true } @state = Diplomat :: Kv . get ( prefix , options , :return ) decode_semaphore_state unless state . empty? state end | Get the current semaphore state by fetching all conterder keys and the lock key |
16,517 | def write_lock index = lock_modify_index . nil? ? 0 : lock_modify_index value = generate_lockfile return true if value == true Diplomat :: Kv . put ( @lock , value , cas : index ) end | Write a new lock file if the number of contenders is less than limit |
16,518 | def renew? logger . debug ( "Watching Consul #{prefix} for changes" ) options = { recurse : true } changes = Diplomat :: Kv . get ( prefix , options , :wait , :wait ) logger . info ( "Changes on #{prefix} detected" ) if changes changes rescue StandardError => e logger . error ( e ) end | Start a blocking query on the prefix if there are changes we need to try to obtain the lock again . |
16,519 | def decode_semaphore_state lock_key = state . find { | k | k [ 'Key' ] == @lock } member_keys = state . delete_if { | k | k [ 'Key' ] == @lock } member_keys . map! { | k | k [ 'Key' ] } unless lock_key . nil? @lock_modify_index = lock_key [ 'ModifyIndex' ] @lock_content = JSON . parse ( lock_key [ 'Value' ] ) end @memb... | Decode raw response from Consul Set |
16,520 | def prune_members @holders = if lock_exists? holders = lock_content [ 'Holders' ] return @holders = [ ] if holders . nil? holders = holders . keys holders & members else [ ] end end | Get the active members from the lock file removing any _dead_ members . This is accomplished by using the contenders keys ( |
16,521 | def add_self_to_holders @holders . uniq! @reset = true if @holders . length == 0 return true if @holders . include? session . id if @holders . length < limit @holders << session . id end end | Add our session . id to the holders list if holders is less than limit |
16,522 | def format_holders @holders . uniq! @holders . sort! holders = { } logger . debug "Holders are: #{@holders.join(',')}" @holders . map { | m | holders [ m ] = true } @holders = holders end | Format the list of holders for the lock file |
16,523 | def generate_lockfile if lock_exists? && lock_content [ 'Holders' ] == @holders logger . info 'Holders are unchanged, not updating' return true end lockfile_format = { 'Limit' => limit , 'Holders' => @holders } JSON . generate ( lockfile_format ) end | Generate JSON formatted lockfile content only if the content has changed |
16,524 | def bump! return unless @started update_children candidate_children . each do | child | next if @child_pids . any? do | pid | get_build_by_pid ( pid ) . parent == child . parent end Juici . dbgp "Starting another child process" return child . tap do | cld | if pid = cld . build! Juici . dbgp "Started child: #{pid}" @ch... | Magic hook that starts a process if there s a good reason to . Stopgap measure that means you can knock on this if there s a chance we should start a process |
16,525 | def got_message message @client . got_message self , message rescue StandardError => exception puts "#{exception.class}: #{exception.message}" puts puts '---' puts exception . backtrace end | Forwards the received message to the client instance . |
16,526 | def disconnected! @channels . each { | _name , channel | channel . users . clear } @channels . clear @users . clear @client . network_connection_closed self end | Called when the connection was closed . |
16,527 | def transmit name , * arguments message = IRCParser :: Message . new command : name . to_s , parameters : arguments if @client . verbose formatted_command = message . command . to_s . ljust 8 , ' ' formatted_params = message . parameters . map ( & :inspect ) . join ' ' log "#{'→' ^ :red} #{formatted_command} #{formatte... | Transmit a command to the server . |
16,528 | def lock_id ( locker_uid , id_to_lock , expire_in_sec = 5 ) now = redis_time @con . multi do @con . zadd ( "#{LOCK_MAP_KEY}_z" , ( now + expire_in_sec ) , id_to_lock ) @con . hset ( "#{LOCK_MAP_KEY}_h" , id_to_lock , locker_uid ) end end | Locking mechanisem is based on sorted set sorted set is used to allow a simulation of expiration time on the keys in the map |
16,529 | def connect networks = @networks . reject & :connected? EventMachine . run do load_scripts! networks . each & :connect EventMachine . error_handler do | exception | log . error "#{exception.message ^ :bold} on line #{exception.line.to_s ^ :bold}" puts exception . backtrace . join "\n" end end end | Instantiates the client stores the options instantiates the networks and then loads available scripts . |
16,530 | def quit signal = :SIGINT @networks . each do | network | network . transmit :QUIT , 'Got SIGINT?' network . disconnect end EventMachine . stop end | Try to gracefully disconnect from each network unload all scripts and exit properly . |
16,531 | def load_scripts! scripts_dir = File . expand_path @config [ 'blur' ] [ 'scripts_dir' ] script_file_paths = Dir . glob File . join scripts_dir , '*.rb' script_file_paths = script_file_paths . sort do | a , b | File . basename ( a ) <=> File . basename ( b ) end script_file_paths . each { | script_path | load_script_fil... | Loads all scripts in the script directory . |
16,532 | def load_script_file file_path load file_path , true rescue Exception => exception warn "The script `#{file_path}' failed to load" warn "#{exception.class}: #{exception.message}" warn '' warn 'Backtrace:' , '---' , exception . backtrace end | Loads the given + file_path + as a Ruby script wrapping it in an anonymous module to protect our global namespace . |
16,533 | def unload_scripts! @scripts . each do | name , script | script . __send__ :unloaded if script . respond_to? :unloaded end . clear Blur . reset_scripts! end | Unloads initialized scripts and superscripts . |
16,534 | def load_config! config = YAML . load_file @config_path if config . key? @environment @config = config [ @environment ] @config . deeper_merge! DEFAULT_CONFIG emit :config_load else raise Error , "No configuration found for specified environment `#{@environment}'" end end | Load the user - specified configuration file . |
16,535 | def setup_path ( dir = nil ) dir ||= chapter . path dir = Tools . valid_path_name ( dir ) name = self . name . tr ( '/' , '' ) file = Dir . entries ( dir ) . find { | f | f [ name ] } if Dir . exist? ( dir ) path = Tools . file_join ( dir , file || name ) @path = Tools . relative_or_absolute_path ( path ) end | Set path of page to file path if a file exists or to path without file extension if file is not found . File extensions are appended only after the file has been downloaded . |
16,536 | def is_text_in_page? ( content , flag = true ) if flag assert page . has_content? ( "#{content}" ) , "Error: #{content} not found page !" else assert ! page . has_content? ( "#{content}" ) , "Error: #{content} found in page !" end end | Check that the text content is on the page set flag to check that it isn t |
16,537 | def is_text_in_section? ( section , content , flag = true ) within ( "#{section}" ) do if flag assert page . has_content? ( "#{content}" ) , "Error: #{content} not found in #{section} !" else assert ! page . has_content? ( "#{content}" ) , "Error: #{content} found in #{section} !" end end end | Check that the text content is within a particular css section set flag to check that it isn t |
16,538 | def load_json! ( json ) return true if json == "" loaded_json = JSON . load ( json ) if loaded_json . is_a? Hash env . merge! ( loaded_json ) return true end false rescue JSON :: ParserError return false end | XXX This is spectacular . Not in the good way |
16,539 | def timestamp ( time = nil ) @timestamp ||= begin time ||= Time . now . utc . freeze time = time . getutc . freeze unless time . utc? && time . frozen? time end end | Returns the time of the current buffer as an ISO 8601 formatted string . If the timestamp was not yet set on the buffer it is is set to the the passed time or the current time . |
16,540 | def event event = fields . to_h event [ FIELD_TAGS ] = tags . to_a event [ FIELD_MESSAGE ] = messages event [ FIELD_TIMESTAMP ] = timestamp event end | Create an event hash from self . |
16,541 | def url_encode ( str ) encoded_string = "" str . each_char do | char | case char when "+" encoded_string << "%2b" when "=" encoded_string << "%3d" when "?" encoded_string << "%3f" when "&" encoded_string << "%26" when "%" encoded_string << "%25" when "," encoded_string << "%2C" else encoded_string << char end end encod... | Creates a new HTTP instance which will automatically handle authenting to the RETS server . |
16,542 | def save_digest ( header ) @request_count = 0 @digest = { } header . split ( "," ) . each do | line | k , v = line . strip . split ( "=" , 2 ) @digest [ k ] = ( k != "algorithm" and k != "stale" ) && v [ 1 .. - 2 ] || v end @digest_type = @digest [ "qop" ] ? @digest [ "qop" ] . split ( "," ) : [ ] end | Creates and manages the HTTP digest auth if the WWW - Authorization header is passed then it will overwrite what it knows about the auth data . |
16,543 | def create_digest ( method , request_uri ) first = Digest :: MD5 . hexdigest ( "#{@config[:username]}:#{@digest["realm"]}:#{@config[:password]}" ) second = Digest :: MD5 . hexdigest ( "#{method}:#{request_uri}" ) if @digest_type . include? ( "auth" ) cnonce = Digest :: MD5 . hexdigest ( "#{@headers["User-Agent"]}:#{@co... | Creates a HTTP digest header . |
16,544 | def get_rets_response ( rets ) code , text = nil , nil rets . attributes . each do | attr | key = attr . first . downcase if key == "replycode" code = attr . last . value elsif key == "replytext" text = attr . last . value end end return code , text end | Finds the ReplyText and ReplyCode attributes in the response |
16,545 | def groups ( name , opts = { } , * args , & block ) instance_handler ( name , Groups , opts , * args , block ) end | Creates an instance of Group or calls an existing |
16,546 | def steps ( name , opts = { } , * args , & block ) opts [ :page ] && opts [ :page ] = pages ( opts . fetch ( :page ) ) instance_handler ( name , Steps , opts , * args , block ) end | Creates an instance of Step or calls an existing |
16,547 | def pages ( name , opts = { } , * args , & block ) instance_handler ( name , Page , opts , * args , block ) end | Creates an instance of Page or calls an existing |
16,548 | def to_s s = matcher_name . gsub ( / / , '\1_\2' ) . gsub ( / \d / , '\1_\2' ) . downcase defined? ( @expected ) ? [ s , @expected . inspect ] . join ( ' ' ) : s end | Returns a string representing the matcher . |
16,549 | def query ( query_string ) results = FogTracker :: Query :: QueryProcessor . new ( @trackers , :logger => @log ) . execute ( query_string ) ( results . each { | r | yield r } ) if block_given? results end | Returns an array of Resources matching the query_string . Calls any block passed for each resulting resource . |
16,550 | def accounts = ( new_accounts ) old_accounts = @accounts @accounts = FogTracker . validate_accounts ( new_accounts ) if ( @accounts != old_accounts ) stop if ( was_running = running? ) create_trackers start if was_running end @accounts end | Sets the account information . If any account info has changed all trackers are restarted . |
16,551 | def create_trackers @trackers = Hash . new @accounts . each do | name , account | @log . debug "Setting up tracker for account #{name}" @trackers [ name ] = AccountTracker . new ( name , account , { :delay => @delay , :error_callback => @error_proc , :logger => @log , :callback => Proc . new do | resources | qp = FogTr... | Creates a Hash of AccountTracker objects indexed by account name |
16,552 | def << ( msg ) buffer . add_message Message . new ( msg , time : Time . now . utc . freeze , progname : @progname , severity : UNKNOWN ) msg end | Create a new Logger instance . |
16,553 | def capture ( buffer_args = { } ) raise ArgumentError , 'block required' unless block_given? buffer_stack . push ( buffer_args ) begin yield ensure buffer_stack . flush_and_pop end end | Capture all messages and fields logged for the duration of the provided block in the current thread . |
16,554 | def load @config = YAML . load_file ( config_path ) @status . set ( errors : Status :: INFO_FILE_LOADED ) if @config == false @status . set ( errors : Status :: ERR_NOT_LOADING_EMPTY_FILE ) end rescue @status . set ( errors : Status :: ERR_CANT_LOAD ) end | Populate the configuration ( |
16,555 | def is_css_in_page? ( css , flag = true ) if flag assert page . has_css? ( "#{css}" ) , "Error: #{css} not found on page !" else assert ! page . has_css? ( "#{css}" ) , "Error: #{css} found on page !" end end | Check that a css element is on the page set flag to check that it isn t |
16,556 | def is_css_in_section? ( css1 , css2 , flag = true ) within ( "#{css1}" ) do if flag assert page . has_css? ( "#{css2}" ) , "Error: #{css2} not found in #{css1} !" else assert ! page . has_css? ( "#{css2}" ) , "Error: #{css2} found in #{css1} !" end end end | Check that a css element is nested within another css element set flag to check that it isn t |
16,557 | def its ( method , & spec ) i = It . new ( described , ( challenges + [ Defi . send ( method ) ] ) , helpers . dup ) result = i . verify ( & spec ) if configuration . fetch ( :verbose , true ) print result . to_char ( configuration . fetch ( :color , false ) ) end results << result end | Add its method to the DSL . |
16,558 | def before_dump ( value ) self . value = value if ! value . nil? if ! @block . nil? value = @parent . instance_exec ( self , :dump , & @block ) end self . value = value if ! value . nil? end | Se ejecuta antes de serializar los datos |
16,559 | def run_and_detach log_r , log_w = IO . pipe @pid = Process . spawn ( command , pgroup : true , err : :out , out : log_w ) log_r . close log_w . close @pid end | Run a command in a new process group thus ignoring any furthur updates about the status of the process |
16,560 | def gsub ( pattern , replacement = UNDEFINED , & block ) if UNDEFINED . equal? replacement if block_given? copy_with @message . gsub ( pattern , & block ) . freeze else enum_for ( __method__ ) end else copy_with @message . gsub ( pattern , replacement , & block ) . freeze end end | Returns a copy of the Message with all occurances of pattern in the message attribute substituted for the second argument . |
16,561 | def sub ( pattern , replacement = UNDEFINED , & block ) message = if UNDEFINED . equal? replacement @message . sub ( pattern , & block ) else @message . sub ( pattern , replacement , & block ) end copy_with ( message . freeze ) end | Returns a copy of the Message with the first occurance of pattern in the message attribute substituted for the second argument . |
16,562 | def secure_compare ( a , b ) return false unless a . bytesize == b . bytesize l = a . unpack ( "C*" ) r , i = 0 , - 1 b . each_byte { | v | r |= v ^ l [ i += 1 ] } r == 0 end | After the Rack implementation |
16,563 | def notify ( channel : '#general' , text : nil , ** opts ) attachments = text . nil? ? report : [ ] text ||= '<http://danger.systems/|Danger> reports' @conn . post do | req | req . url 'chat.postMessage' req . params = { token : @api_token , channel : channel , text : text , attachments : attachments . to_json , link_n... | notify to Slack |
16,564 | def report attachment = status_report . reject { | _ , v | v . empty? } . map do | k , v | case k . to_s when 'errors' then { text : v . join ( "\n" ) , color : 'danger' } when 'warnings' then { text : v . join ( "\n" ) , color : 'warning' } when 'messages' then { text : v . join ( "\n" ) , color : 'good' } when 'markd... | get status_report text |
16,565 | def fields ( markdown ) fields = [ ] if markdown . file fields . push ( title : 'file' , value : markdown . file , short : true ) end if markdown . line fields . push ( title : 'line' , value : markdown . line , short : true ) end fields end | get markdown fields |
16,566 | def fields_for ( record_name , record_object = nil , fields_options = { } , & block ) hash = { } array = [ ] if nested_attributes_association? ( record_name ) hash [ "#{record_name}_attributes" ] = fields_options [ :signed_attributes_context ] = array else hash [ record_name ] = fields_options [ :signed_attributes_cont... | Wrapper for Rails fields_for |
16,567 | def say_with_time ( message , indent = 2 ) say ( message , indent ) result = nil time = Benchmark . measure { result = yield } say ( "-> %.4fs" % time . real , indent ) result end | Time how long the block takes to run and output it with the message . |
16,568 | def update_migration_info ( direction ) save , @verbose = @verbose , false create_migration_info_table_if_needed if direction . to_sym == :up execute ( "INSERT INTO #{migration_info_table} (#{migration_name_column}) VALUES (#{quoted_name})" ) elsif direction . to_sym == :down execute ( "DELETE FROM #{migration_info_tab... | Inserts or removes a row into the migration_info table so we can mark this migration as run or un - done |
16,569 | def setup! @adapter = DataMapper . repository ( @repository ) . adapter case @adapter . class . name when / / then @adapter . extend ( SQL :: Sqlite ) when / / then @adapter . extend ( SQL :: Mysql ) when / / then @adapter . extend ( SQL :: Postgres ) when / / then @adapter . extend ( SQL :: Sqlserver ) when / / then @... | Sets up the migration . |
16,570 | def migration ( number , name , opts = { } , & block ) raise "Migration name conflict: '#{name}'" if migrations . map { | m | m . name } . include? ( name . to_s ) migrations << DataMapper :: Migration . new ( number , name . to_s , opts , & block ) end | Creates a new migration and adds it to the list of migrations to be run . Migrations can be defined in any order they will be sorted and run in the correct order . |
16,571 | def migrate_up! ( level = nil ) migrations . sort . each do | migration | if level . nil? migration . perform_up ( ) else migration . perform_up ( ) if migration . position <= level . to_i end end end | Run all migrations that need to be run . In most cases this would be called by a rake task as part of a larger project but this provides the ability to run them in a script or test . |
16,572 | def migrate_down! ( level = nil ) migrations . sort . reverse . each do | migration | if level . nil? migration . perform_down ( ) else migration . perform_down ( ) if migration . position > level . to_i end end end | Run all the down steps for the migrations that have already been run . |
16,573 | def copy ( from_path , to_path ) resp = request ( '/files/copy' , from_path : from_path , to_path : to_path ) parse_tagged_response ( resp ) end | Copy a file or folder to a different location in the user s Dropbox . |
16,574 | def get_copy_reference ( path ) resp = request ( '/files/copy_reference/get' , path : path ) metadata = parse_tagged_response ( resp [ 'metadata' ] ) return metadata , resp [ 'copy_reference' ] end | Get a copy reference to a file or folder . |
16,575 | def save_copy_reference ( copy_reference , path ) resp = request ( '/files/copy_reference/save' , copy_reference : copy_reference , path : path ) parse_tagged_response ( resp [ 'metadata' ] ) end | Save a copy reference to the user s Dropbox . |
16,576 | def download ( path ) resp , body = content_request ( '/files/download' , path : path ) return FileMetadata . new ( resp ) , body end | Download a file from a user s Dropbox . |
16,577 | def get_preview ( path ) resp , body = content_request ( '/files/get_preview' , path : path ) return FileMetadata . new ( resp ) , body end | Get a preview for a file . |
16,578 | def get_temporary_link ( path ) resp = request ( '/files/get_temporary_link' , path : path ) return FileMetadata . new ( resp [ 'metadata' ] ) , resp [ 'link' ] end | Get a temporary link to stream content of a file . |
16,579 | def get_thumbnail ( path , format = 'jpeg' , size = 'w64h64' ) resp , body = content_request ( '/files/get_thumbnail' , path : path , format : format , size : size ) return FileMetadata . new ( resp ) , body end | Get a thumbnail for an image . |
16,580 | def list_folder ( path ) resp = request ( '/files/list_folder' , path : path ) resp [ 'entries' ] . map { | e | parse_tagged_response ( e ) } end | Get the contents of a folder . |
16,581 | def continue_list_folder ( cursor ) resp = request ( '/files/list_folder/continue' , cursor : cursor ) resp [ 'entries' ] . map { | e | parse_tagged_response ( e ) } end | Get the contents of a folder that are after a cursor . |
16,582 | def list_revisions ( path ) resp = request ( '/files/list_revisions' , path : path ) entries = resp [ 'entries' ] . map { | e | FileMetadata . new ( e ) } return entries , resp [ 'is_deleted' ] end | Get the revisions of a file . |
16,583 | def move ( from_path , to_path ) resp = request ( '/files/move' , from_path : from_path , to_path : to_path ) parse_tagged_response ( resp ) end | Move a file or folder to a different location in the user s Dropbox . |
16,584 | def restore ( path , rev ) resp = request ( '/files/restore' , path : path , rev : rev ) FileMetadata . new ( resp ) end | Restore a file to a specific revision . |
16,585 | def save_url ( path , url ) resp = request ( '/files/save_url' , path : path , url : url ) parse_tagged_response ( resp ) end | Save a specified URL into a file in user s Dropbox . |
16,586 | def search ( path , query , start = 0 , max_results = 100 , mode = 'filename' ) resp = request ( '/files/search' , path : path , query : query , start : start , max_results : max_results , mode : mode ) matches = resp [ 'matches' ] . map { | m | parse_tagged_response ( m [ 'metadata' ] ) } return matches end | Search for files and folders . |
16,587 | def upload ( path , body , options = { } ) options [ :client_modified ] = Time . now . utc . iso8601 options [ :path ] = path resp = upload_request ( '/files/upload' , body , options . merge ( path : path ) ) FileMetadata . new ( resp ) end | Create a new file . |
16,588 | def start_upload_session ( body , close = false ) resp = upload_request ( '/files/upload_session/start' , body , close : close ) UploadSessionCursor . new ( resp [ 'session_id' ] , body . length ) end | Start an upload session to upload a file using multiple requests . |
16,589 | def append_upload_session ( cursor , body , close = false ) args = { cursor : cursor . to_h , close : close } resp = upload_request ( '/files/upload_session/append_v2' , body , args ) cursor . offset += body . length cursor end | Append more data to an upload session . |
16,590 | def finish_upload_session ( cursor , path , body , options = { } ) options [ :client_modified ] = Time . now . utc . iso8601 options [ :path ] = path args = { cursor : cursor . to_h , commit : options } resp = upload_request ( '/files/upload_session/finish' , body , args ) FileMetadata . new ( resp ) end | Finish an upload session and save the uploaded data to the given file path . |
16,591 | def get_account_batch ( account_ids ) resp = request ( '/users/get_account_batch' , account_ids : account_ids ) resp . map { | a | BasicAccount . new ( a ) } end | Get information about multiple user accounts . |
16,592 | def tempfile_path ( content ) tempfile = Tempfile . new ( 'tty-editor' ) tempfile << content tempfile . flush unless tempfile . nil? tempfile . close end tempfile . path end | Create tempfile with content |
16,593 | def open status = system ( env , * Shellwords . split ( command_path ) ) return status if status fail CommandInvocationError , "`#{command_path}` failed with status: #{$? ? $?.exitstatus : nil}" end | Inovke editor command in a shell |
16,594 | def gemset_globalcache ( enable = true ) case enable when "enabled" , :enabled run ( :__rvm_using_gemset_globalcache ) . successful? when true , "enable" , :enable rvm ( :gemset , :globalcache , :enable ) . successful? when false , "disable" , :disable rvm ( :gemset , :globalcache , :disable ) . successful? else false ... | Enable or disable the rvm gem global cache . |
16,595 | def scope if tree . columns . scope? tree . base_class . where Hash [ tree . columns . scope . map { | column | [ column , record [ column ] ] } ] else tree . base_class . where ( nil ) end end | Returns scope to which record should be applied |
16,596 | def lower position? ? siblings . where ( klass . arel_table [ klass . ordered_tree . columns . position ] . gteq ( position ) ) : siblings end | Returns all nodes that are lower than current position |
16,597 | def disconnect if @connection . respond_to? ( :actors ) @connection . actors . each do | connection | connection . async . disconnect if connection . alive? end else @connection . async . disconnect if @connection . alive? end end | Closes the connection to the service . |
16,598 | def group ( timeout : nil ) group = nil monitor do | condition | group = RequestGroup . new ( self , condition ) yield group if ! group . empty? && exception = condition . wait ( timeout || DEFAULT_GROUP_TIMEOUT ) raise exception end end ensure group . terminate end | Use this to group a batch of requests and halt the caller thread until all of the requests in the group have been performed . |
16,599 | def monitor condition = Connection :: Monitor :: Condition . new if defined? ( Mock :: Connection ) && @connection . class == Mock :: Connection yield condition else begin @connection . __register_lowdown_crash_condition__ ( condition ) yield condition ensure @connection . __deregister_lowdown_crash_condition__ ( condi... | Registers a condition object with the connection pool for the duration of the given block . It either returns an exception that caused a connection to die or whatever value you signal to it . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.