idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
10,600 | def validate_token token = params [ :token ] return false if token . nil? user = User . validate_token ( token ) return false if user . nil? login_user ( user ) return true end | Checks to see if a token is given . If so it tries to validate the token and log the user in . |
10,601 | def validate_cookie if cookies [ :caboose_user_id ] user = User . where ( :id => cookies [ :caboose_user_id ] ) . first if user login_user ( user ) return true end end return false end | Checks to see if a remember me cookie value is present . |
10,602 | def reject_param ( url , param ) arr = url . split ( '?' ) return url if ( arr . count == 1 ) qs = arr [ 1 ] . split ( '&' ) . reject { | pair | pair . split ( / / ) . first == param } url2 = arr [ 0 ] url2 += "?" + qs . join ( '&' ) if qs . count > 0 return url2 end | Removes a given parameter from a URL querystring |
10,603 | def under_construction_or_forwarding_domain? d = Caboose :: Domain . where ( :domain => request . host_with_port ) . first if d . nil? Caboose . log ( "Could not find domain for #{request.host_with_port}\nAdd this domain to the caboose site." ) elsif d . under_construction == true if d . site . under_construction_html ... | Make sure we re not under construction or on a forwarded domain |
10,604 | def shipping_json render :json => { :error => 'Not logged in.' } and return if ! logged_in? render :json => { :error => 'No shippable items.' } and return if ! @invoice . has_shippable_items? render :json => { :error => 'Empty shipping address.' } and return if @invoice . shipping_address . nil? @invoice . calculate ra... | Step 3 - Shipping method |
10,605 | def update_stripe_details render :json => false and return if ! logged_in? sc = @site . store_config Stripe . api_key = sc . stripe_secret_key . strip u = logged_in_user c = nil if u . stripe_customer_id c = Stripe :: Customer . retrieve ( u . stripe_customer_id ) begin c . source = params [ :token ] c . save rescue c ... | Step 5 - Update Stripe Details |
10,606 | def fulfillment_new_invoice ( invoice ) @invoice = invoice sc = invoice . site . store_config mail ( :to => sc . fulfillment_email , :subject => 'New Order' ) end | Sends a notification email to the fulfillment dept about a new invoice |
10,607 | def shipping_invoice_ready ( invoice ) @invoice = invoice sc = invoice . site . store_config mail ( :to => sc . shipping_email , :subject => 'Order ready for shipping' ) end | Sends a notification email to the shipping dept that an invoice is ready to be shipped |
10,608 | def accessors_module return @accessors_module unless @accessors_module . nil? @accessors_module = Module . new @accessors_module . instance_eval do define_method :indexed_class do self . values [ 0 ] . value end define_method :score do @score end define_method :attributes do blueprint = XapianDb :: DocumentBlueprint . ... | Lazily build and return a module that implements accessors for each field |
10,609 | def attribute ( name , options = { } , & block ) raise ArgumentError . new ( "You cannot use #{name} as an attribute name since it is a reserved method name of Xapian::Document" ) if reserved_method_name? ( name ) do_not_index = options . delete ( :index ) == false @type_map [ name ] = ( options . delete ( :as ) || :st... | Add an attribute to the blueprint . Attributes will be stored in the xapian documents an can be accessed from a search result . |
10,610 | def attributes ( * attributes ) attributes . each do | attr | raise ArgumentError . new ( "You cannot use #{attr} as an attribute name since it is a reserved method name of Xapian::Document" ) if reserved_method_name? ( attr ) @attributes_hash [ attr ] = { } @type_map [ attr ] = :string self . index attr end end | Add a list of attributes to the blueprint . Attributes will be stored in the xapian documents ans can be accessed from a search result . |
10,611 | def index ( * args , & block ) case args . size when 1 @indexed_methods_hash [ args . first ] = IndexOptions . new ( :weight => 1 , :block => block ) when 2 if args . last . is_a? Hash options = args . last assert_valid_keys options , :weight , :prefixed , :no_split @indexed_methods_hash [ args . first ] = IndexOptions... | Add an indexed value to the blueprint . Indexed values are not accessible from a search result . |
10,612 | def natural_sort_order ( name = nil , & block ) raise ArgumentError . new ( "natural_sort_order accepts a method name or a block, but not both" ) if name && block @_natural_sort_order = name || block end | Define the natural sort order . |
10,613 | def database ( path ) if @_database . is_a? ( XapianDb :: PersistentDatabase ) @_database = nil GC . start end if path . to_sym == :memory @_database = XapianDb . create_db else begin @_database = XapianDb . open_db :path => path rescue IOError @_database = XapianDb . create_db :path => path end end end | Set the global database to use |
10,614 | def adapter ( type ) begin @_adapter = XapianDb :: Adapters . const_get ( "#{camelize(type.to_s)}Adapter" ) rescue NameError require File . dirname ( __FILE__ ) + "/adapters/#{type}_adapter" @_adapter = XapianDb :: Adapters . const_get ( "#{camelize(type.to_s)}Adapter" ) end end | Set the adapter |
10,615 | def writer ( type ) begin require File . dirname ( __FILE__ ) + "/index_writers/#{type}_writer" @_writer = XapianDb :: IndexWriters . const_get ( "#{camelize(type.to_s)}Writer" ) rescue LoadError puts "XapianDb: cannot load #{type} writer; see README for supported writers and how to install neccessary queue infrastruct... | Set the index writer |
10,616 | def language ( lang ) lang ||= :none @_stemmer = XapianDb :: Repositories :: Stemmer . stemmer_for lang @_stopper = lang == :none ? nil : XapianDb :: Repositories :: Stopper . stopper_for ( lang ) end | Set the language . |
10,617 | def assert_valid_keys ( hash , * valid_keys ) unknown_keys = hash . keys - [ valid_keys ] . flatten raise ( ArgumentError , "Unsupported option(s) detected: #{unknown_keys.join(", ")}" ) unless unknown_keys . empty? end | Taken from Rails |
10,618 | def assert_received ( mock , expected_method_name ) matcher = have_received ( expected_method_name ) yield ( matcher ) if block_given? assert matcher . matches? ( mock ) , matcher . failure_message end | Asserts that the given mock received the given method . |
10,619 | def decorate ( match ) klass_name = match . document . values [ 0 ] . value blueprint = XapianDb :: DocumentBlueprint . blueprint_for klass_name match . document . extend blueprint . accessors_module match . document . instance_variable_set :@score , match . percent match end | Decorate a Xapian match with field accessors for each configured attribute |
10,620 | def delete_docs_of_class ( klass ) writer . delete_document ( "C#{klass}" ) if klass . respond_to? :descendants klass . descendants . each do | subclass | writer . delete_document ( "C#{subclass}" ) end end true end | Delete all docs of a specific class . |
10,621 | def search ( expression , options = { } ) opts = { :sort_decending => false } . merge ( options ) @query_parser ||= QueryParser . new ( self ) query = @query_parser . parse ( expression ) return Resultset . new ( nil , opts ) unless query start = Time . now enquiry = Xapian :: Enquire . new ( reader ) enquiry . query =... | Perform a search |
10,622 | def facets ( attribute , expression ) return { } if expression . nil? || expression . strip . empty? value_number = XapianDb :: DocumentBlueprint . value_number_for ( attribute ) @query_parser ||= QueryParser . new ( self ) query = @query_parser . parse ( expression ) enquiry = Xapian :: Enquire . new ( reader ) enquir... | A very simple implementation of facets using Xapian collapse key . |
10,623 | def store_fields @xapian_doc . add_value 0 , @obj . class . name if @blueprint . _natural_sort_order . is_a? Proc sort_value = @obj . instance_eval & @blueprint . _natural_sort_order else sort_value = @obj . send @blueprint . _natural_sort_order end @xapian_doc . add_value 1 , sort_value . to_s @blueprint . attribute_n... | Store all configured fields |
10,624 | def index_text term_generator = Xapian :: TermGenerator . new term_generator . database = @database . writer term_generator . document = @xapian_doc if XapianDb :: Config . stemmer term_generator . stemmer = XapianDb :: Config . stemmer term_generator . stopper = XapianDb :: Config . stopper if XapianDb :: Config . sto... | Index all configured text methods |
10,625 | def get_values_to_index_from ( obj ) if obj . is_a? Array return obj . map { | element | get_values_to_index_from element } . flatten . compact end return obj . attributes . values . compact if obj . respond_to? ( :attributes ) && obj . attributes . is_a? ( Hash ) obj . to_s . nil? ? [ ] : [ obj ] end | Get the values to index from an object |
10,626 | def preprocess if group_by? parse_file { | row | @preprocessed_csv << csv_to_hash_with_duplicates ( row ) } @preprocessed_csv = @preprocessed_csv . group_by { | row | row [ key_column ] } end end | note that group_by requires the entire file to be read into memory |
10,627 | def contains_row? row raise ArgumentError , "table should be a Workbook::Row (you passed a #{t.class})" unless row . is_a? ( Workbook :: Row ) self . collect { | r | r . object_id } . include? row . object_id end | Returns true if the row exists in this table |
10,628 | def dimensions height = self . count width = self . collect { | a | a . length } . max [ width , height ] end | Returns The dimensions of this sheet based on longest row |
10,629 | def create_or_find_format_by name , variant = :default fs = @formats [ name ] fs = @formats [ name ] = { } if fs . nil? f = fs [ variant ] if f . nil? f = Workbook :: Format . new if variant != :default and fs [ :default ] f = fs [ :default ] . clone end @formats [ name ] [ variant ] = f end return @formats [ name ] [ ... | Create or find a format by name |
10,630 | def import filename , extension = nil , options = { } extension = file_extension ( filename ) unless extension if [ 'txt' , 'csv' , 'xml' ] . include? ( extension ) open_text filename , extension , options else open_binary filename , extension , options end end | Loads an external file into an existing worbook |
10,631 | def open_binary filename , extension = nil , options = { } extension = file_extension ( filename ) unless extension f = open ( filename ) send ( "load_#{extension}" . to_sym , f , options ) end | Open the file in binary read - only mode do not read it but pas it throug to the extension determined loaded |
10,632 | def open_text filename , extension = nil , options = { } extension = file_extension ( filename ) unless extension t = text_to_utf8 ( open ( filename ) . read ) send ( "load_#{extension}" . to_sym , t , options ) end | Open the file in non - binary read - only mode read it and parse it to UTF - 8 |
10,633 | def write filename , options = { } extension = file_extension ( filename ) send ( "write_to_#{extension}" . to_sym , filename , options ) end | Writes the book to a file . Filetype is based on the extension but can be overridden |
10,634 | def text_to_utf8 text unless text . valid_encoding? and text . encoding == "UTF-8" source_encoding = text . valid_encoding? ? text . encoding : "US-ASCII" text = text . encode ( 'UTF-8' , source_encoding , { :invalid => :replace , :undef => :replace , :replace => "" } ) text = text . gsub ( "\u0000" , "" ) end text end | Helper method to convert text in a file to UTF - 8 |
10,635 | def create_or_open_sheet_at index s = self [ index ] s = self [ index ] = Workbook :: Sheet . new if s == nil s . book = self s end | Create or open the existing sheet at an index value |
10,636 | def missing missing , array = [ ] , self . rangify i , length = 0 , array . size - 1 while i < length current = comparison_value ( array [ i ] , :last ) nextt = comparison_value ( array [ i + 1 ] , :first ) missing << ( current + 2 == nextt ? current + 1 : ( current + 1 ) .. ( nextt - 1 ) ) i += 1 end missing end | Returns the missing elements in an array set |
10,637 | def comparison_value ( value , position ) return value if value . class != Range position == :first ? value . first : value . last end | For a Range will return value . first or value . last . A non - Range will return itself . |
10,638 | def table = table raise ( ArgumentError , "value should be nil or Workbook::Table" ) unless [ NilClass , Workbook :: Table ] . include? table . class @table = table end | Set the table this column belongs to |
10,639 | def validate! ( * acceptable ) i = 0 if acceptable . first . is_a? ( Hash ) acceptable = Hash [ acceptable . first ] acceptable . keys . each { | k | acceptable [ k . to_s ] = acceptable [ k ] acceptable . delete ( k ) unless k . is_a? ( String ) } while ( i < length ) do val = self [ i ] passed = acceptable . has_key?... | Validate arguments against acceptable values . |
10,640 | def extract ( map ) map = Hash [ map ] map . keys . each { | k | map [ k . to_s ] = map [ k ] map . delete ( k ) unless k . is_a? ( String ) } groups = [ ] i = 0 while ( i < length ) do val = self [ i ] i += 1 next unless ! ! map . has_key? ( val ) num = map [ val ] group = [ val ] 0 . upto ( num - 1 ) do | j | group <... | Extract groups of values from argument list |
10,641 | def exec ( lock ) lock . synchronize { @thread = Thread . current @time_started = Time . now } @handler . call * @params lock . synchronize { @time_completed = Time . now @thread = nil } end | Set job metadata and execute job with specified params . |
10,642 | def launch_worker @worker_threads << Thread . new { while work = @work_queue . pop begin @running_queue << work work . exec ( @thread_lock ) rescue Exception => e puts "Thread raised Fatal Exception #{e}" puts "\n#{e.backtrace.join("\n")}" end end } end | Internal helper launch worker thread |
10,643 | def check_workers if @terminate @worker_threads . each { | t | t . kill } @worker_threads = [ ] elsif @timeout readd = [ ] while @running_queue . size > 0 && work = @running_queue . pop @thread_lock . synchronize { if work . expired? ( @timeout ) work . thread . kill @worker_threads . delete ( work . thread ) launch_wo... | Internal helper performs checks on workers |
10,644 | def table = t raise ArgumentError , "table should be a Workbook::Table (you passed a #{t.class})" unless t . is_a? ( Workbook :: Table ) or t == nil if t @table = t table . push ( self ) end end | Set reference to the table this row belongs to and add the row to this table |
10,645 | def find_cells_by_background_color color = :any , options = { } options = { :hash_keys => true } . merge ( options ) cells = self . collect { | c | c if c . format . has_background_color? ( color ) } . compact r = Row . new cells options [ :hash_keys ] ? r . to_symbols : r end | Returns an array of cells allows you to find cells by a given color normally a string containing a hex |
10,646 | def compact r = self . clone r = r . collect { | c | c unless c . nil? } . compact end | Compact detaches the row from the table |
10,647 | def flattened ff = Workbook :: Format . new ( ) formats . each { | a | ff . merge! ( a ) } return ff end | Applies the formatting options of self with its parents until no parent can be found |
10,648 | def load_stats ( data , user ) return data if data raise ( 'No data or user provided' ) unless user stats = GithubStats . new ( user ) . data raise ( "Failed to find data for #{user} on GitHub" ) unless stats stats end | Load stats from provided arg or github |
10,649 | def connection_event ( event , * args ) return unless @connection_event_handlers . keys . include? ( event ) @connection_event_handlers [ event ] . each { | h | h . call ( self , * args ) } end | Internal helper run connection event handlers for specified event passing self and args to handler |
10,650 | def client_for ( connection ) return nil , nil if self . indirect? || self . node_type == :local begin return Socket . unpack_sockaddr_in ( connection . get_peername ) rescue Exception => e end return nil , nil end | Internal helper extract client info from connection |
10,651 | def handle_message ( msg , connection = { } ) intermediate = Messages :: Intermediate . parse ( msg ) if Messages :: Request . is_request_message? ( intermediate ) tp << ThreadPoolJob . new ( intermediate ) { | i | handle_request ( i , false , connection ) } elsif Messages :: Notification . is_notification_message? ( i... | Internal helper handle message received |
10,652 | def handle_request ( message , notification = false , connection = { } ) client_port , client_ip = client_for ( connection ) msg = notification ? Messages :: Notification . new ( :message => message , :headers => @message_headers ) : Messages :: Request . new ( :message => message , :headers => @message_headers ) callb... | Internal helper handle request message received |
10,653 | def handle_response ( message ) msg = Messages :: Response . new ( :message => message , :headers => self . message_headers ) res = err = nil begin res = @dispatcher . handle_response ( msg . result ) rescue Exception => e err = e end @response_lock . synchronize { result = [ msg . msg_id , res ] result << err if ! err... | Internal helper handle response message received |
10,654 | def wait_for_result ( message ) res = nil message_id = message . msg_id @pending [ message_id ] = Time . now while res . nil? @response_lock . synchronize { if @timeout now = Time . now @pending . delete_if { | _ , start_time | ( now - start_time ) > @timeout } end pending_ids = @pending . keys fail 'Timed out' unless ... | Internal helper block until response matching message id is received |
10,655 | def add_module ( name ) require name m = name . downcase . gsub ( File :: SEPARATOR , '_' ) method ( "dispatch_#{m}" . intern ) . call ( self ) self end | Loads module from fs and adds handlers defined there |
10,656 | def handle ( signature , callback = nil , & bl ) if signature . is_a? ( Array ) signature . each { | s | handle ( s , callback , & bl ) } return self end @handlers [ signature ] = callback unless callback . nil? @handlers [ signature ] = bl unless bl . nil? self end | Register json - rpc handler with dispatcher |
10,657 | def handler_for ( rjr_method ) handler = @handlers . find { | k , v | k == rjr_method } handler ||= @handlers . find { | k , v | k . is_a? ( Regexp ) && ( k =~ rjr_method ) } handler . nil? ? nil : handler . last end | Return handler for specified method . |
10,658 | def env_for ( rjr_method ) env = @environments . find { | k , v | k == rjr_method } env ||= @environments . find { | k , v | k . is_a? ( Regexp ) && ( k =~ rjr_method ) } env . nil? ? nil : env . last end | Return the environment registered for the specified method |
10,659 | def start @em_lock . synchronize { @reactor_thread = Thread . new { begin EventMachine . run rescue Exception => e puts "Critical exception #{e}\n#{e.backtrace.join("\n")}" ensure @em_lock . synchronize { @reactor_thread = nil } end } unless @reactor_thread } sleep 0.01 until EventMachine . reactor_running? self end | EMAdapter initializer Start the eventmachine reactor thread if not running |
10,660 | def handle node_sig = "#{@rjr_node_id}(#{@rjr_node_type})" method_sig = "#{@rjr_method}(#{@rjr_method_args.join(',')})" RJR :: Logger . info "#{node_sig}->#{method_sig}" retval = instance_exec ( * @rjr_method_args , & @rjr_handler ) RJR :: Logger . info "#{node_sig}<-#{method_sig}<-#{retval.nil? ? "nil" : retval}" retu... | Invoke the request by calling the registered handler with the registered method parameters in the local scope |
10,661 | def validate return [ ] unless country country . validations . select do | validation | normalized_number . match? ( Regexp . new ( "^(#{validation.pattern})$" ) ) end . map ( & :name ) end | returns an array of valid types for the normalized number if array is empty we can assume that the number is invalid |
10,662 | def lint ( use_inline_comments = false ) ensure_flake8_is_installed errors = run_flake return if errors . empty? || errors . count <= threshold if use_inline_comments comment_inline ( errors ) else print_markdown_table ( errors ) end end | Lint all python files inside a given directory . Defaults to . |
10,663 | def create! ( attributes ) new_attributes = map_to_keys ( attributes ) new_attributes = new_attributes . merge ( RecordTypeManager :: FIELD_NAME => klass . record_type_id ) if klass . record_type_id client . create! ( klass . object_name , new_attributes ) end | create! doesn t return the SalesForce object back It will return only the object id |
10,664 | def produce ( topic , msg , key : nil ) Rafka . wrap_errors do redis_key = "topics:#{topic}" redis_key << ":#{key}" if key @redis . rpushx ( redis_key , msg . to_s ) end end | Create a new producer . |
10,665 | def publish ( topic_name : nil , event_name : nil , schema_name : nil , primary_key : nil , body : ) defaults = self . class . get_publish_defaults published_messages << Maitredee . publish ( topic_name : topic_name || defaults [ :topic_name ] , event_name : event_name || defaults [ :event_name ] , schema_name : schema... | publish a message with defaults |
10,666 | def consume ( timeout = 5 ) raised = false msg = consume_one ( timeout ) return nil if ! msg begin yield ( msg ) if block_given? rescue => e raised = true raise e end msg ensure commit ( msg ) if @rafka_opts [ :auto_commit ] && msg && ! raised end | Initialize a new consumer . |
10,667 | def consume_batch ( timeout : 1.0 , batch_size : 0 , batching_max_sec : 0 ) if batch_size == 0 && batching_max_sec == 0 raise ArgumentError , "one of batch_size or batching_max_sec must be greater than 0" end raised = false start_time = Time . now msgs = [ ] loop do break if batch_size > 0 && msgs . size >= batch_size ... | Consume a batch of messages . |
10,668 | def commit ( * msgs ) tp = prepare_for_commit ( * msgs ) tp . each do | topic , po | po . each do | partition , offset | Rafka . wrap_errors do @redis . rpush ( "acks" , "#{topic}:#{partition}:#{offset}" ) end end end tp end | Commit offsets for the given messages . |
10,669 | def prepare_for_commit ( * msgs ) tp = Hash . new { | h , k | h [ k ] = Hash . new ( 0 ) } msgs . each do | msg | if msg . offset >= tp [ msg . topic ] [ msg . partition ] tp [ msg . topic ] [ msg . partition ] = msg . offset end end tp end | Accepts one or more messages and prepare them for commit . |
10,670 | def add_type ( type ) hash = type . hash raise "upps #{hash} #{hash.class}" unless hash . is_a? ( :: Integer ) was = types [ hash ] return was if was types [ hash ] = type end | add a type meaning the instance given must be a valid type |
10,671 | def get_all_methods methods = [ ] each_type do | type | type . each_method do | meth | methods << meth end end methods end | all methods form all types |
10,672 | def pack ( body , key ) signed = plaintext_signature ( body , 'application/atom+xml' , 'base64url' , 'RSA-SHA256' ) signature = Base64 . urlsafe_encode64 ( key . sign ( digest , signed ) ) Nokogiri :: XML :: Builder . new do | xml | xml [ 'me' ] . env ( { 'xmlns:me' => XMLNS } ) do xml [ 'me' ] . data ( { type : 'appli... | Create a magical envelope XML document around the original body and sign it with a private key |
10,673 | def post ( salmon_url , envelope ) http_client . headers ( HTTP :: Headers :: CONTENT_TYPE => 'application/magic-envelope+xml' ) . post ( Addressable :: URI . parse ( salmon_url ) , body : envelope ) end | Deliver the magical envelope to a Salmon endpoint |
10,674 | def verify ( raw_body , key ) _ , plaintext , signature = parse ( raw_body ) key . public_key . verify ( digest , signature , plaintext ) rescue OStatus2 :: BadSalmonError false end | Verify the magical envelope s integrity |
10,675 | def swap_names ( left , right ) left , right = left . to_s , right . to_s l = @names [ left ] r = @names [ right ] raise "No such name #{left}" unless l raise "No such name #{right}" unless r @names [ left ] = r @names [ right ] = l end | To avoid many an if it can be handy to swap variable names . But since the names in the builder are not variables we need this method . As it says swap the two names around . Names must exist |
10,676 | def translate_method ( method_compiler , translator ) all = [ ] all << translate_cpu ( method_compiler , translator ) method_compiler . block_compilers . each do | block_compiler | all << translate_cpu ( block_compiler , translator ) end all end | translate one method which means the method itself and all blocks inside it returns an array of assemblers |
10,677 | def verify ( content , signature ) hmac = OpenSSL :: HMAC . hexdigest ( 'sha1' , @secret , content ) signature . downcase == "sha1=#{hmac}" end | Verify that the feed contents were meant for this subscription |
10,678 | def disable_memoization @_memoize = false @_memo_identifiers . each { | identifier | ( @_memo_cache_clear_proc || Proc . new { | ident | eval "@_memo_#{ident} = nil" } ) . call ( identifier ) } @_memo_identifiers . clear end | Halts memoization of API calls and clears the memoization cache . |
10,679 | def translate_Branch ( code ) target = code . label . is_a? ( Risc :: Label ) ? code . label . to_cpu ( self ) : code . label ArmMachine . b ( target ) end | This implements branch logic which is simply assembler branch |
10,680 | def set_length ( len , fill_char ) return if len <= 0 old = char_length return if old >= len self . char_length = len check_length fill_from_with ( old + 1 , fill_char ) end | pad the string with the given character to the given length |
10,681 | def set_char ( at , char ) raise "char not fixnum #{char.class}" unless char . kind_of? :: Integer index = range_correct_index ( at ) set_internal_byte ( index , char ) end | set the character at the given index to the given character character must be an integer as is the index the index starts at one but may be negative to count from the end indexes out of range will raise an error |
10,682 | def range_correct_index ( at ) index = at raise "index not integer #{at.class}" unless at . is_a? ( :: Integer ) raise "index must be positive , not #{at}" if ( index < 0 ) raise "index too large #{at} > #{self.length}" if ( index >= self . length ) return index + 11 end | private method to account for |
10,683 | def compare ( other ) return false if other . class != self . class return false if other . length != self . length len = self . length - 1 while ( len >= 0 ) return false if self . get_char ( len ) != other . get_char ( len ) len = len - 1 end return true end | compare the word to another currently checks for same class though really identity of the characters in right order would suffice |
10,684 | def normalize_name ( condition ) if ( condition . is_a? ( ScopeStatement ) and condition . single? ) condition = condition . first end return [ condition ] if condition . is_a? ( Variable ) or condition . is_a? ( Constant ) local = "tmp_#{object_id}" . to_sym assign = LocalAssignment . new ( local , condition ) [ Local... | given a something determine if it is a Name |
10,685 | def position_listener ( listener ) unless listener . class . name . include? ( "Listener" ) listener = PositionListener . new ( listener ) end register_event ( :position_changed , listener ) end | initialize with a given object first parameter The object will be the key in global position map |
10,686 | def get_code listener = event_table . find { | one | one . class == InstructionListener } return nil unless listener listener . code end | look for InstructionListener and return its code if found |
10,687 | def to_risc ( compiler ) l_reg = left . to_register ( compiler , self ) r_reg = right . to_register ( compiler , self ) compiler . add_code Risc . op ( self , :- , l_reg , r_reg ) compiler . add_code Risc :: IsZero . new ( self , false_jump . risc_label ( compiler ) ) end | basically move both left and right values into register subtract them and see if IsZero comparison |
10,688 | def to_register ( compiler , source ) if known_object . respond_to? ( :ct_type ) type = known_object . ct_type elsif ( known_object . respond_to? ( :get_type ) ) type = known_object . get_type else type = :Object end right = compiler . use_reg ( type ) case known_object when Constant parfait = known_object . to_parfait... | load the slots into a register the code is added to compiler the register returned |
10,689 | def to_binary ( platform ) linker = to_risc ( platform ) linker . position_all linker . create_binary linker end | Process previously stored vool source to binary . Binary code is generated byu calling to_risc then positioning and calling create_binary on the linker . The linker may then be used to creat a binary file . The biary the method name refers to is binary code in memory or in BinaryCode objects to be precise . |
10,690 | def ruby_to_vool ( ruby_source ) ruby_tree = Ruby :: RubyCompiler . compile ( ruby_source ) unless ( @vool ) @vool = ruby_tree . to_vool return @vool end unless ( @vool . is_a? ( Vool :: ScopeStatement ) ) @vool = Vool :: ScopeStatement . new ( [ @vool ] ) end @vool << ruby_tree . to_vool end | ruby_to_vool compiles the ruby to ast and then to vool |
10,691 | def request ( endpoint , method = 'get' , file = nil , params = { } ) method = method . downcase if file self . send ( "post_file" , endpoint , file ) else if endpoint [ 0 ] == '/' endpoint [ 0 ] = '' end self . send ( "#{method}_request" , endpoint , params ) end end | Connect to the PokitDok API with the specified Client ID and Client Secret . |
10,692 | def pharmacy_network ( params = { } ) npi = params . delete :npi endpoint = npi ? "pharmacy/network/#{npi}" : "pharmacy/network" get ( endpoint , params ) end | Invokes the pharmacy network cost endpoint . |
10,693 | def slot_type_for ( name ) if @callable . arguments_type . variable_index ( name ) slot_def = [ :arguments ] elsif @callable . frame_type . variable_index ( name ) slot_def = [ :frame ] elsif @method . arguments_type . variable_index ( name ) slot_def = [ :caller , :caller , :arguments ] elsif @method . frame_type . va... | determine how given name need to be accsessed . For blocks the options are args or frame or then the methods arg or frame |
10,694 | def to_risc ( compiler ) transfer = SlotLoad . new ( [ :message , :next_message , :receiver ] , @receiver , self ) . to_risc ( compiler ) compiler . reset_regs @arguments . each do | arg | arg . to_risc ( compiler ) compiler . reset_regs end transfer end | load receiver and then each arg into the new message delegates to SlotLoad for receiver and to the actual args . to_risc |
10,695 | def trigger ( name , * args ) event_table [ name ] . each { | handler | handler . send ( name . to_sym , * args ) } end | Trigger the given event name and passes all args to each handler for this event . |
10,696 | def execute_DynamicJump method = get_register ( @instruction . register ) pos = Position . get ( method . binary ) log . debug "Jump to binary at: #{pos} #{method.name}:#{method.binary.class}" raise "Invalid position for #{method.name}" unless pos . valid? pos = pos + Parfait :: BinaryCode . byte_offset set_pc ( pos ) ... | Instruction interpretation starts here |
10,697 | def position_code ( code_start ) assemblers . each do | asm | Position . log . debug "Method start #{code_start.to_s(16)} #{asm.callable.name}" code_pos = CodeListener . init ( asm . callable . binary , platform ) instructions = asm . instructions InstructionListener . init ( instructions , asm . callable . binary ) co... | Position all BinaryCode . |
10,698 | def position_inserted ( position ) Position . log . debug "extending one at #{position}" pos = CodeListener . init ( position . object . next_code , @platform ) raise "HI #{position}" unless position . valid? return unless position . valid? Position . log . debug "insert #{position.object.next_code.object_id.to_s(16)}"... | need to pass the platform to translate new jumps |
10,699 | def set_jump_for ( position ) at = position . at code = position . object return unless code . next_code jump = Branch . new ( "BinaryCode #{at.to_s(16)}" , code . next_code ) translator = @platform . translator cpu_jump = translator . translate ( jump ) pos = at + code . padded_length - cpu_jump . byte_length Position... | insert a jump to the next instruction at the last instruction thus hopping over the object header |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.