idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
14,300 | def erase children . each { | c | c . erase } @win . werase if @win component . component . erase if cdk? && component? && component . init? end | Erase window drawing area |
14,301 | def no_border! @win . border ( ' ' . ord , ' ' . ord , ' ' . ord , ' ' . ord , ' ' . ord , ' ' . ord , ' ' . ord , ' ' . ord ) end | Remove Border around window |
14,302 | def sync_getch return self . getch unless sync_enabled? c = - 1 while c == - 1 && ! shutdown? c = self . getch run_sync! end c end | Normal getch unless sync enabled in which case timeout will be checked & components synchronized |
14,303 | def colors = ( c ) @colors = c . is_a? ( ColorPair ) ? c : ColorPair . for ( c ) . first @win . bkgd ( Ncurses . COLOR_PAIR ( @colors . id ) ) unless @win . nil? component . colors = @colors if component? children . each { | ch | ch . colors = c } end | Set window color |
14,304 | def dimensions rows = [ ] cols = [ ] @win . getmaxyx ( rows , cols ) rows = rows . first cols = cols . first [ rows , cols ] end | Return window dimensions as an array containing rows & cols |
14,305 | def next_ip ( arg ) octets = arg . split ( / \. / , 4 ) . map ( & :to_i ) octets [ 3 ] += 1 raise "out of ips!" if octets [ 3 ] > 255 return octets . map ( & :to_s ) . join ( "." ) end | Gets the next unallocated IP given an IP to start with . |
14,306 | def sanitize! self . class . sanitizable_attributes . each do | attr_name | cleaned_text = process_text_via_sanitization_method ( self . send ( attr_name ) , attr_name ) self . send ( ( attr_name . to_s + '=' ) , cleaned_text ) end end | sanitize! is the method that is called when a model is saved . It can be called to manually sanitize attributes . |
14,307 | def factorygirl_attributes symbolize_attributes! @attributes . each do | key , value | next unless respond_to? ( method = method_name ( key ) ) if ( result = send method , value ) || value . nil? @attributes [ key ] = result if @attributes . key? key else @attributes . delete key end end end | Returns the FactoryGirl version of this Creator s attributes |
14,308 | def add_provider ( provider , * args ) unless provider . respond_to? ( :instance_methods ) && provider . instance_methods . include? ( :lookup ) raise ArgumentError , "the given provider does not respond to lookup" end @provider << provider . new ( * args ) end | Adds a provider to the chain . Providers are tried in the order they are added so the order is important . |
14,309 | def lookup ( setting , * args ) setting = SettingPath . new setting if setting . is_a? String @provider . each do | provider | begin return special_value_or_string ( provider . lookup ( setting . clone , * args ) ) rescue SettingNotFoundError ; end end nil end | Tries all providers in the order they were added to provide a response for setting . |
14,310 | def build_dir ( src_dir , obj_dir ) if src_dir . is_a? ( String ) src_dir = src_dir . gsub ( "\\" , "/" ) . sub ( %r{ } , "" ) end @build_dirs . unshift ( [ src_dir , obj_dir ] ) end | Specify a build directory for this Environment . |
14,311 | def process cache = Cache . instance failure = nil begin while @job_set . size > 0 or @threaded_commands . size > 0 if failure @job_set . clear! job = nil else targets_still_building = @threaded_commands . map do | tc | tc . build_operation [ :target ] end job = @job_set . get_next_job_to_run ( targets_still_building )... | Build all build targets specified in the Environment . |
14,312 | def expand_varref ( varref , extra_vars = nil ) vars = if extra_vars . nil? @varset else @varset . merge ( extra_vars ) end lambda_args = [ env : self , vars : vars ] vars . expand_varref ( varref , lambda_args ) end | Expand a construction variable reference . |
14,313 | def execute ( short_desc , command , options = { } ) print_builder_run_message ( short_desc , command ) env_args = options [ :env ] ? [ options [ :env ] ] : [ ] options_args = options [ :options ] ? [ options [ :options ] ] : [ ] system ( * env_args , * Rscons . command_executer , * command , * options_args ) . tap do ... | Execute a builder command . |
14,314 | def method_missing ( method , * args ) if @builders . has_key? ( method . to_s ) target , sources , vars , * rest = args vars ||= { } unless vars . is_a? ( Hash ) or vars . is_a? ( VarSet ) raise "Unexpected construction variable set: #{vars.inspect}" end builder = @builders [ method . to_s ] target = expand_path ( exp... | Define a build target . |
14,315 | def depends ( target , * user_deps ) target = expand_varref ( target . to_s ) user_deps = user_deps . map { | ud | expand_varref ( ud ) } @user_deps [ target ] ||= [ ] @user_deps [ target ] = ( @user_deps [ target ] + user_deps ) . uniq build_after ( target , user_deps ) end | Manually record a given target as depending on the specified files . |
14,316 | def build_sources ( sources , suffixes , cache , vars ) sources . map do | source | if source . end_with? ( * suffixes ) source else converted = nil suffixes . each do | suffix | converted_fname = get_build_fname ( source , suffix ) if builder = find_builder_for ( converted_fname , source , [ ] ) converted = run_builde... | Build a list of source files into files containing one of the suffixes given by suffixes . |
14,317 | def register_builds ( target , sources , suffixes , vars , options = { } ) options [ :features ] ||= [ ] @registered_build_dependencies [ target ] ||= Set . new sources . map do | source | if source . end_with? ( * suffixes ) source else output_fname = nil suffixes . each do | suffix | attempt_output_fname = get_build_... | Find and register builders to build source files into files containing one of the suffixes given by suffixes . |
14,318 | def run_builder ( builder , target , sources , cache , vars , options = { } ) vars = @varset . merge ( vars ) build_operation = { builder : builder , target : target , sources : sources , cache : cache , env : self , vars : vars , setup_info : options [ :setup_info ] } call_build_hooks = lambda do | sec | @build_hooks ... | Invoke a builder to build the given target based on the given sources . |
14,319 | def expand_path ( path ) if Rscons . phony_target? ( path ) path elsif path . is_a? ( Array ) path . map do | path | expand_path ( path ) end else path . sub ( %r{ \^ \\ } , @build_root ) . gsub ( "\\" , "/" ) end end | Expand a path to be relative to the Environment s build root . |
14,320 | def shell ( command ) shell_cmd = if self [ "SHELL" ] flag = self [ "SHELLFLAG" ] || ( self [ "SHELL" ] == "cmd" ? "/c" : "-c" ) [ self [ "SHELL" ] , flag ] else Rscons . get_system_shell end IO . popen ( [ * shell_cmd , command ] ) do | io | io . read end end | Execute a command using the system shell . |
14,321 | def merge_flags ( flags ) flags . each_pair do | key , val | if self [ key ] . is_a? ( Array ) and val . is_a? ( Array ) self [ key ] += val else self [ key ] = val end end end | Merge construction variable flags into this Environment s construction variables . |
14,322 | def dump varset_hash = @varset . to_h varset_hash . keys . sort_by ( & :to_s ) . each do | var | var_str = var . is_a? ( Symbol ) ? var . inspect : var Ansi . write ( $stdout , :cyan , var_str , :reset , " => #{varset_hash[var].inspect}\n" ) end end | Print the Environment s construction variables for debugging . |
14,323 | def print_builder_run_message ( short_description , command ) case @echo when :command if command . is_a? ( Array ) message = command_to_s ( command ) elsif command . is_a? ( String ) message = command elsif short_description . is_a? ( String ) message = short_description end when :short message = short_description if ... | Print the builder run message depending on the Environment s echo mode . |
14,324 | def add_target ( target , builder , sources , vars , args ) setup_info = builder . setup ( target : target , sources : sources , env : self , vars : vars ) @job_set . add_job ( builder : builder , target : target , sources : sources , vars : vars , setup_info : setup_info ) end | Add a build target . |
14,325 | def start_threaded_command ( tc ) print_builder_run_message ( tc . short_description , tc . command ) env_args = tc . system_env ? [ tc . system_env ] : [ ] options_args = tc . system_options ? [ tc . system_options ] : [ ] system_args = [ * env_args , * Rscons . command_executer , * tc . command , * options_args ] tc ... | Start a threaded command in a new thread . |
14,326 | def wait_for_threaded_commands ( options = { } ) options [ :which ] ||= @threaded_commands threads = options [ :which ] . map ( & :thread ) if finished_thread = find_finished_thread ( threads , options [ :nonblock ] ) threaded_command = @threaded_commands . find do | tc | tc . thread == finished_thread end @threaded_co... | Wait for threaded commands to complete . |
14,327 | def find_finished_thread ( threads , nonblock ) if nonblock threads . find do | thread | ! thread . alive? end else if threads . empty? raise "No threads to wait for" end ThreadsWait . new ( * threads ) . next_wait end end | Check if any of the requested threads are finished . |
14,328 | def find_builder_for ( target , source , features ) @builders . values . find do | builder | features_met? ( builder , features ) and builder . produces? ( target , source , self ) end end | Find a builder that meets the requested features and produces a target of the requested name . |
14,329 | def features_met? ( builder , features ) builder_features = builder . features features . all? do | feature | want_feature = true if feature =~ / / want_feature = false feature = $1 end builder_has_feature = builder_features . include? ( feature ) want_feature ? builder_has_feature : ! builder_has_feature end end | Determine if a builder meets the requested features . |
14,330 | def answer_for ( options , q , default = nil ) case @format when :bash answer = DEFAULT_ANSWERS [ q ] answers = options [ :answers ] when :hiera answer = DEFAULT_HIERA_ANSWERS [ q ] answers = flatten_keys_to_joined_string ( options [ :answers ] ) if options [ :answers ] else raise NotImplementedError , "Don't know how ... | The answer value for a provided question . Use the user answer when available otherwise return the default . |
14,331 | def build_knife_config FileUtils . mkdir_p ( chef_config_path ) File . binwrite ( knife_config_path , ERB . new ( knife_config_template ) . result ( binding ) ) end | Writes out a knife . rb based on the settings in this configuration . Uses the knife_config_path and chef_config_path to determine where to write it . |
14,332 | def upload_attachment ( storage , attachment , raise_exceptions ) begin unless attachment . respond_to? ( :path ) && attachment . respond_to? ( :read ) raise "file does not exist: #{attachment}" unless File . exists? ( attachment ) attachment = File . open ( attachment , 'rb' ) end key_template = "#{storage[:upload_pat... | upload a single attachment and return the data for the note_attachments returns nil and provides an error in case the attachment upload failed |
14,333 | def itrp_upload ( itrp , key_template , key , attachment ) uri = itrp [ :upload_uri ] =~ / \/ / ? itrp [ :upload_uri ] : itrp [ :upload_uri ] . gsub ( '/attachments' , '/v1/attachments' ) response = send_file ( uri , { file : attachment , key : key_template } , @client . send ( :expand_header ) ) raise "ITRP upload to ... | upload the file directly to ITRP |
14,334 | def sanitize_attributes ( * args , & block ) if ( args . last && args . last . is_a? ( Hash ) ) options = args . pop end options ||= { } unless @sanitize_hook_already_defined include InstanceMethods extend ClassMethods if options [ :before_validation ] before_validation :sanitize! else before_save :sanitize! end cattr_... | sanitize_attributes is used to define sanitizable attributes within a model definition . |
14,335 | def search_local ( name ) if variable = variables [ name ] return variable . nested_reference end if variable = search_scopes ( name ) variables [ name ] = variable return variable . nested_reference end end | Returns a cached reference to a variable or searches all surrounding scopes for a variable . If no variable is found it returns nil and a nested scope will create the variable in itself . |
14,336 | def format_currency ( amount , currency ) currency = currency . upcase ( ) amount = amount / 100.0 options = { separator : currency == 'EUR' ? ',' : '.' , delimiter : currency == 'EUR' ? '.' : ',' , format : currency == 'EUR' ? '%n %u' : '%u%n' , } case currency when 'EUR' options [ :unit ] = '€' when 'LBP' options [ ... | nicely formats the amount and currency |
14,337 | def format ( win ) win . win . attron ( nc ) yield win . win . attroff ( nc ) end | Encapsulates window operation in color pair attribute |
14,338 | def schedule_provision ( group_name , provisioner , dependencies = [ ] ) return nil if vm_groups [ group_name ] provisioner = [ provisioner ] unless provisioner . kind_of? ( Array ) provisioner . each { | x | x . name = group_name } vm_groups [ group_name ] = provisioner unless dependencies . all? { | x | vm_groups . h... | Schedule a group of VMs for provision . This takes a group name which is a string an array of provisioner objects and a list of string dependencies . If anything in the dependencies list hasn t been pre - declared it refuses to continue . |
14,339 | def wait_for ( * dependencies ) return nil if @serial return nil if dependencies . empty? dep_set = dependencies . to_set until dep_set & solved == dep_set sleep 1 @solver_thread . join unless @solver_thread . alive? end end | Sleep until this list of dependencies are resolved . In parallel mode will raise if an exeception occurred while waiting for these resources . In serial mode wait_for just returns nil . |
14,340 | def with_timeout ( do_loop = true ) Timeout . timeout ( 10 ) do dead_working = @working . values . reject ( & :alive? ) if dead_working . size > 0 dead_working . map ( & :join ) end yield end rescue TimeoutError retry if do_loop end | Helper method for scheduling . Wraps items in a timeout and immediately checks all running workers for exceptions which are immediately bubbled up if there are any . If do_loop is true it will retry the timeout . |
14,341 | def service_resolved_waiters @waiters_mutex . synchronize do @waiters . replace ( @waiters . to_set - ( @working . keys . to_set + solved ) ) end waiter_iteration = lambda do @waiters . each do | group_name | if ( solved . to_set & vm_dependencies [ group_name ] ) . to_a == vm_dependencies [ group_name ] if_debug do $s... | This method determines what waiters or provisioners that cannot provision yet because of unresolved dependencies can be executed . |
14,342 | def layout_containing ( component ) return self if children . include? ( component ) found = nil children . each { | c | next if found if c . kind_of? ( Layout ) found = c unless c . layout_containing ( component ) . nil? end } found end | Return layout containing component If coordinates are contained in a child in current layout |
14,343 | def contains? ( child ) children . any? { | c | ( c . kind_of? ( Layout ) && c . contains? ( child ) ) || c == child } end | Return boolean indicating if layout contains specified child |
14,344 | def add_child ( h = { } ) c = nil if h . key? ( :component ) c = h [ :component ] h = { :rows => c . requested_rows + c . extra_padding , :cols => c . requested_cols + c . extra_padding } . merge ( h ) end raise ArgumentError , "must specify x/y" unless h . key? ( :x ) && h . key? ( :y ) raise ArgumentError , "must spe... | Create new child window and add it to layout |
14,345 | def select ( & predicate ) filter ( "select" ) do | yielder | each do | element | yielder . call ( element ) if yield ( element ) end end end | Select elements using a predicate block . |
14,346 | def uniq filter ( "uniq" ) do | yielder | seen = Set . new each do | element | key = if block_given? yield element else element end yielder . call ( element ) if seen . add? ( key ) end end end | Remove duplicate values . |
14,347 | def take ( n ) filter ( "take" ) do | yielder , all_done | if n > 0 each_with_index do | element , index | yielder . call ( element ) throw all_done if index + 1 == n end end end end | Select the first n elements . |
14,348 | def take_while ( & predicate ) filter ( "take_while" ) do | yielder , all_done | each do | element | throw all_done unless yield ( element ) yielder . call ( element ) end end end | Select elements while a predicate returns true . |
14,349 | def drop ( n ) filter ( "drop" ) do | yielder | each_with_index do | element , index | next if index < n yielder . call ( element ) end end end | Ignore the first n elements . |
14,350 | def drop_while ( & predicate ) filter ( "drop_while" ) do | yielder | take = false each do | element | take ||= ! yield ( element ) yielder . call ( element ) if take end end end | Reject elements while a predicate returns true . |
14,351 | def grep ( pattern ) filter ( "grep" ) do | yielder | each do | element | if pattern === element result = if block_given? yield element else element end yielder . call ( result ) end end end end | Select elements matching a pattern . |
14,352 | def flatten ( level = 1 ) filter ( "flatten" ) do | yielder | each do | element | if level > 0 && element . respond_to? ( :each ) element . flatten ( level - 1 ) . each ( & yielder ) else yielder . call ( element ) end end end end | Flatten the collection such that Enumerable elements are included inline . |
14,353 | def compact filter ( "compact" ) do | yielder | each do | element | yielder . call ( element ) unless element . nil? end end end | Ignore nil values . |
14,354 | def handle_input ( from_parent = false ) @focus ||= 0 ch = handle_focused unless nav_select until quit_nav? ( ch ) if self . nav_select if self . contains? ( self . nav_select ) nav_to_selected else nav_to_parent return nil end elsif ENTER_CONTROLS . include? ( ch ) focused . activate! elsif MOVEMENT_CONTROLS . include... | Helper to be internally invoked by navigation component on activation |
14,355 | def handle_focused ch = nil focused . dispatch :focused update_focus if focused . activate_focus? focused . activate! elsif focused . kind_of? ( Layout ) ch = focused . handle_input ( true ) elsif ! deactivate? && ! nav_select ch = sync_getch end if self . ch_select ch = self . ch_select self . ch_select = nil end ch e... | Internal helper logic invoked when a component gains focus |
14,356 | def nav_to_selected ns = self . nav_select self . nav_select = nil if self . children . include? ( ns ) remove_focus @focus = focusable . index ( ns ) else child = self . layout_containing ( ns ) child . nav_select = ns ch = child . handle_input ( true ) end end | Internal helper navigate to selected component under current |
14,357 | def must_implement ( * args ) parsed_args ( args ) . each do | method , arity | raise_interface_error ( method , arity ) unless valid_method? ( method , arity ) end end | Errors raised here identify the class_name that is not implementing or is implemented with the wrong arity required by the Interface . |
14,358 | def parsed_args ( args ) args . inject ( { } ) do | memo , method | memo . merge ( method . is_a? ( Hash ) ? method : { method => nil } ) end end | Transform symbol arguments to a hash of nil arity |
14,359 | def get_request ( slug , params = { } ) connection . get do | req | req . url "api/#{slug}" params . each_pair do | k , v | req . params [ k ] = v end end end | Makes a get - request to apilayer s service |
14,360 | def download_sites_urls ( response ) return [ ] if ! response . is_a? ( Hash ) || ( sites_urls = response . dig ( 'receipt' , 'sites_urls' ) ) . nil? sites_urls . map do | url | Infosimples :: Data :: HTTP . request ( url : url , http_timeout : 30 ) end end | Download sites_urls from response . |
14,361 | def request ( service , method = :get , payload = { } ) res = Infosimples :: Data :: HTTP . request ( url : BASE_URL . gsub ( ':service' , service ) , http_timeout : timeout , method : method , payload : payload . merge ( token : token , timeout : timeout , max_age : max_age , header : 1 ) ) JSON . parse ( res ) end | Perform an HTTP request to the Infosimples Data API . |
14,362 | def source_country cus = Stripe :: Customer . retrieve self . indifferent_json [ :customer ] cus . sources . data [ 0 ] . country end | the country the source is registered in |
14,363 | def start ( options = { } , & block ) @stdout = options [ :stdout ] || $stdout @stderr = options [ :stdout ] || @stdout @stdin = options [ :stdin ] || $stdin while line = @stdin == $stdin ? Readline . readline ( "> " , true ) : @stdin . gets line . strip! next if line . length == 0 parse_tree_node = parser . parse line... | Each line of input is parsed . If parser fails output explaination of why . If parser succeeds evaluate parse_tree_node &block |
14,364 | def set_vars_to_stage ( stage , variables ) vars_array = variables . map { | k , v | "#{k}=#{v}" } Capistrano :: Application . invoke ( stage ) Capistrano :: Application . invoke ( "rbenv:vars:set" , * vars_array ) end | Sets the variables to the selected stage using cap rbenv set |
14,365 | def get_variables return unless File . exists? ( ENV_FILE ) File . open ( ENV_FILE ) . each do | line | var_name = line . split ( "=" ) . first yield var_name unless line =~ / \# / end end | build a list of variables from ENV_FILE and yeilds it |
14,366 | def select_variables selection = { } puts I18n . t ( :ask_variables_message , scope : :negroku ) get_variables do | var_name | selection [ var_name ] = Ask . input ( var_name ) end selection . reject { | key , value | value . empty? } end | Returns a hash of selected variables and values |
14,367 | def [] ( key ) if @my_vars . include? ( key ) @my_vars [ key ] else @coa_vars . each do | coa_vars | if coa_vars . include? ( key ) @my_vars [ key ] = deep_dup ( coa_vars [ key ] ) return @my_vars [ key ] end end nil end end | Create a VarSet . |
14,368 | def include? ( key ) if @my_vars . include? ( key ) true else @coa_vars . find do | coa_vars | coa_vars . include? ( key ) end end end | Check if the VarSet contains a variable . |
14,369 | def append ( values ) coa! if values . is_a? ( VarSet ) values . send ( :coa! ) @coa_vars = values . instance_variable_get ( :@coa_vars ) + @coa_vars else @my_vars = deep_dup ( values ) end self end | Add or overwrite a set of variables . |
14,370 | def merge ( other = { } ) coa! varset = self . class . new varset . instance_variable_set ( :@coa_vars , @coa_vars . dup ) varset . append ( other ) end | Create a new VarSet object based on the first merged with other . |
14,371 | def to_h result = deep_dup ( @my_vars ) @coa_vars . reduce ( result ) do | result , coa_vars | coa_vars . each_pair do | key , value | unless result . include? ( key ) result [ key ] = deep_dup ( value ) end end result end end | Return a Hash containing all variables in the VarSet . |
14,372 | def deep_dup ( obj ) obj_class = obj . class if obj_class == Hash obj . reduce ( { } ) do | result , ( k , v ) | result [ k ] = deep_dup ( v ) result end elsif obj_class == Array obj . map { | v | deep_dup ( v ) } elsif obj_class == String obj . dup else obj end end | Create a deep copy of an object . |
14,373 | def import ( csv , type , block_until_completed = false ) csv = File . open ( csv , 'rb' ) unless csv . respond_to? ( :path ) && csv . respond_to? ( :read ) data , headers = Itrp :: Multipart :: Post . prepare_query ( type : type , file : csv ) request = Net :: HTTP :: Post . new ( expand_path ( '/import' ) , expand_he... | upload a CSV file to import |
14,374 | def export ( types , from = nil , block_until_completed = false , locale = nil ) data = { type : [ types ] . flatten . join ( ',' ) } data [ :from ] = from unless from . blank? data [ :locale ] = locale unless locale . blank? response = post ( '/export' , data ) if response . valid? if response . raw . code . to_s == '... | Export CSV files |
14,375 | def expand_header ( header = { } ) header = DEFAULT_HEADER . merge ( header ) header [ 'X-ITRP-Account' ] = option ( :account ) if option ( :account ) header [ 'AUTHORIZATION' ] = 'Basic ' + [ "#{option(:api_token)}:x" ] . pack ( 'm*' ) . gsub ( / \s / , '' ) if option ( :source ) header [ 'X-ITRP-Source' ] = option ( ... | Expand the given header with the default header |
14,376 | def typecast ( value , escape = true ) case value . class . name . to_sym when :NilClass then '' when :String then escape ? uri_escape ( value ) : value when :TrueClass then 'true' when :FalseClass then 'false' when :DateTime then datetime = value . new_offset ( 0 ) . iso8601 ; escape ? uri_escape ( datetime ) : dateti... | Parameter value typecasting |
14,377 | def component enable_cdk! @component ||= begin c = _component c . setBackgroundColor ( "</#{@colors.id}>" ) if colored? c . timeout ( SYNC_TIMEOUT ) if sync_enabled? c . title_attrib = @title_attrib if @title_attrib c end end | Return completely initialized CDK component |
14,378 | def activate! ( * input ) dispatch :activated component . resetExitType r = nil while [ :EARLY_EXIT , :NEVER_ACTIVATED , :TIMEOUT ] . include? ( component . exit_type ) && ! shutdown? r = component . activate ( input ) run_sync! if sync_enabled? end dispatch :deactivated r end | Invoke CDK activation routine |
14,379 | def bind_key ( key , kcb = nil , & bl ) kcb = bl if kcb . nil? && ! bl . nil? cb = lambda do | cdktype , widget , component , key | kcb . call component , key end component . bind ( :ENTRY , key , cb , self ) end | Override bind_key to use cdk bindings mechanism |
14,380 | def ask_name question = I18n . t :application_name , scope : :negroku Ask . input question , default : File . basename ( Dir . getwd ) end | Ask the application name |
14,381 | def select_repo remote_urls = %x( ) . split ( "\n" ) remote_urls << ( I18n . t :other , scope : :negroku ) question = I18n . t :choose_repo_url , scope : :negroku selected_idx = Ask . list question , remote_urls if selected_idx == remote_urls . length - 1 question = I18n . t :type_repo_url , scope : :negroku Ask . inpu... | Get git remotes from current git and ask to select one |
14,382 | def pattern_elements @pattern_elements ||= pattern . collect { | match | [ PatternElement . new ( match , :rule_variant => self , :pattern_element => true ) , delimiter_pattern ] } . flatten [ 0 .. - 2 ] end | convert the pattern into a set of lamba functions |
14,383 | def parse ( parent_node ) node = variant_node_class . new ( parent_node , delimiter_pattern ) node . match parser . delimiter_pattern if root_rule? pattern_elements . each do | pe | return unless node . match ( pe ) end node . pop_match if node . last_match && node . last_match . delimiter node . match parser . delimit... | returns a Node object if it matches nil otherwise |
14,384 | def write @cache [ "version" ] = VERSION File . open ( CACHE_FILE , "w" ) do | fh | fh . puts ( JSON . dump ( @cache ) ) end end | Write the cache to disk . |
14,385 | def mkdir_p ( path ) parts = path . split ( / \\ \/ / ) parts . each_index do | i | next if parts [ i ] == "" subpath = File . join ( * parts [ 0 , i + 1 ] ) unless File . exists? ( subpath ) FileUtils . mkdir_p ( subpath ) @cache [ "directories" ] [ subpath ] = true end end end | Make any needed directories and record the ones that are created for removal upon a clean operation . |
14,386 | def calculate_checksum ( file ) @lookup_checksums [ file ] = Digest :: MD5 . hexdigest ( File . read ( file , mode : "rb" ) ) rescue "" end | Calculate and return a file s checksum . |
14,387 | def from_file ( filename ) filename = filename . to_s if File . exists? ( filename ) && File . readable? ( filename ) self . instance_eval ( IO . read ( filename ) , filename , 1 ) self else raise IOError , "Could not open or read: '#{filename}'" end end | Loads the contents of a file within the context of the current object |
14,388 | def class_from_file ( filename ) filename = filename . to_s if File . exists? ( filename ) && File . readable? ( filename ) self . class_eval ( IO . read ( filename ) , filename , 1 ) self else raise IOError , "Could not open or read: '#{filename}'" end end | Loads the contents of a file within the context of the current object s class |
14,389 | def parse ( parent_node ) begin parent_node . parser . matching_negative if negative match = parser . call ( parent_node ) ensure parent_node . parser . unmatching_negative if negative end match = match ? nil : EmptyNode . new ( parent_node ) if negative match = EmptyNode . new ( parent_node ) if ! match && optional ma... | attempt to match the pattern defined in self . parser in parent_node . src starting at offset parent_node . next |
14,390 | def init_rule ( rule_name ) rule_name . to_s [ / / ] rule_name = $1 . to_sym option = $2 match_rule = rules [ rule_name ] raise "no rule for #{rule_name}" unless match_rule self . parser = lambda { | parent_node | match_rule . parse ( parent_node ) } self . name ||= rule_name case option when "?" then self . optional =... | initialize PatternElement as a parser that matches a named sub - rule |
14,391 | def init_hash ( hash ) if hash [ :parser ] self . parser = hash [ :parser ] elsif hash [ :many ] init_many hash elsif hash [ :match ] init hash [ :match ] elsif hash [ :any ] init_any hash [ :any ] else raise "extended-options patterns (specified by a hash) must have either :parser=> or a :match=> set" end self . name ... | initialize the PatternElement from hashed parameters |
14,392 | def each pos = 0 while ( pos < @original_duration ) do chunk = nil begin chunk = Chunk . new ( @original_file , @original_duration , pos , ( @chunk_duration + @overlap ) , @rate ) yield chunk pos = pos + [ chunk . duration , @chunk_duration ] . min ensure chunk . close_file if chunk end end end | return temp file for each chunk |
14,393 | def ssh_role_command ( role , command ) t = [ ] ChefWorkflow :: IPSupport . get_role_ips ( role ) . each do | ip | t . push ( Thread . new do ssh_command ( ip , command ) end ) end t . each ( & :join ) end | run a command against a group of servers . These commands are run in parallel but the command itself does not complete until all the threads have finished running . |
14,394 | def ssh_command ( ip , command ) configure_ssh_command ( ip , command ) do | ch , success | return 1 unless success if_debug ( 2 ) do ch . on_data do | ch , data | $stderr . puts data end end ch . on_request ( "exit-status" ) do | ch , data | return data . read_long end end end | Run a command against a single IP . Returns the exit status . |
14,395 | def ssh_capture ( ip , command ) retval = "" configure_ssh_command ( ip , command ) do | ch , success | return "" unless success ch . on_data do | ch , data | retval << data end ch . on_request ( "exit-status" ) do | ch , data | return retval end end return retval end | run a command and instead of capturing the exit status return the data captured during the command run . |
14,396 | def create_security_group aws_ec2 = ec2_obj name = nil loop do name = 'chef-workflow-' + ( 0 .. rand ( 10 ) . to_i ) . map { rand ( 0 .. 9 ) . to_s } . join ( "" ) if_debug ( 3 ) do $stderr . puts "Seeing if security group name #{name} is taken" end break unless aws_ec2 . security_groups . filter ( 'group-name' , [ nam... | Creates a security group and saves it to the security_group_setting_path . |
14,397 | def assert_security_groups aws_ec2 = ec2_obj if security_groups == :auto loaded_groups = load_security_group if loaded_groups self . security_groups loaded_groups assert_security_groups else self . security_groups create_security_group end else self . security_groups = [ security_groups ] unless security_groups . kind_... | Ensures security groups exist . |
14,398 | def json return @json if defined? ( @json ) if @response . code . to_s == '204' data = { } elsif @response . body . blank? data = { message : @response . message . blank? ? 'empty body' : @response . message . strip } end begin data ||= JSON . parse ( @response . body ) rescue :: Exception => e data = { message : "Inva... | The JSON value if single resource is queried this is a Hash if multiple resources where queried it is an Array If the response is not + valid? + it is a Hash with message and optionally errors |
14,399 | def [] ( * keys ) values = json . is_a? ( Array ) ? json : [ json ] keys . each { | key | values = values . map { | value | value . is_a? ( Hash ) ? value [ key ] : nil } } json . is_a? ( Array ) ? values : values . first end | retrieve a value from the resource if the JSON value is an Array a array with the value for each resource will be given |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.