idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
13,000 | def request ( method , * options ) response_handler = if options . last . is_a? ( Hash ) && options . last [ :handler ] options . last . delete ( :handler ) else handler end self . class . base_uri Jiralicious . uri before_request if respond_to? ( :before_request ) response = self . class . send ( method , * options ) ... | Main access method to request data from the Jira API |
13,001 | def update_hostgroup_list old_deployment_role_hostgroups = deployment_role_hostgroups . to_a new_deployment_role_hostgroups = layout . layout_roles . map do | layout_role | deployment_role_hostgroup = deployment_role_hostgroups . where ( :role_id => layout_role . role ) . first_or_initialize do | drh | drh . hostgroup ... | After setting or changing layout update the set of child hostgroups adding groups for any roles not already represented and removing others no longer needed . |
13,002 | def update ( details ) details . each do | k , v | send ( "#{k}=" , v ) end self . class . update ( version_key , details ) end | Updates a version |
13,003 | def get_secret if Jiralicious . oauth_secret . nil? IO . read ( Jiralicious . config_path + Jiralicious . oauth_secret_filename ) else Jiralicious . oauth_secret end end | returns the oauth_secret parameter or the file |
13,004 | def handler proc do | response | case response . code when 200 .. 204 response else message = response . body message = message [ "errorMessages" ] . join ( '\n' ) if message . is_a? ( Hash ) Jiralicious :: JiraError . new ( message ) end end end | Configures the default handler . This can be overridden in the child class to provide additional error handling . |
13,005 | def after_request ( response ) unless @authenticating if captcha_required ( response ) raise Jiralicious :: CaptchaRequired , "Captacha is required. Try logging into Jira via the web interface" elsif cookie_invalid ( response ) clear_session raise Jiralicious :: CookieExpired end end @authenticating = false end | Handles the response from the request |
13,006 | def login @authenticating = true handler = proc do | response | if response . code == 200 @session = response [ "session" ] @login_info = response [ "loginInfo" ] self . class . cookies ( session [ "name" ] => session [ "value" ] ) else clear_session case response . code when 401 then raise Jiralicious :: InvalidLogin ... | Authenticates the login |
13,007 | def logout handler = proc do if response . code == 204 clear_session else case response . code when 401 then raise Jiralicious :: NotLoggedIn , "Not logged in" else raise Jiralicious :: JiraError , response end end end request ( :delete , "/rest/auth/latest/session" , handler : handler ) end | Logs out of the API |
13,008 | def save if loaded? self . class . update ( @fields . format_for_update , jira_key ) else response = self . class . create ( @fields . format_for_create ) self . jira_key = response . parsed_response [ "key" ] end jira_key end | Saves the current Issue but does not update itself . |
13,009 | def lint_results bin = eslint_path raise 'eslint is not installed' unless bin return run_lint ( bin , '.' ) unless filtering ( ( git . modified_files - git . deleted_files ) + git . added_files ) . select { | f | f . end_with? '.js' } . map { | f | f . gsub ( "#{Dir.pwd}/" , '' ) } . map { | f | run_lint ( bin , f ) . ... | Get lint result regards the filtering option |
13,010 | def send_comment ( results ) dir = "#{Dir.pwd}/" results [ 'messages' ] . each do | r | filename = results [ 'filePath' ] . gsub ( dir , '' ) method = r [ 'severity' ] > 1 ? 'fail' : 'warn' send ( method , r [ 'message' ] , file : filename , line : r [ 'line' ] ) end end | Send comment with danger s warn or fail method . |
13,011 | def update ( details ) details . each do | k , v | send ( "#{k}=" , v ) end self . class . update ( component_key , details ) end | Updates a component |
13,012 | def method_missing ( meth , * args , & block ) if ! loaded? self . loaded = true reload send ( meth , * args , & block ) else super end end | Overrides the default method_missing check . This override is used in lazy loading to ensure that the requested field or method is truly unavailable . |
13,013 | def options VALID_OPTIONS . inject ( { } ) do | option , key | option . merge! ( key => send ( key ) ) end end | Pass options to set the values |
13,014 | def reset self . username = DEFAULT_USERNAME self . password = DEFAULT_PASSWORD self . uri = DEFAULT_URI self . api_version = DEFAULT_API_VERSION self . auth_type = DEFAULT_AUTH_TYPE self . project = nil self . oauth_secret = nil self . oauth_secret_filename = nil self . oauth_pass_phrase = nil self . oauth_consumer_ke... | Resets all attributes to default values |
13,015 | def load_yml ( yml_file , mode = nil ) if File . exist? ( yml_file ) yml_cfg = OpenStruct . new ( YAML . load_file ( yml_file ) ) if mode . nil? || mode =~ / /i yml_cfg . jira . each do | k , v | instance_variable_set ( "@#{k}" , v ) end else yml_cfg . send ( mode ) . each do | k , v | instance_variable_set ( "@#{k}" ,... | Loads the provided YML file . |
13,016 | def unassign_physical ( interface ) interface . ip = nil if interface . subnet . ipam? interface . subnet_id = nil unless interface . save @errors . push ( interface . errors . full_messages ) end end | if subnet has IP suggesting enabled we also clear the IP that was suggested this IP will be used for another interface |
13,017 | def load parsed = JSON . parse ( File . read ( SPECPATH ) ) structs = StructureContainer . new ( parsed [ 'PropertyTypes' ] ) parsed [ 'ResourceTypes' ] . each do | key , spec | match = key . match ( / \A \w \w \w \z / ) register ( match [ 1 ] , match [ 2 ] , match [ 3 ] , spec , structs . search ( key ) ) end end | loop through the specs and register each class |
13,018 | def find_each_with_progress ( options = { } ) Progress . start ( name . tableize , count ( options ) ) do find_each do | model | Progress . step do yield model end end end end | run find_each with progress |
13,019 | def find_in_batches_with_progress ( options = { } ) Progress . start ( name . tableize , count ( options ) ) do find_in_batches do | batch | Progress . step batch . length do yield batch end end end end | run find_in_batches with progress |
13,020 | def method_missing ( name , * args ) if ! valid_accessor? ( name ) super elsif self . class . prop? ( name . to_s ) self . class . build_property_reader ( name ) send ( name ) else self . class . build_property_writer ( name ) send ( name , args . first ) end end | Patches method_missing to include property accessors After the first method call builds the accessor methods to get a speed boost |
13,021 | def update ( properties , raw = false ) properties . each do | property , value | update_property ( property , value , raw ) end end | Update a set of properties defined by the given properties hash |
13,022 | def update_property ( property , value , raw = false ) property = property . to_s property = validate_property ( property , raw ) value = validate_value ( property , value , raw ) properties [ property ] = value end | Update an individual property on this resource |
13,023 | def find_by_path ( url , map = { } ) object = find_object_by_path ( url , map ) if object . is_a? ( Array ) object . map { | o | klass . new ( o . merge ( 'cloud_id' => cloud . id ) ) } elsif object [ 'id' ] klass . new ( object . merge ( 'cloud_id' => cloud . id ) ) else raise APIError . new ( object ) end end | Overide the function to set the cloud_id as the same as the scope |
13,024 | def open return if @connected socket = Thrift :: Socket . new ( @host , @port , @options [ :timeout ] ) if @options [ :kerberos ] @transport = SASLTransport . new ( socket , :GSSAPI , @options [ :kerberos ] ) elsif @options [ :sasl ] @transport = SASLTransport . new ( socket , :PLAIN , @options [ :sasl ] ) else @transp... | Open the connection if it s currently closed . |
13,025 | def execute ( query , query_options = { } ) raise ConnectionError . new ( "Connection closed" ) unless open? handle = send_query ( query , query_options ) check_result ( handle ) Cursor . new ( handle , @service ) end | Perform a query and return a cursor for iterating over the results . |
13,026 | def add ( name , resource , attributes = { } ) resources [ name ] = resource resource . update_attributes ( attributes ) if attributes . any? resource end | Add a resource to the stack and optionally set its attributes |
13,027 | def to_cf ( serializer = :json ) resources = static_resources . merge ( enumerable_resources ) case serializer when :json then JSON . pretty_generate ( resources ) when :yaml then YAML . dump ( resources ) end end | A string representation of the stack that s valid for CFN |
13,028 | def slice ( target , filters = { } , format , & block ) validate_target ( target ) validate_filters ( filters ) validate_format ( format ) begin target = File . directory? ( target ) ? CukeModeler :: Directory . new ( target ) : CukeModeler :: FeatureFile . new ( target ) rescue => e if e . message =~ / /i raise ( Argu... | Slices up the given location into individual test cases . |
13,029 | def insert ( index , key , value ) tmp = IIIF :: OrderedHash . new index = self . length + 1 + index if index < 0 if index < 0 m = "Index #{index} is too small for current length (#{length})" raise IndexError , m end if index > 0 i = 0 self . each do | k , v | tmp [ k ] = v self . delete ( k ) i += 1 break if i == inde... | Insert a new key and value at the suppplied index . |
13,030 | def remove_empties self . keys . each do | key | if ( self [ key ] . kind_of? ( Array ) && self [ key ] . empty? ) || self [ key ] . nil? self . delete ( key ) end end end | Delete any keys that are empty arrays |
13,031 | def camelize_keys self . keys . each_with_index do | key , i | if key != key . camelize ( :lower ) self . insert ( i , key . camelize ( :lower ) , self [ key ] ) self . delete ( key ) end end self end | Covert snake_case keys to camelCase |
13,032 | def snakeize_keys self . keys . each_with_index do | key , i | if key != key . underscore self . insert ( i , key . underscore , self [ key ] ) self . delete ( key ) end end self end | Covert camelCase keys to snake_case |
13,033 | def add_z ( bookings ) data3 = '0256' data3 += 'Z' sum = 0 bookings . each do | b | sum += b . value . divmod ( 100 ) [ 0 ] end data3 += '%015i' % sum data3 += '%015i' % bookings . count data3 += '%0221s' % '' raise "DTAUS: Längenfehler Z (#{data3.size} <> 256)\n" f ata3. s ize = 56 dta_string << data3 end | THE MAGICAL Z SEGMENT |
13,034 | def select new_instance = self . class . new if block_given? @data . each { | k , v | new_instance . data [ k ] = v if yield ( k , v ) } end return new_instance end | Returns a new instance consisting of entries for which the block returns true . Not that an enumerator is not available for the OrderedHash implementation |
13,035 | def bank_account_number = ( number ) raise ArgumentError . new ( 'Bank account number cannot be nil' ) if number . nil? nr_str = "#{number}" . gsub ( / \s / , '' ) raise ArgumentError . new ( 'Bank account number too long, max 10 allowed' ) if nr_str . length > 10 raise ArgumentError . new ( 'Bank account number cannot... | Cast given account number to integer . Strips spaces and leading zeros from the bank account number . DTA relies on integers for checksums and field values . |
13,036 | def time if Time . respond_to? ( :zone ) && Time . zone self . class . send ( :define_method , :time ) { Time . zone . now . to_s } else self . class . send ( :define_method , :time ) { Time . now . to_s } end time end | time redefines itself with a faster implementation since it gets called a lot . |
13,037 | def init ( key , value ) with_failure_grace ( value ) { @redis . set ( key , value ) if get ( key , nil ) . nil? } end | initialize key if not set |
13,038 | def get ( key , default = 0 ) with_failure_grace ( default ) { val = @redis . get ( key ) return default if val . nil? val . numeric? ? val . to_i : val } end | get key if exists otherwise 0 |
13,039 | def bandit_session_choose ( exp ) name = "bandit_#{exp}" . intern value = params [ name ] . nil? ? cookies . signed [ name ] : params [ name ] cookies . signed [ name ] = Bandit . get_experiment ( exp ) . choose ( value ) end | stick to one alternative for the entire browser session |
13,040 | def bandit_sticky_choose ( exp ) name = "bandit_#{exp}" . intern value = params [ name ] . nil? ? cookies . signed [ name ] : params [ name ] alternative = if Bandit . get_experiment ( exp ) . alternatives . include? ( value ) value else Bandit . get_experiment ( exp ) . choose ( value ) end cookies . permanent . signe... | stick to one alternative until user deletes cookies or changes browser |
13,041 | def sanitise_conf ( conf ) conf [ :username ] ||= 'admin' conf [ :password ] ||= 'admin' conf [ :protocol ] ||= 'http' conf [ :host ] ||= 'localhost' conf [ :port ] ||= 4502 conf [ :timeout ] ||= 300 conf [ :port ] = conf [ :port ] . to_i conf [ :timeout ] = conf [ :timeout ] . to_i conf [ :verify_ssl ] = conf [ :verif... | Initialise a Ruby AEM instance . |
13,042 | def config_property ( name , type , value ) RubyAem :: Resources :: ConfigProperty . new ( @client , name , type , value ) end | Create a config property instance . |
13,043 | def package ( group_name , package_name , package_version ) RubyAem :: Resources :: Package . new ( @client , group_name , package_name , package_version ) end | Create a package instance . |
13,044 | def part_key ( exp , alt , date_hour = nil ) parts = [ "participants" , exp . name , alt ] parts += [ date_hour . date , date_hour . hour ] unless date_hour . nil? make_key parts end | if date_hour is nil create key for total otherwise create key for hourly based |
13,045 | def unauthenticated_response ( errors ) realm = @options [ :realm ] || '' response_headers = { "WWW-Authenticate" => %Q(OAuth realm="#{realm}") , 'Content-Type' => 'application/json' } body = { 'errors' => errors } error_message = begin error_values = errors . values . inject ( [ ] , & :+ ) if error_values . size <= 1 ... | the response for an unauthenticated request . the argument will be a hash with the key errors whose value is a hash with string keys indicating attributes with errors and values being arrays of strings indicating error messages on the attribute key . |
13,046 | def bandit_simple_convert! ( exp , alt , count = 1 ) Bandit . get_experiment ( exp ) . convert! ( alt , count ) end | look mum no cookies |
13,047 | def bandit_session_convert! ( exp , alt = nil , count = 1 ) cookiename = "bandit_#{exp}" . intern cookiename_converted = "bandit_#{exp}_converted" . intern alt ||= cookies . signed [ cookiename ] unless alt . nil? or cookies . signed [ cookiename_converted ] Bandit . get_experiment ( exp ) . convert! ( alt , count ) co... | expects a session cookie deletes it will convert again |
13,048 | def bandit_sticky_convert! ( exp , alt = nil , count = 1 ) cookiename = "bandit_#{exp}" . intern cookiename_converted = "bandit_#{exp}_converted" . intern alt ||= cookies . signed [ cookiename ] unless alt . nil? or cookies . signed [ cookiename_converted ] cookies . permanent . signed [ cookiename_converted ] = "true"... | creates a _converted cookie prevents multiple conversions |
13,049 | def each_tags ( & block ) return enum_for ( :each_tags ) unless block_given? arr = [ ] 0 . step do | i | tag = tag_at ( i ) . tap ( & block ) arr << tag break if tag . header . d_tag == ELFTools :: Constants :: DT_NULL end arr end | Iterate all tags . |
13,050 | def tag_at ( n ) return if n < 0 @tag_at_map ||= { } return @tag_at_map [ n ] if @tag_at_map [ n ] dyn = Structs :: ELF_Dyn . new ( endian : endian ) dyn . elf_class = header . elf_class stream . pos = tag_start + n * dyn . num_bytes dyn . offset = stream . pos @tag_at_map [ n ] = Tag . new ( dyn . read ( stream ) , st... | Get the + n + - th tag . |
13,051 | def build_id section = section_by_name ( '.note.gnu.build-id' ) return nil if section . nil? note = section . notes . first return nil if note . nil? note . desc . unpack ( 'H*' ) . first end | Return the BuildID of ELF . |
13,052 | def each_sections ( & block ) return enum_for ( :each_sections ) unless block_given? Array . new ( num_sections ) do | i | section_at ( i ) . tap ( & block ) end end | Iterate all sections . |
13,053 | def sections_by_type ( type , & block ) type = Util . to_constant ( Constants :: SHT , type ) Util . select_by_type ( each_sections , type , & block ) end | Fetch all sections with specific type . |
13,054 | def each_segments ( & block ) return enum_for ( :each_segments ) unless block_given? Array . new ( num_segments ) do | i | segment_at ( i ) . tap ( & block ) end end | Iterate all segments . |
13,055 | def segments_by_type ( type , & block ) type = Util . to_constant ( Constants :: PT , type ) Util . select_by_type ( each_segments , type , & block ) end | Fetch all segments with specific type . |
13,056 | def offset_from_vma ( vma , size = 0 ) segments_by_type ( :load ) do | seg | return seg . vma_to_offset ( vma ) if seg . vma_in? ( vma , size ) end end | Get the offset related to file given virtual memory address . |
13,057 | def patches patch = { } loaded_headers . each do | header | header . patches . each do | key , val | patch [ key + header . offset ] = val end end patch end | The patch status . |
13,058 | def save ( filename ) stream . pos = 0 all = stream . read . force_encoding ( 'ascii-8bit' ) patches . each do | pos , val | all [ pos , val . size ] = val end IO . binwrite ( filename , all ) end | Apply patches and save as + filename + . |
13,059 | def loaded_headers explore = lambda do | obj | return obj if obj . is_a? ( :: ELFTools :: Structs :: ELFStruct ) return obj . map ( & explore ) if obj . is_a? ( Array ) obj . instance_variables . map do | s | explore . call ( obj . instance_variable_get ( s ) ) end end explore . call ( self ) . flatten end | bad idea .. |
13,060 | def parse ( inst , data ) :: HttpParser . http_parser_execute ( inst , @settings , data , data . length ) return inst . error? end | Parses data . |
13,061 | def call ( clazz , action , call_params ) resource_name = clazz . name . downcase . sub ( 'rubyaem::resources::' , '' ) resource = @spec [ resource_name ] action_spec = resource [ 'actions' ] [ action ] api = @apis [ action_spec [ 'api' ] . to_sym ] operation = action_spec [ 'operation' ] params = [ ] required_params =... | Initialise a client . |
13,062 | def add_optional_param ( key , value , params , call_params ) if ! value params [ - 1 ] [ key . to_sym ] = call_params [ key . to_sym ] if call_params . key? key . to_sym elsif value . class == String case value when '__FILE_PACKAGE__' file_path = "#{call_params[:file_path]}/#{call_params[:package_name]}-#{call_params[... | Add optional param into params list . |
13,063 | def handle ( response , responses_spec , call_params ) if responses_spec . key? ( response . status_code ) response_spec = responses_spec [ response . status_code ] handler = response_spec [ 'handler' ] Handlers . send ( handler , response , response_spec , call_params ) else message = "Unexpected response\nstatus code... | Handle a response based on status code and a given list of response specifications . If none of the response specifications contains the status code a failure result will then be returned . |
13,064 | def save if data = session [ Evercookie . hash_name_for_get ] if data [ :key ] && cookies [ data [ :key ] ] session [ Evercookie . hash_name_for_saved ] = { data [ :key ] => cookies [ data [ :key ] ] } end end render nothing : true end | Saves current evercookie value to session |
13,065 | def ec_png if not cookies [ Evercookie . cookie_png ] . present? render :nothing => true , :status => 304 return true end response . headers [ "Content-Type" ] = "image/png" response . headers [ "Last-Modified" ] = "Wed, 30 Jun 2010 21:36:48 GMT" response . headers [ "Expires" ] = "Tue, 31 Dec 2030 23:30:45 GMT" respon... | Renders png image with encoded evercookie value in it |
13,066 | def ec_etag if not cookies [ Evercookie . cookie_etag ] . present? render :text => request . headers [ 'If-None-Match' ] || '' , :status => 304 return true end puts "cache value (#{Evercookie.cookie_etag}): #{cookies[Evercookie.cookie_etag]}" response . headers [ "Etag" ] = cookies [ Evercookie . cookie_etag ] render t... | Renders page with etag header for evercookie js script |
13,067 | def ec_cache if not cookies [ Evercookie . cookie_cache ] . present? render :nothing => true , :status => 304 return true end puts "cache value (#{Evercookie.cookie_cache}): #{cookies[Evercookie.cookie_cache]}" response . headers [ "Content-Type" ] = "text/html" response . headers [ "Last-Modified" ] = "Wed, 30 Jun 201... | Renders page with cache header for evercookie js script |
13,068 | def each_notes return enum_for ( :each_notes ) unless block_given? @notes_offset_map ||= { } cur = note_start notes = [ ] while cur < note_start + note_total_size stream . pos = cur @notes_offset_map [ cur ] ||= create_note ( cur ) note = @notes_offset_map [ cur ] name_size = Util . align ( note . header . n_namesz , 2... | Iterate all notes in a note section or segment . |
13,069 | def config_method_not_implemented caller_name = caller [ 0 ] . match ( %r( ) ) [ 1 ] using_middleware = caller . any? { | l | l =~ %r( ) } message = "method \##{caller_name} must be implemented on a module of oauth config methods, which is " + begin if using_middleware "passed to OAuthenticator::RackAuthenticator using... | raise a nice error message for a method that needs to be implemented on a module of config methods |
13,070 | def error error = ( self [ :error_upgrade ] & 0b1111111 ) return nil if error == 0 err = :: HttpParser . err_name ( error ) [ 4 .. - 1 ] klass = ERRORS [ err . to_sym ] err = "#{::HttpParser.err_desc(error)} (#{err})" return klass . nil? ? Error :: UNKNOWN . new ( err ) : klass . new ( err ) end | Returns the error that occurred during processing . |
13,071 | def call ( request_env ) media_type = Rack :: Request . new ( 'CONTENT_TYPE' => request_env [ :request_headers ] [ 'Content-Type' ] ) . media_type request_attributes = { :request_method => request_env [ :method ] , :uri => request_env [ :url ] , :media_type => media_type , :body => request_env [ :body ] } if METHODS_WI... | do the thing |
13,072 | def signature_base parts = [ normalized_request_method , base_string_uri , normalized_request_params_string ] parts . map { | v | OAuthenticator . escape ( v ) } . join ( '&' ) end | signature base string for signing . section 3 . 4 . 1 |
13,073 | def base_string_uri Addressable :: URI . parse ( @attributes [ 'uri' ] . to_s ) . tap do | uri | uri . scheme = uri . scheme . downcase if uri . scheme uri . host = uri . host . downcase if uri . host uri . normalize! uri . fragment = nil uri . query = nil end . to_s end | section 3 . 4 . 1 . 2 |
13,074 | def normalized_request_params_string normalized_request_params . map { | kv | kv . map { | v | OAuthenticator . escape ( v ) } } . sort . map { | p | p . join ( '=' ) } . join ( '&' ) end | section 3 . 4 . 1 . 3 . 2 |
13,075 | def normalized_request_params query_params + protocol_params . reject { | k , v | %w( realm oauth_signature ) . include? ( k ) } . to_a + entity_params end | section 3 . 4 . 1 . 3 |
13,076 | def parse_form_encoded ( data ) data . split ( / / ) . map do | pair | key , value = pair . split ( '=' , 2 ) . map { | v | CGI :: unescape ( v ) } [ key , value ] unless [ nil , '' ] . include? ( key ) end . compact end | like CGI . parse but it keeps keys without any value . doesn t keep blank keys though . |
13,077 | def read_body body = @attributes [ 'body' ] if body . nil? '' elsif body . is_a? ( String ) body elsif body . respond_to? ( :read ) && body . respond_to? ( :rewind ) body . rewind body . read . tap do body . rewind end else raise TypeError , "Body must be a String or something IO-like (responding to #read and #rewind).... | reads the request body be it String or IO |
13,078 | def rsa_sha1_signature private_key = OpenSSL :: PKey :: RSA . new ( @attributes [ 'consumer_secret' ] ) Base64 . encode64 ( private_key . sign ( OpenSSL :: Digest :: SHA1 . new , signature_base ) ) . gsub ( / \n / , '' ) end | signature with method RSA - SHA1 . section 3 . 4 . 3 |
13,079 | def hmac_sha1_signature secret = plaintext_signature Base64 . encode64 ( OpenSSL :: HMAC . digest ( OpenSSL :: Digest :: SHA1 . new , secret , signature_base ) ) . gsub ( / \n / , '' ) end | signature with method HMAC - SHA1 . section 3 . 4 . 2 |
13,080 | def bash ( command = nil ) Tempfile . open ( "tetra-history" ) do | history_file | Tempfile . open ( "tetra-bashrc" ) do | bashrc_file | kit = Tetra :: Kit . new ( @project ) ant_path = kit . find_executable ( "ant" ) ant_in_kit = ant_path != nil ant_commandline = Tetra :: Ant . commandline ( @project . full_path , ant... | runs bash in a subshell returns list of commands that were run in the session |
13,081 | def bitlbee ( port , nick , password , use_ssl = false ) Bitlbee . new ( port , nick , password , use_ssl ) end | Serverspec Type method for Bitlbee |
13,082 | def commit_directories ( directories , message ) log . debug "committing with message: #{message}" Dir . chdir ( @directory ) do directories . each do | directory | run ( "git rm -r --cached --ignore-unmatch #{directory}" ) run ( "git add #{directory}" ) end run ( "git commit --allow-empty -F -" , false , message ) end... | adds all files in the specified directories removes all files not in the specified directories commits with message |
13,083 | def commit_file ( path , message ) Dir . chdir ( @directory ) do log . debug "committing path #{path} with message: #{message}" run ( "git add #{path}" ) run ( "git commit --allow-empty -F -" , false , message ) end end | commits one single file |
13,084 | def revert_directories ( directories , id ) Dir . chdir ( @directory ) do directories . each do | directory | run ( "git checkout -f #{id} -- #{directory}" ) files_in_commit = run ( "git ls-tree --name-only -r #{id} -- #{directory}" ) . split ( "\n" ) files_in_head = run ( "git ls-tree --name-only -r HEAD -- #{director... | reverts multiple directories contents as per specified id |
13,085 | def disable_special_files ( path ) Dir . chdir ( File . join ( @directory , path ) ) do Find . find ( "." ) do | file | next unless file =~ / \. / FileUtils . mv ( file , "#{file}_disabled_by_tetra" ) end end end | renames git special files to disable them |
13,086 | def merge_with_id ( path , new_path , id ) Dir . chdir ( @directory ) do run ( "git show #{id}:#{path} > #{path}.old_version" ) conflict_count = 0 begin run ( "git merge-file #{path} #{path}.old_version #{new_path} \ -L \"newly generated\" \ -L \"previously generated\" \ -L ... | 3 - way merges the git file at path with the one in new_path assuming they have a common ancestor at the specified id returns the conflict count |
13,087 | def changed_files ( directory , id ) Dir . chdir ( @directory ) do tracked_files = [ ] begin tracked_files += run ( "git diff-index --name-only #{id} -- #{directory}" ) . split rescue ExecutionFailed => e raise e if e . status != 1 end untracked_files = run ( "git ls-files --exclude-standard --others -- #{directory}" )... | returns the list of files changed from since_id including changes in the working tree and staging area |
13,088 | def archive ( directory , id , destination_path ) Dir . chdir ( @directory ) do FileUtils . mkdir_p ( File . dirname ( destination_path ) ) run ( "git archive --format=tar #{id} -- #{directory} | xz -9e > #{destination_path}" ) end destination_path end | archives version id of directory in destination_path |
13,089 | def configure_log_level ( v , vv , vvv ) if vvv log . level = :: Logger :: DEBUG elsif vv log . level = :: Logger :: INFO elsif v log . level = :: Logger :: WARN else log . level = :: Logger :: ERROR end end | maps verbosity options to log level |
13,090 | def bypass_parsing ( args ) log . level = :: Logger :: WARN if args . delete "--verbose" log . level = :: Logger :: INFO if args . delete "--very-verbose" log . level = :: Logger :: DEBUG if args . delete "--very-very-verbose" @options = args end | override default option parsing to pass options to other commands |
13,091 | def format_path ( path , project ) full_path = ( if Pathname . new ( path ) . relative? File . join ( project . full_path , path ) else path end ) Pathname . new ( full_path ) . relative_path_from ( Pathname . new ( Dir . pwd ) ) end | generates a version of path relative to the current directory |
13,092 | def checking_exceptions yield rescue Errno :: EACCES => e $stderr . puts e rescue Errno :: ENOENT => e $stderr . puts e rescue Errno :: EEXIST => e $stderr . puts e rescue NoProjectDirectoryError => e $stderr . puts "#{e.directory} is not a tetra project directory, see \"tetra init\"" rescue GitAlreadyInitedError $stde... | handles most fatal exceptions |
13,093 | def process_map output = ` ` processes = { } output . split ( "\n" ) . each do | line | if result = line . match ( / \d \s \d / ) parent = result [ 1 ] . to_i child = result [ 2 ] . to_i processes [ parent ] ||= [ ] processes [ parent ] << child end end processes end | Generates a map of parent process and child processes . This method will currently only work on unix . |
13,094 | def read_io ( io ) data = "" while true begin if Platform . windows? results = IO . select ( [ io ] , nil , nil , 0.1 ) break if ! results || results [ 0 ] . empty? data << io . readpartial ( READ_CHUNK_SIZE ) else data << io . read_nonblock ( READ_CHUNK_SIZE ) end rescue Exception => e breakable = false if e . is_a? (... | Reads data from an IO object while it can returning the data it reads . When it encounters a case when it can t read anymore it returns the data . |
13,095 | def virtualenv? pip_path = :: File . join ( @name , 'bin' , 'pip' ) python_path = :: File . join ( @name , 'bin' , 'python' ) act_path = :: File . join ( @name , 'bin' , 'activate' ) cmd = "grep -q 'export VIRTUAL_ENV' #{act_path}" @runner . check_file_is_executable ( pip_path , 'owner' ) and @runner . check_file_is_ex... | Test whether this appears to be a working venv |
13,096 | def run_interactive ( command ) log . debug "running `#{command}`" success = system ( { } , command ) log . debug "`#{command}` exited with success #{success}" fail ExecutionFailed . new ( command , $CHILD_STATUS , nil , nil ) unless success end | runs an interactive executable in a subshell |
13,097 | def merge_new_content ( new_content , path , comment , kind ) from_directory do log . debug "merging new content to #{path} of kind #{kind}" already_existing = File . exist? ( path ) generated_comment = "tetra: generated-#{kind}" whole_comment = [ comment , generated_comment ] . join ( "\n\n" ) if already_existing unle... | replaces content in path with new_content commits using comment and 3 - way merges new and old content with the previous version of file of the same kind if it exists . returns the number of conflicts |
13,098 | def src_archive from_directory do Find . find ( File . join ( "packages" , name ) ) do | file | if File . file? ( file ) && file . match ( / \. / ) . nil? return File . basename ( file ) end end nil end end | returns the name of the source archive file if any |
13,099 | def authenticate! ( options = { } , connection = self . connection ) creds = options . to_json connection . post ( '/auth' , { } , :body => creds ) @creds = creds true rescue Docker :: Error :: ServerError , Docker :: Error :: UnauthorizedError raise Docker :: Error :: AuthenticationError end | Login to the Docker registry . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.