idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
21,400 | def [] ( key = nil ) key ||= BasicCache . caller_name raise KeyError , 'Key not cached' unless include? key . to_sym @store [ key . to_sym ] end | Retrieve cached value |
21,401 | def setup_propositions ( params ) self . params = { sigla : params [ :sigla ] , numero : params [ :numero ] , ano : params [ :ano ] , datApresentacaoIni : params [ :datApresentacaoIni ] , generoAutor : params [ :generoAutor ] , datApresentacaoFim : params [ :datApresentacaoFim ] , parteNomeAutor : params [ :parteNomeAu... | SetUp the params to be not nil |
21,402 | def api_errors! ( model_name , model_errors ) base_error = model_errors [ :base ] field_errors = model_errors . reject { | k , _ | k == :base } unless base_error . blank? set! 'error' , "#{model_name.humanize} #{base_error.map{|e| h(e.to_s)}.join("<br>\n#{model_name.humanize} ")}" end unless field_errors . blank? set! ... | List out the errors for the model . |
21,403 | def assign ( value ) value = value . simplify if @value . r . respond_to? :assign @value . r . assign value . get . r else @value . r = value . get . r end if @value . g . respond_to? :assign @value . g . assign value . get . g else @value . g = value . get . g end if @value . b . respond_to? :assign @value . b . assig... | Constructor for native RGB value |
21,404 | def r_with_decompose if typecode == OBJECT or is_a? ( Variable ) or Thread . current [ :lazy ] r_without_decompose elsif typecode < RGB_ decompose 0 else self end end | Fast extraction for red channel of RGB array |
21,405 | def g_with_decompose if typecode == OBJECT or is_a? ( Variable ) or Thread . current [ :lazy ] g_without_decompose elsif typecode < RGB_ decompose 1 else self end end | Fast extraction for green channel of RGB array |
21,406 | def b_with_decompose if typecode == OBJECT or is_a? ( Variable ) or Thread . current [ :lazy ] b_without_decompose elsif typecode < RGB_ decompose 2 else self end end | Fast extraction for blue channel of RGB array |
21,407 | def b = ( value ) if typecode < RGB_ decompose ( 2 ) [ ] = value elsif typecode == OBJECT self [ ] = Hornetseye :: lazy do r * RGB . new ( 1 , 0 , 0 ) + g * RGB . new ( 0 , 1 , 0 ) + value * RGB . new ( 0 , 0 , 1 ) end else raise "Cannot assign blue channel to elements of type #{typecode.inspect}" end end | Assignment for blue channel values of RGB array |
21,408 | def histogram_with_rgb ( * ret_shape ) if typecode < RGB_ [ r , g , b ] . histogram * ret_shape else histogram_without_rgb * ret_shape end end | Compute colour histogram of this array |
21,409 | def lut_with_rgb ( table , options = { } ) if typecode < RGB_ [ r , g , b ] . lut table , options else lut_without_rgb table , options end end | Perform element - wise lookup with colour values |
21,410 | def currency_field ( method , options = { } ) sym = options . delete ( :currency_symbol ) || '$' if ( val = object . send ( method ) ) options [ :value ] = number_with_precision val , precision : 2 , delimiter : ',' end fld = text_field ( method , options ) "<div class=\"input-symbol\"><span>#{CGI::escape_html sym}</sp... | Creates a currency entry field . |
21,411 | def text_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lbl = label_w_small ( method , lopt ) fld = gopt [ :wrap ] . call ( text_field ( method , fopt ) ) form_group lbl , fld , gopt end | Creates a standard form group with a label and text field . |
21,412 | def password_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lbl = label_w_small ( method , lopt ) fld = gopt [ :wrap ] . call ( password_field ( method , fopt ) ) form_group lbl , fld , gopt end | Creates a standard form group with a label and password field . |
21,413 | def textarea_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lbl = label_w_small method , lopt fld = gopt [ :wrap ] . call ( text_area ( method , fopt ) ) form_group lbl , fld , gopt end | Creates a form group including a label and a text area . |
21,414 | def currency_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lbl = label_w_small ( method , lopt ) fld = gopt [ :wrap ] . call ( currency_field ( method , fopt ) ) form_group lbl , fld , gopt end | Creates a standard form group with a label and currency field . |
21,415 | def static_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lbl = label_w_small ( method , lopt ) fld = gopt [ :wrap ] . call ( "<input type=\"text\" class=\"form-control disabled\" readonly=\"readonly\" value=\"#{CGI::escape_html(fopt[:value] || object.send(method))}\">" ... | Creates a standard form group with a label and a static text field . |
21,416 | def datepicker_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lbl = label_w_small ( method , lopt ) fld = gopt [ :wrap ] . call ( date_picker ( method , fopt ) ) form_group lbl , fld , gopt end | Creates a standard form group with a datepicker field . |
21,417 | def multi_input_form_group ( methods , options = { } ) gopt , lopt , fopt = split_form_group_options ( options ) lopt [ :text ] ||= gopt [ :label ] if lopt [ :text ] . blank? lopt [ :text ] = methods . map { | k , _ | k . to_s . humanize } . join ( ', ' ) end lbl = label_w_small ( methods . map { | k , _ | k } . first ... | Creates a standard form group with a multiple input control . |
21,418 | def check_box_form_group ( method , options = { } ) gopt , lopt , fopt = split_form_group_options ( { class : 'checkbox' , field_class : '' } . merge ( options ) ) if gopt [ :h_align ] gopt [ :class ] = gopt [ :class ] . blank? ? "col-sm-#{12-gopt[:h_align]} col-sm-offset-#{gopt[:h_align]}" : "#{gopt[:class]} col-sm-#{... | Creates a standard form group with a checkbox field . |
21,419 | def recaptcha ( method , options = { } ) Incline :: Recaptcha :: Tag . new ( @object_name , method , @template , options ) . render end | Adds a recaptcha challenge to the form configured to set the specified attribute to the recaptcha response . |
21,420 | def addopt ( opt ) raise TypeError , 'Incorrectly types for option object.' unless opt . instance_of? Cmdlib :: Option @options [ opt . longname . to_sym ] = opt end | Add CLICommand object to CLIHandler . |
21,421 | def display_commands ( cmdlist ) maxlen = 0 cmdlist . each do | cmd | maxlen = cmd . name . length if cmd . name . length > maxlen end cmdlist . each do | cmd | print ' ' + cmd . name print "#{' ' * (maxlen - cmd.name.length)} # " puts cmd . brief end end | Display commands info |
21,422 | def display_options ( optlist ) maxlen = 0 listout = [ ] optlist . each_value do | opt | optnames = '' if opt . shortname . length == 0 optnames += ' ' else optnames += OPTION_PREFIX_SHORT + opt . shortname end optnames += ',' optnames += OPTION_PREFIX_LONG + opt . longname if opt . longname . length != 0 optnames += ... | Display options info |
21,423 | def run option_parser @options if @options [ :version ] . value then puts "#{@name}, version #{@version}" exit end if ARGV [ 0 ] == 'help' or ARGV [ 0 ] == '--help' or ARGV [ 0 ] == '-h' then if ARGV . size == 1 then puts puts "*** #{@name} ***" . center ( 80 ) if @about . size > 0 then puts '** ABOUT:' @about . each d... | Main method to run application . |
21,424 | def command_select command = command_search ( @commands , ARGV [ 0 ] ) if command != nil then ARGV . delete_at ( 0 ) ARGV . each do | arg | cmd = command_search ( command . subcmd , arg ) break if cmd == nil ARGV . delete_at ( 0 ) command = cmd end end return command end | Select and return command object in application . |
21,425 | def option_excess ARGV . each do | opt | o = getopt ( opt ) if o [ :n ] != '' then puts "fatal error: unknown option '#{o[:t]}#{o[:n]}'" exit end end end | Check ARGV to exess options . |
21,426 | def option_parser ( optlist ) return if optlist . size == 0 deletelist = [ ] ARGV . each_with_index do | opt , i | o = getopt ( opt ) if o [ :n ] != '' and o [ :n ] != 'h' and o [ :n ] != 'help' o [ :i ] = i result = option_search ( o , optlist ) if result != nil then deletelist << opt result = option_set ( o , optlist... | Parsing options in command line . |
21,427 | def run puts ( 1 .. tests . length ) . to_s tests . each_with_index do | test , i | begin if test . is_ok? ok ( test , i ) else not_ok ( test , i ) end rescue Sequel :: DatabaseError puts $! . sql raise $! end end end | Drives the evaluation of each test emitting TAP - compliant messages for each test |
21,428 | def ok ( test , i ) message = "ok #{i + 1}" message += ' - ' + test . name if test . name puts message end | Emits a TAP - compliant OK message |
21,429 | def not_ok ( test , i ) message = "not ok #{i + 1}" message += ' - ' + test . name if test . name message += "\n " + test . errors . join ( "\n " ) if test . errors puts message end | Emits a TAP - compliant NOT OK message |
21,430 | def resolve_method name : , default_type : nil name_string = name . to_s case name_string when Meta :: Names :: Method :: Bare bare_name = Meta :: Names :: Method :: Bare . new name_string case default_type &. to_sym when nil raise NRSER :: ArgumentError . new "When `default_type:` param is `nil` `name:` must start wit... | Resolve a method name to a reference object . |
21,431 | def parse_uri self . uri = URI . parse ( raw_url ) uri . path = "/" if uri . path . empty? uri . fragment = nil rescue self . valid = false end | Parse the raw URL as a URI object |
21,432 | def descendants ( include_singletons = false ) return _inherited_by . map { | c | [ c , c . descendants ] } . flatten . uniq if BBLib . in_opal? ObjectSpace . each_object ( Class ) . select do | c | ( include_singletons || ! c . singleton_class? ) && c < self end end | Return all classes that inherit from this class |
21,433 | def direct_descendants ( include_singletons = false ) return _inherited_by if BBLib . in_opal? ObjectSpace . each_object ( Class ) . select do | c | ( include_singletons || ! c . singleton_class? ) && c . ancestors [ 1 .. - 1 ] . find { | k | k . is_a? ( Class ) } == self end end | Return all classes that directly inherit from this class |
21,434 | def instances ( descendants = true ) inst = ObjectSpace . each_object ( self ) . to_a descendants ? inst : inst . select { | i | i . class == self } end | Return all live instances of the class Passing false will not include instances of sub classes |
21,435 | def find_git_dir ( path ) path = Pathname . new ( path ) . realpath while path . parent != path && ! ( path + ".git" ) . directory? path = path . parent end path = path + ".git" raise "Could not find suitable .git dir in #{path}" if ! path . directory? path end | Find the git dir |
21,436 | def has_key? ( key , opts = { } ) key = normalize_key ( key ) if opts . fetch ( :normalize , true ) @source . has_key? ( key ) end | Lookup whether the key exists . |
21,437 | def const_missing ( sym ) unless defined? @introspected then configure_importer load_definitions return const_get ( sym ) end logger . debug { "Detecting whether #{sym} is a #{self} Java class..." } klass = @packages . detect_value do | pkg | begin java_import "#{pkg}.#{sym}" rescue NameError nil end end if klass then ... | Imports a Java class constant on demand . If the class does not already include this module s mixin then the mixin is included in the class . |
21,438 | def configure_importer @packages ||= [ name . split ( '::' ) . map { | n | n . downcase } . join ( '.' ) ] @packages . each do | pkg | begin eval "java_package Java::#{pkg}" rescue Exception => e raise ArgumentError . new ( "#{self} Java package #{pkg} not found - #{$!}" ) end end @introspected = Set . new @unresolved_... | Initializes this importer on demand . This method is called the first time a class is referenced . |
21,439 | def load_dir ( dir ) logger . debug { "Loading the class definitions in #{dir}..." } srcs = sources ( dir ) klasses = srcs . keys . transitive_closure { | k | [ k . superclass ] } . select { | k | srcs [ k ] } . reverse klasses . each { | klass | add_metadata ( klass ) unless introspected? ( klass ) } klasses . each do... | Loads the Ruby source files in the given directory . |
21,440 | def add_metadata ( klass ) logger . debug ( "Adding #{self}::#{klass.qp} metadata..." ) @introspected << klass add_superclass_metadata ( klass ) unless klass < self then m = self klass . class_eval { include m } end name = klass . name . demodulize unless const_defined? ( name ) then java_import ( klass . java_class . ... | Introspects the given class meta - data . |
21,441 | def get params = nil path = if params paramaterize params . dup else @url end { path : path , title : self . flags . fetch ( :title ) { nil } , params : params_hash ( params ) , route : self } end | get route hash and paramaterize url if needed |
21,442 | def match ( path ) if match = @regexp . match ( path ) params = { } @named . each_with_index { | name , i | params [ name ] = match [ i + 1 ] } if @type == :handlers { path : path , title : self . flags . fetch ( :title ) { nil } , params : params , route : self } else false end end | match this route against a given path |
21,443 | def execute_handler params = { } , path = nil case @type when :handlers @handlers . each do | handler_ident | handler = @context_ref . handlers . fetch ( handler_ident ) { raise "handler #{handler_ident} doesn't exist in context #{@context_ref.ref}" } component = handler . ( params , path || @url , & :call ) Context . ... | execute s route s associated handlers |
21,444 | def has_one ( * args , & extension ) options = args . extract_options! || { } if VALID_DEPENDENTS . include? ( options [ :dependent ] . try ( :to_sym ) ) reflection = if active_record_4? association_id , scope = * args restrict_create_reflection ( :has_one , association_id , scope || { } , options , self ) else associa... | We should be aliasing configure_dependency_for_has_many but that method is private so we can t . We alias has_many instead trying to be as fair as we can to the original behaviour . |
21,445 | def run pipe = IO . popen ( @cmd + " 2>&1" ) @pid = pipe . pid begin @output = pipe . readlines pipe . close @exitstatus = $? . exitstatus rescue => e @exception = e end end | run the cmd |
21,446 | def link_to ( content , href = nil , options = { } ) href ||= content options . update :href => url_for ( href ) content_tag :a , content , options end | Works like link_to but href is optional . If no href supplied content is used as href |
21,447 | def check! return unless @files @file_list = file_list ( @files ) new_signature = signature ( @file_list ) if @signature != new_signature puts "* Aerogel::Reloader reloading: #{@file_list}, group: #{@group}" if @group Aerogel :: Reloader . reloaders . select { | r | r . group == @group && r . opts [ :before ] } . each ... | Checks if files are changed and reloads if so . |
21,448 | def file_list ( files ) case files when String [ files ] when Array files when Proc files . call else [ ] end end | Re - calculates file list |
21,449 | def dsl_eval ( dsl , fallback_dsl , * args , & block ) exec_in_proxy_context ( dsl , fallback_dsl , Docile :: FallbackContextProxy , * args , & block ) dsl end | Execute a block in the context of an object whose methods represent the commands in a DSL . |
21,450 | def user_modify ( attribs ) defaults = { user_name : "!" , min_bal : "!" , email : "!" , dept_name : "!" , pimary_pin : "!" , secondary_pin : "!" , quota : "!" , alternate_pin : "!" , home_server : "!" , locked : "!" , location : "!" , default_bc : "!" , additional_info : "!" , home_folder : "!" } attribs = defaults . ... | Process to lock a user in the Equitrac System |
21,451 | def user_adjust_set ( attribs ) defaults = { new_bal : 0.0 , description : nil } attribs = defaults . merge ( attribs ) attribs = check_atrribs ( attribs ) "adjust ur #{attribs[:user_id]} set #{attribs[:new_bal]} #{attribs[:description]}" end | Process to set a new balance for a user in the Equitrac System |
21,452 | def start_time_f day if dtstart . class == Date "" elsif start_time . to_date == day . to_date start_time . strftime ( '%H:%M' ) else "..." end end | Time it starts at day or ... |
21,453 | def finish_time_f day if dtend . class == Date "" elsif finish_time . to_date == day . to_date finish_time . strftime ( '%H:%M' ) else return "..." end end | Time it finishes at day or ... |
21,454 | def time_f day start = start_time_f day finish = finish_time_f day if start == finish && start == "" "" elsif start == finish && start == "..." "..." else "#{start_time_f day} - #{finish_time_f day}" end end | Time it finishes and or starts at day or ... |
21,455 | def get_executor_from ( opts = { } ) if ( executor = opts [ :executor ] ) . is_a? Symbol case opts [ :executor ] when :fast Garcon . global_fast_executor when :io Garcon . global_io_executor when :immediate Garcon :: ImmediateExecutor . new else raise ArgumentError , "executor '#{executor}' not recognized" end elsif op... | Get the requested Executor based on the values set in the options hash . |
21,456 | def rename ( filter , source_uri , target_uri = nil , & each_key ) target_uri ||= source_uri move_keys filter , source_uri , target_uri if source_uri != target_uri source_keys = Familia . redis ( source_uri ) . keys ( filter ) puts "Renaming #{source_keys.size} keys from #{source_uri} (filter: #{filter})" source_keys .... | Use the return value from each_key as the new key name |
21,457 | def deal_with_abnormalaties self . comment = comment . to_s . gsub ( %r{ } , '' ) . gsub ( / \s \S \/ /i , "" ) if ! self . website . blank? website = self . website . sub ( / \: \/ \/ / , '' ) . sub ( / / , '' ) unless self . website [ / \A \/ \/ / ] || self . website [ / \A \/ \/ / ] website = "www.#{website}" end se... | strip any sort of html we don t want javascrpt injection |
21,458 | def lease_server! begin if num_current_generation_servers < MAX_SERVERS_PER_GENERATION && registry_open? start_a_server end lease_server rescue ServerOffline => e Bullring . logger . debug { "Lost connection with a server, retrying..." } retry end end | First starts up a server if needed then blocks until it is available and returns it |
21,459 | def update ( message ) unless message . nil? @latest_reading = Reading . from_xml ( message ) changed notify_observers ( @latest_reading ) end rescue CurrentCost :: ParseError nil end | Internal use only client code does not need to use this function . Informs the Meter object that a new message has been received by the serial port . |
21,460 | def open conn = connection . protocol :: DbOpen . new ( params ( name : @name , storage : @storage , user : @user , password : @password ) ) . process ( connection ) @session = conn [ :session ] || OrientdbBinary :: OperationTypes :: NEW_SESSION @clusters = conn [ :clusters ] self end | Initializes connection to database |
21,461 | def reload answer = connection . protocol :: DbReload . new ( params ) . process ( connection ) @clusters = answer [ :clusters ] self end | Reloads information about database . |
21,462 | def send_invoice ( invoice ) response = post_xml ( invoice . to_xml , { :action => 'send' , :type => 'invoice' } ) InvoiceParser . parse ( response , invoice ) end | Sends an invoice |
21,463 | def find_invoice ( invoice_id ) builder = Builder :: XmlMarkup . new ( :indent => 2 ) builder . instruct! :xml , :version => "1.0" , :encoding => "UTF-8" request_xml = builder . select do | select | select . invoiceNumbers do | numbers | numbers . invoiceNumber invoice_id end end response = post_xml ( request_xml , { :... | Finds an invoice by invoice number |
21,464 | def find_file ( name ) @load_path . each do | dir | file_path = File . join ( dir , "#{name}.rb" ) return file_path if File . exist? file_path end raise ( "Module #{name} not found" ) end | Check module path for module |
21,465 | def flattened_filenames ( filenames ) return filenames if ! filenames . is_a? ( Array ) filenames . map! do | filename | Dir . exist? ( filename ) ? directory_to_filenames ( filename ) : filename end filenames . flatten . compact end | Creates an array consisting of only files contained in a directory and its subdirectories . |
21,466 | def flatten_files ( directoryname , filename ) if Dir . exist? ( "#{directoryname}/#{filename}" ) directory_to_filenames ( "#{directoryname}/#{filename}" ) unless [ '.' , '..' ] . include? ( filename ) else "#{directoryname}/#{filename}" if File . exists? ( "#{directoryname}/#{filename}" ) end end | Expects the directory path and filename checks to see if its another directory or filename if directory calls directory_to_filenames . |
21,467 | def profile_name if @options [ :profile ] && File . exist? ( @options [ :profile ] ) filename_profile = File . basename ( @options [ :profile ] , '.yml' ) end name = derandomize ( @name ) if File . exist? ( profile_file ( name ) ) name_profile = name end filename_profile || @options [ :profile ] || name_profile || "def... | Determines a valid profile_name . Falls back to default |
21,468 | def add_source ( sql ) sql_def = BarkestCore :: MsSqlDefinition . new ( sql , '' ) sql_def . instance_variable_set ( :@source_location , "::#{sql_def.name}::" ) add_sql_def sql_def nil end | Adds a source using a specific timestamp . |
21,469 | def add_source_path ( path ) raise 'path must be a string' unless path . is_a? ( String ) path = File . expand_path ( path ) raise 'cannot add root path' if path == '/' path = path [ 0 ... - 1 ] if path [ - 1 ] == '/' unless @source_paths . include? ( path ) @source_paths << path if Dir . exist? ( path ) Dir . glob ( "... | Adds all SQL files found in the specified directory to the sources for this updater . |
21,470 | def extract begin_connection entries . map do | entry | local_file = File . join ( @local_path , entry . name ) logger . info "Downloading #{entry.name} to #{local_file}" sftp_retry { sftp_session . download! ( File . join ( @remote_path , entry . name ) , local_file ) } local_file end ensure end_connection end | Called to extract files from the source filesystem . |
21,471 | def load ( data ) begin_connection logger . info "Uploading #{data} to #{@username}@#{@host}: #{@remote_path}" sftp_retry { sftp_session . upload! data , @remote_path } true ensure end_connection end | Copies data to the SFTP Server |
21,472 | def run result = CssCompare :: Engine . new ( @options ) . parse! . equal? write_output ( result . to_s + "\n" , @options [ :output ] ) end | Runs the comparison . |
21,473 | def html_file ( html ) file = Tempfile . new ( [ 'ghost_in_the_post' , '.html' ] , encoding : Encoding :: UTF_8 ) file . write ( html ) file . close file end | generate a tempfile with all the html that we need so that phantom can inject easily and not have to max out a single command |
21,474 | def render ( grouping , name , tags , count ) posts = JSON . parse ( @bibsonomy . get_posts ( grouping , name , 'publication' , tags , 0 , count ) ) cp = CiteProc :: Processor . new style : @style , format : 'html' cp . import posts file_names = [ ] sorted_keys = posts . keys . sort { | a , b | get_sort_posts ( posts [... | Create a new BibSonomy instance . |
21,475 | def get_public_docs ( documents ) result = [ ] for doc in documents file_name = doc [ "fileName" ] if file_name . end_with? ".pdf" if documents . length < 2 or file_name . end_with? @public_doc_postfix result << doc end end end return result end | only show PDF files |
21,476 | def find_by ( type , filter , single = true , & block ) nodes = [ ] env = node . chef_environment if node . public_send ( Inflections . pluralize ( type . to_s ) ) . include? filter nodes << node end if ! single || nodes . empty? search ( :node , "#{type}:#{filter} AND chef_environment:#{env}" ) do | n | nodes << n end... | Search for a matching node by a given role or tag . |
21,477 | def cookbook_version ( name = nil ) cookbook = name . nil? ? cookbook_name : name node . run_context . cookbook_collection [ cookbook ] . metadata . version end | Retrieve the version number of the cookbook in the run list . |
21,478 | def file_cache_path ( * args ) if args . nil? Chef :: Config [ :file_cache_path ] else :: File . join ( Chef :: Config [ :file_cache_path ] , args ) end end | Shortcut to return cache path if you pass in a file it will return the file with the cache path . |
21,479 | def _? ( * args , & block ) if args . empty? && block_given? yield self else resp = public_send ( * args [ 0 ] , & block ) if respond_to? ( args . first ) return nil if resp . nil? ! ! resp == resp ? args [ 1 ] : [ args [ 1 ] , resp ] end end | Invokes the public method whose name goes as first argument just like public_send does except that if the receiver does not respond to it the call returns nil rather than raising an exception . |
21,480 | def zip_hash ( col1 , col2 ) col1 . zip ( col2 ) . inject ( { } ) { | r , i | r [ i [ 0 ] ] = i [ 1 ] ; r } end | Returns a hash using col1 as keys and col2 as values . |
21,481 | def with_tmp_dir ( & block ) Dir . mktmpdir ( SecureRandom . hex ( 3 ) ) do | tmp_dir | Dir . chdir ( tmp_dir , & block ) end end | Creates a temp directory executing the block provided . When done the temp directory and all it s contents are garbage collected . |
21,482 | def create ( ** params ) path = nest_path_within_parent ( plural_resource_path , params ) api_request ( :post , path , params : params ) end | Template method for creating a new record on the API . |
21,483 | def index ( ** params ) params . stringify_keys! path = nest_path_within_parent ( plural_resource_path , params ) api_request ( :get , path , params : params ) end | Template method for fetching an index of record from the API . |
21,484 | def show ( record_id = nil , ** params ) if record_id . nil? && ! singular_resource? raise ArgumentError , "record_id cannot be nil" end path = nest_path_within_parent ( singular_path_for_record ( record_id , params ) , params ) api_request ( :get , path , params : params ) end | Template method for creating a given record |
21,485 | def call ( definition , klass ) is_a = is [ definition . type ] define_writer ( definition , is_a , klass ) end | Creates write method with type - checking |
21,486 | def assert_no_route ( verb , action , args = { } ) test "#{brand}no route to #{verb} #{action} #{args}" do assert_raise ( ActionController :: RoutingError ) { send ( verb , action , args ) } end end | def assert_route end |
21,487 | def debug ( depth = 0 ) if debug? debug_info = yield debug_info = debug_info . inspect unless debug_info . is_a? ( String ) STDERR . puts debug_info . split ( "\n" ) . map { | s | " " * depth + s } end end | Conveys debug information to the user . |
21,488 | def role_list_command ( role_command ) role_command . desc _ ( 'cli.role.list.desc' ) role_command . command :list do | role_list_command | role_list_command . action do | global_options , options , args | roles = Bebox :: Role . list ( project_root ) title _ ( 'cli.role.list.current_roles' ) roles . map { | role | msg... | Role list command |
21,489 | def role_new_command ( role_command ) role_command . desc _ ( 'cli.role.new.desc' ) role_command . arg_name "[name]" role_command . command :new do | role_new_command | role_new_command . action do | global_options , options , args | help_now! ( error ( _ ( 'cli.role.new.name_arg_missing' ) ) ) if args . count == 0 Beb... | Role new command |
21,490 | def generate_role_command ( role_command , command , send_command , description ) role_command . desc description role_command . command command do | generated_command | generated_command . action do | global_options , options , args | Bebox :: RoleWizard . new . send ( send_command , project_root ) end end end | For add_profile remove_profile and remove_role commands |
21,491 | def role_list_profiles_command ( role_command ) role_command . desc _ ( 'cli.role.list_profiles.desc' ) role_command . arg_name "[role_name]" role_command . command :list_profiles do | list_profiles_command | list_profiles_command . action do | global_options , options , args | help_now! ( error ( _ ( 'cli.role.list_pr... | Role list profiles command |
21,492 | def filename ( name ) pre , dot , ext = name . rpartition ( '.' ) name = "#{pre.gsub(' ', '_')}.#{ext.downcase}" name = name . gsub ( %r{ \p \- \_ \. } , '' ) name end | Make sure the file name is valid |
21,493 | def load ( data ) @monitor . synchronize do data . each do | key , value | expire! store ( key , val ) end end end | Initializes the cache . |
21,494 | def fetch ( key ) @monitor . synchronize do found , value = get ( key ) found ? value : store ( key , yield ) end end | Retrieves a value from the cache if available and not expired or yields to a block that calculates the value to be stored in the cache . |
21,495 | def delete ( key ) @monitor . synchronize do entry = @stash . delete ( key ) if entry @expires_at . delete ( entry ) entry . value else nil end end end | Removes a value from the cache . |
21,496 | def reset_segments ( segmentA = nil , segmentB = nil ) if ! segmentA @segments = [ :days , :hours , :minutes , :seconds ] elsif ! segmentB case segmentA when Array @segments = segmentA . map { | p | ( p . to_s . downcase . chomp ( 's' ) + 's' ) . to_sym } raise ArgumentError unless @segments . all? { | s | SEGMENTS . i... | Reset segments . |
21,497 | def strftime ( fmt ) h = to_h hx = { 'y' => h [ :years ] , 'w' => h [ :weeks ] , 'd' => h [ :days ] , 'h' => h [ :hours ] , 'm' => h [ :minutes ] , 's' => h [ :seconds ] , 't' => total , 'x' => to_s } fmt . gsub ( / / ) do | match | hx [ match [ 1 .. 1 ] ] end . gsub ( '%%' , '%' ) end | Format duration . |
21,498 | def verify_recaptcha_challenge ( model = nil ) return true if recaptcha_disabled? if ! model || ! model . respond_to? ( 'errors' ) || ! model . send ( 'errors' ) . respond_to? ( 'add' ) model = nil end begin recaptcha = nil http = Net :: HTTP remote_ip = ( request . respond_to? ( 'remote_ip' ) && request . send ( 'remo... | Verifies the response from a recaptcha challenge in a controller . |
21,499 | def get_queue_attributes ( queue_url : nil , attribute_names : nil ) r = MockResponse . new if attribute_names == "All" r . attributes = FAUX_ATTRIBUTES else attribute_names . each do | attribute_name | r . attributes [ attribute_name ] = FAUX_ATTRIBUTES [ attribute_name ] end end r end | Just a static mock of the get_queue_attributes API |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.