idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
14,200 | def read ( addr , num_elements , ** options ) mem_io ( :read ) { | io | io . read ( num_elements , from : MemoryIO :: Util . safe_eval ( addr , bases ) , ** options ) } end | Read from process s memory . |
14,201 | def write ( addr , objects , ** options ) mem_io ( :write ) { | io | io . write ( objects , from : MemoryIO :: Util . safe_eval ( addr , bases ) , ** options ) } end | Write objects at + addr + . |
14,202 | def netrc_path unencrypted = Netrc . default_path encrypted = unencrypted + '.gpg' if File . exists? ( encrypted ) encrypted else unencrypted end end | Returns the path to the . netrc file containing the Turbot host s entry with the user s email address and API key . |
14,203 | def open_netrc begin Netrc . read ( netrc_path ) rescue Netrc :: Error => e error e . message end end | Reads a . netrc file . |
14,204 | def save_netrc_entry ( email_address , api_key ) netrc = open_netrc netrc [ "api.#{host}" ] = [ email_address , api_key ] netrc . save end | Saves the user s email address and AP key to the Turbot host s entry in the . netrc file . |
14,205 | def seed_from_dump id target_path = File . expand_path ( "../../fixtures/trunk-#{id}.dump" , __FILE__ ) raise "Dump #{id} could not be found." unless File . exists? target_path puts "Restoring #{ENV['RACK_ENV']} database from #{target_path}" system "dropdb trunk_cocoapods_org_test" system "createdb trunk_cocoapods_org_... | Seed the database from a downloaded dump . |
14,206 | def dump_prod id target_path = File . expand_path ( "../../fixtures/trunk-#{id}.dump" , __FILE__ ) puts "Dumping production database from Heroku (works only if you have access to the database)" command = "curl -o #{target_path} \`heroku pg:backups public-url #{id} -a cocoapods-trunk-service\`" puts "Executing command:"... | Dump the production DB . |
14,207 | def try_function ( name , params , returns , options = { } , & def_block ) begin function name , params , returns , options , & def_block rescue Win :: Errors :: NotFoundError "This platform does not support function #{name}" end end | Try to define platform - specific function rescue error return message |
14,208 | def define_api ( name , camel_name , effective_names , params , returns , options ) params , returns = generate_signature ( params . dup , returns ) ffi_lib * ( ffi_libraries . map ( & :name ) << options [ :dll ] ) if options [ :dll ] libs = ffi_libraries . map ( & :name ) alternative = options . delete ( :alternative ... | Defines CamelCase method calling Win32 API function and associated API object |
14,209 | def recursively_find_and_replace_command_substitutions ( input ) input = input . dup Parser . each_command_substitution_for ( input ) do | substitution_result , start_position , end_position | debug_log "found command substitution at position=#{(start_position..end_position)} #{substitution_result.inspect}" result = re... | + recursively_find_and_replace_command_substitutions + is responsible for recursively finding and expanding command substitutions in a depth first manner . |
14,210 | def visit_CommandNode ( node ) debug_visit ( node ) @aliases_expanded ||= [ ] @command_node_args_stack ||= [ ] with_standard_streams do | stdin , stdout , stderr | args = process_ArgumentNodes ( node . args ) if ! node . literal? && ! @aliases_expanded . include? ( node . command ) && Aliases . instance . has_key? ( no... | VISITOR METHODS FOR AST TREE WALKING |
14,211 | def undocumented ( scope = :modified ) return [ ] unless scope != :ignore && File . exist? ( undocumented_path ) @undocumented = { modified : [ ] , all : [ ] } if @undocumented . nil? load_undocumented ( scope ) if @undocumented [ scope ] . empty? @undocumented [ scope ] end | Returns a list of undocumented symbols in the current diff . |
14,212 | def update @payment_method = PaymentMethod . find params [ :payment_method_id ] data = JSON . parse Base64 . strict_decode64 params [ :data ] render text : "Bad signature\n" , status : 401 and return unless @payment_method . check_signature params [ :data ] , params [ :signature ] @order = Order . find data [ 'order_id... | callbacks from Liqpay server |
14,213 | def brokers @brokers_mutex . synchronize do @brokers ||= begin brokers = zk . get_children ( path : "/brokers/ids" ) if brokers . fetch ( :rc ) != Zookeeper :: Constants :: ZOK raise NoClusterRegistered , "No Kafka cluster registered on this Zookeeper location." end result , mutex = { } , Mutex . new threads = brokers ... | Returns a hash of all the brokers in the |
14,214 | def consumergroups @consumergroups ||= begin consumers = zk . get_children ( path : "/consumers" ) consumers . fetch ( :children ) . map { | name | Kazoo :: Consumergroup . new ( self , name ) } end end | Returns a list of consumer groups that are registered against the Kafka cluster . |
14,215 | def topics ( preload : Kazoo :: Topic :: DEFAULT_PRELOAD_METHODS ) @topics_mutex . synchronize do @topics ||= begin topics = zk . get_children ( path : "/brokers/topics" ) raise Kazoo :: Error , "Failed to list topics. Error code: #{topics.fetch(:rc)}" unless topics . fetch ( :rc ) == Zookeeper :: Constants :: ZOK prel... | Returns a hash of all the topics in the Kafka cluster indexed by the topic name . |
14,216 | def create_topic ( name , partitions : nil , replication_factor : nil , config : nil ) raise ArgumentError , "partitions must be a positive integer" if Integer ( partitions ) <= 0 raise ArgumentError , "replication_factor must be a positive integer" if Integer ( replication_factor ) <= 0 Kazoo :: Topic . create ( self ... | Creates a topic on the Kafka cluster with the provided number of partitions and replication factor . |
14,217 | def preferred_leader_election ( partitions : nil ) partitions = self . partitions if partitions . nil? result = zk . create ( path : "/admin/preferred_replica_election" , data : JSON . generate ( version : 1 , partitions : partitions ) ) case result . fetch ( :rc ) when Zookeeper :: Constants :: ZOK return true when Zo... | Triggers a preferred leader elections for the provided list of partitions . If no list of partitions is provided the preferred leader will be elected for all partitions in the cluster . |
14,218 | def recursive_create ( path : nil ) raise ArgumentError , "path is a required argument" if path . nil? result = zk . stat ( path : path ) case result . fetch ( :rc ) when Zookeeper :: Constants :: ZOK return when Zookeeper :: Constants :: ZNONODE recursive_create ( path : File . dirname ( path ) ) result = zk . create ... | Recursively creates a node in Zookeeper by recusrively trying to create its parent if it doesn not yet exist . |
14,219 | def recursive_delete ( path : nil ) raise ArgumentError , "path is a required argument" if path . nil? result = zk . get_children ( path : path ) raise Kazoo :: Error , "Failed to list children of #{path} to delete them. Result code: #{result.fetch(:rc)}" if result . fetch ( :rc ) != Zookeeper :: Constants :: ZOK threa... | Deletes a node and all of its children from Zookeeper . |
14,220 | def find ( text ) nodes = parser . parse ( text ) nodes . length . times . find do | index | if ( song = Song . new ( nodes [ index .. - 1 ] , rule : @rule ) ) . valid? break song end end end | Find one valid song from given text . |
14,221 | def judge ( text ) Song . new ( parser . parse ( text ) , exactly : true , rule : @rule ) . valid? end | Judge if given text is valid song or not . |
14,222 | def search ( text ) nodes = parser . parse ( text ) nodes . length . times . map do | index | Song . new ( nodes [ index .. - 1 ] , rule : @rule ) end . select ( & :valid? ) end | Search all valid songs from given text . |
14,223 | def led_partitions result , mutex = [ ] , Mutex . new threads = cluster . partitions . map do | partition | Thread . new do Thread . abort_on_exception = true select = partition . leader == self mutex . synchronize { result << partition } if select end end threads . each ( & :join ) result end | Returns a list of all partitions that are currently led by this broker . |
14,224 | def replicated_partitions result , mutex = [ ] , Mutex . new threads = cluster . partitions . map do | partition | Thread . new do Thread . abort_on_exception = true select = partition . replicas . include? ( self ) mutex . synchronize { result << partition } if select end end threads . each ( & :join ) result end | Returns a list of all partitions that host a replica on this broker . |
14,225 | def critical? ( replicas : 1 ) result , mutex = false , Mutex . new threads = replicated_partitions . map do | partition | Thread . new do Thread . abort_on_exception = true isr = partition . isr . reject { | r | r == self } mutex . synchronize { result = true if isr . length < Integer ( replicas ) } end end threads . ... | Returns whether this broker is currently considered critical . |
14,226 | def get_bits need val = @bit_bucket while @bit_count < need val |= ( @input_buffer [ @in_pos += 1 ] << @bit_count ) @bit_count += 8 end @bit_bucket = val >> need @bit_count -= need val & ( ( 1 << need ) - 1 ) end | returns need bits from the input buffer == Format Notes bits are stored LSB to MSB |
14,227 | def inflate zstring = nil @zstring = zstring unless zstring . nil? @zstring . each_byte { | b | @input_buffer << b } unless @rawdeflate then compression_method_and_flags = @input_buffer [ @in_pos += 1 ] flags = @input_buffer [ @in_pos += 1 ] if ( ( compression_method_and_flags << 0x08 ) + flags ) % 31 != 0 then raise Z... | == Example f = File . open example . z i = Inflate . new i . inflate f . read |
14,228 | def do_layout ( payload , layouts ) pre_render if respond_to? ( :pre_render ) && hooks if respond_to? ( :merge_payload ) && hooks old_do_layout ( merge_payload ( payload . dup ) , layouts ) else old_do_layout ( payload , layouts ) end post_render if respond_to? ( :post_render ) && hooks end | Calls the pre_render method if it exists and then adds any necessary layouts to this convertible document . |
14,229 | def site_payload @cached_payload = begin payload = old_site_payload site_hooks . each do | hook | p = hook . merge_payload ( payload , self ) next unless p && p . is_a? ( Hash ) payload = Jekyll :: Utils . deep_merge_hashes ( payload , p ) end payload end end | Allows site hooks to merge data into the site payload |
14,230 | def distance ( coordinates ) coordinates = coordinates . center if coordinates . respond_to? ( :center ) Math . sqrt ( [ center , coordinates ] . transpose . map { | a , b | ( b - a ) ** 2 } . reduce { | d1 , d2 | d1 + d2 } ) end | Compute euclidien distance . |
14,231 | def decorate ( block = nil , name : "generated" , & callback ) @decorations << callback if block alias_name = "__" << name . to_s . downcase . gsub ( / / , ?_ ) << ?1 alias_name = alias_name . succ while private_method_defined? alias_name or method_defined? alias_name without_decorations { define_method ( name , & bloc... | Set up a decoration . |
14,232 | def find reset ; return @images unless @url @page_no = @options [ "start" ] until @images . count > @options [ "total" ] || thread_has_ended? page = @agent . get "#{@url}&page=#{@page_no}" puts "[VERBOSE] Searching: #{@url}&page=#{@page_no}" if @options [ "verbose" ] && options [ "cli" ] sources = page . image_urls . m... | find images for this thread specified by starting page_no |
14,233 | def detekt ( inline_mode : false ) unless skip_gradle_task || gradlew_exists? fail ( "Could not find `gradlew` inside current directory" ) return end unless SEVERITY_LEVELS . include? ( severity ) fail ( "'#{severity}' is not a valid value for `severity` parameter." ) return end system "./gradlew #{gradle_task || 'dete... | Calls Detekt task of your gradle project . It fails if gradlew cannot be found inside current directory . It fails if severity level is not a valid option . It fails if xmlReport configuration is not set to true in your build . gradle file . |
14,234 | def get_builder_obj ( shell_id , command_id , & block ) body = { "#{NS_WIN_SHELL}:DesiredStream" => 'stdout stderr' , :attributes! => { "#{NS_WIN_SHELL}:DesiredStream" => { 'CommandId' => command_id } } } builder = Builder :: XmlMarkup . new builder . instruct! ( :xml , :encoding => 'UTF-8' ) builder . tag! :env , :Env... | Override winrm to support sspinegotiate option . |
14,235 | def get_command_output ( shell_id , command_id , & block ) done_elems = [ ] output = Output . new while done_elems . empty? resp_doc = nil builder = get_builder_obj ( shell_id , command_id , & block ) request_msg = builder . target! resp_doc = send_get_output_message ( request_msg ) REXML :: XPath . match ( resp_doc , ... | Get the Output of the given shell and command |
14,236 | def setting_attribute_is_allowed? ( name , user ) return false unless user . can_write? ( self , name ) ( self . whitelisted_attributes && self . whitelisted_attributes . has_key? ( name . to_sym ) ) || ( self . attribute_names . include? ( name . to_s ) && ( self . blacklisted_attributes . nil? || ! self . blacklisted... | An attribute is allowed if it s white listed or it s a valid attribute and not black listed |
14,237 | def turbot_api_parameters uri = URI . parse ( host ) { :host => uri . host , :port => uri . port , :scheme => uri . scheme , } end | Returns the parameters for the Turbot API based on the base URL of the Turbot server . |
14,238 | def handles? ( device ) device = Pling . _convert ( device , :device ) self . class . handled_types . include? ( device . type ) end | Checks if this gateway is able to handle the given device |
14,239 | def to_h ret = Hash . new @list . each do | i | ret [ i . car . to_ruby ] = i . cdr . to_ruby end ret end | alist - > hash |
14,240 | def parse ( str ) if str . nil? || str == "" raise ParserError . new ( "Empty input" , 0 , "" ) end s = StringScanner . new str @tokens = [ ] until s . eos? s . skip ( / \s / ) ? nil : s . scan ( / \A \. /i ) ? ( @tokens << [ :FLOAT , s . matched ] ) : s . scan ( / \A \d / ) ? ( @tokens << [ :INTEGER , s . matched ] ) ... | parse s - expression string and return sexp objects . |
14,241 | def normalize ( ast ) if ast . class == SExpSymbol case ast . name when "nil" return SExpNil . new else return ast end elsif ast . cons? then ast . visit do | i | normalize ( i ) end end return ast end | replace special symbols |
14,242 | def write ( objects , from : nil , as : nil ) stream . pos = from if from as ||= objects . class if objects . class . ancestors . include? ( MemoryIO :: Types :: Type ) return stream . write ( objects ) if as . nil? conv = to_proc ( as , :write ) Array ( objects ) . map { | o | conv . call ( stream , o ) } end | Write to stream . |
14,243 | def underscore ( str ) return '' if str . empty? str = str . gsub ( '::' , '/' ) str . gsub! ( / / , '\1_\2' ) str . gsub! ( / \d / , '\1_\2' ) str . downcase! str end | Convert input into snake - case . |
14,244 | def safe_eval ( str , ** vars ) return str if str . is_a? ( Integer ) str = str . gsub ( / / ) { | c | c . to_i ( 16 ) } Dentaku :: Calculator . new . store ( vars ) . evaluate ( str ) end | Evaluate string safely . |
14,245 | def unpack ( str ) str . bytes . reverse . reduce ( 0 ) { | s , c | s * 256 + c } end | Unpack a string into an integer . Little endian is used . |
14,246 | def pack ( val , b ) Array . new ( b ) { | i | ( val >> ( i * 8 ) ) & 0xff } . pack ( 'C*' ) end | Pack an integer into + b + bytes . Little endian is used . |
14,247 | def nearest ( coord , options = { } ) return nil if root . nil? return nil if coord . nil? results = ( options [ :results ] ? options [ :results ] : ResultSet . new ( { limit : options [ :limit ] || 1 } ) ) root_ball = options [ :root ] || root parents = [ ] best_balls = [ ] in_target = [ ] current_best = nil current =... | Retrieve the nearest point from the given coord array . |
14,248 | def parent_ball ( coord ) current = root d_idx = current . dimension - 1 result = nil while ( result . nil? ) if ( coord [ d_idx ] <= current . center [ d_idx ] ) if current . left . nil? result = current else current = current . left end else if current . right . nil? result = current else current = current . right en... | Retrieve the parent to which this coord should belongs to |
14,249 | def command ( cmd , params = { } , options = '' ) flood_control out = '' response = '' out += cmd params . each_pair do | key , value | out += " #{key}=#{encode_param(value.to_s)}" end out += ' ' + options @sock . puts out if cmd == 'servernotifyregister' 2 . times { response += @sock . gets } return parse_response ( r... | Sends command to the TeamSpeak 3 server and returns the response |
14,250 | def trh ( tokens = { } , options = { } , & block ) return '' unless block_given? label = capture ( & block ) tokenizer = Tml :: Tokenizers :: Dom . new ( tokens , options ) tokenizer . translate ( label ) . html_safe end | Translates HTML block noinspection RubyArgCount |
14,251 | def tml_language_flag_tag ( lang = tml_current_language , opts = { } ) return '' unless tml_application . feature_enabled? ( :language_flags ) html = image_tag ( lang . flag_url , :style => ( opts [ :style ] || 'vertical-align:middle;' ) , :title => lang . native_name ) html << ' ' . html_safe html . html_sa... | Returns language flag |
14,252 | def tml_language_name_tag ( lang = tml_current_language , opts = { } ) show_flag = opts [ :flag ] . nil? ? true : opts [ :flag ] name_type = opts [ :language ] . nil? ? :english : opts [ :language ] . to_sym html = [ ] html << "<span style='white-space: nowrap'>" html << tml_language_flag_tag ( lang , opts ) if show_fl... | Returns language name |
14,253 | def tml_language_selector_tag ( type = nil , opts = { } ) return unless Tml . config . enabled? type ||= :default type = :dropdown if type == :select opts = opts . collect { | key , value | "data-tml-#{key}='#{value}'" } . join ( ' ' ) "<div data-tml-language-selector='#{type}' #{opts}></div>" . html_safe end | Returns language selector UI |
14,254 | def tml_style_attribute_tag ( attr_name = 'float' , default = 'right' , lang = tml_current_language ) return "#{attr_name}:#{default}" . html_safe if Tml . config . disabled? "#{attr_name}:#{lang.align(default)}" . html_safe end | Language Direction Support |
14,255 | def clone_and_transform_each ( collection , & block ) collection . inject ( element_to_clone ) do | sibling , item | item_element = clone_with_item ( item , & block ) sibling . add_next_sibling ( item_element ) end end | Creates a clone for each item in the collection and yields it for transformation along with the corresponding item . The transformed clones are inserted after the element to clone . |
14,256 | def clone_with_item ( item , & block ) item_element = element_to_clone . dup view . find ( item_element ) { yield ( item ) } item_element end | Creates a clone and yields it to the given block along with the given item . |
14,257 | def text ( selector , content ) select ( selector ) . each do | node | node . content = content end end | Replaces the text content of the selected elements . |
14,258 | def attr ( selector , attributes_or_attribute_name , value = nil ) attributes = attributes_or_attribute_name . to_effigy_attributes ( value ) select ( selector ) . each do | element | element . merge! ( attributes ) end end | Adds or updates the given attribute or attributes of the selected elements . |
14,259 | def replace_each ( selector , collection , & block ) selected_elements = select ( selector ) ExampleElementTransformer . new ( self , selected_elements ) . replace_each ( collection , & block ) end | Replaces the selected elements with a clone for each item in the collection . If multiple elements are selected only the first element will be used for cloning . All selected elements will be removed . |
14,260 | def add_class ( selector , * class_names ) select ( selector ) . each do | element | class_list = ClassList . new ( element ) class_list . add class_names end end | Adds the given class names to the selected elements . |
14,261 | def remove_class ( selector , * class_names ) select ( selector ) . each do | element | class_list = ClassList . new ( element ) class_list . remove ( class_names ) end end | Removes the given class names from the selected elements . |
14,262 | def html ( selector , inner_html ) select ( selector ) . each do | node | node . inner_html = inner_html end end | Replaces the contents of the selected elements with live markup . |
14,263 | def append ( selector , html_to_append ) select ( selector ) . each { | node | node . append_fragment html_to_append } end | Adds the given markup to the end of the selected elements . |
14,264 | def find ( selector ) if block_given? old_context = @current_context @current_context = select ( selector ) yield @current_context = old_context else Selection . new ( self , selector ) end end | Selects an element or elements for chained transformation . |
14,265 | def clone_element_with_item ( original_element , item , & block ) item_element = original_element . dup find ( item_element ) { yield ( item ) } item_element end | Clones an element sets it as the current context and yields to the given block with the given item . |
14,266 | def handle_input ( * input ) while ch = next_ch ( input ) quit = QUIT_CONTROLS . include? ( ch ) enter = ENTER_CONTROLS . include? ( ch ) inc = INC_CONTROLS . include? ( ch ) dec = DEC_CONTROLS . include? ( ch ) break if shutdown? || ( quit && ( ! enter || quit_on_enter? ) ) if enter on_enter elsif inc on_inc elsif dec... | Helper to be internally invoked by component on activation |
14,267 | def match ( pattern_element ) @num_match_attempts += 1 return :no_pattern_element unless pattern_element return :skipped if pattern_element . delimiter && ( if last_match last_match . delimiter else @num_match_attempts > 1 end ) if result = pattern_element . parse ( self ) add_match result , pattern_element . name end ... | Attempts to match the pattern_element starting at the end of what has already been matched If successful adds the resulting Node to matches . returns nil on if pattern_element wasn t matched ; non - nil if it was skipped or matched |
14,268 | def attempt_match matches_before = matches . length match_length_before = match_length ( yield && match_length > match_length_before ) . tap do | success | unless success @matches = matches [ 0 .. matches_before - 1 ] update_match_length end end end | a simple transaction - logs the curent number of matches if the block s result is false it discards all new matches |
14,269 | def to_canonical_s parts = [ ] parts << self . number . upcase if self . number parts << StreetAddress . string_for ( self . pre_direction , :short ) . upcase if self . pre_direction parts << StreetAddress . string_for ( StreetAddress . find_token ( self . ordinal , ORDINALS ) , :short ) . upcase if self . ordinal cano... | to_canonical_s format the address in a postal service canonical format |
14,270 | def to_horizontal_table mortadella = Mortadella :: Horizontal . new headers : @cucumber_table . headers @database_content = @database_content . all if @database_content . respond_to? :all @database_content . each do | record | cucumberator = cucumberator_for record mortadella << @cucumber_table . headers . map do | hea... | Returns all entries in the database as a horizontal Mortadella table |
14,271 | def to_vertical_table object mortadella = Mortadella :: Vertical . new cucumberator = cucumberator_for object @cucumber_table . rows_hash . each do | key , _ | mortadella [ key ] = cucumberator . value_for key end mortadella . table end | Returns the given object as a vertical Mortadella table |
14,272 | def handle_json ( json_str ) begin req = JSON :: parse ( json_str ) resp = handle ( req ) rescue JSON :: ParserError => e resp = err_resp ( { } , - 32700 , "Unable to parse JSON: #{e.message}" ) end return JSON :: generate ( resp , { :ascii_only => true } ) end | Handles a request encoded as JSON . Returns the result as a JSON encoded string . |
14,273 | def handle ( req ) if req . kind_of? ( Array ) resp_list = [ ] req . each do | r | resp_list << handle_single ( r ) end return resp_list else return handle_single ( req ) end end | Handles a deserialized request and returns the result |
14,274 | def handle_single ( req ) method = req [ "method" ] if ! method return err_resp ( req , - 32600 , "No method provided on request" ) end if method == "barrister-idl" return ok_resp ( req , @contract . idl ) end err_resp , iface , func = @contract . resolve_method ( req ) if err_resp != nil return err_resp end err_resp =... | Internal method that validates and executes a single request . |
14,275 | def init_proxies singleton = class << self ; self end @contract . interfaces . each do | iface | proxy = InterfaceProxy . new ( self , iface ) singleton . send :define_method , iface . name do return proxy end end end | Internal method invoked by initialize . Iterates through the Contract and creates proxy classes for each interface . |
14,276 | def request ( method , params ) req = { "jsonrpc" => "2.0" , "id" => Barrister :: rand_str ( 22 ) , "method" => method } if params req [ "params" ] = params end err_resp , iface , func = @contract . resolve_method ( req ) if err_resp != nil return err_resp end if @validate_req err_resp = @contract . validate_params ( r... | Sends a JSON - RPC request . This method is automatically called by the proxy classes so in practice you don t usually call it directly . However it is available if you wish to avoid the use of proxy classes . |
14,277 | def request ( req ) json_str = JSON :: generate ( req , { :ascii_only => true } ) http = Net :: HTTP . new ( @uri . host , @uri . port ) request = Net :: HTTP :: Post . new ( @uri . request_uri ) request . body = json_str request [ "Content-Type" ] = "application/json" response = http . request ( request ) if response ... | Takes the URL to the server endpoint and parses it request is the only required method on a transport class . |
14,278 | def send if @trans . sent raise "Batch has already been sent!" end @trans . sent = true requests = @trans . requests if requests . length < 1 raise RpcException . new ( - 32600 , "Batch cannot be empty" ) end resp_list = @parent . trans . request ( requests ) sorted = [ ] by_req_id = { } resp_list . each do | resp | by... | Sends the batch of requests to the server . |
14,279 | def resolve_method ( req ) method = req [ "method" ] iface_name , func_name = Barrister :: parse_method ( method ) if iface_name == nil return err_resp ( req , - 32601 , "Method not found: #{method}" ) end iface = interface ( iface_name ) if ! iface return err_resp ( req , - 32601 , "Interface not found on IDL: #{iface... | Takes a JSON - RPC request hash and returns a 3 element tuple . This is called as part of the request validation sequence . |
14,280 | def validate_params ( req , func ) params = req [ "params" ] if ! params params = [ ] end e_params = func . params . length r_params = params . length if e_params != r_params msg = "Function #{func.name}: Param length #{r_params} != expected length: #{e_params}" return err_resp ( req , - 32602 , msg ) end for i in ( 0 ... | Validates that the parameters on the JSON - RPC request match the types specified for this function |
14,281 | def validate_result ( req , result , func ) invalid = validate ( "" , func . returns , func . returns [ "is_array" ] , result ) if invalid == nil return nil else return err_resp ( req , - 32001 , invalid ) end end | Validates that the result from a handler method invocation match the return type for this function |
14,282 | def validate ( name , expected , expect_array , val ) if val == nil if expected [ "optional" ] return nil else return "#{name} cannot be null" end else exp_type = expected [ "type" ] if expect_array if val . kind_of? ( Array ) stop = val . length - 1 for i in ( 0 .. stop ) invalid = validate ( "#{name}[#{i}]" , expecte... | Validates the type for a single value . This method is recursive when validating arrays or structs . |
14,283 | def all_struct_fields ( arr , struct ) struct [ "fields" ] . each do | f | arr << f end if struct [ "extends" ] parent = @structs [ struct [ "extends" ] ] if parent return all_struct_fields ( arr , parent ) end end return arr end | Recursively resolves all fields for the struct and its ancestors |
14,284 | def notify ( exception , request = { } , environment = { } , session = { } ) begin notification = Notification . new ( exception , request , environment , session ) @notifiers . each do | notifier | notifier . notify ( notification ) end rescue Exception warn ( 'Rusen: Some or all the notifiers failed to sent the notif... | Sends a notification to the configured outputs . |
14,285 | def []= ( key , value ) coerced_value = coercion ( key ) . present? ? coercion ( key ) . call ( value ) : value old_setter ( key , coerced_value ) end | Override setter to coerce the given value if a coercion is defined |
14,286 | def show Ncurses :: Panel . top_panel ( @panel ) update_reterm @@registry . values . each { | panel | if panel == self dispatch :panel_show else panel . dispatch :panel_hide end } end | Initialize panel from the given window . |
14,287 | def generate_id Base64 . encode64 ( Digest :: MD5 . digest ( "#{Time.now}-#{rand}" ) ) . gsub ( '/' , 'x' ) . gsub ( '+' , 'y' ) . gsub ( '=' , '' ) . strip end | Generate a unique id |
14,288 | def _pv_opts_lookup ( opts , key ) if opts . has_key? ( key . to_s ) opts [ key . to_s ] elsif opts . has_key? ( key . to_sym ) opts [ key . to_sym ] else nil end end | Return the value of a parameter or nil if it doesn t exist . |
14,289 | def _pv_required ( opts , key , is_required = true ) if is_required if ( opts . has_key? ( key . to_s ) && ! opts [ key . to_s ] . nil? ) || ( opts . has_key? ( key . to_sym ) && ! opts [ key . to_sym ] . nil? ) true else raise ValidationFailed , "Required argument #{key} is missing!" end end end | Raise an exception if the parameter is not found . |
14,290 | def _pv_respond_to ( opts , key , method_name_list ) value = _pv_opts_lookup ( opts , key ) unless value . nil? Array ( method_name_list ) . each do | method_name | unless value . respond_to? ( method_name ) raise ValidationFailed , "Option #{key} must have a #{method_name} method!" end end end end | Raise an exception if the parameter does not respond to a given set of methods . |
14,291 | def _pv_default ( opts , key , default_value ) value = _pv_opts_lookup ( opts , key ) if value == nil opts [ key ] = default_value end end | Assign a default value to a parameter . |
14,292 | def _pv_regex ( opts , key , regex ) value = _pv_opts_lookup ( opts , key ) if value != nil passes = false [ regex ] . flatten . each do | r | if value != nil if r . match ( value . to_s ) passes = true end end end unless passes raise ValidationFailed , "Option #{key}'s value #{value} does not match regular expression ... | Check a parameter against a regular expression . |
14,293 | def _pv_callbacks ( opts , key , callbacks ) raise ArgumentError , "Callback list must be a hash!" unless callbacks . kind_of? ( Hash ) value = _pv_opts_lookup ( opts , key ) if value != nil callbacks . each do | message , zeproc | if zeproc . call ( value ) != true raise ValidationFailed , "Option #{key}'s value #{val... | Check a parameter against a hash of proc s . |
14,294 | def _pv_name_attribute ( opts , key , is_name_attribute = true ) if is_name_attribute if opts [ key ] == nil opts [ key ] = self . instance_variable_get ( "@name" ) end end end | Allow a parameter to default to |
14,295 | def answer_hiera json = JSON . pretty_generate ( answers ) hocon = Hocon :: Parser :: ConfigDocumentFactory . parse_string ( json ) hocon . render end | This converts a data hash provided by answers and returns a Puppet Enterprise compatible hiera config file ready for use . |
14,296 | def convertDT ( tpitDT ) return nil if tpitDT . nil? date = tpitDT [ "date" ] time = tpitDT [ "time" ] offset = tpitDT [ "utc_offset" ] if time . nil? Date . parse ( date ) elsif date . nil? Time . parse ( time ) else DateTime . parse ( "#{date}T#{time}#{offset}" ) end end | Convert a TripIt DateTime Object to a Ruby DateTime Object |
14,297 | def standard_build ( short_cmd_string , target , command , sources , env , cache ) unless cache . up_to_date? ( target , command , sources , env ) unless Rscons . phony_target? ( target ) cache . mkdir_p ( File . dirname ( target ) ) FileUtils . rm_f ( target ) end return false unless env . execute ( short_cmd_string ,... | Check if the cache is up to date for the target and if not execute the build command . This method does not support parallelization . |
14,298 | def finalize! erase @@registry . delete ( self ) children . each { | c | del_child c } cdk_scr . destroy if cdk? component . finalize! if component? end | Invoke window finalization routine by destroying it and all children |
14,299 | def child_containing ( x , y , z ) found = nil children . find { | c | next if found if c . component . kind_of? ( Layout ) found = c . child_containing ( x , y , z ) else found = c . total_x <= x && c . total_y <= y && ( c . total_x + c . cols ) >= x && ( c . total_y + c . rows ) >= y found = c if found end } found en... | Return child containing specified screen coordiantes else nil |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.