idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
12,700
def add_plan ( plan ) raise ArgumentError , "Invalid argument 'plan'. Expected Plan, got #{plan.class}." unless plan . is_a? ( Plan ) @plans << plan unless @associated_plans [ plan . uid ] @associated_plans [ plan . uid ] = plan end
Adds a Plan Series to this StructureSet .
12,701
def add_poi ( poi ) raise ArgumentError , "Invalid argument 'poi'. Expected POI, got #{poi.class}." unless poi . is_a? ( POI ) @structures << poi unless @structures . include? ( poi ) end
Adds a POI instance to this StructureSet .
12,702
def add_structure ( structure ) raise ArgumentError , "Invalid argument 'structure'. Expected ROI/POI, got #{structure.class}." unless structure . respond_to? ( :to_roi ) or structure . respond_to? ( :to_poi ) @structures << structure unless @structures . include? ( structure ) end
Adds a Structure instance to this StructureSet .
12,703
def add_roi ( roi ) raise ArgumentError , "Invalid argument 'roi'. Expected ROI, got #{roi.class}." unless roi . is_a? ( ROI ) @structures << roi unless @structures . include? ( roi ) end
Adds a ROI instance to this StructureSet .
12,704
def create_roi ( frame , options = { } ) raise ArgumentError , "Expected Frame, got #{frame.class}." unless frame . is_a? ( Frame ) algorithm = options [ :algorithm ] || 'Automatic' name = options [ :name ] || 'RTKIT-VOLUME' interpreter = options [ :interpreter ] || 'RTKIT' type = options [ :type ] || 'CONTROL' if opti...
Creates a ROI belonging to this StructureSet .
12,705
def remove_structure ( instance_or_number ) raise ArgumentError , "Invalid argument 'instance_or_number'. Expected a ROI Instance or an Integer (ROI Number). Got #{instance_or_number.class}." unless [ ROI , Integer ] . include? ( instance_or_number . class ) s_instance = instance_or_number if instance_or_number . is_a?...
Removes a ROI or POI from the structure set .
12,706
def structure_names names = Array . new @structures . each do | s | names << s . name end return names end
Gives the names of the structure set s associated structures .
12,707
def structure_numbers numbers = Array . new @structures . each do | s | numbers << s . number end return numbers end
Gives the numbers of the structure set s associated structures .
12,708
def to_dcm @dcm [ STRUCTURE_SET_ROI_SQ ] . delete_children @dcm [ ROI_CONTOUR_SQ ] . delete_children @dcm [ RT_ROI_OBS_SQ ] . delete_children @rois . each do | roi | @dcm [ STRUCTURE_SET_ROI_SQ ] . add_item ( roi . ss_item ) @dcm [ ROI_CONTOUR_SQ ] . add_item ( roi . contour_item ) @dcm [ RT_ROI_OBS_SQ ] . add_item ( r...
Converts the structure set instance to a DICOM object .
12,709
def load_structures if @dcm [ STRUCTURE_SET_ROI_SQ ] && @dcm [ ROI_CONTOUR_SQ ] && @dcm [ RT_ROI_OBS_SQ ] item_group = Hash . new @dcm [ STRUCTURE_SET_ROI_SQ ] . each do | roi_item | item_group [ roi_item . value ( ROI_NUMBER ) ] = { :roi => roi_item } end @dcm [ ROI_CONTOUR_SQ ] . each do | contour_item | item_group [...
Loads the ROI Items contained in the structure set and creates ROI and POI instances which are referenced to this structure set .
12,710
def add_image ( image ) raise ArgumentError , "Invalid argument 'image'. Expected Image, got #{image.class}." unless image . is_a? ( Image ) @associated_instance_uids [ image . uid ] = image add_series ( image . series ) unless series ( image . series . uid ) end
Adds an Image to this Frame .
12,711
def add_series ( series ) raise ArgumentError , "Invalid argument 'series' Expected ImageSeries or DoseVolume, got #{series.class}." unless [ ImageSeries , DoseVolume ] . include? ( series . class ) @image_series << series @associated_series [ series . uid ] = series end
Adds an ImageSeries to this Frame .
12,712
def add_coordinate ( coordinate ) raise ArgumentError , "Invalid argument 'coordinate'. Expected Coordinate, got #{coordinate.class}." unless coordinate . is_a? ( Coordinate ) @coordinates << coordinate unless @coordinates . include? ( coordinate ) end
Adds a Coordinate instance to this Contour .
12,713
def coords x , y , z = Array . new , Array . new , Array . new @coordinates . each do | coord | x << coord . x y << coord . y z << coord . z end return x , y , z end
Extracts and transposes all coordinates of this contour such that the coordinates are given in arrays of x y and z coordinates .
12,714
def create_coordinates ( contour_data ) raise ArgumentError , "Invalid argument 'contour_data'. Expected String (or nil), got #{contour_data.class}." unless [ String , NilClass ] . include? ( contour_data . class ) if contour_data && contour_data != "" string_values = contour_data . split ( "\\" ) size = string_values ...
Creates and connects Coordinate instances with this Contour instance by processing the value of the Contour Data element value .
12,715
def to_item item = DICOM :: Item . new item . add ( DICOM :: Sequence . new ( CONTOUR_IMAGE_SQ ) ) item [ CONTOUR_IMAGE_SQ ] . add_item item [ CONTOUR_IMAGE_SQ ] [ 0 ] . add ( DICOM :: Element . new ( REF_SOP_CLASS_UID , @slice . image ? @slice . image . series . class_uid : '1.2.840.10008.5.1.4.1.1.2' ) ) item [ CONTO...
Creates a Contour Sequence Item from the attributes of the Contour .
12,716
def translate ( x , y , z ) @coordinates . each do | c | c . translate ( x , y , z ) end end
Moves the coordinates of this contour according to the given offset vector .
12,717
def handle_message ( message ) begin message = decode_message message rescue InvalidMessageError => ex Logger . crash ( "couldn't decode message" , ex ) return end begin message . dispatch rescue => ex Logger . crash ( "message dispatch failed" , ex ) end end
Handle incoming messages
12,718
def decode_message ( message ) begin msg = MessagePack . unpack ( message , symbolize_keys : true ) rescue => ex raise InvalidMessageError , "couldn't unpack message: #{ex}" end begin klass = Utils . full_const_get msg [ :type ] o = klass . new ( * msg [ :args ] ) o . id = msg [ :id ] if o . respond_to? ( :id= ) && msg...
Decode incoming messages
12,719
def run while true message = @socket . read_multipart if @socket . is_a? Celluloid :: ZMQ :: RouterSocket message = message [ 1 ] else message = message [ 0 ] end handle_message message end end
Wait for incoming 0MQ messages
12,720
def operate ( prefix , data ) data = Radius :: OrdString . new data @nodes = [ '' ] re = scanner_regex ( prefix ) if md = re . match ( data ) remainder = '' while md start_tag , attributes , self_enclosed , end_tag = $1 , $2 , $3 , $4 flavor = self_enclosed == '/' ? :self : ( start_tag ? :open : :close ) @nodes << md ....
Parses a given string and returns an array of nodes . The nodes consist of strings and hashes that describe a Radius tag that was found .
12,721
def add_stage ( name , options = { } ) stage = build_stage ( name , options ) . proxy @peer . add ( stage . peer ) return stage end
Adds a Stage to the Theater . Raises an exception is the name of the Stage is duplicated .
12,722
def fill_blanks if @volumes . length > 0 images = Set . new [ @volumes , @master ] . flatten . compact . each do | volume | volume . bin_images . each do | bin_image | images << bin_image . image unless images . include? ( bin_image . image ) end end images . each do | image | [ @volumes , @master ] . flatten . compact...
Ensures that a valid comparison between volumes can be done by making sure that every volume has a BinImage for any image that is referenced among the BinVolumes . If some BinVolumes are missing one or more BinImages empty BinImages will be created for these BinVolumes .
12,723
def add_image ( image ) raise ArgumentError , "Invalid argument 'image'. Expected Image, got #{image.class}." unless image . is_a? ( Image ) @images << image unless @associated_images [ image . uid ] @associated_images [ image . uid ] = image @image_positions [ image . pos_slice . round ( 2 ) ] = image end
Adds an Image to this Volume .
12,724
def image_by_slice_pos ( pos ) image = @image_positions [ pos . round ( 2 ) ] if ! image && @images . length > 1 proximity = @images . collect { | img | ( img . pos_slice - pos ) . abs } if proximity . min < slice_spacing / 3.0 index = proximity . index ( proximity . min ) image = @images [ index ] end end return image...
Returns an image instance matched by the given slice position .
12,725
def dirty_or_db_setting_or_default ( key ) if @dirty_options . key? ( key ) @dirty_options [ key ] elsif Configuration . exists? ( name : namespaced_key ( key ) ) db_setting ( key ) else @default_options [ key ] end end
This method looks up in the configuration repository DB to see if the user has provided a value for the given setting . If not the default value is returned .
12,726
def issue_cache @issue_cache ||= begin issues_map = all_issues . map do | issue | cache_key = [ issue . fields [ 'plugin' ] , issue . fields [ 'plugin_id' ] ] . join ( '-' ) [ cache_key , issue ] end Hash [ issues_map ] end end
Create a hash with all issues where the keys correspond to the field passed as an argument .
12,727
def render_liquid ( content , payload , info , path = nil ) template = site . liquid_renderer . file ( path ) . parse ( content ) template . warnings . each do | e | Bunto . logger . warn "Liquid Warning:" , LiquidRenderer . format_error ( e , path || document . relative_path ) end template . render! ( payload , info )...
Render the given content with the payload and info
12,728
def place_in_layouts ( content , payload , info ) output = content . dup layout = layouts [ document . data [ "layout" ] ] Bunto . logger . warn ( "Build Warning:" , "Layout '#{document.data["layout"]}' requested in " "#{document.relative_path} does not exist." ) if invalid_layout? layout used = Set . new ( [ layout ] ...
Render layouts and place given content inside .
12,729
def reset if config [ "time" ] self . time = Utils . parse_date ( config [ "time" ] . to_s , "Invalid time in _config.yml." ) else self . time = Time . now end self . layouts = { } self . pages = [ ] self . static_files = [ ] self . data = { } @collections = nil @regenerator . clear_cache @liquid_renderer . reset if li...
Reset Site details .
12,730
def setup ensure_not_in_dest plugin_manager . conscientious_require self . converters = instantiate_subclasses ( Bunto :: Converter ) self . generators = instantiate_subclasses ( Bunto :: Generator ) end
Load necessary libraries plugins converters and generators .
12,731
def ensure_not_in_dest dest_pathname = Pathname . new ( dest ) Pathname . new ( source ) . ascend do | path | if path == dest_pathname raise ( Errors :: FatalException , "Destination directory cannot be or contain the Source directory." ) end end end
Check that the destination dir isn t the source dir or a directory parent to the source dir .
12,732
def generate generators . each do | generator | start = Time . now generator . generate ( self ) Bunto . logger . debug "Generating:" , "#{generator.class} finished in #{Time.now - start} seconds." end end
Run each of the Generators .
12,733
def render relative_permalinks_are_deprecated payload = site_payload Bunto :: Hooks . trigger :site , :pre_render , self , payload render_docs ( payload ) render_pages ( payload ) Bunto :: Hooks . trigger :site , :post_render , self , payload end
Render the site to the destination .
12,734
def dir if url . end_with? ( FORWARD_SLASH ) url else url_dir = File . dirname ( url ) url_dir . end_with? ( FORWARD_SLASH ) ? url_dir : "#{url_dir}/" end end
Initialize a new Page .
12,735
def read_yaml ( base , name , opts = { } ) filename = File . join ( base , name ) begin self . content = File . read ( @path || site . in_source_dir ( base , name ) , Utils . merged_file_read_opts ( site , opts ) ) if content =~ Document :: YAML_FRONT_MATTER_REGEXP self . content = $POSTMATCH self . data = SafeYAML . l...
Read the YAML frontmatter .
12,736
def sassify ( input ) site = @context . registers [ :site ] converter = site . find_converter_instance ( Bunto :: Converters :: Sass ) converter . convert ( input ) end
Convert a Sass string into CSS output .
12,737
def scssify ( input ) site = @context . registers [ :site ] converter = site . find_converter_instance ( Bunto :: Converters :: Scss ) converter . convert ( input ) end
Convert a Scss string into CSS output .
12,738
def extract_imgs_from_page ( page ) return Set [ ] if page . is_redirect? page . doc . search ( '//img[@src]' ) . reduce ( Set [ ] ) do | result , elem | u = elem . attributes [ 'src' ] . content result << page . to_absolute ( URI . parse ( URI . encode ( u ) ) ) end end
Extract imgs urls from page
12,739
def each if block_given? num_geometries . times do | n | yield get_geometry_n ( n ) end self else num_geometries . times . collect { | n | get_geometry_n ( n ) } . to_enum end end
Yields each Geometry in the GeometryCollection .
12,740
def read filtered_entries . each do | file_path | full_path = collection_dir ( file_path ) next if File . directory? ( full_path ) if Utils . has_yaml_header? full_path read_document ( full_path ) else read_static_file ( file_path , full_path ) end end docs . sort! end
Read the allowed documents into the collection s array of docs .
12,741
def index_as_calendar ( options = { } , & block ) default_options = { :ajax => true , :model => nil , :includes => [ ] , :start_date => :created_at , :end_date => nil , :block => block , :fullCalendarOptions => nil , :default => false } options = default_options . deep_merge ( options ) controller do def event_mapping ...
Initializes activeadmin index as calendar
12,742
def union ( geom = nil ) if geom check_geometry ( geom ) cast_geometry_ptr ( FFIGeos . GEOSUnion_r ( Geos . current_handle_pointer , ptr , geom . ptr ) , srid_copy : pick_srid_from_geoms ( srid , geom . srid ) ) else if respond_to? ( :unary_union ) unary_union else union_cascaded end end end
Calling without a geom argument is equivalent to calling unary_union when using GEOS 3 . 3 + and is equivalent to calling union_cascaded in older versions .
12,743
def relate_pattern ( geom , pattern ) check_geometry ( geom ) bool_result ( FFIGeos . GEOSRelatePattern_r ( Geos . current_handle_pointer , ptr , geom . ptr , pattern ) ) end
Checks the DE - 9IM pattern against the geoms .
12,744
def contents ( custom_binding = nil ) return @contents unless @contents . nil? @contents = File . read ( path ) if path . extname == '.erb' @contents = ERB . new ( @contents , nil , '>' ) . result ( custom_binding ? custom_binding : binding ) end @contents end
Reads the contents of the effective robots . txt file
12,745
def regenerate? ( document ) case document when Page regenerate_page? ( document ) when Document regenerate_document? ( document ) else source_path = document . respond_to? ( :path ) ? document . path : nil dest_path = if document . respond_to? ( :destination ) document . destination ( @site . dest ) end source_modifie...
Checks if a renderable object needs to be regenerated
12,746
def read_metadata @metadata = if ! disabled? && File . file? ( metadata_file ) content = File . binread ( metadata_file ) begin Marshal . load ( content ) rescue TypeError SafeYAML . load ( content ) rescue ArgumentError => e Bunto . logger . warn ( "Failed to load #{metadata_file}: #{e}" ) { } end else { } end end
Read metadata from the metadata file if no file is found initialize with an empty hash
12,747
def applies? ( scope , path , type ) applies_path? ( scope , path ) && applies_type? ( scope , type ) end
Checks if a given default setting scope matches the given path and type
12,748
def show @script_versions = Script :: Version . friendly . find ( params [ :id ] ) @versions = Phcscriptcdn :: ScriptversionVersions . where ( item_id : params [ :id ] , item_type : 'Phcscriptcdn::Script::Version' ) end
DETAILS - Script Versions
12,749
def new @script_version = Script :: Version . new @script_version . user_id = current_user . id @script_version . org_id = current_user . org_id end
NEW - Script Versions
12,750
def create @script_version = Script :: Version . new ( script_version_params ) @script_version . user_id = current_user . id @script_version . org_id = current_user . org_id if @script_version . save redirect_to script_versions_url , notice : 'Version was successfully created.' else render :new end end
POST - Script Versions
12,751
def for ( queue : , worker : nil ) worker_name = worker . to_s . underscore . tr ( "/" , "_" ) if worker [ namespace , queue , worker_name ] . compact . join ( "." ) end
Generates a metric name
12,752
def show script_listing = Script :: Listing . find ( params [ :listing_id ] ) @script_url = script_listing . urls . friendly . find ( params [ :id ] ) end
DETAILED PROFILE - Script Authors
12,753
def new script_listing = Script :: Listing . find ( params [ :listing_id ] ) @script_url = script_listing . urls . build @script_url . user_id = current_user . id @script_url . org_id = current_user . org_id end
NEW - Script Athors
12,754
def edit script_listing = Script :: Listing . find ( params [ :listing_id ] ) @script_url = script_listing . urls . find ( params [ :id ] ) end
EDIT - Script Athors
12,755
def create @script_listing = Script :: Listing . find ( params [ :listing_id ] ) @script_url = @script_listing . urls . create ( script_url_params ) @script_url . user_id = current_user . id @script_url . org_id = current_user . org_id if @script_url . save redirect_to script_listing_urls_path , notice : 'Author was su...
POST - Script Athors
12,756
def destroy @script_listing = Script :: Listing . find ( params [ :listing_id ] ) @script_url = @script_listing . urls . find ( params [ :id ] ) @script_url . destroy redirect_to script_listing_urls_path , notice : 'Author was successfully destroyed.' end
DELETE - Script Athors
12,757
def show @script_listings = Script :: Listing . friendly . find ( params [ :id ] ) @versions = Phcscriptcdn :: ListingVersions . where ( item_id : params [ :id ] , item_type : 'Phcscriptcdn::Script::Listing' ) end
DETAILS - Script Listings
12,758
def create @script_listing = Script :: Listing . new ( script_listing_params ) @script_listing . user_id = current_user . id @script_listing . org_id = current_user . org_id if @script_listing . save redirect_to script_listings_path , notice : 'Listing was successfully created.' else render :new end end
POST - Script Listings
12,759
def put_object ( obj_path , data , opts = { } ) url = obj_url ( obj_path ) opts [ :data ] = data headers = gen_headers ( opts ) cors_headers = gen_cors_headers ( opts ) headers = headers . concat ( cors_headers ) durability_level = opts [ :durability_level ] if durability_level raise ArgumentError unless durability_lev...
Initialize a MantaClient instance .
12,760
def get_object ( obj_path , opts = { } ) url = obj_url ( obj_path ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do method = opts [ :head ] ? :head : :get result = @client . send ( method , url , nil , headers ) raise unless result . is_a? HTTP :: Message if result . status == 200 return true , result ...
Get an object from Manta at a given path and checks it s uncorrupted .
12,761
def delete_object ( obj_path , opts = { } ) url = obj_url ( obj_path ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do result = @client . delete ( url , nil , headers ) raise unless result . is_a? HTTP :: Message return true , result . headers if result . status == 204 raise_error ( result ) end end
Deletes an object off Manta at a given path .
12,762
def put_directory ( dir_path , opts = { } ) url = obj_url ( dir_path ) headers = gen_headers ( opts ) headers . push ( [ 'Content-Type' , 'application/json; type=directory' ] ) cors_headers = gen_cors_headers ( opts ) headers = headers . concat ( cors_headers ) attempt ( opts [ :attempts ] ) do result = @client . put (...
Creates a directory on Manta at a given path .
12,763
def list_directory ( dir_path , opts = { } ) url = obj_url ( dir_path ) headers = gen_headers ( opts ) query_parameters = { } limit = opts [ :limit ] || MAX_LIMIT raise ArgumentError unless 0 < limit && limit <= MAX_LIMIT query_parameters [ :limit ] = limit marker = opts [ :marker ] if marker raise ArgumentError unless...
Gets a lexicographically sorted directory listing on Manta at a given path
12,764
def find ( dir_path , opts = { } ) regex = opts . key? ( :regex ) ? opts [ :regex ] : nil opts . delete ( :head ) begin exists = list_directory ( dir_path , head : true ) . first rescue exists = false end return [ ] unless exists response = list_directory ( dir_path , opts ) listing = response . first listing . inject ...
Finds all objects recursively under a given directory . Optionally a regular expression can be specified and used to filter the results returned .
12,765
def delete_directory ( dir_path , opts = { } ) url = obj_url ( dir_path ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do result = @client . delete ( url , nil , headers ) raise unless result . is_a? HTTP :: Message return true , result . headers if result . status == 204 raise_error ( result ) end end
Removes a directory from Manta at a given path .
12,766
def put_snaplink ( orig_path , link_path , opts = { } ) headers = gen_headers ( opts ) headers . push ( [ 'Content-Type' , 'application/json; type=link' ] , [ 'Location' , obj_url ( orig_path ) ] ) attempt ( opts [ :attempts ] ) do result = @client . put ( obj_url ( link_path ) , nil , headers ) raise unless result . i...
Creates a snaplink from one object in Manta at a given path to a different path .
12,767
def create_job ( job , opts = { } ) raise ArgumentError unless job [ :phases ] || job [ 'phases' ] headers = gen_headers ( opts ) headers . push ( [ 'Content-Type' , 'application/json; type=job' ] ) data = job . to_json attempt ( opts [ :attempts ] ) do result = @client . post ( job_url ( ) , data , headers ) raise unl...
Creates a job in Manta .
12,768
def get_job ( job_path , opts = { } ) url = job_url ( job_path , '/live/status' ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do method = opts [ :head ] ? :head : :get result = @client . send ( method , url , nil , headers ) raise unless result . is_a? HTTP :: Message if result . status == 200 raise u...
Gets various information about a job in Manta at a given path .
12,769
def get_job_errors ( job_path , opts = { } ) url = job_url ( job_path , '/live/err' ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do method = opts [ :head ] ? :head : :get result = @client . send ( method , url , nil , headers ) raise unless result . is_a? HTTP :: Message if result . status == 200 rai...
Gets errors that occured during the execution of a job in Manta at a given path .
12,770
def cancel_job ( job_path , opts = { } ) url = job_url ( job_path , 'live/cancel' ) body = '{}' opts [ :data ] = body headers = gen_headers ( opts ) headers << [ 'Accept' , 'application/json' ] headers << [ 'Content-Type' , 'application/json' ] headers << [ 'Content-Length' , body . bytesize ] args = { header : headers...
Cancels a running job in Manta at a given path .
12,771
def add_job_keys ( job_path , obj_paths , opts = { } ) url = job_url ( job_path , '/live/in' ) headers = gen_headers ( opts ) headers . push ( [ 'Content-Type' , 'text/plain' ] ) data = obj_paths . join ( "\n" ) attempt ( opts [ :attempts ] ) do result = @client . post ( url , data , headers ) raise unless result . is_...
Adds objects for a running job in Manta to process .
12,772
def end_job_input ( job_path , opts = { } ) url = job_url ( job_path , '/live/in/end' ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do result = @client . post ( url , nil , headers ) raise unless result . is_a? HTTP :: Message return true , result . headers if result . status == 202 raise_error ( resu...
Inform Manta that no more objects will be added for processing by a job and that the job should finish all phases and terminate .
12,773
def list_jobs ( state , opts = { } ) raise ArgumentError unless [ :all , :running , :done ] . include? state state = nil if state == :all headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do method = :get result = @client . send ( method , job_url ( ) , { :state => state } , headers ) raise unless result . ...
Get lists of Manta jobs .
12,774
def gen_signed_url ( expires , method , path , args = [ ] ) methods = method . is_a? ( Array ) ? method : [ method ] raise ArgumentError unless ( methods - [ :get , :put , :post , :delete , :options ] ) . empty? raise ArgumentError unless path =~ OBJ_PATH_REGEX key_id = '/%s/keys/%s' % [ user_path , @fingerprint ] args...
Generates a signed URL which can be used by unauthenticated users to make a request to Manta at the given path . This is typically used to GET an object or to make a CORS preflighted PUT request .
12,775
def get_job_state_streams ( type , path , opts ) raise ArgumentError unless [ :in , :out , :fail ] . include? type url = job_url ( path , '/live/' + type . to_s ) headers = gen_headers ( opts ) attempt ( opts [ :attempts ] ) do method = :get result = @client . send ( method , url , nil , headers ) raise unless result ....
Fetch lists of objects that have a given status .
12,776
def job_url ( * args ) path = if args . size == 0 @job_base else raise ArgumentError unless args . first =~ JOB_PATH_REGEX args . join ( '/' ) end URI . encode ( @host + path ) end
Returns a full URL for a given path to a job .
12,777
def gen_headers ( opts ) now = Time . now . httpdate sig = gen_signature ( 'date: ' + now ) headers = [ [ 'Date' , now ] , [ 'Authorization' , sig ] , [ 'User-Agent' , HTTP_AGENT ] , [ 'Accept-Version' , '~1.0' ] ] for arg , conditional in [ [ :if_modified_since , 'If-Modified-Since' ] , [ :if_unmodified_since , 'If-Un...
Creates headers to be given to the HTTP client and sent to the Manta service . The most important is the Authorization header without which none of this class would work .
12,778
def gen_cors_headers ( opts ) headers = [ ] allow_credentials = opts [ :access_control_allow_credentials ] if allow_credentials allow_credentials = allow_credentials . to_s raise ArgumentError unless allow_credentials == 'true' || allow_credentials == 'false' headers . push ( [ 'Access-Control-Allow-Credentials' , allo...
Do some sanity checks and create CORS - related headers
12,779
def gen_signature ( data ) raise ArgumentError unless data sig = @priv_key . sign ( @digest , data ) base64sig = Base64 . strict_encode64 ( sig ) return HTTP_SIGNATURE % [ user_path , @fingerprint , @digest_name , base64sig ] end
Given a chunk of data creates an HTTP signature which the Manta service understands and uses for authentication .
12,780
def show @script_authors = Script :: Author . friendly . find ( params [ :id ] ) @versions = Phcscriptcdn :: AuthorVersions . where ( item_id : params [ :id ] , item_type : 'Phcscriptcdn::Script::Author' ) end
DETAILS - Script Author
12,781
def new @script_author = Script :: Author . new @script_author . user_id = current_user . id @script_author . org_id = current_user . org_id end
NEW - Script Author
12,782
def create @script_author = Script :: Author . new ( script_author_params ) @script_author . user_id = current_user . id @script_author . org_id = current_user . org_id if @script_author . save redirect_to script_authors_url , notice : 'Author was successfully created.' else render :new end end
CREATE - Script Author
12,783
def show @script_extensions = Script :: Extension . friendly . find ( params [ :id ] ) @versions = Phcscriptcdn :: ExtensionVersions . where ( item_id : params [ :id ] , item_type : 'Phcscriptcdn::Script::Extension' ) end
DETAILS - Script Extension
12,784
def new @script_extension = Script :: Extension . new @script_extension . user_id = current_user . id @script_extension . org_id = current_user . org_id end
NEW - Script Extension
12,785
def create @script_extension = Script :: Extension . new ( script_extension_params ) @script_extension . user_id = current_user . id @script_extension . org_id = current_user . org_id if @script_extension . save redirect_to script_extensions_url , notice : 'Extension was successfully created.' else render :new end end
CREATE - Script Extension
12,786
def show @script_licences = Script :: Licence . friendly . find ( params [ :id ] ) @versions = Phcscriptcdn :: LicenceVersions . where ( item_id : params [ :id ] , item_type : 'Phcscriptcdn::Script::Licence' ) end
DETAILS - Script Licences
12,787
def new @script_licence = Script :: Licence . new @script_licence . user_id = current_user . id @script_licence . org_id = current_user . org_id end
NEW - Script Licences
12,788
def create @script_licence = Script :: Licence . new ( script_licence_params ) @script_licence . user_id = current_user . id @script_licence . org_id = current_user . org_id if @script_licence . save redirect_to script_licences_url , notice : 'Licence was successfully created.' else render :new end end
POST - Script Licences
12,789
def save raise EntityModelIsNotPersistedError unless entity . persisted? if persisted? return false unless changed? update else create end @previously_changed = changes @changed_attributes . clear true end
Saves model Performs + insert + or + update + sql query Method doesn t perform sql query if model isn t modified
12,790
def arel_insert table = self . class . arel_tables [ entity . class . table_name ] [ hydra_attribute . backend_type ] fields = { } fields [ table [ :entity_id ] ] = entity . id fields [ table [ :hydra_attribute_id ] ] = hydra_attribute . id fields [ table [ :value ] ] = value fields [ table [ :created_at ] ] = Time . n...
Creates arel insert manager
12,791
def arel_update table = self . class . arel_tables [ entity . class . table_name ] [ hydra_attribute . backend_type ] arel = table . from ( table ) arel . where ( table [ :id ] . eq ( id ) ) . compile_update ( table [ :value ] => value , table [ :updated_at ] => Time . now ) end
Creates arel update manager
12,792
def add_records ( records ) atoms = ActiveSupport :: OrderedHash . new records_count = 0 records . each do | record | next unless allow_indexing? ( record ) records_count += 1 condensed_record = condense_record ( record ) atoms = add_occurences ( condensed_record , record . id , atoms ) end @storage . add ( atoms , rec...
Adds multiple records to the index . Accepts an array of + records + .
12,793
def remove_record ( record ) condensed_record = condense_record ( record ) atoms = add_occurences ( condensed_record , record . id ) @storage . remove ( atoms ) end
Removes + record + from the index .
12,794
def search ( query ) return [ ] if query . nil? @atoms = @storage . fetch ( cleanup_atoms ( query ) , query [ / \^ / ] ) queries = parse_query ( query . dup ) positive = run_queries ( queries [ :positive ] ) positive_quoted = run_quoted_queries ( queries [ :positive_quoted ] ) negative = run_queries ( queries [ :negati...
Returns an array of IDs for records matching + query + .
12,795
def record_unchanged? ( record_new , record_old ) allow_indexing? ( record_old ) == allow_indexing? ( record_new ) && ! @fields . map { | field | record_old . send ( field ) == record_new . send ( field ) } . include? ( false ) end
The record is unchanged for our purposes if all the fields are the same and the if_proc returns the same result for both .
12,796
def memory @pagesize ||= Vmstat . pagesize has_available = false total = free = active = inactive = pageins = pageouts = available = 0 procfs_file ( "meminfo" ) do | file | content = file . read ( 2048 ) content . scan ( / \w \s \d / ) do | name , kbytes | pages = ( kbytes . to_i * 1024 ) / @pagesize case name when "Me...
Fetches the memory usage information .
12,797
def network_interfaces netifcs = [ ] procfs_file ( "net" , "dev" ) do | file | file . read . scan ( NET_DATA ) do | columns | type = case columns [ 0 ] when / / then NetworkInterface :: ETHERNET_TYPE when / / then NetworkInterface :: LOOPBACK_TYPE end netifcs << NetworkInterface . new ( columns [ 0 ] . to_sym , columns...
Fetches the information for all available network devices .
12,798
def task @pagesize ||= Vmstat . pagesize procfs_file ( "self" , "stat" ) do | file | data = file . read . split ( / / ) Task . new ( data [ 22 ] . to_i / @pagesize , data [ 23 ] . to_i , data [ 13 ] . to_i * 1000 , data [ 14 ] . to_i * 1000 ) end end
Fetches the current process cpu and memory data .
12,799
def boot_time raw = procfs_file ( "uptime" ) { | file | file . read } Time . now - raw . split ( / \s / ) . first . to_f end
Fetches the boot time of the system .