idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
19,400
def resolve! self . bundles . each do | bundle_name , requirements | self . paths [ bundle_name ] = [ ] requirements . each do | name , version | path = self . index . find ( name , version ) if ! path raise ( MissingFile , "Could not find #{name} #{version} in any of these paths #{index.directories.join(':')}" ) end s...
Resolve the requirements specified in the Jimfile for each bundle to paths Raises MissingFile error
19,401
def vector_work parents . select do | parent | parent . class . included_modules . include? ( :: GeoWorks :: VectorWorkBehavior ) end . to_a end
Retrieve the Vector Work of which this Object is a member
19,402
def invoke ( method , * args ) @log . debug ( "Invoking plugin API #{method}" ) plugins . map do | p | if p . respond_to? method @log . debug ( "Sending message to #{p.class.name}" ) p . public_send method , * args else nil end end . select { | i | i } end
Call all plugins and collate any data returned .
19,403
def alter ( method , value , * context ) @log . debug ( "Invoking plugin alter API #{method}" ) plugins . each do | p | if p . respond_to? "#{method}_alter" @log . debug ( "Sending message to #{p.class.name}" ) value = p . public_send "#{method}_alter" , value , * context end end value end
Call all plugins and allow for altering a value .
19,404
def load_gem ( spec ) load_path = spec . name . gsub ( '-' , '/' ) require load_path unless @loaded . include? load_path @loaded << load_path klass = path_to_class ( load_path ) @log . debug ( "Loading plugin #{klass} from '#{load_path}'" ) plugins . push plugin_get ( klass ) end nil end
Helper function to load a plugin from a gem specification
19,405
def expected_runtime_seconds ( report_count : ) runs = report_count * options [ :lines_multipliers ] . length warmup_time_seconds = runs * options [ :benchmark_warmup ] bench_time_seconds = runs * options [ :benchmark_time ] warmup_time_seconds + bench_time_seconds end
Instantiate the CLI
19,406
def fetch_default_benchmark_csv cache_path = CSV_TEST_DATA_CACHE_PATH if File . exist? ( cache_path ) writer . puts "Cache file found at #{cache_path}." , verbose : true @used_input_path = cache_path return File . read ( cache_path ) end writer . print 'Downloading test data file from GitHub..' , verbose : true require...
Download or fetch the default benchmark file from cache
19,407
def incomplete_end_operations last_entry_per_session = Staging :: CommitEntry . group ( :session ) . select ( 'MAX(id) AS id' ) return Staging :: CommitEntry . uncontained . end_operations . where . not ( :id => last_entry_per_session ) end
Incomplete End Operation that are not the last entry in their session
19,408
def incomplete_start_operations last_start_entry_per_session = Staging :: CommitEntry . start_operations . group ( :session ) . select ( 'MAX(id) AS id' ) return Staging :: CommitEntry . uncontained . start_operations . where . not ( :id => last_start_entry_per_session ) end
Incomplete Start on the same session as a subsequent start operation
19,409
def populate_metadata ( id ) extract_metadata ( id ) . each do | k , v | send ( "#{k}=" . to_sym , v ) end end
Sets properties from the constitutent external metadata file
19,410
def generate_page ( page ) output_filename = page . output_filename @log . success ( "creating #{output_filename}..." ) @log . debug ( "Rendering #{output_filename} from #{page.name}" ) file = File . join ( @configuration . destination_path , output_filename ) directory = File . dirname ( file ) unless File . directory...
Helper function to generate a page
19,411
def replace_string_node ( target , value ) quote = target . loc . begin . source rewriter . replace ( target . loc . expression , "#{quote}#{value}#{quote}" ) end
Change content of string keeping quoting style .
19,412
def remove_node_with_comma ( target ) expression = target . loc . expression comma_pos = expression . source_buffer . source . rindex ( ',' , expression . begin_pos ) rewriter . remove ( expression . with ( begin_pos : comma_pos ) ) end
Remove node with preceding comma .
19,413
def paginate ( * args ) options = args . extract_options! raise ArgumentError , "first argument must be a RailsPaginate::Collection" unless args . first . is_a? RailsPaginate :: Collection collection = args . first renderer = options [ :renderer ] || RailsPaginate . default_renderer pager = options [ :pager ] || RailsP...
view_helper for paginate
19,414
def acknowledgment_xml xml = Builder :: XmlMarkup . new xml . instruct! @xml = xml . tag! ( 'notification-acknowledgment' , { :xmlns => "http://checkout.google.com/schema/2" , 'serial-number' => serial_number } ) @xml end
Returns an XML string that can be sent back to Google to communicate successful receipt of the notification .
19,415
def method_missing ( method_name , * args ) element_name = method_name . to_s . gsub ( / / , '-' ) if element = ( @doc . at element_name ) if element . respond_to? ( :inner_html ) return element . inner_html end end super end
Take requests for an XML element and returns its value .
19,416
def to_csv ( columns : nil , & block ) columns = columns &. map ( & :to_sym ) @header . to_csv ( columns : columns ) + @rows . to_csv ( columns : columns , & block ) end
Convert matrix to CSV - string .
19,417
def some ids : nil , tags : nil , dom : nil , active : true some = [ ] f = Helpers . filter ( ids : ids , tags : tags , dom : dom ) a = Helpers . pending_or_waiting ( active ) Execute . task_popen3 ( * @override_a , f , a , "export" ) do | i , o , e , t | some = MultiJson . load ( o . read ) . map do | x | Rtasklib :: ...
Retrieves the current task list filtered by id tag or a dom query
19,418
def get_rc res = [ ] Execute . task_popen3 ( * @override_a , "_show" ) do | i , o , e , t | res = o . read . each_line . map { | l | l . chomp } end Taskrc . new ( res , :array ) end
Calls task _show with initial overrides returns a Taskrc object of the result
19,419
def get_version version = nil Execute . task_popen3 ( "_version" ) do | i , o , e , t | version = Helpers . to_gem_version ( o . read . chomp ) end version end
Calls task _version and returns the result
19,420
def get_udas udas = { } taskrc . config . attributes . select { | attr , val | Helpers . uda_attr? attr } . sort . chunk { | attr , val | Helpers . arbitrary_attr attr } . each do | attr , arr | uda = arr . map do | pair | [ Helpers . deep_attr ( pair [ 0 ] ) , pair [ 1 ] ] end udas [ attr . to_sym ] = Hash [ uda ] end...
Retrieves a hash of hashes with info about the UDAs currently available
19,421
def update_config! attr , val Execute . task_popen3 ( * override_a , "config #{attr} #{val}" ) do | i , o , e , t | return t . value end end
Update a configuration variable in the . taskrc
19,422
def add_udas_to_model! uda_hash , type = nil , model = Models :: TaskModel uda_hash . each do | attr , val | val . each do | k , v | type = Helpers . determine_type ( v ) if type . nil? model . attribute attr , type end end end
Add new found udas to our internal TaskModel
19,423
def get_uda_names Execute . task_popen3 ( * @override_a , "_udas" ) do | i , o , e , t | return o . read . each_line . map { | l | l . chomp } end end
Retrieve an array of the uda names
19,424
def sync! Execute . task_popen3 ( * override_a , "sync" ) do | i , o , e , t | return t . value end end
Sync the local TaskWarrior database changes to the remote databases . Remotes need to be configured in the . taskrc .
19,425
def contents ( revision = nil , cmd_options = { } ) revision ||= 'tip' hg ( manifest_cmd ( revision ) , cmd_options ) . tap do | res | if RUBY_VERSION >= '1.9.1' res . force_encoding ( 'utf-8' ) end end end
Returns contents of the manifest as a String at a specified revision . Latest version of the manifest is used if + revision + is ommitted .
19,426
def process_normal_style_attr ( selector , property , value ) if ( @style_info [ selector ] == nil ) then @style_info [ selector ] = DeclarationBlock . new ( ) @style_info [ selector ] . push Declaration . new ( property , value ) else found = @style_info [ selector ] . find { | obj | obj . property == property } if ( ...
If the style hasn t been registered yet create a new array with the style property and value .
19,427
def asm_instr ( instr ) command = extract_command ( instr ) param = extract_param ( instr ) if [ :bpl , :bmi , :bvc , :bvs , :bcc , :bcs , :bne , :beq ] . include? ( command ) mode = :rel else mode = addr_mode ( param ) end bytes = [ ] bytes << opcode ( command , mode ) if [ :imp ] . include? ( mode ) return bytes end ...
This method got nasty .
19,428
def all ( * promises ) deferred = Q . defer counter = promises . length results = [ ] if counter > 0 promises . each_index do | index | ref ( promises [ index ] ) . then ( proc { | result | if results [ index ] . nil? results [ index ] = result counter -= 1 deferred . resolve ( results ) if counter <= 0 end result } , ...
Combines multiple promises into a single promise that is resolved when all of the input promises are resolved .
19,429
def shipping_cost_xml xml = Builder :: XmlMarkup . new if @flat_rate_shipping xml . price ( :currency => currency ) { xml . text! @flat_rate_shipping [ :price ] . to_s } else xml . price ( :currency => @currency ) { xml . text! shipping_cost . to_s } end end
Generates the XML for the shipping cost conditional on
19,430
def shipping_cost currency = 'USD' shipping = @contents . inject ( 0 ) { | total , item | total + item [ :regular_shipping ] . to_i } . to_s end
Returns the shipping cost for the contents of the cart .
19,431
def currency currencies = @contents . map { | item | item [ :currency ] } . uniq || "USD" case currencies . count when 0 "USD" when 1 currencies . first else raise RuntimeError . new ( "Mixing currency not allowed" ) end end
Returns the currency for the cart . Mixing currency not allowed ; this library can t convert between currencies .
19,432
def signature @xml or to_xml digest = OpenSSL :: Digest :: Digest . new ( 'sha1' ) OpenSSL :: HMAC . digest ( digest , @merchant_key , @xml ) end
Returns the signature for the cart XML .
19,433
def checkout_button ( button_opts = { } ) @xml or to_xml burl = button_url ( button_opts ) html = Builder :: XmlMarkup . new ( :indent => 2 ) html . form ( { :action => submit_url , :style => 'border: 0;' , :id => 'BB_BuyButtonForm' , :method => 'post' , :name => 'BB_BuyButtonForm' } ) do html . input ( { :name => 'car...
Returns HTML for a checkout form for buying all the items in the cart .
19,434
def table if ( header . size == 1 && y_size == 0 ) cell_data [ 0 ] else ( 0 ... y_axe . size ) . reduce ( header ) do | result , j | result << ( y_axe [ j ] + ( 0 ... x_size ) . map { | i | "#{cell_data[i + j]}" } ) end end end
header and rows
19,435
def load_result if array_or_relation . is_a? Array result = array_or_relation [ offset .. ( offset + per_page - 1 ) ] else result = array_or_relation . limit ( per_page ) . offset ( offset ) . all end self . replace result . nil? ? [ ] : result end
load result from input array_or_relation to internal array
19,436
def open begin begin with_timeout do @socket = TCPSocket . new ( @host , @port ) @socket . sync = true welcome = @socket . gets unless welcome =~ / / raise Munin :: AccessDenied end @connected = true end rescue Timeout :: Error raise Munin :: ConnectionError , "Timed out talking to #{@host}" end rescue Errno :: ETIMEDO...
Establish connection to the server
19,437
def send_data ( str ) if ! connected? if ! @socket . nil? && @reconnect == false raise Munin :: ConnectionError , "Not connected." else open end end begin with_timeout { @socket . puts ( "#{str.strip}\n" ) } rescue Timeout :: Error raise Munin :: ConnectionError , "Timed out on #{@host} trying to send." end end
Send a string of data followed by a newline symbol
19,438
def read_line begin with_timeout { @socket . gets . to_s . strip } rescue Errno :: ETIMEDOUT , Errno :: ECONNREFUSED , Errno :: ECONNRESET , EOFError => ex raise Munin :: ConnectionError , ex . message rescue Timeout :: Error raise Munin :: ConnectionError , "Timed out reading from #{@host}." end end
Reads a single line from socket
19,439
def read_packet begin with_timeout do lines = [ ] while ( str = @socket . readline . to_s ) do break if str . strip == '.' lines << str . strip end parse_error ( lines ) lines end rescue Errno :: ETIMEDOUT , Errno :: ECONNREFUSED , Errno :: ECONNRESET , EOFError => ex raise Munin :: ConnectionError , ex . message rescu...
Reads a packet of data until . reached
19,440
def with_timeout ( time = @options [ :timeout ] ) raise ArgumentError , "Block required" if ! block_given? if Munin :: TIMEOUT_CLASS . respond_to? ( :timeout_after ) Munin :: TIMEOUT_CLASS . timeout_after ( time ) { yield } else Munin :: TIMEOUT_CLASS . timeout ( time ) { yield } end end
Execute operation with timeout
19,441
def authorized? ( options = { } ) raise "Configuration values not found. Please run rails g restful_api_authentication:install to generate a config file." if @@header_timestamp . nil? || @@header_signature . nil? || @@header_api_key . nil? || @@time_window . nil? || @@disabled_message . nil? return_val = false if heade...
Checks if the current request passes authorization
19,442
def is_disabled? client = RestClient . where ( :api_key => @http_headers [ @@header_api_key ] ) . first return true if client . nil? return false if client . is_disabled . nil? client . is_disabled end
determines if a RestClient is disabled or not
19,443
def in_time_window? @@time_window = 4 if @@time_window < 4 minutes = ( @@time_window / 2 ) . floor ts = Chronic . parse @http_headers [ @@header_timestamp ] before = Time . now . utc - 60 * minutes after = Time . now . utc + 60 * minutes if ts . nil? @errors << "timestamp was in an invalid format; should be YYYY-MM-DD ...
determines if given timestamp is within a specific window of minutes
19,444
def str_to_hash client = RestClient . where ( :api_key => @http_headers [ @@header_api_key ] ) . first if client . nil? @errors << "client is not registered" end client . nil? ? "" : client . secret + @request_uri . gsub ( / \? / , "" ) + @http_headers [ @@header_timestamp ] end
generates the string that is hashed to produce the signature
19,445
def format ( data , fasta_mapper , first ) data = integrate_fasta_headers ( data , fasta_mapper ) if fasta_mapper convert ( data , first ) end
Converts the given input data and corresponding fasta headers to another format .
19,446
def integrate_fasta_headers ( data , fasta_mapper ) data_dict = group_by_first_key ( data ) data = fasta_mapper . map do | header , key | result = data_dict [ key ] unless result . nil? result = result . map do | row | copy = { fasta_header : header } copy . merge ( row ) end end result end data . compact . flatten ( 1...
Integrates the fasta headers into the data object
19,447
def convert ( data , first ) output = data . map ( & :to_json ) . join ( ',' ) first ? output : ',' + output end
Converts the given input data to the JSON format .
19,448
def header ( data , fasta_mapper = nil ) CSV . generate do | csv | first = data . first keys = fasta_mapper ? [ 'fasta_header' ] : [ ] csv << ( keys + first . keys ) . map ( & :to_s ) if first end end
Returns the header row for the given data and fasta_mapper . This row contains all the keys of the first element of the data preceded by fasta_header if a fasta_mapper is given .
19,449
def convert ( data , _first ) CSV . generate do | csv | data . each do | o | csv << o . values . map { | v | v == '' ? nil : v } end end end
Converts the given input data to the CSV format .
19,450
def convert ( data , _first ) data . reject { | o | o [ 'refseq_protein_ids' ] . empty? } . map do | o | "#{o['peptide']}\tref|#{o['refseq_protein_ids']}|\t100\t10\t0\t0\t0\t10\t0\t10\t1e-100\t100\n" end . join end
Converts the given input data to the Blast format .
19,451
def for_role ( * roles ) sql = with_role_sql ( roles ) || '' sql += ' OR ' if sql . present? sql += "(#{self.table_name}.roles_mask = 0) OR (#{self.table_name}.roles_mask IS NULL)" where ( sql ) end
Returns all records which have been assigned any of the given roles as well as any record with no role assigned
19,452
def auth_params return { } unless Softlayer . configuration auth_hash = { authenticate : { 'username' => Softlayer . configuration . username , 'apiKey' => Softlayer . configuration . api_key } } auth_hash . merge! ( { "clientLegacySession" => { "userId" => Softlayer . configuration . impersonate_user , "authToken" => ...
Authorization hash to use with all SOAP requests
19,453
def image_work parents . select do | parent | parent . class . included_modules . include? ( :: GeoWorks :: ImageWorkBehavior ) end . to_a end
Retrieve the Image Work of which this Object is a member
19,454
def visible_pages visible = [ ] last_inserted = 0 splited = false ( 1 .. pages ) . each do | page | if visible? page visible << page last_inserted = page splited = false else if not splited and outer > 0 and last_inserted < page visible << nil splited = true end end end visible end
build array with all visible pages
19,455
def visible? ( page ) if outer > 0 return true if outer >= page return true if ( pages - outer ) < page end return true if current_page == page return true if inner_range . include? page false end
looks should this page visible
19,456
def required_attributes validators . map { | v | v . attributes if v . is_a? ( Mongoid :: Validations :: PresenceValidator ) } . flatten . compact end
Return Array of attribute names with presence validations
19,457
def translated_attributes @translated_attributes ||= translated_attribute_names . inject ( { } ) do | attrs , name | attrs . merge ( name . to_s => translation . send ( name ) ) end end
Returns translations for current locale . Is used for initial mixing into
19,458
def translation_for ( locale ) @translation_caches ||= { } @stop_merging_translated_attributes = true unless @translation_caches [ locale ] _translation = translations . find_by_locale ( locale ) _translation ||= translations . build ( :locale => locale ) @translation_caches [ locale ] = _translation end @stop_merging_...
Returns instance of Translation for given locale . Param String or Symbol
19,459
def used_locales locales = globalize . stash . keys . concat ( globalize . stash . keys ) . concat ( translations . translated_locales ) locales . uniq! locales end
Return Array with locales used for translation of this document
19,460
def prepare_translations! @stop_merging_translated_attributes = true translated_attribute_names . each do | name | @attributes . delete name . to_s @changed_attributes . delete name . to_s if @changed_attributes end globalize . prepare_translations! end
Before save callback . Cleans
19,461
def build @local_event . tap do | le | if @event . rrule . present? @rrule = @event . rrule . first le . attributes = recurrence_attributes set_date_exclusion frequency_set else le . attributes = non_recurrence_attributes end end end
Get single - occurrence events built and get a lits of recurrence events these must be build last
19,462
def define_methods_into ( client ) links . each do | link | @client . define_singleton_method ( link . method_signature ) do | params = { } , headers = { } | Request . call ( client : client , headers : headers , link : link , params : params ) end end end
Defines methods into client
19,463
def bbox ( property ) markup = '' markup << %(<div id='bbox'></div>) markup << bbox_display_inputs markup << bbox_script_tag ( property ) markup . html_safe end
Builds HTML string for bounding box selector tool . Calls boundingBoxSelector javascript function and passes the id of the location input element that it binds to .
19,464
def process_database_param unless @options [ :config ] || Grantinee . configuration . configured? Grantinee :: Engine . detect_active_record_connection! unless Grantinee . configuration . configured? raise "No configuration file found. Please use the -c option" " to pass a configuration file." end end require options [...
Database configuration file
19,465
def process_verbosity_param return unless @options [ :verbose ] log_levels = %w[ debug info warn error fatal unknown ] @logger . level = log_levels . index ( @options [ :verbose ] ) end
Explicit verbose mode overrides configuration value
19,466
def report ( file_path ) raise 'ShellCheck summary file not found' unless File . file? ( file_path ) shellcheck_summary = JSON . parse ( File . read ( file_path ) , symbolize_names : true ) run_summary ( shellcheck_summary ) end
Reads a file with JSON ShellCheck summary and reports it .
19,467
def parse_files ( shellcheck_summary ) shellcheck_summary . each do | element | file = element [ :file ] @files . add ( file ) level = element [ :level ] message = format_violation ( file , element ) if level == 'error' @error_count += 1 fail ( message , sticky : false ) else if level == 'warning' @warning_count += 1 e...
A method that takes the ShellCheck summary and parses any violations found
19,468
def sign_up_with ( email , password ) Capybara . exact = true visit new_user_registration_path fill_in 'Email' , with : email fill_in 'Password' , with : password fill_in 'Password confirmation' , with : password click_button 'Sign up' end
Poltergeist - friendly sign - up Use this in feature tests
19,469
def sign_in ( who = :user ) user = if who . instance_of? ( User ) who else FactoryGirl . build ( :user ) . tap ( & :save! ) end visit new_user_session_path fill_in 'Email' , with : user . email fill_in 'Password' , with : user . password click_button 'Log in' expect ( page ) . not_to have_text 'Invalid email or passwor...
Poltergeist - friendly sign - in Use this in feature tests
19,470
def clear_extended_doc_fresh_cache :: CouchRest :: ExtendedDocument . subclasses . each { | klass | klass . req_design_doc_refresh if klass . respond_to? ( :req_design_doc_refresh ) } end
If the database is deleted ensure that the design docs will be refreshed .
19,471
def register_style ( element ) style_name = element . attribute ( "#{element.prefix}:style-name" ) ; if ( style_name != nil ) then style_name = style_name . value . tr_s ( '.' , '_' ) if ( @style_info [ style_name ] != nil ) then @style_info [ style_name ] . block_used = true end end return style_name end
Return the style name for this element with periods changed to underscores to make it valid CSS .
19,472
def entities_of_type ( type ) @entities . select { | entity | entity [ 'type' ] == type } . map { | entity | Entity . new entity } end
Entitities with specific type
19,473
def convert_map_to_hash ( object , & block ) hash = Hash . new i = object . entrySet . iterator if block_given? while i . hasNext entry = i . next yield hash , entry . getKey , entry . getValue end else while i . hasNext entry = i . next hash [ entry . getKey ] = entry . getValue end end hash end
Converts Java Map object to Ruby Hash object .
19,474
def parse_file ( path , file_encoding = nil ) file_encoding = @internal_encoding unless file_encoding code = IO . read ( path , { :encoding => file_encoding , :mode => 'rb' } ) code = code . encode ( @internal_encoding ) artifact = FileArtifact . new ( path , code ) parse_artifact ( artifact ) end
Parse the file by producing an artifact corresponding to the file
19,475
def parse_string ( code ) code = code . encode ( @internal_encoding ) artifact = StringArtifact . new ( code ) parse_artifact ( artifact ) end
Parse the file by producing an artifact corresponding to the string
19,476
def devices devices = @adb . devices . map { | d | serial = d . serial_number ( @devices . has_key? ( serial ) && same_jobject? ( @devices [ serial ] . jobject , d ) ) ? @devices [ serial ] : Device . new ( d ) } @devices = DeviceList . new ( devices ) return @devices end
Get devices attached with ADB .
19,477
def attributes { :vault_id => vault_id , :currency => currency , :card_number => card_number , :cvv_number => cvv_number , :expires_on => expires_on , :first_name => first_name , :last_name => last_name , :street_address => street_address , :locality => locality , :region => region , :postal_code => postal_code , :coun...
The unique gateway - generated identifier for this credit card .
19,478
def paginate ( * args ) options = args . extract_options! per_page = options . delete ( :per_page ) page = options . delete ( :page ) || 1 :: RailsPaginate :: Collection . new ( self , args . first || page , per_page ) end
paginate with options
19,479
def post uri = URI . parse ( url ) request = Net :: HTTP :: Post . new ( uri . path ) request . basic_auth ( @merchant_id , @merchant_key ) https = Net :: HTTP . new ( uri . host , uri . port ) https . use_ssl = true https . cert_store = self . class . x509_store https . verify_mode = OpenSSL :: SSL :: VERIFY_PEER http...
Sends the Command s XML to GoogleCheckout via HTTPS with Basic Auth .
19,480
def to_xml xml = Builder :: XmlMarkup . new xml . instruct! @xml = xml . tag! ( 'send-buyer-message' , { :xmlns => "http://checkout.google.com/schema/2" , "google-order-number" => @google_order_number } ) do xml . tag! ( "message" , @message ) xml . tag! ( "send-email" , true ) end @xml end
Make a new message to send .
19,481
def hash_to_model taskrc_hash taskrc_hash . each do | attr , value | add_model_attr ( attr , value ) set_model_attr_value ( attr , value ) end config end
Generate a dynamic Virtus model with the attributes defined by the input
19,482
def mappable_to_model rc_file rc_file . map! { | l | line_to_tuple ( l ) } . compact! taskrc = Hash [ rc_file ] hash_to_model ( taskrc ) end
Converts a . taskrc file path into a Hash that can be converted into a TaskrcModel object
19,483
def part_of_model_to_rc * attrs attrs . map do | attr | value = get_model_attr_value attr hash_attr = get_rc_attr_from_hash attr . to_s attr = "rc.#{hash_attr}=#{value}" end end
Serialize the given attrs model back to the taskrc format
19,484
def path_exist? path if path . is_a? Pathname return path . exist? elsif path . is_a? String return Pathname . new ( path ) . exist? else return false end end
Check whether a given object is a path and it exists on the file system
19,485
def find_all ( name , version = nil ) matched = [ ] find ( name , version ) { | p | matched << p } matched end
Find _all_ paths matching name and version . Returning an array .
19,486
def to_csv ( columns : nil ) attributes = if columns self . columns & columns . map ( & :to_sym ) else self . columns end :: CSV . generate_line ( attributes ) end
Header as CSV - string
19,487
def build_columns ( header ) columns = header . each_with_index . map do | header_column , index | convert_column ( header_column , index ) . tap do | column | maybe_raise_missing_column! ( column ) end end @deduplicator . call ( columns ) end
Convert original header
19,488
def convert_column ( column , index ) value = if converter_arity == 1 @converter . call ( column ) else @converter . call ( column , index ) end value . to_sym end
Convert the column value
19,489
def goto ( key ) if @idx . has_key? ( key . to_sym ) @dat_file . pos = @idx [ key . to_sym ] else raise Exception . new "Invalid DAT section \"#{key}\"" end end
Go to a section of the Mascot DAT file
19,490
def read_section ( key ) self . goto ( key . to_sym ) tmp = @dat_file . readline @dat_file . each do | l | break if l =~ @boundary tmp << l end tmp end
Read a section of the DAT file into memory . THIS IS NOT RECOMMENDED UNLESS YOU KNOW WHAT YOU ARE DOING .
19,491
def excluded? ( filename ) exclude . each do | f | f += '**/*' if f . end_with? '/' return true if File . fnmatch ( f , filename , File :: FNM_EXTGLOB | File :: FNM_PATHNAME ) end false end
Helper to determine if a filename is excluded according to the exclude configuration parameter .
19,492
def render if engine . respond_to? ( :render ) engine . render ( Object . new , :items => items ) else engine . result ( binding ) end end
Initialize with your paginated collection .
19,493
def map! ( & block ) return to_enum ( :map! ) unless block_given? ( 0 ... self . length ) . each { | index | store ( index , yield ( fetch ( index ) ) ) } self end
In the first form iterates over all elements of the object yields them to the block given and overwrites the element s value with the value returned by the block .
19,494
def query ( api_query_name ) query_class = "#{api_query_name.camelize}Query" query_file = "query/#{api_query_name.gsub('-', '_')}_query" require query_file PaynetEasy :: PaynetEasyApi :: Query . const_get ( query_class ) . new ( api_query_name ) end
Create API query object by API query method
19,495
def start puts "\n******************************************************************************************************************************************\n\n" puts " JumpStarting....\n" . purple check_setup execute_install_command run_scripts_from_yaml ( :run_after_install_command ) parse_template_dir create_dirs p...
Runs the configuration generating the new project from the chosen template .
19,496
def check_install_path @install_path = JumpStart :: LAUNCH_PATH if @install_path . nil? || @install_path . empty? if File . directory? ( FileUtils . join_paths ( @install_path , @project_name ) ) puts "\nThe directory #{FileUtils.join_paths(@install_path, @project_name).red} already exists.\nAs this is the location you...
Sets the install path to executing directory if
19,497
def create_template if File . directory? ( FileUtils . join_paths ( JumpStart . templates_path , @template_name ) ) puts "\nThe directory #{FileUtils.join_paths(JumpStart.templates_path, @template_name).red} already exists. The template will not be created." exit_normal else FileUtils . mkdir_p ( FileUtils . join_paths...
Creates a new blank template in whichever directory the default templates directory has been set to .
19,498
def jumpstart_menu puts "\n\n******************************************************************************************************************************************\n\n" puts " JUMPSTART MENU\n" . purple puts " Here are your options:\n\n" puts " 1" . yellow + " Create a new project from an existing template.\n" p...
Displays options for the main jumpstart menu .
19,499
def jumpstart_menu_options input = gets . chomp . strip . downcase case when input == "1" new_project_from_template_menu when input == "2" new_template_menu when input == "3" set_default_template_menu when input == "4" templates_dir_menu when input == "x" exit_normal else puts "That command hasn't been understood. Try ...
Captures user input for the main jumpstart menu and calls the appropriate method