idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
15,700 | def validate_value ( value ) unless value . is_a? ( String ) raise TypeError , "can't convert #{ value.class } into PryTheme::HEX" end if value !~ PryTheme :: HEX :: PATTERN fail ArgumentError , %|invalid value for PryTheme::HEX#new(): "#{value}"| end true end | Validates whether + value + is a valid hex colour value . |
15,701 | def recreate_user_themes_from_default_ones FileUtils . mkdir_p ( USER_THEMES_DIR ) unless File . exist? ( USER_THEMES_DIR ) default_themes = Dir . entries ( DEF_THEMES_DIR ) - %w( . .. ) default_themes . each do | theme | user_theme_path = File . join ( USER_THEMES_DIR , theme ) next if File . exist? ( user_theme_path ... | Copy a default theme to theme directory but only if it isn t there yet . |
15,702 | def files ( input ) ( :: Readline :: FILENAME_COMPLETION_PROC . call ( input ) || [ ] ) . map { | f | f =~ / / ? File . expand_path ( f ) : f } end | Action method with search which returns array of files that match current input . |
15,703 | def objects_of ( klass ) object = [ ] ObjectSpace . each_object ( klass ) { | e | object . push ( e ) } object end | Helper method which returns objects of a given class . |
15,704 | def call_search ( search , input , list ) Rc . send ( "#{search}_search" , input || '' , list ) rescue message = $! . is_a? ( NoMethodError ) && ! Rc . respond_to? ( "#{search}_search" ) ? "Completion search '#{search}' doesn't exist." : "Failed during completion search with '#{$!.message}'." raise FailedMissionError .... | Searches possible completions from the action which match the input . |
15,705 | def call_action ( input ) @action . respond_to? ( :call ) ? @action . call ( input ) : Rc . send ( @action , input ) rescue StandardError , SyntaxError message = $! . is_a? ( NoMethodError ) && ! @action . respond_to? ( :call ) && ! Rc . respond_to? ( @action ) ? "Completion action '#{@action}' doesn't exist." : "Faile... | Calls the action to generate an array of possible completions . |
15,706 | def ensure_position ( rect ) if cur_x + rect . width > canvas . width @cur_x = 0 @cur_y += row_height @row_height = 0 end restart_canvas! if cur_y + rect . height > canvas . height end | ensure this rect can be drawn at current position or shift position of it can t |
15,707 | def remove_token_from_category ( category , token ) cat_data ( category ) [ :tokens ] [ token ] -= 1 delete_token_from_category ( category , token ) if cat_data ( category ) [ :tokens ] [ token ] < 1 cat_data ( category ) [ :total_tokens ] -= 1 delete_category ( category ) if cat_data ( category ) [ :total_tokens ] < 1... | Decrement the token counter in a category If the counter is 0 delete the token . If the total number of tokens is 0 delete the category . |
15,708 | def load ( yml ) if yml . nil? nbayes = NBayes :: Base . new elsif yml [ 0 .. 2 ] == "---" nbayes = self . class . from_yml ( yml ) else nbayes = self . class . from ( yml ) end nbayes end | Load class instance |
15,709 | def complete ( options = { } , & block ) if ( mission = create_mission ( options , & block ) ) . is_a? ( Mission ) mission . place . is_a? ( Integer ) ? @missions . insert ( mission . place - 1 , mission ) . compact! : @missions << mission sort_last_missions end mission end | Creates a mission . |
15,710 | def recomplete ( options = { } , & block ) if ( mission = create_mission ( options , & block ) ) . is_a? ( Mission ) if ( existing_mission = @missions . find { | e | e . name == mission . name } ) @missions [ @missions . index ( existing_mission ) ] = mission sort_last_missions else return "No existing mission found to... | Creates a mission and replaces the mission it matches if possible . |
15,711 | def spy ( input ) if ( mission = find_mission ( input ) ) puts mission . match_message , "Possible completions: #{mission.execute.inspect}" , "Matches for #{mission.condition.inspect} are #{mission.matched.to_a.inspect}" else puts "Doesn't match a completion." end rescue FailedMissionError => e puts e . mission . match... | Given a hypothetical user input reports back what mission it would have found and executed . |
15,712 | def debrief ( options = { } ) config . merge! options config [ :readline ] ||= default_readline if ! config [ :readline ] . is_a? ( Module ) && Bond . const_defined? ( config [ :readline ] . to_s . capitalize ) config [ :readline ] = Bond . const_get ( config [ :readline ] . to_s . capitalize ) end unless %w{ setup lin... | Validates and sets values in M . config . |
15,713 | def find_gem_file ( rubygem , file ) begin gem ( rubygem ) ; rescue Exception ; end ( dir = $: . find { | e | File . exist? ( File . join ( e , file ) ) } ) && File . join ( dir , file ) end | Finds the full path to a gem s file relative it s load path directory . Returns nil if not found . |
15,714 | def load_file ( file ) Rc . module_eval File . read ( file ) rescue Exception => e $stderr . puts "Bond Error: Completion file '#{file}' failed to load with:" , e . message end | Loads a completion file in Rc namespace . |
15,715 | def load_dir ( base_dir ) if File . exist? ( dir = File . join ( base_dir , 'completions' ) ) Dir [ dir + '/*.rb' ] . each { | file | load_file ( file ) } true end end | Loads completion files in given directory . |
15,716 | def home [ 'HOME' , 'USERPROFILE' ] . each { | e | return ENV [ e ] if ENV [ e ] } return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" if ENV [ 'HOMEDRIVE' ] && ENV [ 'HOMEPATH' ] File . expand_path ( "~" ) rescue File :: ALT_SEPARATOR ? "C:/" : "/" end | Find a user s home in a cross - platform way |
15,717 | def user_add ( username , password , permissions , type ) payload = { :username => username , :password => password , :permissions => permissions , :type => type , :json => 1 } http_post ( :uri => "/users" , :fields => x_cookie , :data => payload ) end | Add user to server |
15,718 | def user_chpasswd ( user_id , password ) payload = { :password => password , :json => 1 } res = http_put ( :uri => "/users/#{user_id}/chpasswd" , :data => payload , :fields => x_cookie ) return res . code end | change password for user_id |
15,719 | def http_delete ( opts = { } ) ret = http_delete_low ( opts ) if ret . is_a? ( Hash ) and ret . has_key? ( 'error' ) and ret [ 'error' ] == 'Invalid Credentials' then authdefault ret = http_delete_low ( opts ) return ret else return ret end end | Perform HTTP delete method with uri data and fields |
15,720 | def http_get ( opts = { } ) raw_content = opts [ :raw_content ] || false ret = http_get_low ( opts ) if ! raw_content then if ret . is_a? ( Hash ) and ret . has_key? ( 'error' ) and ret [ 'error' ] == 'Invalid Credentials' then authdefault ret = http_get_low ( opts ) return ret else return ret end else return ret end e... | Perform HTTP get method with uri and fields |
15,721 | def http_post ( opts = { } ) if opts . has_key? ( :authenticationmethod ) then authzmethod = opts [ :authenticationmethod ] opts . delete ( :authenticationmethod ) end ret = http_post_low ( opts ) if ret . is_a? ( Hash ) and ret . has_key? ( 'error' ) and ret [ 'error' ] == 'Invalid Credentials' then if not authzmethod... | Perform HTTP post method with uri data body and fields |
15,722 | def parse_json ( body ) buf = { } begin buf = JSON . parse ( body ) rescue JSON :: ParserError end buf end | Perform JSON parsing of body |
15,723 | def build_url ( uri , opts = { } ) path = opts [ :path ] || '' query = opts [ :params ] || { } fragment = opts [ :fragment ] || { } url = Addressable :: URI . parse uri url . path = path url . query_values = query unless query . empty? url . fragment = Addressable :: URI . form_encode ( fragment ) unless fragment . emp... | convenience method to build response URI |
15,724 | def generate_urlsafe_key ( size = 48 ) seed = Time . now . to_i size = size - seed . to_s . length Base64 . encode64 ( "#{ OpenSSL::Random.random_bytes(size) }#{ seed }" ) . gsub ( / \W / , '' ) end | generates a random key of up to + size + bytes . The value returned is Base64 encoded with non - word characters removed . |
15,725 | def to_query ( params ) unless params . is_a? ( Hash ) raise "Expected Hash but got #{params.class.name}" end Addressable :: URI . form_encode ( params ) end | converts a hash to a URI query string |
15,726 | def [] ( property_name ) if get_property ( property_name ) . is_a? ( :: OData :: ComplexType ) get_property ( property_name ) else get_property ( property_name ) . value end rescue NoMethodError raise ArgumentError , "Unknown property: #{property_name}" end | Get property value |
15,727 | def []= ( property_name , value ) properties [ property_name . to_s ] . value = value rescue NoMethodError raise ArgumentError , "Unknown property: #{property_name}" end | Set property value |
15,728 | def to_xml builder = Nokogiri :: XML :: Builder . new do | xml | xml . entry ( 'xmlns' => 'http://www.w3.org/2005/Atom' , 'xmlns:data' => 'http://schemas.microsoft.com/ado/2007/08/dataservices' , 'xmlns:metadata' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' , 'xmlns:georss' => 'http://www.georss.... | Converts Entity to its XML representation . |
15,729 | def add ( service ) initialize_instance_variables @services << service if service . is_a? ( OData :: Service ) && ! @services . include? ( service ) @services_by_name [ service . name ] = @services . find_index ( service ) @services_by_url [ service . service_url ] = @services . find_index ( service ) end | Add a service to the Registry |
15,730 | def entity_sets @entity_sets ||= Hash [ metadata . xpath ( '//EntityContainer/EntitySet' ) . collect { | entity | [ entity . attributes [ 'EntityType' ] . value . gsub ( "#{namespace}." , '' ) , entity . attributes [ 'Name' ] . value ] } ] end | Returns a hash of EntitySet names keyed to their respective EntityType name |
15,731 | def associations @associations ||= Hash [ metadata . xpath ( '//Association' ) . collect do | association_definition | [ association_definition . attributes [ 'Name' ] . value , build_association ( association_definition ) ] end ] end | Returns the associations defined by the service |
15,732 | def execute ( url_chunk , additional_options = { } ) request = :: Typhoeus :: Request . new ( URI . escape ( "#{service_url}/#{url_chunk}" ) , options [ :typhoeus ] . merge ( { method : :get } ) . merge ( additional_options ) ) request . run response = request . response validate_response ( response ) response end | Execute a request against the service |
15,733 | def find_node ( results , node_name ) document = :: Nokogiri :: XML ( results . body ) document . remove_namespaces! document . xpath ( "//#{node_name}" ) . first end | Find a specific node in the given result set |
15,734 | def find_entities ( results ) document = :: Nokogiri :: XML ( results . body ) document . remove_namespaces! document . xpath ( '//entry' ) end | Find entity entries in a result set |
15,735 | def get_title_property_name ( entity_name ) node = metadata . xpath ( "//EntityType[@Name='#{entity_name}']/Property[@FC_TargetPath='SyndicationTitle']" ) . first node . nil? ? nil : node . attributes [ 'Name' ] . value end | Get the property used as the title for an entity from metadata . |
15,736 | def properties_for_entity ( entity_name ) type_definition = metadata . xpath ( "//EntityType[@Name='#{entity_name}']" ) . first raise ArgumentError , "Unknown EntityType: #{entity_name}" if type_definition . nil? properties_to_return = { } type_definition . xpath ( './Property' ) . each do | property_xml | property_nam... | Get the list of properties and their various options for the supplied Entity name . |
15,737 | def properties_for_complex_type ( type_name ) type_definition = metadata . xpath ( "//ComplexType[@Name='#{type_name}']" ) . first raise ArgumentError , "Unknown ComplexType: #{type_name}" if type_definition . nil? properties_to_return = { } type_definition . xpath ( './Property' ) . each do | property_xml | property_n... | Get list of properties and their various options for the supplied ComplexType name . |
15,738 | def each ( & block ) per_page = @each_batch_size page = 0 loop do entities = get_paginated_entities ( per_page , page ) break if entities . empty? entities . each do | entity | block_given? ? block . call ( entity ) : yield ( entity ) end page += 1 end end | Sets up the EntitySet to permit querying for the resources in the set . |
15,739 | def first ( count = 1 ) query = OData :: Query . new ( self ) . limit ( count ) result = service . execute ( query ) entities = service . find_entities ( result ) res = count == 1 ? single_entity_from_xml ( entities ) : multiple_entities_from_xml ( entities ) res end | Return the first n Entities for the set . If count is 1 it returns the single entity otherwise its an array of entities |
15,740 | def [] ( key ) entity = new_entity key_property = entity . get_property ( entity . primary_key ) key_property . value = key result = service . execute ( "#{name}(#{key_property.url_value})" ) entities = service . find_entities ( result ) single_entity_from_xml ( entities ) end | Find the Entity with the supplied key value . |
15,741 | def groups size @array = in_groups_of ( @number . to_s . reverse . split ( "" ) , size ) @array . reverse! @array . map! { | group | group . reverse . join ( "" ) . to_i } @array . reverse! power = 0 @array . inject ( { } ) do | o , digits | o [ power ] = digits power += size o end end | split into groups this gives us 1234567 = > 123 456 7 so we need to reverse first in stages |
15,742 | def [] ( property ) property_instance = @entity_set . new_entity . get_property ( property ) property_instance = property if property_instance . nil? OData :: Query :: Criteria . new ( property : property_instance ) end | Create a new Query for the provided EntitySet |
15,743 | def execute response = entity_set . service . execute ( self . to_s ) OData :: Query :: Result . new ( self , response ) end | Execute the query . |
15,744 | def template_dir external_templates = File . expand_path ( File . join ( config_data [ :template_dir ] , 'providers' , 'provider_template.rb.retrospec.erb' ) ) if File . exist? ( external_templates ) File . join ( config_data [ :template_dir ] , 'providers' ) else File . expand_path ( File . join ( File . dirname ( Fil... | retrospec will initaialize this class so its up to you to set any additional variables you need in the context in feed the templates . returns the path to the templates first looks inside the external templates directory for specific file then looks inside the gem path templates directory which is really only useful wh... |
15,745 | def type_file ( p_type = provider_type ) if TypeGenerator :: CORE_TYPES . include? ( p_type ) type_file = "puppet/type/#{p_type}.rb" else type_file = File . join ( type_dir , "#{p_type}.rb" ) end type_file end | returns the type file that the provider uses if the type file does not exist it assumes a core puppet type because we could potentially dealing with multiple |
15,746 | def create_tmp_module_path ( module_path ) fail 'ModulePathNotFound' unless module_path path = File . join ( tmp_modules_dir , module_dir_name ) unless File . exist? ( path ) FileUtils . ln_s ( module_path , path ) end path end | puts a symlink in that module directory that points back to the user supplied module path |
15,747 | def tmp_modules_dir if @tmp_modules_dir . nil? || ! File . exist? ( @tmp_modules_dir ) tmp_path = File . expand_path ( File . join ( temporary_environment_path , 'modules' ) ) FileUtils . mkdir_p ( tmp_path ) @tmp_modules_dir = tmp_path end @tmp_modules_dir end | creates a tmp module directory so puppet can work correctly |
15,748 | def request ( key , method ) instance = :: Puppet :: Indirector :: Indirection . instance ( :resource_type ) indirection_name = 'test' @request = :: Puppet :: Indirector :: Request . new ( indirection_name , method , key , instance ) @request . environment = puppet_environment @request end | creates a puppet resource request to be used indirectly |
15,749 | def render_template ( opts = { } ) template_file_path = File . expand_path ( TEMPLATE_PATH , __FILE__ ) template_file = File . read ( template_file_path ) erb_template = ERB . new ( template_file ) last_bootstrap_line = LAST_BOOTSTRAP_LINE generated_template = erb_template . result ( binding ) @log . debug "genereated ... | this is made public for ec2admin usage |
15,750 | def get_vpc_security_group_ids ( vpc_id , group_names ) group_map = { } @log . info "resolving security groups #{group_names} in #{vpc_id}" vpc = AWS :: EC2 :: VPC . new ( vpc_id , :ec2_endpoint => "ec2.#{@region}.amazonaws.com" ) vpc . security_groups . each do | sg | next if sg . vpc_id != vpc_id group_map [ sg . nam... | Resolve security group names to their ids in the given VPC |
15,751 | def runcmd @success = false @success = run logger . debug ( @lastcall . inspect ) unless @lastcall . nil? if logger logger . debug ( @result ) unless @result . nil? if logger @success end | Use this function to run the command line tool it will inherently use the options hash for all options That need to be specified on the command line |
15,752 | def find_fix ( result ) return unless result begin fix = ErrorCodes . search ( result ) @options . merge_notify! ( fix ) rescue Rubyipmi . logger . debug ( "Could not find fix for error code: \n#{result}" ) if logger raise "Could not find fix for error code: \n#{result}" end end | The findfix method acts like a recursive method and applies fixes defined in the errorcodes If a fix is found it is applied to the options hash and then the last run command is retried until all the fixes are exhausted or a error not defined in the errorcodes is found this must be overrided in the subclass as there are... |
15,753 | def find_fix ( result ) return unless result begin fix = ErrorCodes . search ( result ) @options . merge_notify! ( fix ) rescue raise "Could not find fix for error code: \n#{result}" end end | The findfix method acts like a recursive method and applies fixes defined in the errorcodes If a fix is found it is applied to the options hash and then the last run command is retried until all the fixes are exhausted or a error not defined in the errorcodes is found |
15,754 | def bootdevice ( device , reboot = false , persistent = false ) if config . bootdevices . include? ( device ) bootstatus = config . bootdevice ( device , persistent ) power . cycle if reboot && bootstatus else logger . error ( "Device with name: #{device} is not a valid boot device for host #{options['hostname']}" ) if... | set boot device from given boot device |
15,755 | def bootpxe ( reboot = false , persistent = false ) bootstatus = config . bootpxe ( persistent ) power . cycle if reboot && bootstatus end | set boot device to pxe with option to reboot |
15,756 | def bootdisk ( reboot = false , persistent = false ) bootstatus = config . bootdisk ( persistent ) power . cycle if reboot && bootstatus end | set boot device to disk with option to reboot |
15,757 | def bootcdrom ( reboot = false , persistent = false ) bootstatus = config . bootcdrom ( persistent ) power . cycle if reboot && bootstatus end | set boot device to cdrom with option to reboot |
15,758 | def bootbios ( reboot = false , persistent = false ) bootstatus = config . bootbios ( persistent ) power . cycle if reboot && bootstatus bootstatus end | boot into bios setup with option to reboot |
15,759 | def identifystatus options [ "cmdargs" ] = "chassis identify status" value = runcmd options . delete_notify ( "cmdargs" ) @result . chomp . split ( ":" ) . last . strip if value end | A currently unsupported method to retrieve the led status |
15,760 | def parse ( data ) return unless data data . each do | line | key , value = line . split ( ':' , 2 ) if key =~ / / if value =~ / \w \s \( \) / self [ :name ] = $~ [ 1 ] . strip . gsub ( / \ / , '_' ) . downcase end else key = key . strip . gsub ( / \ / , '_' ) . downcase . gsub ( / / , '' ) self [ key ] = value . str... | parse the fru information that should be an array of lines |
15,761 | def pipeline_filters ( options ) filters = [ HTML :: Pipeline :: MarkdownFilter , HTML :: Pipeline :: SanitizationFilter , HTML :: Pipeline :: ImageMaxWidthFilter , HTML :: Pipeline :: HttpsFilter , HTML :: Pipeline :: EmojiFilter , GithubMarkdownPreview :: Pipeline :: TaskListFilter ] if HtmlPreview :: SYNTAX_HIGHLIGH... | Compute the filters to use in the html - pipeline based on the given options |
15,762 | def update unless File . exist? ( @source_file ) raise FileNotFoundError . new ( "Source file deleted" ) end markdown_render = @preview_pipeline . call ( IO . read ( @source_file ) , @pipeline_context , { } ) [ :output ] . to_s preview_html = wrap_preview ( markdown_render ) File . open ( @preview_file , 'w' ) do | f |... | Update the preview file |
15,763 | def reset ( type = 'cold' ) if [ 'cold' , 'warm' ] . include? ( type ) key = "#{type}-reset" command ( key ) else logger . error ( "reset type: #{type} is not a valid choice, use warm or cold" ) if logger raise "reset type: #{type} is not a valid choice, use warm or cold" end end | reset the bmc device useful for debugging and troubleshooting |
15,764 | def reset ( type = 'cold' ) if [ 'cold' , 'warm' ] . include? ( type ) @options [ "cmdargs" ] = "bmc reset #{type}" value = runcmd @options . delete_notify ( "cmdargs" ) return value else logger . error ( "reset type: #{type} is not a valid choice, use warm or cold" ) if logger raise "reset type: #{type} is not a valid... | reset the bmc device useful for troubleshooting |
15,765 | def retrieve @options [ "cmdargs" ] = "bmc info" status = runcmd @options . delete_notify ( "cmdargs" ) subkey = nil if ! status raise @result else @result . lines . each do | line | item = line . split ( ':' ) key = item . first . strip value = item . last . strip if value . empty? subkey = key @bmcinfo [ subkey ] = [... | This function will get the bmcinfo and return a hash of each item in the info |
15,766 | def fanlist ( refreshdata = false ) refresh if refreshdata list . each_with_object ( { } ) { | ( name , sensor ) , flist | flist [ name ] = sensor if name =~ / / } end | returns a hash of fan sensors where the key is fan name and value is the sensor |
15,767 | def templist ( refreshdata = false ) refresh if refreshdata list . each_with_object ( { } ) do | ( name , sensor ) , tlist | tlist [ name ] = sensor if ( sensor [ :unit ] =~ / / || name =~ / / ) end end | returns a hash of sensors where each key is the name of the sensor and the value is the sensor |
15,768 | def checkout ( section = nil ) @options [ "checkout" ] = false @options [ "section" ] = section if section value = runcmd @options . delete_notify ( "checkout" ) @options . delete_notify ( "section" ) if section value end | This is the raw command to get the entire ipmi chassis configuration If you pass in a section you will get just the section |
15,769 | def parse ( data ) return unless data parsed_data = [ ] data . lines . each do | line | if line =~ / / if parsed_data . count != 0 new_fru = FruData . new ( parsed_data ) parsed_data = [ ] @list [ new_fru [ :name ] ] = new_fru end end parsed_data << line end return if parsed_data . count == 0 new_fru = FruData . new ( ... | parse the fru information |
15,770 | def write_spec ( file_path , force_write = false , dry_run = false , rails_mode = false ) class_or_module = RSpecKickstarter :: RDocFactory . get_rdoc_class_or_module ( file_path ) if class_or_module spec_path = get_spec_path ( file_path ) if force_write && File . exist? ( spec_path ) append_to_existing_spec ( class_or... | Writes new spec or appends to the existing spec . |
15,771 | def create_new_spec ( class_or_module , dry_run , rails_mode , file_path , spec_path ) methods_to_generate = class_or_module . method_list . select { | m | m . visibility == :public } c = class_or_module self_path = to_string_value_to_require ( file_path ) erb = RSpecKickstarter :: ERBFactory . new ( @full_template ) .... | Creates new spec . |
15,772 | def get_instance_for_new_spec ( rails_mode , target_path ) template = get_erb_template ( @custom_template , true , rails_mode , target_path ) ERB . new ( template , nil , '-' , '_new_spec_code' ) end | Returns ERB instance for creating new spec |
15,773 | def get_instance_for_appending ( rails_mode , target_path ) template = get_erb_template ( @custom_template , false , rails_mode , target_path ) ERB . new ( template , nil , '-' , '_additional_spec_code' ) end | Returns ERB instance for appeding lacking tests |
15,774 | def get_erb_template ( custom_template , is_full , rails_mode , target_path ) if custom_template custom_template elsif rails_mode && target_path . match ( / / ) get_rails_controller_template ( is_full ) elsif rails_mode && target_path . match ( / / ) get_rails_helper_template ( is_full ) else get_basic_template ( is_fu... | Returns ERB template |
15,775 | def percona_connection ( config ) mysql2_connection = mysql2_connection ( config ) config [ :username ] = 'root' if config [ :username ] . nil? connection_details = Departure :: ConnectionDetails . new ( config ) verbose = ActiveRecord :: Migration . verbose sanitizers = [ Departure :: LogSanitizers :: PasswordSanitize... | Establishes a connection to the database that s used by all Active Record objects . |
15,776 | def add_index ( columns , index_name = nil ) options = { name : index_name } if index_name migration . add_index ( table_name , columns , options || { } ) end | Adds an index in the specified columns through ActiveRecord . Note you can provide a name as well |
15,777 | def remove_index ( columns , index_name = nil ) options = if index_name { name : index_name } else { column : columns } end migration . remove_index ( table_name , options ) end | Removes the index in the given columns or by its name |
15,778 | def change_column ( column_name , definition ) attributes = column_attributes ( column_name , definition ) migration . change_column ( * attributes ) end | Change the column to use the provided definition through ActiveRecord |
15,779 | def add_unique_index ( columns , index_name = nil ) options = { unique : true } options . merge! ( name : index_name ) if index_name migration . add_index ( table_name , columns , options ) end | Adds a unique index on the given columns with the provided name if passed |
15,780 | def column ( name , definition ) @column ||= if definition . is_a? ( Symbol ) ColumnWithType . new ( name , definition ) else ColumnWithSql . new ( name , definition ) end end | Returns the instance of ActiveRecord column with the given name and definition |
15,781 | def column cast_type = ActiveRecord :: Base . connection . lookup_cast_type ( definition ) @column ||= self . class . column_factory . new ( name , default_value , cast_type , definition , null_value ) end | Returns the column instance with the provided data |
15,782 | def default_value match = if definition =~ / /i / /i . match ( definition ) else / \w /i . match ( definition ) end return unless match match [ 1 ] . downcase != 'null' ? match [ 1 ] : nil end | Gets the DEFAULT value the column takes as specified in the definition if any |
15,783 | def null_value match = / \w /i . match ( definition ) return true unless match match [ 2 ] . downcase == 'not' ? false : true end | Checks whether the column accepts NULL as specified in the definition |
15,784 | def run_in_process Open3 . popen3 ( full_command ) do | _stdin , stdout , _stderr , waith_thr | begin loop do IO . select ( [ stdout ] ) data = stdout . read_nonblock ( 8 ) logger . write_no_newline ( data ) end rescue EOFError ensure @status = waith_thr . value end end end | Runs the command in a separate process capturing its stdout and execution status |
15,785 | def validate_status! raise SignalError . new ( status ) if status . signaled? raise CommandNotFoundError if status . exitstatus == COMMAND_NOT_FOUND raise Error , error_message unless status . success? end | Validates the status of the execution |
15,786 | def all_options env_variable_options = UserOptions . new global_configuration_options = UserOptions . new ( Departure . configuration . global_percona_args ) options = env_variable_options . merge ( global_configuration_options ) . merge ( DEFAULT_OPTIONS ) options . to_a . join ( ' ' ) end | Returns all the arguments to execute pt - online - schema - change with |
15,787 | def adapt ( delta , numpoints , firsttime ) delta = firsttime ? ( delta / DAMP ) : ( delta >> 1 ) delta += ( delta / numpoints ) k = 0 while delta > ( ( ( BASE - TMIN ) * TMAX ) / 2 ) delta /= BASE - TMIN k += BASE end k + ( BASE - TMIN + 1 ) * delta / ( delta + SKEW ) end | Bias adaptation function |
15,788 | def encode ( input ) input_encoding = input . encoding input = input . encode ( Encoding :: UTF_8 ) . codepoints . to_a output = [ ] n = INITIAL_N delta = 0 bias = INITIAL_BIAS output = input . select { | char | char <= ASCII_MAX } h = b = output . length output << DELIMITER if b > 0 while h < input . length m = MAXINT... | Main encode function |
15,789 | def to_xml if signature? and signature . have_document? Gyoku . xml wsse_signature . merge! ( hash ) elsif username_token? && timestamp? Gyoku . xml wsse_username_token . merge! ( wsu_timestamp ) { | key , v1 , v2 | v1 . merge! ( v2 ) { | key , v1 , v2 | v1 . merge! ( v2 ) } } elsif username_token? Gyoku . xml wsse_use... | Returns the XML for a WSSE header . |
15,790 | def digest_password token = nonce + timestamp + password Base64 . encode64 ( Digest :: SHA1 . digest ( token ) ) . chomp! end | Returns the WSSE password encrypted for digest authentication . |
15,791 | def call ( severity , time , progname , msg ) return if msg . blank? || _silence? ( msg ) msg = [ _tagged ( time , :timestamp ) , _tagged ( progname , :progname ) , formatted_severity_tag ( severity ) , formatted_message ( severity , msg ) ] . compact . join ( " " ) super severity , time , progname , msg end | Called by the logger to prepare a message for output . |
15,792 | def formatted_severity_tag ( severity ) length = configuration [ :severity_tags ] [ :_length ] ||= begin configuration [ :severity_tags ] . reduce ( 0 ) { | l , ( k , _ ) | [ k . length , l ] . max } end return if length == 0 padded_severity = severity . ljust length formatted = if proc = configuration [ :severity_tags... | Formats the severity indicator prefixed before each line when writing to the log . |
15,793 | def format_time ( time , expected = 30 ) timef = time . uncolorize . to_f case when timef > expected * 2 then time . to_s . uncolorize . red when timef > expected then time . to_s . uncolorize . yellow else time end end | Formats a time value expressed in ms adding color to highlight times outside the expected range . |
15,794 | def create_empty_directories %w{ config/initializers lib spec } . each do | dir | empty_directory File . join ( @app_path , dir ) end empty_directory File . join ( @app_path , 'db/migrate' ) unless @database . empty? create_file File . join ( @app_path , "lib" , ".gitkeep" ) end | Create empty directories |
15,795 | def following_non_gem_lines all_lines [ ( index + 1 ) .. ( - 1 ) ] . reject { | x | x . strip . empty? || x . match ( GemBench :: TRASH_REGEX ) } . map ( & :strip ) . inject ( [ ] ) do | following_lines , next_line | break following_lines if next_line . match ( GEM_REGEX ) following_lines << next_line end end | returns an array with each line following the current line which is not a gem line |
15,796 | def requirements ( requirements ) requirements . map do | requirement | req_parts = requirement . split ( / \b \d / , 2 ) version = req_parts . last version . replace apply ( version ) req_parts . join end end | Apply to a list of requirements |
15,797 | def installed_versions return enum_for ( :installed_versions ) unless block_given? find_executables . each do | executable_path | version = detect_version ( executable_path ) break ( 2 ) if yield ( executable_path , version ) end end | Get all the installed versions of the api - compatible executables . If a block is given it yields once per found executable lazily . |
15,798 | def detect! installed = { } installed_versions . each do | path , version | installed [ path ] = version return path if ENV [ 'CLIVER_NO_VERIFY' ] return path if requirement_satisfied_by? ( version ) strict? end raise_not_found! if installed . empty? raise_version_mismatch! ( installed ) end | Detects an installed version of the executable that matches the requirements . |
15,799 | def check ( path ) raise FileNotFoundError , "#{path}: no such file" unless File . exist? ( path ) valid = false unless disable_extension_check unless check_filename ( path ) errors [ path ] = [ 'File extension must be .yaml or .yml' ] return valid end end File . open ( path , 'r' ) do | f | error_array = [ ] valid = c... | Check a single file |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.