idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
6,500
def add ( type , info ) path , info = type_info ( type , :path ) , force_case ( info ) reply = json_parse_reply ( @key_style , * json_post ( @target , path , info , headers ) ) fake_client_id ( reply ) if type == :client reply end
Creates a SCIM resource .
6,501
def put ( type , info ) path , info = type_info ( type , :path ) , force_case ( info ) ida = type == :client ? 'client_id' : 'id' raise ArgumentError , "info must include #{ida}" unless id = info [ ida ] hdrs = headers if info && info [ 'meta' ] && ( etag = info [ 'meta' ] [ 'version' ] ) hdrs . merge! ( 'if-match' => ...
Replaces the contents of a SCIM object .
6,502
def query ( type , query = { } ) query = force_case ( query ) . reject { | k , v | v . nil? } if attrs = query [ 'attributes' ] attrs = Util . arglist ( attrs ) . map { | a | force_attr ( a ) } query [ 'attributes' ] = Util . strlist ( attrs , "," ) end qstr = query . empty? ? '' : "?#{Util.encode_form(query)}" info = ...
Gets a set of attributes for each object that matches a given filter .
6,503
def get ( type , id ) info = json_get ( @target , "#{type_info(type, :path)}/#{URI.encode(id)}" , @key_style , headers ) fake_client_id ( info ) if type == :client info end
Get information about a specific object .
6,504
def implicit_grant_with_creds ( credentials , scope = nil ) redir_uri = "https://uaa.cloudfoundry.com/redirect/#{@client_id}" response_type = "token" response_type = "#{response_type} id_token" if scope && ( scope . include? "openid" ) uri = authorize_path_args ( response_type , redir_uri , scope , state = random_state...
Gets an access token in a single call to the UAA with the user credentials used for authentication .
6,505
def implicit_uri ( redirect_uri , scope = nil ) response_type = "token" response_type = "#{response_type} id_token" if scope && ( scope . include? "openid" ) @target + authorize_path_args ( response_type , redirect_uri , scope ) end
Constructs a uri that the client is to return to the browser to direct the user to the authorization server to get an authcode .
6,506
def implicit_grant ( implicit_uri , callback_fragment ) in_params = Util . decode_form ( URI . parse ( implicit_uri ) . query ) unless in_params [ 'state' ] && in_params [ 'redirect_uri' ] raise ArgumentError , "redirect must happen before implicit grant" end parse_implicit_params ( callback_fragment , in_params [ 'sta...
Gets a token via an implicit grant .
6,507
def autologin_uri ( redirect_uri , credentials , scope = nil ) headers = { 'content-type' => FORM_UTF8 , 'accept' => JSON_UTF8 , 'authorization' => Http . basic_auth ( @client_id , @client_secret ) } body = Util . encode_form ( credentials ) reply = json_parse_reply ( nil , * request ( @target , :post , "/autologin" , ...
A UAA extension to OAuth2 that allows a client to pre - authenticate a user at the start of an authorization code flow . By passing in the user s credentials the server can establish a session with the user s browser without reprompting for authentication . This is useful for user account management apps so that they c...
6,508
def authcode_grant ( authcode_uri , callback_query ) ac_params = Util . decode_form ( URI . parse ( authcode_uri ) . query ) unless ac_params [ 'state' ] && ac_params [ 'redirect_uri' ] raise ArgumentError , "authcode redirect must happen before authcode grant" end begin params = Util . decode_form ( callback_query ) a...
Uses the instance client credentials in addition to + callback_query + to get a token via the authorization code grant .
6,509
def choice_transition? ( name , from_state ) find ( name ) . select { | trans | trans . matches? ( from_state ) } . size > 1 end
Check if event has branching choice transitions or not
6,510
def match_transition ( name , from_state ) find ( name ) . find { | trans | trans . matches? ( from_state ) } end
Find transition without checking conditions
6,511
def match_transition_with ( name , from_state , * conditions ) find ( name ) . find do | trans | trans . matches? ( from_state ) && trans . check_conditions ( * conditions ) end end
Examine transitions for event name that start in from state and find one matching condition .
6,512
def select_transition ( name , from_state , * conditions ) if choice_transition? ( name , from_state ) match_transition_with ( name , from_state , * conditions ) else match_transition ( name , from_state ) end end
Select transition that matches conditions
6,513
def move_to ( name , from_state , * conditions ) transition = select_transition ( name , from_state , * conditions ) transition ||= UndefinedTransition . new ( name ) transition . to_state ( from_state ) end
Find state that this machine can move to
6,514
def to_s hash = { } @events_map . each_pair do | name , trans | hash [ name ] = trans end hash . to_s end
Return string representation of this map
6,515
def make_conditions @if . map { | c | Callable . new ( c ) } + @unless . map { | c | Callable . new ( c ) . invert } end
Initialize a Transition
6,516
def matches? ( from ) states . keys . any? { | state | [ ANY_STATE , from ] . include? ( state ) } end
Check if this transition matches from state
6,517
def choice ( to , ** conditions ) transition_builder = TransitionBuilder . new ( @machine , @name , @transitions . merge ( conditions ) ) transition_builder . call ( @transitions [ :from ] => to ) end
Initialize a ChoiceMerger
6,518
def define_state_query_method ( state ) return if machine . respond_to? ( "#{state}?" ) machine . send ( :define_singleton_method , "#{state}?" ) do machine . is? ( state . to_sym ) end end
Define state helper method
6,519
def on ( hook_type , state_or_event_name = nil , async = nil , & callback ) sync_exclusive do if state_or_event_name . nil? state_or_event_name = HookEvent . any_state_or_event ( hook_type ) end async = false if async . nil? ensure_valid_callback_name! ( hook_type , state_or_event_name ) callback . extend ( Async ) if ...
Register callback for a given hook type
6,520
def off ( hook_type , name = ANY_STATE , & callback ) sync_exclusive do hooks . unregister hook_type , name , callback end end
Unregister callback for a given event
6,521
def emit ( event , * data ) sync_exclusive do [ event . type ] . each do | hook_type | any_state_or_event = HookEvent . any_state_or_event ( hook_type ) [ any_state_or_event , event . name ] . each do | event_name | hooks [ hook_type ] [ event_name ] . each do | hook | handle_callback ( hook , event , * data ) off ( ho...
Execute each of the hooks in order with supplied data
6,522
def handle_callback ( hook , event , * data ) to = machine . events_map . move_to ( event . event_name , event . from , * data ) trans_event = TransitionEvent . new ( event . event_name , event . from , to ) callable = create_callable ( hook ) if hook . is_a? ( Async ) defer ( callable , trans_event , * data ) else cal...
Handle callback and decide if run synchronously or asynchronously
6,523
def defer ( callable , trans_event , * data ) async_call = AsyncCall . new ( machine , callable , trans_event , * data ) callback_queue . start unless callback_queue . running? callback_queue << async_call end
Defer callback execution
6,524
def create_callable ( hook ) callback = proc do | trans_event , * data | machine . instance_exec ( trans_event , * data , & hook ) end Callable . new ( callback ) end
Create callable instance
6,525
def notify ( subscriber , * data ) return unless subscriber . respond_to? ( MESSAGE ) subscriber . public_send ( MESSAGE , self , * data ) end
Instantiate a new HookEvent object
6,526
def apply ( event_name , silent = false ) define_event_transition ( event_name , silent ) define_event_bang ( event_name , silent ) end
Initialize an EventDefinition
6,527
def define_event_transition ( event_name , silent ) machine . send ( :define_singleton_method , event_name ) do | * data , & block | method = silent ? :transition : :trigger machine . public_send ( method , event_name , * data , & block ) end end
Define transition event
6,528
def initial ( value , ** options ) state = ( value && ! value . is_a? ( Hash ) ) ? value : raise_missing_state name , @defer_initial , @silent_initial = * parse_initial ( options ) @initial_event = name event ( name , FiniteMachine :: DEFAULT_STATE => state , silent : @silent_initial ) end
Initialize top level DSL
6,529
def event ( name , transitions = { } , & block ) detect_event_conflict! ( name ) if machine . auto_methods? if block_given? merger = ChoiceMerger . new ( machine , name , transitions ) merger . instance_eval ( & block ) else transition_builder = TransitionBuilder . new ( machine , name , transitions ) transition_builde...
Create event and associate transition
6,530
def parse_initial ( options ) [ options . fetch ( :event ) { FiniteMachine :: DEFAULT_EVENT_NAME } , options . fetch ( :defer ) { false } , options . fetch ( :silent ) { true } ] end
Parse initial options
6,531
def is? ( state ) if state . is_a? ( Array ) state . include? current else state == current end end
Check if current state matches provided state
6,532
def can? ( * args ) event_name = args . shift events_map . can_perform? ( event_name , current , * args ) end
Checks if event can be triggered
6,533
def valid_state? ( event_name ) current_states = events_map . states_for ( event_name ) current_states . any? { | state | state == current || state == ANY_STATE } end
Check if state is reachable
6,534
def notify ( hook_event_type , event_name , from , * data ) sync_shared do hook_event = hook_event_type . build ( current , event_name , from ) subscribers . visit ( hook_event , * data ) end end
Notify about event all the subscribers
6,535
def try_trigger ( event_name ) if valid_state? ( event_name ) yield else exception = InvalidStateError catch_error ( exception ) || fail ( exception , "inappropriate current state '#{current}'" ) false end end
Attempt performing event trigger for valid state
6,536
def trigger! ( event_name , * data , & block ) from = current sync_exclusive do notify HookEvent :: Before , event_name , from , * data status = try_trigger ( event_name ) do if can? ( event_name , * data ) notify HookEvent :: Exit , event_name , from , * data stat = transition! ( event_name , * data , & block ) notify...
Trigger transition event with data
6,537
def trigger ( event_name , * data , & block ) trigger! ( event_name , * data , & block ) rescue InvalidStateError , TransitionError , CallbackError false end
Trigger transition event without raising any errors
6,538
def transition! ( event_name , * data , & block ) from_state = current to_state = events_map . move_to ( event_name , from_state , * data ) block . call ( from_state , to_state ) if block if log_transitions Logger . report_transition ( event_name , from_state , to_state , * data ) end try_trigger ( event_name ) { trans...
Find available state to transition to and transition
6,539
def transition_to! ( new_state ) from_state = current self . state = new_state self . initial_state = new_state if from_state == DEFAULT_STATE true rescue Exception => e catch_error ( e ) || raise_transition_error ( e ) end
Update this state machine state to new one
6,540
def method_missing ( method_name , * args , & block ) if observer . respond_to? ( method_name . to_sym ) observer . public_send ( method_name . to_sym , * args , & block ) elsif env . aliases . include? ( method_name . to_sym ) env . send ( :target , * args , & block ) else super end end
Forward the message to observer or self
6,541
def respond_to_missing? ( method_name , include_private = false ) observer . respond_to? ( method_name . to_sym ) || env . aliases . include? ( method_name . to_sym ) || super end
Test if a message can be handled by state machine
6,542
def detect_event_conflict! ( event_name , method_name = event_name ) if method_already_implemented? ( method_name ) raise FiniteMachine :: AlreadyDefinedError , EVENT_CONFLICT_MESSAGE % { name : event_name , type : :instance , method : method_name , source : 'FiniteMachine' } end end
Raise error when the method is already defined
6,543
def ensure_valid_callback_name! ( event_type , name ) message = if wrong_event_name? ( name , event_type ) EVENT_CALLBACK_CONFLICT_MESSAGE % { type : "on_#{event_type}" , name : name } elsif wrong_state_name? ( name , event_type ) STATE_CALLBACK_CONFLICT_MESSAGE % { type : "on_#{event_type}" , name : name } elsif ! cal...
Raise error when the callback name is not valid
6,544
def wrong_event_name? ( name , event_type ) machine . states . include? ( name ) && ! machine . events . include? ( name ) && event_type < HookEvent :: Anyaction end
Check if event name exists
6,545
def wrong_state_name? ( name , event_type ) machine . events . include? ( name ) && ! machine . states . include? ( name ) && event_type < HookEvent :: Anystate end
Check if state name exists
6,546
def subscribe ( * args , & block ) @mutex . synchronize do listener = Listener . new ( * args ) listener . on_delivery ( & block ) @listeners << listener end end
Add listener to the queue to receive messages
6,547
def shutdown fail EventQueueDeadError , 'event queue already dead' if @dead queue = [ ] @mutex . synchronize do @dead = true @not_empty . broadcast queue = @queue @queue . clear end while ! queue . empty? discard_message ( queue . pop ) end true end
Shut down this event queue and clean it up
6,548
def process_events until @dead @mutex . synchronize do while @queue . empty? break if @dead @not_empty . wait ( @mutex ) end event = @queue . pop break unless event notify_listeners ( event ) event . dispatch end end rescue Exception => ex Logger . error "Error while running event: #{Logger.format_error(ex)}" end
Process all the events
6,549
def visit ( hook_event , * data ) each { | subscriber | synchronize { hook_event . notify ( subscriber , * data ) } } end
Visit subscribers and notify
6,550
def call ( transitions ) StateParser . parse ( transitions ) do | from , to | transition = Transition . new ( @machine . env . target , @name , @attributes . merge ( states : { from => to } ) ) silent = @attributes . fetch ( :silent , false ) @machine . events_map . add ( @name , transition ) next unless @machine . aut...
Initialize a TransitionBuilder
6,551
def handle ( * exceptions , & block ) options = exceptions . last . is_a? ( Hash ) ? exceptions . pop : { } unless options . key? ( :with ) if block_given? options [ :with ] = block else raise ArgumentError , 'Need to provide error handler.' end end evaluate_exceptions ( exceptions , options ) end
Rescue exception raised in state machine
6,552
def catch_error ( exception ) if handler = handler_for_error ( exception ) handler . arity . zero? ? handler . call : handler . call ( exception ) true end end
Catches error and finds a handler
6,553
def extract_const ( class_name ) class_name . split ( '::' ) . reduce ( FiniteMachine ) do | constant , part | constant . const_get ( part ) end end
Find constant in state machine namespace
6,554
def evaluate_handler ( handler ) case handler when Symbol target . method ( handler ) when Proc if handler . arity . zero? proc { instance_exec ( & handler ) } else proc { | _exception | instance_exec ( _exception , & handler ) } end end end
Executes given handler
6,555
def evaluate_exceptions ( exceptions , options ) exceptions . each do | exception | key = if exception . is_a? ( Class ) && exception <= Exception exception . name elsif exception . is_a? ( String ) exception else raise ArgumentError , "#{exception} isn't an Exception" end error_handlers << [ key , options [ :with ] ] ...
Check if exception inherits from Exception class and add to error handlers
6,556
def team_id_by_slug ( slug , org ) octo . organization_teams ( org ) . each do | team | return team [ :id ] if team [ :slug ] == slug . downcase end nil end
Get the Github team ID using its slug
6,557
def team_id ( team , org ) / \d / . match ( team . to_s ) ? team : team_id_by_slug ( team , org ) end
Get the team id based on either the team slug or the team id
6,558
def opts_parse ( cmd ) o = { } cmd . scan ( LitaGithub :: R :: OPT_REGEX ) . flatten . each do | opt | k , v = symbolize_opt_key ( * opt . strip . split ( ':' ) ) next if o . key? ( k ) v = v . slice! ( 1 , ( v . length - 2 ) ) if %w( ' " ) . include? ( v . slice ( 0 ) ) o [ k ] = to_i_if_numeric ( v ) end o end
Parse the options in the command using the option regex
6,559
def repo_has_team? ( full_name , team_id ) octo . repository_teams ( full_name ) . each { | t | return true if t [ :id ] == team_id } false end
Determine if the team is already on the repository
6,560
def probabilistic_inverse_document_frequency ( term ) count = @model . document_count ( term ) . to_f log ( ( documents . size - count ) / count ) end
SMART p Salton p Chisholm IDFP
6,561
def normalized_log_term_frequency ( document , term ) count = document . term_count ( term ) if count > 0 ( 1 + log ( count ) ) / ( 1 + log ( document . average_term_count ) ) else 0 end end
SMART L Chisholm LOGN
6,562
def set_term_counts_and_size tokenize ( text ) . each do | word | token = Token . new ( word ) if token . valid? term = token . lowercase_filter . classic_filter . to_s @term_counts [ term ] += 1 @size += 1 end end end
Tokenizes the text and counts terms and total tokens .
6,563
def inverse_document_frequency ( term ) df = @model . document_count ( term ) log ( ( documents . size - df + 0.5 ) / ( df + 0.5 ) ) end
Return the term s inverse document frequency .
6,564
def term_frequency ( document , term ) tf = document . term_count ( term ) ( tf * 2.2 ) / ( tf + 0.3 + 0.9 * documents . size / @model . average_document_size ) end
Returns the term s frequency in the document .
6,565
def call ( format : config . default_format , context : config . default_context , ** input ) ensure_config env = self . class . render_env ( format : format , context : context ) template_env = self . class . template_env ( format : format , context : context ) locals = locals ( template_env , input ) output = env . t...
Render the view
6,566
def check_node_overlap! node_to_positions = { } each_node do | node | node . proper_range . each do | position | if node_to_positions [ position ] already = node_to_positions [ position ] puts "There is a proper_range overlap between #{node} and #{already}" puts "Overlapping: #{already.proper_range & node.proper_range}...
For now when an overlap is found just open a binding . pry to make fixing it easier .
6,567
def content_tag ( tag , content , ** options ) attrs = options . map { | kind , value | %{ #{kind}="#{value}"} } . join "<#{tag}#{attrs}>#{content}</#{tag}>" end
Poor man s content_tag . No HTML escaping included
6,568
def results ( analyser ) r = analyser . results [ 0 , nil ] . map do | val | r . select { | node , runs | runs == val } . keys . map ( & :source ) end end
returns not_covered ignored
6,569
def find_all ( lookup ) case lookup when :: Module each_node . grep ( lookup ) when :: Symbol each_node . find_all { | n | n . type == lookup } when :: String each_node . find_all { | n | n . source == lookup } when :: Regexp each_node . find_all { | n | n . source =~ lookup } else raise :: TypeError , "Expected class ...
Public API Search self and descendants for a particular Class or type
6,570
def [] ( lookup ) if lookup . is_a? ( Integer ) children . fetch ( lookup ) else found = find_all ( lookup ) case found . size when 1 found . first when 0 raise "No children of type #{lookup}" else raise "Ambiguous lookup #{lookup}, found #{found}." end end end
Shortcut to access children
6,571
def each_node ( & block ) return to_enum :each_node unless block_given? children_nodes . each do | child | child . each_node ( & block ) end yield self self end
Yields its children and itself
6,572
def add_missing_covered_codes top_level_path = DeepCover . config . paths . detect do | path | next unless path . is_a? ( String ) path = File . expand_path ( path ) File . dirname ( path ) == path end if top_level_path suggestion = "#{top_level_path}/**/*.rb" warn [ "Because the `paths` configured in DeepCover include...
If a file wasn t required it won t be in the trackers . This adds those mossing files
6,573
def load_trackers tracker_hits_per_path_hashes = tracker_files . map do | full_path | JSON . parse ( full_path . binread ) . transform_keys ( & :to_sym ) . yield_self do | version : , tracker_hits_per_path : | raise "dump version mismatch: #{version}, currently #{VERSION}" unless version == VERSION tracker_hits_per_pat...
returns a TrackerHitsPerPath
6,574
def initialize_autoloaded_paths ( mods = ObjectSpace . each_object ( Module ) ) mods . each do | mod | next if mod == Module next unless mod . respond_to? ( :constants ) if mod . frozen? if mod . constants . any? { | name | mod . autoload? ( name ) } self . class . warn_frozen_module ( mod ) end next end mod . constant...
In JRuby ObjectSpace . each_object is allowed for Module and Class so we are good .
6,575
def remove_interceptors @autoloads_by_basename . each do | basename , entries | entries . each do | entry | mod = entry . mod_if_available next unless mod next if mod == Module yield mod , entry . name , entry . target_path end end @autoloaded_paths = { } @interceptor_files_by_path = { } end
We need to remove the interceptor hooks otherwise the problem if manually requiring something that is autoloaded will cause issues .
6,576
def execute_sample ( to_execute , source : nil ) Tools . silence_warnings do if to_execute . is_a? ( CoveredCode ) to_execute . execute_code else to_execute . call end end true rescue StandardError => e return false if e . is_a? ( RuntimeError ) && e . message . empty? source = to_execute . covered_source if to_execute...
Returns true if the code would have continued false if the rescue was triggered .
6,577
def from_file ( filename ) if %w{ .yml .yaml } . include? ( File . extname ( filename ) ) from_yaml ( filename ) elsif File . extname ( filename ) == ".json" from_json ( filename ) elsif File . extname ( filename ) == ".toml" from_toml ( filename ) else instance_eval ( IO . read ( filename ) , filename , 1 ) end end
Loads a given ruby file and runs instance_eval against it in the context of the current object .
6,578
def reset self . configuration = Hash . new config_contexts . values . each { | config_context | config_context . reset } end
Resets all config options to their defaults .
6,579
def save ( include_defaults = false ) result = configuration . dup if include_defaults ( configurables . keys - result . keys ) . each do | missing_default | if configurables [ missing_default ] . has_default result [ missing_default ] = configurables [ missing_default ] . default end end end config_contexts . each_pai...
Makes a copy of any non - default values .
6,580
def restore ( hash ) self . configuration = hash . reject { | key , value | config_contexts . key? ( key ) } config_contexts . each do | key , config_context | if hash . key? ( key ) config_context . restore ( hash [ key ] ) else config_context . reset end end config_context_lists . each do | key , meta | meta [ :value...
Restore non - default values from the given hash .
6,581
def merge! ( hash ) hash . each do | key , value | if config_contexts . key? ( key ) config_contexts [ key ] . restore ( value ) else configuration [ key ] = value end end self end
Merge an incoming hash with our config options
6,582
def config_context ( symbol , & block ) if configurables . key? ( symbol ) raise ReopenedConfigurableWithConfigContextError , "Cannot redefine config value #{symbol} with a config context" end if config_contexts . key? ( symbol ) context = config_contexts [ symbol ] else context = Class . new context . extend ( :: Mixl...
Allows you to create a new config context where you can define new options with default values .
6,583
def config_context_list ( plural_symbol , singular_symbol , & block ) if configurables . key? ( plural_symbol ) raise ReopenedConfigurableWithConfigContextError , "Cannot redefine config value #{plural_symbol} with a config context" end unless config_context_lists . key? ( plural_symbol ) config_context_lists [ plural_...
Allows you to create a new list of config contexts where you can define new options with default values .
6,584
def config_context_hash ( plural_symbol , singular_symbol , & block ) if configurables . key? ( plural_symbol ) raise ReopenedConfigurableWithConfigContextError , "Cannot redefine config value #{plural_symbol} with a config context" end unless config_context_hashes . key? ( plural_symbol ) config_context_hashes [ plura...
Allows you to create a new hash of config contexts where you can define new options with default values .
6,585
def internal_set ( symbol , value ) if configurables . key? ( symbol ) configurables [ symbol ] . set ( configuration , value ) elsif config_contexts . key? ( symbol ) config_contexts [ symbol ] . restore ( value . to_hash ) else if config_strict_mode == :warn Chef :: Log . warn ( "Setting unsupported config value #{sy...
Internal dispatch setter for config values .
6,586
def link_to_remove ( * args , & block ) options = args . extract_options! . symbolize_keys options [ :class ] = [ options [ :class ] , "remove_nested_fields" ] . compact . join ( " " ) md = object_name . to_s . match / \w \] \[ \w \d \] / association = md && md [ 1 ] options [ "data-association" ] = association args <<...
Adds a link to remove the associated record . The first argment is the name of the link .
6,587
def resolve_tree permutations = permutate_simplified_tree permutations = filter_invalid_permutations ( permutations ) user_deps = tree . dependencies . keys result = select_highest_versioned_permutation ( permutations , user_deps ) . flatten if result . empty? && ! tree . dependencies . empty? error ( "Failed to satisf...
Resolve the given dependency tree and return a list of concrete packages that meet all dependency requirements .
6,588
def dependencies_array ( leaf , processed = { } ) return processed [ leaf ] if processed [ leaf ] deps_array = [ ] processed [ leaf ] = deps_array leaf . each do | pack , versions | a = [ ] versions . each do | version , deps | perms = [ ] sub_perms = dependencies_array ( deps , processed ) if sub_perms == [ ] perms +=...
Converts a simplified dependency tree into an array of dependencies containing a sub - array for each top - level dependency . Each such sub - array contains in its turn version permutations for the top - level dependency and any transitive dependencies .
6,589
def filter_invalid_permutations ( permutations ) valid = [ ] permutations . each do | perm | versions = { } ; invalid = false perm . each do | ref | if ref =~ / / name , version = $1 , $2 if versions [ name ] && versions [ name ] != version invalid = true break else versions [ name ] = version end end end valid << perm...
Remove invalid permutations that is permutations that contain multiple versions of the same package a scenario which could arrive in the case of circular dependencies or when different dependencies rely on different versions of the same transitive dependency .
6,590
def select_highest_versioned_permutation ( permutations , user_deps ) sorted = sort_permutations ( permutations , user_deps ) sorted . empty? ? [ ] : sorted . last end
Select the highest versioned permutation of package versions
6,591
def sort_permutations ( permutations , user_deps ) versions = { } map = lambda do | m , p | if p =~ Lyp :: PACKAGE_RE m [ $1 ] = versions [ p ] ||= ( Lyp . version ( $2 || '0.0' ) rescue nil ) end m end compare = lambda do | x , y | x_versions = x . inject ( { } , & map ) y_versions = y . inject ( { } , & map ) x_versi...
Sort permutations by version numbers
6,592
def find_matching_packages ( req ) return { } unless req =~ Lyp :: PACKAGE_RE req_package = $1 req_version = $2 req = nil if @opts [ :forced_package_paths ] && @opts [ :forced_package_paths ] [ req_package ] req_version = 'forced' end req = Lyp . version_req ( req_version || '>=0' ) rescue nil available_packages . sele...
Find packages meeting the version requirement
6,593
def find_package_versions ( ref , leaf , location ) return { } unless ref =~ Lyp :: PACKAGE_RE ref_package = $1 version_clause = $2 matches = find_matching_packages ( ref ) if matches . empty? && ( leaf == tree ) && ! opts [ :ignore_missing ] msg = "Missing package dependency #{ref} in %sYou can install any missing pac...
Find available packaging matching the package specifier and queue them for processing any include files or transitive dependencies .
6,594
def squash_old_versions specifiers = map_specifiers_to_versions compare_versions = lambda do | x , y | v_x = x =~ Lyp :: PACKAGE_RE && Lyp . version ( $2 ) v_y = y =~ Lyp :: PACKAGE_RE && Lyp . version ( $2 ) x <=> y end specifiers . each do | package , clauses | next unless clauses . size == 1 specs = clauses . values...
Remove redundant older versions of dependencies by collating package versions by package specifiers then removing older versions for any package for which a single package specifier exists .
6,595
def map_specifiers_to_versions specifiers = { } processed = { } l = lambda do | t | return if processed [ t . object_id ] processed [ t . object_id ] = true t . dependencies . each do | package , spec | specifiers [ package ] ||= { } specifiers [ package ] [ spec . clause ] ||= [ ] specifiers [ package ] [ spec . claus...
Return a hash mapping packages to package specifiers to spec objects to be used to eliminate older versions from the dependency tree
6,596
def remove_unfulfilled_dependencies ( leaf , raise_on_missing = true , processed = { } ) tree . dependencies . each do | package , dependency | dependency . versions . select! do | version , leaf | if processed [ version ] true else processed [ version ] = true remove_unfulfilled_dependencies ( leaf , false , processed...
Recursively remove any dependency for which no version is locally available . If no version is found for any of the dependencies specified by the user an error is raised .
6,597
def add_filter ( filter ) @filters = ( @filters << filter ) . sort_by do | f | f . respond_to? ( :weight ) ? f . weight : DEFAULT_WEIGHT end . reverse! end
Adds a filter to the filter chain . Sorts filters by weight .
6,598
def delete_filter ( filter_class ) index = @filters . index { | f | f . class . name == filter_class . name } @filters . delete_at ( index ) if index end
Deletes a filter from the the filter chain .
6,599
def replace_invalid_characters ( str ) encoding = str . encoding utf8_string = ( encoding == Encoding :: UTF_8 || encoding == Encoding :: ASCII ) return str if utf8_string && str . valid_encoding? temp_str = str . dup temp_str . encode! ( TEMP_ENCODING , ENCODING_OPTIONS ) if utf8_string temp_str . encode! ( 'utf-8' , ...
Replaces invalid characters in a string with arbitrary encoding .