idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
9,800
def call_length_repartition ( min , max , interval ) partition_table 'CallLengthRepartition' , min . to_i , max . to_i , interval . to_i end
Create partition table for Call Length
9,801
def response_time_repartition ( min , max , interval ) partition_table 'ResponseTimeRepartition' , min . to_i , max . to_i , interval . to_i end
Create partition table for Response Time
9,802
def to_xml ( options = { } ) pcap_path = options [ :pcap_path ] docdup = doc . dup @media_nodes . reverse . each do | nop | nopdup = docdup . xpath ( nop . path ) if pcap_path . nil? or @media . blank? nopdup . remove else exec = nopdup . xpath ( "./action/exec" ) . first exec [ 'play_pcap_audio' ] = pcap_path end end ...
Dump the scenario to a SIPp XML string
9,803
def compile! unless @media . blank? print "Compiling media to #{@filename}.pcap..." compile_media . to_file filename : "#{@filename}.pcap" puts "done." end scenario_filename = "#{@filename}.xml" print "Compiling scenario to #{scenario_filename}..." File . open scenario_filename , 'w' do | file | file . write to_xml ( :...
Compile the scenario and its media to disk
9,804
def to_tmpfiles scenario_file = Tempfile . new 'scenario' scenario_file . write @xml scenario_file . rewind if @media media_file = Tempfile . new 'media' media_file . write @media media_file . rewind else media_file = nil end { scenario : scenario_file , media : media_file } end
Create a scenario instance
9,805
def wait exit_status = Process . wait2 @sipp_pid . to_i @err_rd . close if @err_rd @stdout_rd . close if @stdout_rd final_result = process_exit_status exit_status , @stderr_buffer if final_result @logger . info "Test completed successfully!" else @logger . info "Test completed successfully but some calls failed." end @...
Waits for the runner to finish execution
9,806
def blueprint ( name = :master , & block ) @blueprints ||= { } if block_given? parent = ( name == :master ? superclass : self ) @blueprints [ name ] = blueprint_class . new ( self , :parent => parent , & block ) end @blueprints [ name ] end
Define a blueprint with the given name for this class .
9,807
def make! ( * args ) decode_args_to_make ( * args ) do | blueprint , attributes | raise BlueprintCantSaveError . new ( blueprint ) unless blueprint . respond_to? ( :make! ) blueprint . make! ( attributes ) end end
Construct and save an object from a blueprint if the class allows saving .
9,808
def decode_args_to_make ( * args ) shift_arg = lambda { | klass | args . shift if args . first . is_a? ( klass ) } count = shift_arg [ Fixnum ] name = shift_arg [ Symbol ] || :master attributes = shift_arg [ Hash ] || { } raise ArgumentError . new ( "Couldn't understand arguments" ) unless args . empty? @blueprints ||=...
Parses the arguments to make .
9,809
def make ( attributes = { } ) lathe = lathe_class . new ( @klass , new_serial_number , attributes ) lathe . instance_eval ( & @block ) each_ancestor { | blueprint | lathe . instance_eval ( & blueprint . block ) } lathe . object end
Generate an object from this blueprint .
9,810
def get_watcher ( req_id , opts = { } ) @mutex . synchronize do if Constants :: ZKRB_GLOBAL_CB_REQ == req_id { :watcher => @default_watcher , :watcher_context => nil } elsif opts [ :keep ] @watcher_reqs [ req_id ] else @watcher_reqs . delete ( req_id ) end end end
Return the watcher hash associated with the req_id . If the req_id is the ZKRB_GLOBAL_CB_REQ then does not clear the req from the internal store otherwise the req_id is removed .
9,811
def wait_until_connected ( timeout = 10 ) time_to_stop = timeout ? Time . now + timeout : nil return false unless wait_until_running ( timeout ) @state_mutex . synchronize do while true if timeout now = Time . now break if ( @state == ZOO_CONNECTED_STATE ) || unhealthy? || ( now > time_to_stop ) delay = time_to_stop . ...
this implementation is gross but i don t really see another way of doing it without more grossness
9,812
def submit_and_block ( meth , * args ) @mutex . synchronize do raise Exceptions :: NotConnected if unhealthy? end cnt = Continuation . new ( meth , * args ) @reg . synchronize do | r | if meth == :state r . state_check << cnt else r . pending << cnt end end wake_event_loop! cnt . value end
submits a job for processing blocks the caller until result has returned
9,813
def call ( hash ) logger . debug { "continuation req_id #{req_id}, got hash: #{hash.inspect}" } @rval = hash . values_at ( * METH_TO_ASYNC_RESULT_KEYS . fetch ( meth ) ) logger . debug { "delivering result #{@rval.inspect}" } deliver! end
receive the response from the server set
9,814
def close sd_thread = nil @mutex . synchronize do return unless @czk inst , @czk = @czk , nil sd_thread = Thread . new ( inst ) do | _inst | stop_dispatch_thread! _inst . close end end unless event_dispatch_thread? if sd_thread . join ( 30 ) != sd_thread logger . error { "timed out waiting for shutdown thread to exit" ...
close the connection normally stops the dispatch thread and closes the underlying connection cleanly
9,815
def create ( * args ) rc , new_path = czk . create ( * args ) [ rc , @req_registry . strip_chroot_from ( new_path ) ] end
the C lib doesn t strip the chroot path off of returned path values which is pretty damn annoying . this is used to clean things up .
9,816
def strip_chroot_from ( path ) return path unless ( chrooted? and path and path . start_with? ( chroot_path ) ) path [ chroot_path . length .. - 1 ] end
if we re chrooted this method will strip the chroot prefix from + path +
9,817
def rm_rf ( z , path ) z . get_children ( :path => path ) . tap do | h | if h [ :rc ] . zero? h [ :children ] . each do | child | rm_rf ( z , File . join ( path , child ) ) end elsif h [ :rc ] == ZNONODE else raise "Oh noes! unexpected return value! #{h.inspect}" end end rv = z . delete ( :path => path ) unless ( rv [ ...
this is not as safe as the one in ZK just to be used to clean up when we re the only one adjusting a particular path
9,818
def params ( method_or_path , options = { } ) method_or_path = method_or_path . to_s [ path_for ( method_or_path , options ) , options_for ( method_or_path , options ) ] end
Return node route params which can be used in Rails route options
9,819
def maintain_name postfix = nil total_count = 0 while self . class . where ( parent_id : parent_id , name : "#{name}#{postfix}" ) . where ( "id != ?" , id . to_i ) . exists? do total_count += 1 postfix = "(#{total_count})" end if postfix self . name = "#{name}#{postfix}" end end
Maintain unique name within parent_id scope . If name is not unique add numeric postfix .
9,820
def maintain_slug postfix = nil total_count = 0 while self . class . where ( parent_id : parent_id , slug : "#{slug}#{postfix}" ) . where ( "id != ?" , id . to_i ) . exists? do total_count += 1 postfix = "-#{total_count}" end if postfix self . slug = "#{slug}#{postfix}" end end
Maintain unique slug within parent_id scope . If slug is not unique add numeric postfix .
9,821
def acts_as_node ( params : nil , fields : nil ) configuration = { params : params , fields : fields } ActsAsNode . register_class ( self . name ) cattr_accessor :acts_as_node_configuration self . acts_as_node_configuration = configuration end
There are no configuration options yet .
9,822
def verify_ordered_double ( double ) unless double . terminal? raise RR :: Errors . build_error ( :DoubleOrderError , "Ordered Doubles cannot have a NonTerminal TimesCalledExpectation" ) end unless @ordered_doubles . first == double message = Double . formatted_name ( double . method_name , double . expected_arguments ...
Verifies that the passed in ordered Double is being called in the correct position .
9,823
def reset RR . trim_backtrace = false RR . overridden_error_class = nil reset_ordered_doubles Injections :: DoubleInjection . reset reset_method_missing_injections reset_singleton_method_added_injections reset_recorded_calls reset_bound_objects end
Resets the registered Doubles and ordered Doubles
9,824
def load_gems_in ( * spec_dirs ) @gems . clear spec_dirs . reverse_each do | spec_dir | spec_files = Dir . glob File . join ( spec_dir , '*.gemspec' ) spec_files . each do | spec_file | gemspec = self . class . load_specification spec_file . untaint add_spec gemspec if gemspec end end self end
Reconstruct the source index from the specifications in + spec_dirs + .
9,825
def index_signature require 'digest' Digest :: SHA256 . new . hexdigest ( @gems . keys . sort . join ( ',' ) ) . to_s end
The signature for the source index . Changes in the signature indicate a change in the index .
9,826
def gem_signature ( gem_full_name ) require 'digest' Digest :: SHA256 . new . hexdigest ( @gems [ gem_full_name ] . to_yaml ) . to_s end
The signature for the given gem specification .
9,827
def find_name ( gem_name , version_requirement = Gem :: Requirement . default ) dep = Gem :: Dependency . new gem_name , version_requirement search dep end
Find a gem by an exact match on the short name .
9,828
def update ( source_uri , all ) source_uri = URI . parse source_uri unless URI :: Generic === source_uri source_uri . path += '/' unless source_uri . path =~ / \/ / use_incremental = false begin gem_names = fetch_quick_index source_uri , all remove_extra gem_names missing_gems = find_missing gem_names return false if m...
Updates this SourceIndex from + source_uri + . If + all + is false only the latest gems are fetched .
9,829
def fetch_quick_index ( source_uri , all ) index = all ? 'index' : 'latest_index' zipped_index = fetcher . fetch_path source_uri + "quick/#{index}.rz" unzip ( zipped_index ) . split ( "\n" ) rescue :: Exception => e unless all then say "Latest index not found, using quick index" if Gem . configuration . really_verbose ...
Get the quick index needed for incremental updates .
9,830
def find_missing ( spec_names ) unless defined? @originals then @originals = { } each do | full_name , spec | @originals [ spec . original_name ] = spec end end spec_names . find_all { | full_name | @originals [ full_name ] . nil? } end
Make a list of full names for all the missing gemspecs .
9,831
def fetch_single_spec ( source_uri , spec_name ) @fetch_error = nil begin marshal_uri = source_uri + "quick/Marshal.#{Gem.marshal_version}/#{spec_name}.gemspec.rz" zipped = fetcher . fetch_path marshal_uri return Marshal . load ( unzip ( zipped ) ) rescue => ex @fetch_error = ex if Gem . configuration . really_verbose ...
Tries to fetch Marshal representation first then YAML
9,832
def update_with_missing ( source_uri , missing_names ) progress = ui . progress_reporter ( missing_names . size , "Updating metadata for #{missing_names.size} gems from #{source_uri}" ) missing_names . each do | spec_name | gemspec = fetch_single_spec ( source_uri , spec_name ) if gemspec . nil? then ui . say "Failed t...
Update the cached source index with the missing names .
9,833
def ssh_exec! ( node , command ) r = on node , command , { :acceptable_exit_codes => ( 0 .. 127 ) } { :exit_status => r . exit_code , :stdout => r . stdout , :stderr => r . stderr } end
Execute the provided ssh command
9,834
def run_command ( cmd , opt = { } ) node = get_working_node script = create_script ( cmd ) if node . is_cygwin? delete_command = "rm -rf" redirection = "< /dev/null" else delete_command = "del" redirection = "< NUL" end on node , "#{delete_command} script.ps1" create_remote_file ( node , 'script.ps1' , script ) ret = s...
Run a windows style command using serverspec . Defaults to running on the default_node test node otherwise uses the node specified in
9,835
def run_command ( cmd , opt = { } ) node = get_working_node cmd = build_command ( cmd ) cmd = add_pre_command ( cmd ) ret = ssh_exec! ( node , cmd ) if @example @example . metadata [ :command ] = cmd @example . metadata [ :stdout ] = ret [ :stdout ] end CommandResult . new ret end
Run a unix style command using serverspec . Defaults to running on the default_node test node otherwise uses the node specified in
9,836
def setup ( args = [ ] ) options_parser = Beaker :: Options :: Parser . new options = options_parser . parse_args ( args ) options [ :debug ] = true RSpec . configuration . logger = Beaker :: Logger . new ( options ) options [ :logger ] = logger RSpec . configuration . hosts = [ ] RSpec . configuration . options = opti...
Setup the testing environment
9,837
def suites $: . unshift "./test" , "./spec" , "./lib" begin require "./#{testable.file}" rescue LoadError => e STDERR . puts "Failed loading test file:\n#{e.message}" return [ ] end suites = runner . suites suites . each_with_object ( { } ) do | suite_class , test_suites | if runner . test_methods ( suite_class ) . any...
Finds all test suites in this test file with test methods included .
9,838
def approve_paypal_payment_url ( opts = { } ) if opts . is_a? ( Symbol ) || opts . is_a? ( String ) warn "[DEPRECATION] use approve_paypal_payment_url(:type => #{opts})" opts = { :type => opts } end return nil if self [ 'payKey' ] . nil? if [ 'mini' , 'light' ] . include? ( opts [ :type ] . to_s ) "#{@paypal_base_url}/...
URL to redirect to in order for the user to approve the payment
9,839
def scrape ( ) prepare document case document when Array stack = @document . reverse when HTML :: Node root_element = option ( :root_element ) root = root_element ? @document . find ( :tag => root_element ) : @document stack = root ? ( root . tag? ? [ root ] : root . children . reverse ) : [ ] else return end @skip = [...
Create a new scraper instance .
9,840
def document if @document . is_a? ( URI ) options = { } READER_OPTIONS . each { | key | options [ key ] = option ( key ) } request ( @document , options ) end if @document . is_a? ( String ) parsed = Reader . parse_page ( @document , @page_info . encoding , option ( :parser_options ) , option ( :parser ) ) @document = ...
Returns the document being processed .
9,841
def next_sibling ( ) if siblings = parent . children siblings . each_with_index do | node , i | return siblings [ i + 1 ] if node . equal? ( self ) end end nil end
Returns the next sibling node .
9,842
def previous_sibling ( ) if siblings = parent . children siblings . each_with_index do | node , i | return siblings [ i - 1 ] if node . equal? ( self ) end end nil end
Returns the previous sibling node .
9,843
def previous_element ( name = nil ) if siblings = parent . children found = nil siblings . each do | node | return found if node . equal? ( self ) found = node if node . tag? && ( name . nil? || node . name == name ) end end nil end
Return the previous element before this one . Skips sibling text nodes .
9,844
def each ( value = nil , & block ) yield self , value if @children @children . each do | child | child . each value , & block end end value end
Process each node beginning with the current node .
9,845
def scan_tag tag = @scanner . getch if @scanner . scan ( / / ) tag << @scanner . matched tag << ( @scanner . scan_until ( / \s / ) || @scanner . scan_until ( / \Z / ) ) elsif @scanner . scan ( / \[ \[ / ) tag << @scanner . matched tag << @scanner . scan_until ( / \] \] / ) elsif @scanner . scan ( / / ) tag << @scanner ...
Treat the text at the current position as a tag and scan it . Supports comments doctype tags and regular tags and ignores less - than and greater - than characters within quoted strings .
9,846
def next_element ( element , name = nil ) if siblings = element . parent . children found = false siblings . each do | node | if node . equal? ( element ) found = true elsif found && node . tag? return node if ( name . nil? || node . name == name ) end end end nil end
Return the next element after this one . Skips sibling text nodes .
9,847
def only_child ( of_type ) lambda do | element | return false unless element . parent and element . parent . tag? name = of_type ? element . name : nil other = false for child in element . parent . children if child . tag? and ( name == nil or child . name == name ) unless child . equal? ( element ) other = true break ...
Creates a only child lambda . Pass + of - type + to only look at elements of its type .
9,848
def find_all ( conditions ) conditions = validate_conditions ( conditions ) matches = [ ] matches << self if match ( conditions ) @children . each do | child | matches . concat child . find_all ( conditions ) end matches end
Search for all nodes that match the given conditions and return them as an array .
9,849
def to_s if @closing == :close "</#{@name}>" else s = "<#{@name}" @attributes . each do | k , v | s << " #{k}" s << "='#{v.gsub(/'/,"\\\\'")}'" if String === v end s << " /" if @closing == :self s << ">" @children . each { | child | s << child . to_s } s << "</#{@name}>" if @closing != :self && ! @children . empty? s e...
Returns a textual representation of the node
9,850
def match_condition ( value , condition ) case condition when String value && value == condition when Regexp value && value . match ( condition ) when Numeric value == condition . to_s when true ! value . nil? when false , nil value . nil? else false end end
Match the given value to the given condition .
9,851
def resource ( resource , version = 1 , options = { } ) endpoint_options = { :discoverer => @discoverer , :session_id => @session_id , :locale => options [ :locale ] || @locale } Hoodoo :: Client :: Headers :: HEADER_TO_PROPERTY . each do | rack_header , description | property = description [ :property ] endpoint_optio...
Create a client instance . This is used as a factory for endpoint instances which communicate with Resource implementations .
9,852
def remove ( * writer_instances ) writer_instances . each do | writer_instance | communicator = @writers [ writer_instance ] @pool . remove ( communicator ) unless communicator . nil? @writers . delete ( writer_instance ) end end
Remove a writer instance from this logger . If the instance has not been previously added no error is raised .
9,853
def include_class? ( writer_class ) @writers . keys . each do | writer_instance | return true if writer_instance . is_a? ( writer_class ) end return false end
Does this log instance s collection of writers include any writer instances which are of the given writer _class_? Returns + true + if so else + false + .
9,854
def add_error ( code , options = nil ) options = Hoodoo :: Utilities . stringify ( options || { } ) reference = options [ 'reference' ] || { } message = options [ 'message' ] raise UnknownCode , "In \#add_error: Unknown error code '#{code}'" unless @descriptions . recognised? ( code ) description = @descriptions . desc...
Create an instance .
9,855
def add_precompiled_error ( code , message , reference , http_status = 500 ) @http_status_code = http_status . to_i if @errors . empty? error = { 'code' => code , 'message' => message } error [ 'reference' ] = reference unless reference . nil? || reference . empty? @errors << error end
Add a precompiled error to the error collection . Pass error code error message and reference data directly .
9,856
def run! git = nil path = nil return show_usage ( ) if ARGV . length < 1 name = ARGV . shift ( ) if ARGV . first [ 0 ] != '-' opts = GetoptLong . new ( [ '--help' , '-h' , GetoptLong :: NO_ARGUMENT ] , [ '--version' , '-v' , '-V' , GetoptLong :: NO_ARGUMENT ] , [ '--path' , '-p' , GetoptLong :: REQUIRED_ARGUMENT ] , [ ...
Run the + hoodoo + command implementation . Command line options are taken from the Ruby ARGV constant .
9,857
def set ( key : , payload : , maximum_lifespan : nil ) key = normalise_key ( key , 'set' ) if payload . nil? raise "Hoodoo::TransientStore\#set: Payloads of 'nil' are prohibited" end maximum_lifespan ||= @default_maximum_lifespan begin result = @storage_engine_instance . set ( key : key , payload : payload , maximum_li...
Instantiate a new Transient storage object through which temporary data can be stored or retrieved .
9,858
def normalise_key ( key , calling_method_name ) unless key . is_a? ( String ) || key . is_a? ( Symbol ) raise "Hoodoo::TransientStore\##{ calling_method_name }: Keys must be of String or Symbol class; you provided '#{ key.class }'" end key = key . to_s if key . empty? raise "Hoodoo::TransientStore\##{ calling_method_na...
Given a storage key make sure it s a String or Symbol coerce to a String and ensure it isn t empty . Returns the non - empty String version . Raises exceptions for bad input classes or empty keys .
9,859
def push_gem ( file , options = { } ) ensure_ready! ( :authorization ) push_api = connection ( :url => self . pushpoint ) response = push_api . post ( 'uploads' , options . merge ( :file => file ) ) checked_response_body ( response ) end
Uploading a gem file
9,860
def versions ( name , options = { } ) ensure_ready! ( :authorization ) url = "gems/#{escape(name)}/versions" response = connection . get ( url , options ) checked_response_body ( response ) end
List versions for a gem
9,861
def yank_version ( name , version , options = { } ) ensure_ready! ( :authorization ) url = "gems/#{escape(name)}/versions/#{escape(version)}" response = connection . delete ( url , options ) checked_response_body ( response ) end
Delete a gem version
9,862
def add_collaborator ( login , options = { } ) ensure_ready! ( :authorization ) url = "collaborators/#{escape(login)}" response = connection . put ( url , options ) checked_response_body ( response ) end
Add a collaborator to the account
9,863
def remove_collaborator ( login , options = { } ) ensure_ready! ( :authorization ) url = "collaborators/#{escape(login)}" response = connection . delete ( url , options ) checked_response_body ( response ) end
Remove a collaborator to the account
9,864
def git_repos ( options = { } ) ensure_ready! ( :authorization ) response = connection . get ( git_repo_path , options ) checked_response_body ( response ) end
List Git repos for this account
9,865
def git_update ( repo , options = { } ) ensure_ready! ( :authorization ) response = connection . patch ( git_repo_path ( repo ) , options ) checked_response_body ( response ) end
Update repository name and settings
9,866
def git_reset ( repo , options = { } ) ensure_ready! ( :authorization ) response = connection . delete ( git_repo_path ( repo ) , options ) checked_response_body ( response ) end
Reset repository to initial state
9,867
def git_rebuild ( repo , options = { } ) ensure_ready! ( :authorization ) url = "#{git_repo_path(repo)}/builds" api = connection ( :api_format => :text ) checked_response_body ( api . post ( url , options ) ) end
Rebuild Git repository package
9,868
def status = ( status , reason = nil ) case status when Integer @status = status @reason ||= STATUS_CODES [ status ] when Symbol if code = SYMBOL_TO_STATUS_CODE [ status ] self . status = code else raise ArgumentError , "unrecognized status symbol: #{status}" end else raise TypeError , "invalid status type: #{status.in...
Set the status
9,869
def request raise StateError , "already processing a request" if current_request req = @parser . current_request @request_fsm . transition :headers @keepalive = false if req [ CONNECTION ] == CLOSE || req . version == HTTP_VERSION_1_0 @current_request = req req rescue IOError , Errno :: ECONNRESET , Errno :: EPIPE @req...
Read a request object from the connection
9,870
def readpartial ( maxlen , outbuf = "" ) data = @socket . readpartial ( maxlen , outbuf ) log :read , data data end
Read from the client
9,871
def log ( type , str ) case type when :connect @logger << Colors . green ( str ) when :close @logger << Colors . red ( str ) when :read @logger << Colors . gold ( str ) when :write @logger << Colors . white ( str ) else raise "unknown event type: #{type.inspect}" end end
Log the given event
9,872
def read ( length = nil , buffer = nil ) raise ArgumentError , "negative length #{length} given" if length && length < 0 return '' if length == 0 res = buffer . nil? ? '' : buffer . clear chunk_size = length . nil? ? @connection . buffer_size : length begin while chunk_size > 0 chunk = readpartial ( chunk_size ) break ...
Read a number of bytes looping until they are available or until readpartial returns nil indicating there are no more bytes to read
9,873
def readpartial ( length = nil ) if length . nil? && @buffer . length > 0 slice = @buffer @buffer = "" else unless finished_reading? || ( length && length <= @buffer . length ) @connection . readpartial ( length ? length - @buffer . length : @connection . buffer_size ) end if length slice = @buffer . slice! ( 0 , lengt...
Read a string up to the given number of bytes blocking until some data is available but returning immediately if some data is available
9,874
def created_model ( name ) factory , name_or_index = * parse_model ( name ) if name_or_index . blank? models_by_index ( factory ) . last elsif name_or_index . is_a? ( Integer ) models_by_index ( factory ) [ name_or_index ] else models_by_name ( factory ) [ name_or_index ] or raise ModelNotKnownError , name end end
return the original model stored by create_model or find_model
9,875
def model ( name ) model = created_model ( name ) return nil unless model Pickle :: Adapter . get_model ( model . class , model . id ) end
return a newly selected model
9,876
def store_model ( factory , name , record ) store_record ( record . class . name , name , record ) unless pickle_parser . canonical ( factory ) == pickle_parser . canonical ( record . class . name ) store_record ( factory , name , record ) end
if the factory name ! = the model name store under both names
9,877
def path_to_pickle ( * pickle_names ) options = pickle_names . extract_options! resources = pickle_names . map { | n | model ( n ) || n . to_sym } if options [ :extra ] parts = options [ :extra ] . underscore . gsub ( ' ' , '_' ) . split ( "_" ) find_pickle_path_using_action_segment_combinations ( resources , parts ) e...
given args of pickle model name and an optional extra action or segment will attempt to find a matching named route
9,878
def emails ( fields = nil ) @emails = ActionMailer :: Base . deliveries . select { | m | email_has_fields? ( m , fields ) } end
return the deliveries array optionally selected by the passed fields
9,879
def error_add ( error ) message = error message = "#{error.class.name}: #{error.message}" if error . is_a? ( Exception ) @state [ @server ] = { :count => error_count + 1 , :time => Time . now , :message => message } end
add an error for a server
9,880
def setup_streaming ( request ) if ( request . body && request . body . respond_to? ( :read ) ) body = request . body request . content_length = body . respond_to? ( :lstat ) ? body . lstat . size : body . size request . body_stream = request . body true end end
Detects if an object is streamable - can we read from it and can we know the size?
9,881
def start ( request_params ) finish @server = request_params [ :server ] @port = request_params [ :port ] @protocol = request_params [ :protocol ] @proxy_host = request_params [ :proxy_host ] @proxy_port = request_params [ :proxy_port ] @proxy_username = request_params [ :proxy_username ] @proxy_password = request_para...
Start a fresh connection . The object closes any existing connection and opens a new one .
9,882
def request ( request_params , & block ) current_params = @params . merge ( request_params ) exception = get_param ( :exception , current_params ) || RuntimeError same_auth_params_as_before = SECURITY_PARAMS . select do | param | request_params [ param ] != get_param ( param ) end . empty? mypos = get_fileptr_offset ( ...
= begin rdoc Send HTTP request to server
9,883
def pdf_from_string ( string , output_file = '-' ) with_timeout do pdf = initialize_pdf_from_string ( string , output_file , { :output_to_log_file => false } ) pdf . close_write result = pdf . gets ( nil ) pdf . close_read result . force_encoding ( 'BINARY' ) if RUBY_VERSION >= "1.9" result end end
Makes a pdf from a passed in string .
9,884
def attach ( fei_or_fe , definition , opts = { } ) fe = Ruote . extract_fexp ( @context , fei_or_fe ) . to_h fei = fe [ 'fei' ] cfei = fei . merge ( 'expid' => "#{fei['expid']}_0" , 'subid' => Ruote . generate_subid ( fei . inspect ) ) tree = @context . reader . read ( definition ) tree [ 0 ] = 'sequence' fields = fe [...
Given a flow expression id locates the corresponding ruote expression and attaches a subprocess to it .
9,885
def apply_mutation ( wfid , pdef ) Mutation . new ( self , wfid , @context . reader . read ( pdef ) ) . apply end
Computes mutation and immediately applies it ...
9,886
def processes ( opts = { } ) wfids = @context . storage . expression_wfids ( opts ) opts [ :count ] ? wfids . size : ProcessStatus . fetch ( @context , wfids , opts ) end
Returns an array of ProcessStatus instances .
9,887
def wait_for ( * items ) opts = ( items . size > 1 && items . last . is_a? ( Hash ) ) ? items . pop : { } @context . logger . wait_for ( items , opts ) end
This method expects there to be a logger with a wait_for method in the context else it will raise an exception .
9,888
def register_participant ( regex , participant = nil , opts = { } , & block ) if participant . is_a? ( Hash ) opts = participant participant = nil end pa = @context . plist . register ( regex , participant , opts , block ) @context . storage . put_msg ( 'participant_registered' , 'regex' => regex . is_a? ( Regexp ) ? r...
Registers a participant in the engine .
9,889
def has_attribute ( * args ) args . each { | a | a = a . to_s ; return a if attributes [ a ] != nil } nil end
Given a list of attribute names returns the first attribute name for which there is a value .
9,890
def attribute ( n , workitem = h . applied_workitem , options = { } ) n = n . to_s default = options [ :default ] escape = options [ :escape ] string = options [ :to_s ] || options [ :string ] v = attributes [ n ] v = if v == nil default elsif escape v else dsub ( v , workitem ) end v = v . to_s if v and string v end
Looks up the value for attribute n .
9,891
def att ( keys , values , opts = { } ) default = opts [ :default ] || values . first val = Array ( keys ) . collect { | key | attribute ( key ) } . compact . first . to_s values . include? ( val ) ? val : default end
Returns the value for attribute key this value should be present in the array list values . If not the default value is returned . By default the default value is the first element of values .
9,892
def lookup_val_prefix ( prefix , att_options = { } ) lval ( [ prefix ] + [ 'val' , 'value' ] . map { | s | "#{prefix}_#{s}" } , %w[ v var variable ] . map { | s | "#{prefix}_#{s}" } , %w[ f fld field ] . map { | s | "#{prefix}_#{s}" } , att_options ) end
prefix = on = > will lookup on on_val on_value on_v on_var on_variable on_f on_fld on_field ...
9,893
def compile_atts ( opts = { } ) attributes . keys . each_with_object ( { } ) { | k , r | r [ dsub ( k ) ] = attribute ( k , h . applied_workitem , opts ) } end
Returns a Hash containing all attributes set for an expression with their values resolved .
9,894
def attribute_text ( workitem = h . applied_workitem ) text = attributes . keys . find { | k | attributes [ k ] == nil } dsub ( text . to_s , workitem ) end
Given something like
9,895
def determine_tos to_v = attribute ( :to_v ) || attribute ( :to_var ) || attribute ( :to_variable ) to_f = attribute ( :to_f ) || attribute ( :to_fld ) || attribute ( :to_field ) if to = attribute ( :to ) pre , key = to . split ( ':' ) pre , key = [ 'f' , pre ] if key == nil if pre . match ( / / ) to_f = key else to_v ...
tos meaning many to
9,896
def do_apply ( msg ) if msg [ 'state' ] == 'paused' return pause_on_apply ( msg ) end if msg [ 'flavour' ] . nil? && ( aw = attribute ( :await ) ) return await ( aw , msg ) end unless Condition . apply? ( attribute ( :if ) , attribute ( :unless ) ) return do_reply_to_parent ( h . applied_workitem ) end pi = h . parent_...
Called by the worker when it has just created this FlowExpression and wants to apply it .
9,897
def do_reply_to_parent ( workitem , delete = true ) flavour = if @msg . nil? nil elsif @msg [ 'action' ] == 'cancel' @msg [ 'flavour' ] || 'cancel' elsif h . state . nil? nil else @msg [ 'flavour' ] end %w[ timeout_schedule_id job_id ] . each do | sid | @context . storage . delete_schedule ( h [ sid ] ) if h [ sid ] en...
The essence of the reply_to_parent job ...
9,898
def do_pause ( msg ) return if h . state != nil h . state = 'paused' do_persist || return h . children . each { | i | @context . storage . put_msg ( 'pause' , 'fei' => i ) } unless msg [ 'breakpoint' ] end
Expression received a pause message . Will put the expression in the paused state and then pass the message to the children .
9,899
def ancestor? ( fei ) fei = fei . to_h if fei . respond_to? ( :to_h ) return false unless h . parent_id return true if h . parent_id == fei parent . ancestor? ( fei ) end
Returns true if the given fei points to an expression in the parent chain of this expression .