idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
20,200 | def license ( dir = Dir . pwd , license = FalkorLib :: Config :: Bootstrap :: DEFAULTS [ :metadata ] [ :license ] , authors = '' , options = { :filename => 'LICENSE' } ) return if ( ( license . empty? ) or ( license == 'none' ) or ( license =~ / / ) ) return unless FalkorLib :: Config :: Bootstrap :: DEFAULTS [ :licenses ] . keys . include? ( license ) info "Generate the #{license} licence file" path = normalized_path ( dir ) use_git = FalkorLib :: Git . init? ( path ) rootdir = ( use_git ) ? FalkorLib :: Git . rootdir ( path ) : path Dir . chdir ( rootdir ) do run %( licgen #{license.downcase} #{authors} ) run %( mv LICENSE #{options[:filename]} ) if ( options [ :filename ] and options [ :filename ] != 'LICENSE' ) end end | select_licence license Generate the licence file |
20,201 | def guess_project_config ( dir = Dir . pwd , options = { } ) path = normalized_path ( dir ) use_git = FalkorLib :: Git . init? ( path ) rootdir = ( use_git ) ? FalkorLib :: Git . rootdir ( path ) : path local_config = FalkorLib :: Config . get ( rootdir , :local ) return local_config [ :project ] if local_config [ :project ] config = FalkorLib :: Config :: Bootstrap :: DEFAULTS [ :metadata ] . clone [ :name , :forge ] . each do | k | config [ k . to_sym ] = options [ k . to_sym ] if options [ k . to_sym ] end config [ :name ] = ask ( "\tProject name: " , get_project_name ( dir ) ) if config [ :name ] . empty? if ( use_git ) config [ :origin ] = FalkorLib :: Git . config ( 'remote.origin.url' ) if config [ :origin ] =~ / \. \w \d \/ \w / config [ :forge ] = Regexp . last_match ( 2 ) . to_sym config [ :by ] = Regexp . last_match ( 3 ) elsif config [ :forge ] . empty? config [ :forge ] = select_forge ( config [ :forge ] ) . to_sym end end forges = FalkorLib :: Config :: Bootstrap :: DEFAULTS [ :forge ] [ config [ :forge ] . to_sym ] default_source = case config [ :forge ] when :gforge 'https://' + forges [ :url ] + "/projects/" + config [ :name ] . downcase when :github , :gitlab 'https://' + forges [ :url ] + "/" + config [ :by ] + "/" + config [ :name ] . downcase else "" end config [ :source ] = config [ :project_page ] = default_source config [ :issues_url ] = "#{config[:project_page]}/issues" config [ :license ] = select_licence if config [ :license ] . empty? [ :summary ] . each do | k | config [ k . to_sym ] = ask ( "\t" + Kernel . format ( "Project %-20s" , k . to_s ) ) end config [ :description ] = config [ :summary ] config [ :gitflow ] = FalkorLib :: GitFlow . guess_gitflow_config ( rootdir ) config [ :make ] = File . exists? ( File . join ( rootdir , 'Makefile' ) ) config [ :rake ] = File . exists? ( File . join ( rootdir , 'Rakefile' ) ) config end | license guess_project_config Guess the project configuration |
20,202 | def collect ( job , path_id = nil ) key = job_key ( job ) token = @cache [ key ] token = update_token ( job , token , path_id ) if complete? ( job , token ) @cache . delete ( key ) keep_going ( job ) else @cache [ key ] = token end end | Collects a job and deternines if the job should be moved on to the next Actor or if it should wait until more processing paths have finished . This method is executed asynchronously . |
20,203 | def update_token ( job , token , path_id ) raise NotImplementedError . new ( "neither Collector.update_token() nor Job.update_token() are implemented" ) unless job . respond_to? ( :update_token ) job . update_token ( token , path_id ) end | Updates the token associated with the job . The job or the Collector subclass can use any data desired to keep track of the job s paths that have been completed . This method is executed asynchronously . |
20,204 | def complete? ( job , token ) raise NotImplementedError . new ( "neither Collector.complete?() nor Job.complete?() are implemented" ) unless job . respond_to? ( :complete? ) job . complete? ( token ) end | Returns true if the job has been processed by all paths converging on the collector . This can be implemented in the Collector subclass or in the Job . This method is executed asynchronously . |
20,205 | def reset self . apikey = DEFAULT_APIKEY self . endpoint = DEFAULT_ENDPOINT self . sandbox_endpoint = DEFAULT_SANDBOX_ENDPOINT self . sandbox_enabled = DEFAULT_SANDBOX_ENABLED self . fmt = DEFAULT_FMT end | Reset all configurations back to defaults |
20,206 | def upload ( & block ) @source . files . each do | key , file | object = @target . files . create ( { :key => key , :body => file , :public => true , :cache_control => 'max-age=0' } ) block . call file , object end end | Upload files from target to the source . |
20,207 | def clean ( & block ) @target . files . each do | object | unless @source . files . include? object . key block . call ( object ) object . destroy end end end | Removes files from target that don t exist on the source . |
20,208 | def add ( key , value ) if @env . has_key? ( key ) @env [ key ] += value else set ( key , value ) end end | Adds a value for key |
20,209 | def handle_qt unless tc . qt . check_once puts '### WARN: QT prerequisites not complete!' end @settings [ 'ADD_CFLAGS' ] += tc . qt . cflags @settings [ 'ADD_CXXFLAGS' ] += tc . qt . cflags @settings [ 'ADD_LDFLAGS' ] += tc . qt . ldflags @settings [ 'ADD_LIBS' ] += tc . qt . libs end | Qt special handling |
20,210 | def src_directories ( main_dir , sub_dirs , params = { } ) if params [ :subdir_only ] all_dirs = [ ] else all_dirs = [ main_dir ] end sub_dirs . each do | dir | all_dirs << "#{main_dir}/#{dir}" end all_dirs . compact end | Returns array of source code directories assembled via given parameters |
20,211 | def lib_incs ( libs = [ ] ) includes = Array . new libs . each do | name , param | lib_includes = PrjFileCache . exported_lib_incs ( name ) includes += lib_includes if lib_includes . any? end includes end | Returns list of include directories for name of libraries in parameter libs |
20,212 | def search_files ( directories , extensions ) extensions . each_with_object ( [ ] ) do | ext , obj | directories . each do | dir | obj << FileList [ "#{dir}/*#{ext}" ] end end . flatten . compact end | Search files recursively in directory with given extensions |
20,213 | def find_files_relative ( directory , files ) return [ ] unless files . any? files . each_with_object ( [ ] ) do | file , obj | path = "#{directory}/#{file}" obj << path if File . exist? ( path ) end end | Search list of files relative to given directory |
20,214 | def read_prj_settings ( file ) unless File . file? ( file ) file = File . dirname ( __FILE__ ) + '/prj.rake' end KeyValueReader . new ( file ) end | Read project file if it exists |
20,215 | def load_deps ( deps ) deps . each do | file | if File . file? ( file ) Rake :: MakefileLoader . new . load ( file ) end end end | Loads dependency files if already generated |
20,216 | def obj_to_source ( obj , source_dir , obj_dir ) stub = obj . gsub ( obj_dir , source_dir ) . ext ( '' ) src = stub_to_src ( stub ) return src if src raise "No matching source for #{obj} found." end | Transforms an object file name to its source file name by replacing build directory base with the source directory base and then iterating list of known sources to match |
20,217 | def dep_to_source ( dep , source_dir , dep_dir ) stub = dep . gsub ( dep_dir , source_dir ) . ext ( '' ) src = stub_to_src ( stub ) return src if src raise "No matching source for #{dep} found." end | Transforms a dependency file name into its corresponding source file name by replacing file name extension and object directory with dependency directory . Searches through list of source files to find it . |
20,218 | def platform_flags_fixup ( libs ) libs [ :all ] . each do | lib | ps = tc . platform_settings_for ( lib ) unless ps . empty? @settings [ 'ADD_CFLAGS' ] += " #{ps[:CFLAGS]}" if ps [ :CFLAGS ] @settings [ 'ADD_CXXFLAGS' ] += " #{ps[:CXXFLAGS]}" if ps [ :CXXFLAGS ] @settings [ 'ADD_LDFLAGS' ] += ps [ :LDFLAGS ] . gsub ( / \s \S / , '' ) if ps [ :LDFLAGS ] end end end | Change ADD_CFLAGS ADD_CXXFLAGS ADD_LDFLAGS according to settings in platform file . |
20,219 | def search_libs ( settings ) search_libs = settings [ 'ADD_LIBS' ] . split our_lib_deps = [ ] search_libs . each do | lib | our_lib_deps << lib deps_of_lib = @@all_libs_and_deps [ lib ] if deps_of_lib our_lib_deps += deps_of_lib end end our_lib_deps . uniq! solibs_local = [ ] alibs_local = [ ] our_lib_deps . each do | lib | if PrjFileCache . contain? ( 'LIB' , lib ) alibs_local << lib elsif PrjFileCache . contain? ( 'SOLIB' , lib ) solibs_local << lib end end local_libs = ( alibs_local + solibs_local ) || [ ] { :local => local_libs , :local_alibs => alibs_local , :local_solibs => solibs_local , :all => our_lib_deps } end | Search dependent libraries as specified in ADD_LIBS setting of prj . rake file |
20,220 | def paths_of_libs ( some_libs ) local_libs = Array . new some_libs . each do | lib | if PrjFileCache . contain? ( 'LIB' , lib ) local_libs << "#{tc.settings['LIB_OUT']}/lib#{lib}.a" elsif PrjFileCache . contain? ( 'SOLIB' , lib ) local_libs << "#{tc.settings['LIB_OUT']}/lib#{lib}.so" end end local_libs end | Returns absolute paths to given libraries if they are local libraries of the current project . |
20,221 | def paths_of_local_libs local_libs = Array . new each_local_lib ( ) do | lib | if PrjFileCache . contain? ( 'LIB' , lib ) local_libs << "#{tc.settings['LIB_OUT']}/lib#{lib}.a" elsif PrjFileCache . contain? ( 'SOLIB' , lib ) local_libs << "#{tc.settings['LIB_OUT']}/lib#{lib}.so" end end local_libs end | Returns absolute paths to dependend local libraries i . e . libraries of the current project . |
20,222 | def to_cql if statement . respond_to? ( :cql ) && statement . respond_to? ( :params ) Cassie :: Support :: StatementParser . new ( statement ) . to_cql else statement . to_s end end | A CQL string with inline parameters representing the current statement as it would be executed in a CQL shell |
20,223 | def discover_user ( domain , claimed_id ) url = fetch_host_meta ( domain ) if url . nil? return nil end xrds = fetch_xrds ( domain , url ) user_url , authority = get_user_xrds_url ( xrds , claimed_id ) user_xrds = fetch_xrds ( authority , user_url , false ) return if user_xrds . nil? endpoints = OpenID :: OpenIDServiceEndpoint . from_xrds ( claimed_id , user_xrds ) return [ claimed_id , OpenID . get_op_or_user_services ( endpoints ) ] end | Handles discovery for a user s claimed ID . |
20,224 | def discover_site ( domain ) url = fetch_host_meta ( domain ) if url . nil? return nil end xrds = fetch_xrds ( domain , url ) unless xrds . nil? endpoints = OpenID :: OpenIDServiceEndpoint . from_xrds ( domain , xrds ) return [ domain , OpenID . get_op_or_user_services ( endpoints ) ] end return nil end | Handles discovery for a domain |
20,225 | def fetch_host_meta ( domain ) cached_value = get_cache ( domain ) return cached_value unless cached_value . nil? host_meta_url = "https://www.google.com/accounts/o8/.well-known/host-meta?hd=#{CGI::escape(domain)}" http_resp = OpenID . fetch ( host_meta_url ) if http_resp . code != "200" and http_resp . code != "206" return nil end matches = / / . match ( http_resp . body ) if matches . nil? return nil end put_cache ( domain , matches [ 1 ] ) return matches [ 1 ] end | Kickstart the discovery process by checking against Google s well - known location for hosted domains . This gives us the location of the site s XRDS doc |
20,226 | def fetch_xrds ( authority , url , cache = true ) return if url . nil? cached_xrds = get_cache ( url ) return cached_xrds unless cached_xrds . nil? http_resp = OpenID . fetch ( url ) return if http_resp . code != "200" and http_resp . code != "206" body = http_resp . body signature = http_resp [ "Signature" ] signed_by = SimpleSign . verify ( body , signature ) if ! signed_by . casecmp ( authority ) or ! signed_by . casecmp ( 'hosted-id.google.com' ) return false end if cache put_cache ( url , body ) end return body end | Fetches the XRDS and verifies the signature and authority for the doc |
20,227 | def get_user_xrds_url ( xrds , claimed_id ) types_to_match = [ 'http://www.iana.org/assignments/relation/describedby' ] services = OpenID :: Yadis :: apply_filter ( claimed_id , xrds ) services . each do | service | if service . match_types ( types_to_match ) template = REXML :: XPath . first ( service . service_element , '//openid:URITemplate' , NAMESPACES ) authority = REXML :: XPath . first ( service . service_element , '//openid:NextAuthority' , NAMESPACES ) url = template . text . gsub ( '{%uri}' , CGI :: escape ( claimed_id ) ) return [ url , authority . text ] end end end | Process the URITemplate in the XRDS to derive the location of the claimed id s XRDS |
20,228 | def build_operation_chain ( stack ) empty_op = EmptyOperation . new ( nil ) stack . reverse . reduce ( empty_op ) do | next_op , current_op | klass , args , block = current_op if Class === klass klass . new ( next_op , * args , & block ) elsif Proc === klass lambda do | env | next_op . call ( klass . call ( env , * args ) ) end else raise StandardError , "Invalid operation, doesn't respond to `call`: #{klass.inspect}" end end end | Iterate through the stack and build a single callable object which consists of each operation referencing the next one in the chain |
20,229 | def method_missing ( name , * args , & block ) return attributes [ name . to_sym ] if attributes . include? ( name . to_sym ) return super end | support for Mustache rendering of ad hoc user defined variables if the key exists in the hash use if for a lookup |
20,230 | def helper_method ( name , * args , & block ) if name . match / / helpers . send ( name , * args , & block ) elsif ( const_get ( [ name , 'engine' ] . join ( '/' ) . classify ) rescue nil ) helpers . send ( name , * args , & block ) else current_arbre_element . add_child helpers . send ( name , * args , & block ) end end | In order to not pollute our templates with helpers . prefixed everywhere we want to try to distinguish helpers that are almost always used as parameters to other methods such as path helpers and not add them as elements |
20,231 | def log2file ( filename = File . basename ( $0 ) + '.todo' , level = Log4r :: ALL ) @logger . add ( Log4r :: FileOutputter . new ( 'ToDo' , :filename => filename , :level => level , :formatter => FixmeFormatter ) ) end | = begin rdoc Write the todo s in a logging file . |
20,232 | def save unless [ :handle , :new , :modify , :save ] . all? { | method | api_methods [ method ] } raise "Not all necessary api methods are defined to process this action!" end entry = self . class . find_one ( name ) self . class . in_transaction ( true ) do | token | if entry entryid = self . class . make_call ( api_methods [ :handle ] , name , token ) else entryid = self . class . make_call ( api_methods [ :new ] , token ) self . class . make_call ( api_methods [ :modify ] , entryid , 'name' , name , token ) end cobbler_record_fields . each do | field | field_s = field . to_s if ! locked_fields . include? ( field ) && user_definitions . has_key? ( field_s ) self . class . make_call ( api_methods [ :modify ] , entryid , field_s , user_definitions [ field_s ] , token ) end end cobbler_collections_store_callbacks . each do | callback | send ( callback , entryid , token ) end self . class . make_call ( api_methods [ :save ] , entryid , token ) end end | Save an item on the remote cobbler server This will first lookup if the item already exists on the remote server and use its handle store the attributes . Otherwise a new item is created . |
20,233 | def remove raise "Not all necessary api methods are defined to process this action!" unless api_methods [ :remove ] self . class . in_transaction ( true ) do | token | self . class . make_call ( api_methods [ :remove ] , name , token ) end end | delete the item on the cobbler server |
20,234 | def copy ( newname ) raise "Not all necessary api methods are defined to process this action!" unless api_methods [ :copy ] entry = self . class . find_one ( name ) if entry self . class . in_transaction ( true ) do | token | entryid = self . class . make_call ( api_methods [ :handle ] , name , token ) self . class . make_call ( api_methods [ :copy ] , entryid , newname , token ) end end end | copy the item on the cobbler server |
20,235 | def generate_apprepo_file ( _apprepo_path , options ) gem_path = Helper . gem_path ( 'apprepo' ) apprepo = File . read ( "#{gem_path}/../assets/RepofileDefault" ) apprepo . gsub! ( '[[APP_IDENTIFIER]]' , options [ :app ] . bundle_id ) apprepo . gsub! ( '[[APPREPO_IPA_PATH]]' , options [ :app ] . file_path ) apprepo . gsub! ( '[[APP_VERSION]]' , options [ :app ] . version ) apprepo . gsub! ( '[[APP_NAME]]' , options [ :app ] . name ) end | This method takes care of creating a new apprepo folder with metadata and screenshots folders |
20,236 | def rebuild_nested_interval_tree! skip_callback :update , :before , :update_nested_interval old_default_scopes = default_scopes default_scope -> { where ( "#{quoted_table_name}.lftq > 0" ) } update_hash = { lftp : 0 , lftq : 0 } update_hash [ :rgtp ] = 0 if columns_hash [ "rgtp" ] update_hash [ :rgtq ] = 0 if columns_hash [ "rgtq" ] update_hash [ :lft ] = 0 if columns_hash [ "lft" ] update_hash [ :rgt ] = 0 if columns_hash [ "rgt" ] update_all update_hash clear_cache! update_subtree = -> ( node ) { node . create_nested_interval node . save node . class . unscoped . where ( nested_interval . foreign_key => node . id ) . find_each & update_subtree } unscoped . roots . find_each & update_subtree set_callback :update , :before , :update_nested_interval self . default_scopes = old_default_scopes end | Rebuild the intervals tree |
20,237 | def deliver ( default = nil ) _eval_pre if @pre valid_option_chosen = false until valid_option_chosen response = messenger . prompt ( @prompt_text , default ) if validate ( response ) valid_option_chosen = true @answer = evaluate_behaviors ( response ) _eval_post if @post else messenger . error ( @last_error_message ) end end end | Initializes a new Pref via passed - in parameters . Also initializes objects for each Validator and Behavior on this Pref . |
20,238 | def evaluate_behaviors ( text ) modified_text = text if @behavior_objects @behavior_objects . each do | b | modified_text = b . evaluate ( modified_text ) end end modified_text end | Runs the passed text through this Pref s behaviors . |
20,239 | def _check_validators ( text ) ret = true if @validator_objects @validator_objects . each do | v | v . validate ( text ) unless v . is_valid @last_error_message = v . message ret = false end end end ret end | Validates a text against the validators for this Pref |
20,240 | def _init_action ( action_hash ) obj = _load_asset ( ASSET_TYPE_ACTION , action_hash [ :name ] ) obj . parameters = action_hash [ :parameters ] obj end | Attempts to instantiate a Pre or Post Action based on name ; if successful the new object gets placed in |
20,241 | def _init_and_add_behavior ( behavior_hash ) obj = _load_asset ( ASSET_TYPE_BEHAVIOR , behavior_hash [ :name ] ) unless obj . nil? obj . parameters = behavior_hash [ :parameters ] @behavior_objects << obj end end | Attempts to instantiate a Behavior based on name ; if successful the new object gets placed in |
20,242 | def each_attribute return enum_for ( :each_attribute ) unless block_given? @xml . css ( "symbol attr" ) . each do | attr | yield attr . attribute ( 'name' ) . value , attr . attribute ( 'value' ) . value end end | Iterates over each attribute present in the given symbol . |
20,243 | def set_pin_name ( node , name ) return unless node . name == "pin" original_name = get_pin_name ( node ) pin_labels = @xml . css ( "symbol graph attrtext[attrname=\"PinName\"][type=\"pin #{original_name}\"]" ) pin_labels . each { | pin | pin . attribute ( 'type' ) . value = "pin #{name}" } node . attribute ( "name" ) . value = name end | Sets name of the pin represented by the given node updating all values |
20,244 | def set_pin_width! ( node , width ) _ , left , right = parse_pin_name ( get_pin_name ( node ) ) left ||= 0 right ||= 0 if right > left right = left + width - 1 else left = right + width - 1 end set_pin_bounds! ( node , left , right ) end | Adjusts the bounds of the given bus so the bus is of the provided width by modifying the bus s upper bound . If the node is not a bus it will be made into a bus whose right bound is 0 . |
20,245 | def render ( view_name = nil , context : Attributor :: DEFAULT_ROOT_CONTEXT , renderer : Renderer . new , ** opts ) if ! view_name . nil? warn 'DEPRECATED: please do not pass the view name as the first parameter in Blueprint.render, pass through the view: named param instead.' elsif opts . key? ( :view ) view_name = opts [ :view ] end fields = opts [ :fields ] view_name = :default if view_name . nil? && fields . nil? if view_name unless ( view = self . class . views [ view_name ] ) raise "view with name '#{view_name.inspect}' is not defined in #{self.class}" end return view . render ( self , context : context , renderer : renderer ) end if fields . is_a? Array fields = fields . each_with_object ( { } ) { | field , hash | hash [ field ] = true } end expanded_fields = FieldExpander . expand ( self . class , fields ) renderer . render ( self , expanded_fields , context : context ) end | Render the wrapped data with the given view |
20,246 | def add_column ( table_name , column_name , type , options = { } ) table_definition = TableDefinition . new if ! table_definition . respond_to? ( type ) raise Errors :: MigrationDefinitionError ( "Type '#{type}' is not valid for cassandra migration." ) end table_definition . send ( type , column_name , options ) announce_operation "add_column(#{column_name}, #{type})" cql = "ALTER TABLE #{table_name} ADD " cql << table_definition . to_add_column_cql announce_suboperation cql execute cql end | Adds a column to a table . |
20,247 | def listen Net :: HTTP . start ( @address . host , @address . port ) do | http | http . request ( Net :: HTTP :: Get . new ( @address ) ) do | response | response . read_body do | chunk | @parser . push ( chunk ) . each { | e | yield ( e ) } end end end end | Create new SSE client . |
20,248 | def srs_distribution ( item_type = "all" ) raise ArgumentError , "Please use a valid SRS type (or none for all types)" if ! ITEM_TYPES . include? ( item_type ) response = api_response ( "srs-distribution" ) srs_distribution = response [ "requested_information" ] return srs_distribution if item_type == "all" return srs_distribution [ item_type ] end | Gets the counts for each SRS level and item types . |
20,249 | def srs_items_by_type ( item_type ) raise ArgumentError , "Please use a valid SRS type." if ! ITEM_TYPES . include? ( item_type ) || item_type == "all" items_by_type = [ ] %w( radicals kanji vocabulary ) . each do | type | items = send ( "#{type}_list" ) items . reject! { | item | item [ "user_specific" ] . nil? || item [ "user_specific" ] [ "srs" ] != item_type } . map! do | item | item . merge! ( "type" => ( type == 'radicals' ? 'radical' : type ) ) end items_by_type << items end items_by_type . flatten end | Gets all items for a specific SRS level . |
20,250 | def add ( job ) if @workers . empty? @work_queue . insert ( 0 , job ) else worker = @workers . pop ( ) ask_worker ( worker , job ) end end | Places a job on the work queue . This method is executed asynchronously . |
20,251 | def ready ( worker ) if @work_queue . empty? @workers . insert ( 0 , worker ) unless @workers . include? ( worker ) else job = @work_queue . pop ( ) @add_thread . wakeup ( ) unless @add_thread . nil? ask_worker ( worker , job ) end end | Identifies a worker as available to process jobs when they become available . This method is executed asynchronously . |
20,252 | def post ( url , data = { } , options = { } ) response = connection . post do | req | req . saddle_options = options req . url ( url ) req . body = data end handle_response ( response ) end | Make a POST request |
20,253 | def delete ( url , params = { } , options = { } ) response = connection . delete do | req | req . saddle_options = options req . url ( url , params ) end handle_response ( response ) end | Make a DELETE request |
20,254 | def connection @connection ||= Faraday . new ( base_url , :builder_class => Saddle :: RackBuilder ) do | connection | connection . builder . saddle_options [ :client_options ] = @options connection . options [ :timeout ] = @timeout connection . builder . saddle_options [ :request_style ] = @request_style connection . builder . saddle_options [ :num_retries ] = @num_retries connection . builder . saddle_options [ :client ] = @parent_client connection . use ( Saddle :: Middleware :: Response :: DefaultResponse ) connection . use ( Saddle :: Middleware :: RubyTimeout ) connection . use ( Saddle :: Middleware :: Request :: UserAgent ) connection . use ( Saddle :: Middleware :: Request :: PathPrefix ) @additional_middlewares . each do | m | m [ :args ] ? connection . use ( m [ :klass ] , * m [ :args ] ) : connection . use ( m [ :klass ] ) end connection . use ( Saddle :: Middleware :: Request :: JsonEncoded ) connection . use ( Saddle :: Middleware :: Request :: UrlEncoded ) connection . use ( Saddle :: Middleware :: Request :: Retry ) connection . use ( Saddle :: Middleware :: Response :: RaiseError ) connection . use ( Saddle :: Middleware :: Response :: ParseJson ) connection . use ( FaradayMiddleware :: Instrumentation ) connection . use ( Saddle :: Middleware :: ExtraEnv ) if @stubs . nil? connection . adapter ( @http_adapter [ :key ] , * @http_adapter [ :args ] ) else connection . adapter ( :test , @stubs ) end end end | Build a connection instance wrapped in the middleware that we want |
20,255 | def remove_child ( child ) child = child . name if child . is_a? ( Model ) children . delete ( child ) end | Deletes the specified child from children list |
20,256 | def attach ( p1 , to : , between : nil , and : nil ) p2 = to sender = between receiver = binding . local_variable_get ( :and ) raise ArgumentError . new ( "'between:' keyword was omitted, 'p1' should be a Port." ) if sender . nil? && ! p1 . is_a? ( Port ) raise ArgumentError . new ( "'and:' keyword was omitted, 'to:' should be a Port" ) if receiver . nil? && ! p2 . is_a? ( Port ) a = if p1 . is_a? ( Port ) then p1 . host elsif sender . is_a? ( Coupleable ) then sender elsif sender == @name then self else fetch_child ( sender ) ; end b = if p2 . is_a? ( Port ) then p2 . host elsif receiver . is_a? ( Coupleable ) then receiver elsif receiver == @name then self else fetch_child ( receiver ) ; end if has_child? ( a ) && has_child? ( b ) p1 = a . output_port ( p1 ) unless p1 . is_a? ( Port ) p2 = b . input_port ( p2 ) unless p2 . is_a? ( Port ) raise InvalidPortTypeError . new unless p1 . output? && p2 . input? raise FeedbackLoopError . new ( "#{a} must be different than #{b}" ) if a . object_id == b . object_id _internal_couplings [ p1 ] << p2 elsif a == self && has_child? ( b ) p1 = a . input_port ( p1 ) unless p1 . is_a? ( Port ) p2 = b . input_port ( p2 ) unless p2 . is_a? ( Port ) raise InvalidPortTypeError . new unless p1 . input? && p2 . input? _input_couplings [ p1 ] << p2 elsif has_child? ( a ) && b == self p1 = a . output_port ( p1 ) unless p1 . is_a? ( Port ) p2 = b . output_port ( p2 ) unless p2 . is_a? ( Port ) raise InvalidPortTypeError . new unless p1 . output? && p2 . output? _output_couplings [ p1 ] << p2 else raise InvalidPortHostError . new ( "Illegal coupling between #{p1} and #{p2}" ) end end | Adds a coupling to self between two ports . |
20,257 | def manifest_as_json structure = { appcode : appcode , filename : filename , bundle_identifier : bundle_identifier , bundle_version : bundle_version , title : title , subtitle : subtitle , notify : notify } fputs structure end | Provide JSON serialized data |
20,258 | def copy_options ( options ) copy_options = { can_copy : false , ancestor_exist : false , locked : false } destination = copy_destination options to_path = join_paths @root_dir , destination to_path_exists = File . exist? to_path copy_options [ :ancestor_exist ] = File . exist? parent_path destination copy_options [ :locked ] = can_copy_locked_option to_path , to_path_exists copy_options = can_copy_option copy_options , options , to_path_exists copy_options end | Responsible for returning a hash with keys indicating if the resource can be copied if an ancestor exists or if the copy destinatin is locked . |
20,259 | def print ( formatted = nil ) result = name unless version . nil? result += ", version #{version}" end if formatted result = "#{FORMATTING_STAR.colorize(:yellow)} #{result}" end result end | Get formatted information about process |
20,260 | def source case options [ :processors ] . present? when true then HtmlSlicer :: Process . iterate ( @env . send ( @method_name ) , options [ :processors ] ) else @env . send ( @method_name ) end end | Getting source content |
20,261 | def slice! ( slice = nil ) raise ( Exception , "Slicing unavailable!" ) unless sliced? if slice . present? if slice . to_i . in? ( 1 .. slice_number ) @current_slice = slice . to_i else raise ( ArgumentError , "Slice number must be Integer in (1..#{slice_number}). #{slice.inspect} passed." ) end end self end | General slicing method . Passing the argument changes the + current_slice + . |
20,262 | def view ( node , slice , & block ) slice = slice . to_i case node when :: HTML :: Tag then children_view = node . children . map { | child | view ( child , slice , & block ) } . compact . join if resized? resizing . resize_node ( node ) end if sliced? if slicing . map . get ( node , slice ) || children_view . present? if node . closing == :close "</#{node.name}>" else s = "<#{node.name}" node . attributes . each do | k , v | s << " #{k}" s << "=\"#{v}\"" if String === v end s << " /" if node . closing == :self s << ">" s += children_view s << "</#{node.name}>" if node . closing != :self && ! node . children . empty? s end end else node . to_s end when :: HTML :: Text then if sliced? if range = slicing . map . get ( node , slice ) ( range . is_a? ( Array ) ? node . content [ Range . new ( * range ) ] : node . content ) . tap do | export | unless range == true || ( range . is_a? ( Array ) && range . last == - 1 ) export << slicing . options . text_break if slicing . options . text_break if block_given? yield self , export end end end end else node . to_s end when :: HTML :: CDATA then node . to_s when :: HTML :: Node then node . children . map { | child | view ( child , slice , & block ) } . compact . join end end | Return a textual representation of the node including all children . |
20,263 | def version SelectVersionsQuery . new . fetch_first || Version . new ( '0' ) rescue Cassandra :: Errors :: InvalidError raise uninitialized_error end | The current schema version |
20,264 | def record_version ( version , set_execution_metadata = true ) time = Time . now version . id ||= Cassandra :: TimeUuid :: Generator . new . at ( time ) if set_execution_metadata version . executed_at = time version . executor = Etc . getlogin rescue '<unknown>' end InsertVersionQuery . new ( version : version ) . execute! @applied_versions = nil rescue StandardError => e version . id = nil version . executed_at = nil version . executor = nil raise e end | Record a version in the schema version store . This should only be done if the version has been sucesfully migrated |
20,265 | def load_applied_versions database_versions . tap do | versions | versions . each { | v | VersionObjectLoader . new ( v ) . load } end rescue Cassandra :: Errors :: InvalidError => e raise uninitialized_error end | load version migration class from disk |
20,266 | def init return if @has_been_init @socket = init_socket ( @socket ) @socket . connect internalWrapper = ( Struct . new :url , :socket do def write ( * args ) self . socket . write ( * args ) end end ) . new @url . to_s , @socket @driver = WebSocket :: Driver . client internalWrapper @driver . on :open do @connected = true unless @callbacks [ :open ] . nil? @callbacks [ :open ] . call end end @driver . on :error do | event | @connected = false unless @callbacks [ :error ] . nil? @callbacks [ :error ] . call end end @driver . on :message do | event | data = JSON . parse event . data unless @callbacks [ :message ] . nil? @callbacks [ :message ] . call data end end @driver . start @has_been_init = true end | This init has been delayed because the SSL handshake is a blocking and expensive call |
20,267 | def inner_loop return if @stop data = @socket . readpartial 4096 return if data . nil? or data . empty? @driver . parse data @msg_queue . each { | msg | @driver . text msg } @msg_queue . clear end | All the polling work is done here |
20,268 | def error ( m ) puts _word_wrap ( m , '# ' ) . red @targets . each { | _ , t | t . error ( m ) } end | Outputs a formatted - red error message . |
20,269 | def info ( m ) puts _word_wrap ( m , '# ' ) . blue @targets . each { | _ , t | t . info ( m ) } end | Outputs a formatted - blue informational message . |
20,270 | def section ( m ) puts _word_wrap ( m , '- ) . purple @targets . each { | _ , t | t . section ( m ) } end | Outputs a formatted - purple section message . |
20,271 | def success ( m ) puts _word_wrap ( m , '# ' ) . green @targets . each { | _ , t | t . success ( m ) } end | Outputs a formatted - green success message . |
20,272 | def warn ( m ) puts _word_wrap ( m , '# ' ) . yellow @targets . each { | _ , t | t . warn ( m ) } end | Outputs a formatted - yellow warning message . |
20,273 | def size_in_points size_in_pixels size = Sizes . invert [ size_in_pixels ] return ( size . nil? ) ? size_in_points ( "#{size_in_pixels.to_i + 1}px" ) : size end | or formula or filepath |
20,274 | def parse_json ( json ) hash = JSON . parse ( json , :symbolize_names => true ) if hash [ :created ] hash . merge! ( { :created => parse_iso_date_string ( hash [ :created ] ) } ) end if hash [ :updated ] hash . merge! ( { :updated => parse_iso_date_string ( hash [ :updated ] ) } ) end hash end | Parses a JSON string . |
20,275 | def execute ( query , ** args ) args = args . merge ( with_giraph_root ( args ) ) . merge ( with_giraph_resolvers ( args ) ) super ( query , ** args ) end | Extract special arguments for resolver objects let the rest pass - through Defer the execution only after setting up context and root_value with resolvers and remote arguments |
20,276 | def specification_path ( name , version ) raise ArgumentError , 'No name' unless name raise ArgumentError , 'No version' unless version relative_podspec = pod_path_partial ( name ) . join ( "#{version}/#{name}.podspec.json" ) download_file ( relative_podspec ) pod_path ( name ) . join ( "#{version}/#{name}.podspec.json" ) end | Returns the path of the specification with the given name and version . |
20,277 | def load_options ( * required_options , options ) required_options . each { | o | options = load_option ( o , options ) } options . each_key { | k | options = load_option ( k , options ) } block_given? ? yield : options end | Load instance variables from the provided hash of dependencies . |
20,278 | def build_tree ( requester ) root_node = build_root_node ( requester ) if defined? ( self . implementation_root ) endpoints_directories . each do | endpoints_directories | Dir [ "#{endpoints_directories}/**/*.rb" ] . each { | f | require ( f ) } end build_node_children ( self . endpoints_module , root_node , requester ) end root_node end | Build out the endpoint structure from the root of the implementation |
20,279 | def build_root_node ( requester ) if defined? ( self . implementation_root ) root_endpoint_file = File . join ( self . implementation_root , 'root_endpoint.rb' ) if File . file? ( root_endpoint_file ) warn "[DEPRECATION] `root_endpoint.rb` is deprecated. Please use `ABSOLUTE_PATH` in your endpoints." require ( root_endpoint_file ) root_node_class = self . implementation_module :: RootEndpoint else root_node_class = Saddle :: RootEndpoint end else root_node_class = Saddle :: RootEndpoint end root_node_class . new ( requester , nil , self ) end | Build our root node here . The root node is special in that it lives below the endpoints directory and so we need to manually check if it exists . |
20,280 | def build_node_children ( current_module , current_node , requester ) return unless current_module current_module . constants . each do | const_symbol | const = current_module . const_get ( const_symbol ) if const . class == Module branch_node = current_node . _build_and_attach_node ( Saddle :: TraversalEndpoint , const_symbol . to_s . underscore ) self . build_node_children ( const , branch_node , requester ) end if const < Saddle :: TraversalEndpoint current_node . _build_and_attach_node ( const ) end end end | Build out the traversal tree by module namespace |
20,281 | def combine_submissions ( options ) unless options [ :submission_ids ] . is_a? ( :: Array ) raise InvalidDataError , "submission_ids is required, and must be an Array." end options [ :source_pdfs ] = options [ :submission_ids ] . map do | id | { type : 'submission' , id : id } end options . delete :submission_ids combine_pdfs ( options ) end | Alias for combine_pdfs for backwards compatibility |
20,282 | def ensure_output_port ( port ) raise ArgumentError , "port argument cannot be nil" if port . nil? unless port . kind_of? ( Port ) port = output_port ( port ) raise ArgumentError , "the given port doesn't exists" if port . nil? end unless port . host == self raise InvalidPortHostError , "The given port doesn't belong to this \ model" end unless port . output? raise InvalidPortTypeError , "The given port isn't an output port" end port end | Finds and checks if the given port is an output port |
20,283 | def is_specification_in_effect? ( time = Time . now ) idx = 0 test_results = @cron_values . collect do | cvalues | time_value = time . send ( TimeMethods [ idx ] ) idx += 1 ! cvalues . detect { | cv | cv . is_effective? ( time_value ) } . nil? end . all? end | Constructs a new CronSpecification with a textual cron specificiation . |
20,284 | def hash_block hash_string = [ index , timestamp , data , prev_hash ] . join sha = Digest :: SHA256 . new sha . update ( hash_string ) sha . hexdigest end | Create the blocks hash by encrypting all the blocks data using SHA256 |
20,285 | def ask @prompts . reject { | p | p . prereqs } . each do | p | _deliver_prompt ( p ) end @prompts . select { | p | p . prereqs } . each do | p | _deliver_prompt ( p ) if _prereqs_fulfilled? ( p ) end end | Reads prompt data from and stores it . |
20,286 | def _prereqs_fulfilled? ( p ) ret = true p . prereqs . each do | req | a = @prompts . find do | answer | answer . config_key == req [ :config_key ] && answer . answer == req [ :config_value ] end ret = false if a . nil? end ret end | Utility method for determining whether a prompt s prerequisites have already been fulfilled . |
20,287 | def ask_worker ( worker , job ) raise NoMethodError . new ( "undefined method for #{job.class}. Expected a method invocation" ) unless job . is_a? ( Actor :: Act ) worker . ask ( job . op , * job . args ) end | Asks the worker to invoke the method of an Act Object . |
20,288 | def set_property ( name , value , mark_non_default = true ) node = get_property_node ( name ) node . attribute ( "value" ) . value = value node . attribute ( "valueState" ) . value = 'non-default' if mark_non_default end | Sets the value of an ISE project property . |
20,289 | def minimize_runtime! shortname = CGI :: escape ( get_property ( ShortNameProperty ) ) temp_path = Dir :: mktmpdir ( [ shortname , '' ] ) set_property ( WorkingDirectoryProperty , temp_path ) set_property ( GoalProperty , 'Minimum Runtime' ) end | Attempts to minimize synthesis runtime of a _single run_ . |
20,290 | def top_level_file ( absolute_path = true ) path = get_property ( TopLevelFileProperty ) if absolute_path path = File . expand_path ( path , @base_path ) end path end | Returns a path to the top - level file in the given project . |
20,291 | def bit_file working_directory = get_property ( WorkingDirectoryProperty ) name = get_property ( OutputNameProperty ) name = File . expand_path ( "#{working_directory}/#{name}.bit" , @base_path ) File :: exists? ( name ) ? name : nil end | Returns the best - guess path to the most recently generated bit file or nil if we weren t able to find one . |
20,292 | def slice ( * args , & block ) attr_name = args . first raise ( NameError , "Attribute name expected!" ) unless attr_name options = args . extract_options! config = HtmlSlicer . config ( options . delete ( :config ) ) . duplicate if options . present? options . each do | key , value | config . send ( "#{key}=" , value ) end end if block_given? yield config end if config . processors Array . wrap ( config . processors ) . each do | name | HtmlSlicer . load_processor! ( name ) end end method_name = config . as || "#{attr_name}_slice" config . cache_to = "#{method_name}_cache" if config . cache_to == true class_eval do define_method method_name do var_name = "@_#{method_name}" instance_variable_get ( var_name ) || instance_variable_set ( var_name , HtmlSlicer :: Interface . new ( self , attr_name , config . config ) ) end end if config . cache_to && self . superclass == ActiveRecord :: Base before_save do send ( method_name ) . load! end end end | The basic implementation method . |
20,293 | def uniqable ( * fields , to_param : nil ) fields = [ :uid ] if fields . blank? fields . each do | name | before_create { | record | record . uniqable_uid ( name ) } end define_singleton_method :uniqable_fields do fields end return if to_param . blank? define_method :to_param do public_send ( to_param ) end end | Uniqable fields and options declaration |
20,294 | def normalize_download ( file ) return file unless file . is_a? ( StringIO ) Tempfile . new ( 'download-' , binmode : true ) . tap do | tempfile | IO . copy_stream ( file , tempfile . path ) OpenURI :: Meta . init ( tempfile ) end end | open - uri will return a StringIO instead of a Tempfile if the filesize is less than 10 KB so we patch this behaviour by converting it into a Tempfile . |
20,295 | def keyspace_structure @keyspace_structure ||= begin args = [ "-e" , "'DESCRIBE KEYSPACE #{Cassie.configuration[:keyspace]}'" ] runner = Cassie :: Support :: SystemCommand . new ( "cqlsh" , args ) runner . succeed runner . output end end | Fetch the CQL that can be used to recreate the current environment s keyspace |
20,296 | def remarks ( keyword = nil ) if keyword . nil? @remarks else ukw = keyword . upcase @remarks . find_all { | r | r [ :keyword ] == ( ukw ) } end end | Return the remark - elements found in the document . If _keyword_ is nil then return all remarks else only the ones with the right keyword . |
20,297 | def find_section_title ( node ) title = node . find_first ( './db:title' ) if title . nil? title = node . find_first './db:info/db:title' end if title . nil? "" else title . content end end | Find the _title_ of the current section . That element is either directly following or inside an _info_ element . Return the empty string if no title can be found . |
20,298 | def check_node ( node , level , ctr ) if ( @@text_elements . include? node . name ) ctr << { :type => :para , :level => level , :words => count_content_words ( node ) } elsif ( @@section_elements . include? node . name ) title = find_section_title ( node ) ctr << { :type => :section , :level => level , :title => title , :name => node . name } node . children . each { | inner_elem | check_node ( inner_elem , level + 1 , ctr ) } if node . children? else node . children . each { | inner_elem | check_node ( inner_elem , level + 1 , ctr ) } if node . children? end ctr end | Check the document elements for content and type recursively starting at the current node . Returns an array with paragraph and section maps . |
20,299 | def is_docbook? ( doc ) dbns = doc . root . namespaces . default ( ! dbns . nil? && ( dbns . href . casecmp ( DOCBOOK_NS ) == 0 ) ) end | Check whether the document has a DocBook default namespace |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.