idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
10,500
def modify_host_set ( name , action = nil , setmembers = nil , new_name = nil , comment = nil ) begin @host_set . modify_host_set ( name , action , setmembers , new_name , comment ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Modifies a HostSet .
10,501
def find_host_sets ( host_name ) begin @host_set . find_host_sets ( host_name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Returns an array of every Hostset the given host is a part of . The array can contain zero one or multiple items .
10,502
def get_host_set ( name ) begin @host_set . get_host_set ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets hostset information by name .
10,503
def get_host_vluns ( host_name ) begin @host . get_host_vluns ( host_name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets all of the VLUNs on a specific host .
10,504
def get_volumes begin @volume . get_volumes ( VolumeCopyType :: BASE_VOLUME ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets all Volumes in the array
10,505
def get_snapshots begin @volume . get_volumes ( VolumeCopyType :: VIRTUAL_COPY ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets the list of snapshots in the array
10,506
def get_volume ( name ) begin @volume . get_volume ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets information about a volume by name
10,507
def get_volume_by_wwn ( wwn ) begin @volume . get_volume_by_wwn ( wwn ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets information about a volume by wwn
10,508
def create_volume ( name , cpg_name , size_MiB , optional = nil ) if @current_version < @min_version_with_compression && ! optional . nil? optional . delete_if { | key , _value | key == :compression } end begin @volume . create_volume ( name , cpg_name , size_MiB , optional ) rescue => ex Util . log_exception ( ex , ca...
Creates a new volume .
10,509
def modify_volume ( name , volume_mods ) begin @volume . modify_volume ( name , volume_mods ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Modifies a volume
10,510
def grow_volume ( name , amount ) begin @volume . grow_volume ( name , amount ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Grows an existing volume by amount Mebibytes .
10,511
def create_physical_copy ( src_name , dest_name , dest_cpg , optional = nil ) if @current_version < @min_version_with_compression && ! optional . nil? [ :compression , :allowRemoteCopyParent , :skipZero ] . each { | key | optional . delete key } end begin @volume . create_physical_copy ( src_name , dest_name , dest_cpg...
Creates a physical copy of a VirtualVolume
10,512
def delete_physical_copy ( name ) begin @volume . delete_volume ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Deletes a physical copy
10,513
def tune_volume ( name , tune_operation , optional = nil ) if @current_version < @min_version_with_compression && ! optional . nil? optional . delete_if { | key , _value | key == :compression } end begin object_hash = @volume . tune_volume ( name , tune_operation , optional ) get_task ( object_hash [ 'taskid' ] ) rescu...
Tunes a volume
10,514
def find_all_volume_sets ( name ) begin @volume_set . find_all_volume_sets ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Returns an array of every VolumeSet the given volume is a part of . The array can contain zero one or multiple items .
10,515
def get_volume_sets begin @volume_set . get_volume_sets rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets the Volume Sets
10,516
def get_volume_set ( name ) begin @volume_set . get_volume_set ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets the information about a Volume Set .
10,517
def create_volume_set ( name , domain = nil , comment = nil , setmembers = nil ) begin @volume_set . create_volume_set ( name , domain , comment , setmembers ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Creates a new volume set
10,518
def delete_volume_set ( name ) begin @volume_set . delete_volume_set ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Deletes the volume set . You must clear all QOS rules before a volume set can be deleted .
10,519
def modify_volume_set ( name , action = nil , newName = nil , comment = nil , flash_cache_policy = nil , setmembers = nil ) begin @volume_set . modify_volume_set ( name , action , newName , comment , flash_cache_policy , setmembers ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) ra...
Modifies a volume set by adding or removing a volume from the volume set . It s actions is based on the enums MEM_ADD or MEM_REMOVE .
10,520
def create_snapshot_of_volume_set ( name , copy_of_name , optional = nil ) begin @volume_set . create_snapshot_of_volume_set ( name , copy_of_name , optional ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Creates a snapshot of an existing VolumeSet
10,521
def create_snapshot ( name , copy_of_name , optional = nil ) if @current_version < @min_version_with_compression && ! optional . nil? optional . delete_if { | key , _value | key == :allowRemoteCopyParent } end begin @volume . create_snapshot ( name , copy_of_name , optional ) rescue => ex Util . log_exception ( ex , ca...
Creates a snapshot of an existing Volume .
10,522
def get_volume_snapshots ( name ) begin @volume . get_volume_snapshots ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets the snapshots of a particular volume
10,523
def get_ports begin @port . get_ports rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets an array of all ports on the 3PAR .
10,524
def get_fc_ports ( state = nil ) begin @port . get_fc_ports ( state ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets an array of Fibre Channel Ports .
10,525
def get_iscsi_ports ( state = nil ) begin @port . get_iscsi_ports ( state ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets an array of iSCSI Ports .
10,526
def get_ip_ports ( state = nil ) begin @port . get_ip_ports ( state ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets an array of IP Ports .
10,527
def get_cpgs begin @cpg . get_cpgs rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets entire list of CPGs .
10,528
def get_cpg ( name ) begin @cpg . get_cpg ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets information about a Cpg .
10,529
def create_cpg ( name , optional = nil ) begin @cpg . create_cpg ( name , optional ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Creates a new CPG .
10,530
def modify_cpg ( name , cpg_mods ) begin @cpg . modify_cpg ( name , cpg_mods ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Modifies a CPG .
10,531
def get_cpg_available_space ( name ) begin @cpg . get_cpg_available_space ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets available space information about a cpg .
10,532
def delete_cpg ( name ) begin @cpg . delete_cpg ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Deletes a CPG .
10,533
def get_online_physical_copy_status ( name ) begin @volume . get_online_physical_copy_status ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Gets the status of an online physical copy
10,534
def stop_offline_physical_copy ( name ) begin @volume . stop_offline_physical_copy ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Stops an offline physical copy operation
10,535
def stop_online_physical_copy ( name ) begin @volume . stop_online_physical_copy ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Stops an online physical copy operation
10,536
def resync_physical_copy ( name ) begin @volume . resync_physical_copy ( name ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Resynchronizes a physical copy .
10,537
def wait_for_task_to_end ( task_id , poll_rate_secs = 15 ) begin @task . wait_for_task_to_end ( task_id , poll_rate_secs ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Waits for a 3PAR task to end .
10,538
def cancel_task ( task_id ) begin @task . cancel_task ( task_id ) rescue => ex Util . log_exception ( ex , caller_locations ( 1 , 1 ) [ 0 ] . label ) raise ex end end
Cancel a 3PAR task
10,539
def logout unless @log_file_path . nil? if Hpe3parSdk . logger != nil Hpe3parSdk . logger . close Hpe3parSdk . logger = nil end end begin @http . unauthenticate rescue Hpe3parSdk :: HPE3PARException => ex end end
Logout from the 3PAR Array
10,540
def ey_agent_check results = { :description => 'Run ey-agent to monitor haproxy and monitor' } agent_results = JSON . load ( ` ` ) results . update ( :message => agent_results . inspect , :status => agent_results && agent_results . any? { | k , v | v == 'down' } ) rescue => e return results . update ( :status => :failu...
Call ey - agent to return nginx or apache status as well as database status
10,541
def monitor_health find_features @results = @features . inject ( { } ) do | results , feature_name | results [ feature_name ] = monitor_health_of ( feature_name ) results end healthy? ? on_healthy : on_unhealthy render_health end
Show a status page showing the health of monitored features Returns a 404 if any features have a success of unsuccessful
10,542
def render_health return if performed? respond_to do | format | format . html { render_health_html } format . js { render_health_json } format . xml { render_health_xml } end end
Render the result
10,543
def find_features @features = if params [ :only ] params [ :only ] . to_s . split ( "," ) . collect ( & :to_sym ) . uniq elsif skip = params [ :skip ] || params [ :exclude ] monitored_features . keys - skip . to_s . split ( "," ) . collect ( & :to_sym ) else monitored_features . keys end end
Skip features by appending skip = mongo fun etc Include features by appending feature = mongo urban_airship etc to filter
10,544
def switch_mode ( app , mode ) mode = nil if mode == "none" mode = "run" if mode == "" return false if app . debug == mode if mode . nil? with_progress ( "Removing debug mode" ) do app . debug = nil app . stop! if app . started? end return true end with_progress ( "Switching mode to #{c(mode, :name)}" ) do | s | app . ...
set app debug mode ensuring it s valid and shutting it down
10,545
def add_listname_on_body ( resource , body ) body . kind_of? ( Array ) ? process_body_as_array ( resource , body ) : process_body_as_hash ( resource , body ) end
Process the response body to make sure that its contains the list name defined on resource Returns the list name present on body and the body itself
10,546
def any_listname_of ( resource ) if resource :: LIST_NAME . kind_of? ( Array ) resource :: LIST_NAME . first else resource :: LIST_NAME end end
Return any listname described on resource
10,547
def process_body_as_hash ( resource , body ) result = body if resource :: LIST_NAME . kind_of? Array list_name = resource :: LIST_NAME . find { | name | body . keys . include? ( name ) && body [ name ] . kind_of? ( Array ) } else list_name = any_listname_of ( resource ) end result = { list_name => [ body ] } unless bod...
Discover what list name defined on resource is present on body If none of then is find assume that the body is a single resource and add it value into array and assing to any list name
10,548
def mount_response_change_password ( response ) response = JSON . parse ( response . body ) { changed : response [ 'response' ] [ 'changed' ] , message : response [ 'messages' ] . first [ 'explanation' ] } end
Mounts a friendly response for the change password request
10,549
def capture ( & block ) @streams . push ( @builder . target = Stream . new ) @builder . level += 1 str = instance_eval ( & block ) str = @streams . last . join if @streams . last . any? @streams . pop @builder . level -= 1 @builder . target = @streams . last str end
Captures the HTML code built inside the + block + . This is done by creating a new stream for the builder object running the block and passing back its stream as a string .
10,550
def tag! ( tag , * args , & block ) ele_id = nil if @auto_validation && @tagset if ! @tagset . tagset . has_key? ( tag ) raise InvalidXhtmlError , "no element `#{tag}' for #{tagset.doctype}" elsif args . last . respond_to? ( :to_hash ) attrs = args . last . to_hash if @tagset . forms . include? ( tag ) && attrs [ :id ]...
Create a tag named + tag + . Other than the first argument which is the tag name the arguments are the same as the tags implemented via method_missing .
10,551
def add_uri ( force_update_mode , onerror_mode , uri ) fmode = force_update_mode . nil? uri += '&forceUpdateMode=' + force_update_mode unless fmode uri += '&onErrorMode=' + onerror_mode unless onerror_mode . nil? uri end
splitted create_uri just to fix codeclimate error
10,552
def jobs_with_status status if status . empty? @jobs . reject { | job | job . status == JOB_STATUS_QUEUED } else @jobs . select { | job | job . status == status . to_s } end end
Jobs acess and searching
10,553
def debug_value_utf8 value case value when Symbol return value . to_s . force_encoding ( Encoding :: UTF_8 ) when String return value . dup . force_encoding ( Encoding :: UTF_8 ) if value . is_a? String else return value end end
Force strings to UTF8
10,554
def has_roles_mask_accessors? instance_method_names = instance_methods . map { | method_name | method_name . to_s } [ roles_attribute_name . to_s , "#{roles_attribute_name}=" ] . all? do | accessor | instance_method_names . include? ( accessor ) end end
This is overridden by the ActiveRecord adapter as the attribute accessors don t show up in instance_methods .
10,555
def create_new_post ( params ) post_title = params [ 'post' ] [ 'title' ] post_date = ( Time . now ) . strftime ( "%Y-%m-%d" ) content = yaml_data ( post_title ) . to_yaml + "---\n" + params [ :post ] [ :content ] post_file = ( post_date + " " + post_title ) . to_url + '.md' file = File . join ( jekyll_site . source , ...
Create a new post from scratch . Return filename This would not commit the file .
10,556
def merge_config ( yaml , params ) if params [ 'post' ] . has_key? 'yaml' params [ 'post' ] [ 'yaml' ] . each do | key , value | if value == 'true' yaml [ key ] = true elsif value == 'false' yaml [ key ] = false else yaml [ key ] = value end end end yaml end
Merge existing yaml with post params
10,557
def update_post ( params ) post_file = params [ :post ] [ :name ] post = jekyll_post ( post_file ) yaml_config = merge_config ( post . data , params ) write_post_contents ( params [ :post ] [ :content ] , yaml_config , post_file ) post_file end
Update exiting post .
10,558
def jekyll_site if not @site original_stdout = $stdout $stdout = File . new ( '/tmp/null.txt' , 'w' ) config = Jekyll . configuration ( { 'source' => cloned_repo_path } ) @site = Jekyll :: Site . new ( config ) @site . read $stdout = original_stdout end @site end
Jekyll site instance
10,559
def posts_template_data ( post_items ) if post_items . nil? return [ ] end template_data = post_items . map do | post | { :title => post . data [ 'title' ] , :filename => post . name , :date => post . date } end template_data . sort! { | x , y | y [ :date ] <=> x [ :date ] } template_data end
Gives out a sorted list of post template data for a post or draft
10,560
def nimbus_exception_handling begin yield rescue SystemExit => ex raise rescue Nimbus :: Error => ex display_error_message ( ex ) Nimbus . stop rescue Exception => ex display_error_message ( ex ) Nimbus . stop end end
Provides the default exception handling for the given block .
10,561
def seed ( all_individuals , individuals_sample , ids_fenotypes ) super @structure = build_node individuals_sample , Nimbus :: LossFunctions . average ( individuals_sample , @id_to_fenotype ) end
Creates the structure of the tree as a hash of SNP splits and values .
10,562
def load ( config_file = DEFAULTS [ :config_file ] ) user_config_params = { } dirname = Dir . pwd if File . exists? ( File . expand_path ( config_file , Dir . pwd ) ) begin config_file_path = File . expand_path config_file , Dir . pwd user_config_params = Psych . load ( File . open ( config_file_path ) ) dirname = File...
This is the first method to be called on Configuration when a config . yml file exists with user input options for the forest .
10,563
def fullname ( options = { } ) if lastname . blank? && firstname . blank? login else options = { :flipped => false } . merge ( options ) fullname = options [ :flipped ] ? "#{lastname}, #{firstname}" : "#{firstname} #{lastname}" fullname . squeeze ( " " ) . strip end end
Returns the firstname and lastname as a string
10,564
def deliver_welcome_mail if has_role? ( 'author' ) || has_role? ( 'editor' ) || has_role? ( 'admin' ) Notifications . alchemy_user_created ( self ) . deliver_later else Notifications . member_created ( self ) . deliver_later end end
Delivers a welcome mail depending from user s role .
10,565
def after_sign_out_path_for ( resource_or_scope ) if request . referer . blank? || request . referer . to_s =~ / / root_path else request . referer end end
Overwriting the default of Devise
10,566
def traverse_regression_forest @predictions = { } prediction_count = trees . size @options . read_testing_data { | individual | individual_prediction = 0.0 trees . each do | t | individual_prediction = ( individual_prediction + Nimbus :: Tree . traverse ( t , individual . snp_list ) ) . round ( 5 ) end @predictions [ i...
Traverse a testing set through every regression tree of the forest and get averaged predictions for every individual in the sample .
10,567
def docid_type ( code ) stdclass = standard_class ( code ) or return [ nil , code ] prefix , code = strip_id_wrapper ( code , stdclass ) [ @registry . processors [ stdclass ] . idtype , code ] end
The document identifier class corresponding to the given code
10,568
def to_xml db = @local_db || @db || return Nokogiri :: XML :: Builder . new ( encoding : "UTF-8" ) do | xml | xml . documents do xml . parent . add_child db . all . join ( " " ) end end . to_xml end
list all entries as a serialization
10,569
def new_bib_entry ( code , year , opts , stdclass ) bib = @registry . processors [ stdclass ] . get ( code , year , opts ) bib = bib . to_xml if bib . respond_to? :to_xml bib = "not_found #{Date.today}" if bib . nil? || bib . empty? bib end
hash uses = > because the hash is imported from JSON
10,570
def all Dir . glob ( "#{@dir}/**/*.xml" ) . sort . map do | f | File . read ( f , encoding : "utf-8" ) end end
Returns all items
10,571
def terminate_conversation_and_all_call_legs ( trace_only = false ) if self . conversation Rails . logger . info "zestphone: ** Terminating all linked calls and conversation **" Rails . logger . info "zestphone: conversation - (pre) state: #{self.conversation.state}" Rails . logger . info "zestphone: conversation - (...
Nuclear termination if trace_only is true we only print what we re going to do but not actually do it
10,572
def populate_attributes self . class . normal_attribute_list . each do | normal_attribute | self . public_send "#{normal_attribute}=" , raw_data [ normal_attribute ] end self . class . time_attribute_list . each do | time_attribute | time = raw_data [ time_attribute ] time = Time . parse ( time ) if ! time . nil? self ...
Populates the instance s attributes based on the raw_data .
10,573
def will_paginate ( collection_or_options = nil , options = { } ) if collection_or_options . is_a? Hash options , collection_or_options = collection_or_options , nil end unless options [ :renderer ] options = options . merge :renderer => MaterializePagination :: Rails end super * [ collection_or_options , options ] . c...
Change the default link renderer for will_paginate
10,574
def structure_changes_from ( current_structure = nil ) new_structure = column if current_structure if new_structure [ :limit ] && current_structure [ :limit ] . to_i != new_structure [ :limit ] . to_i || new_structure [ :type ] != current_structure [ :type ] || ! new_structure [ :default ] . nil? && column_default_chan...
Decides if and how a column will be changed Provide the details of a previously column or simply nil to create a new column
10,575
def salesforce_attributes_to_set ( attributes = { } ) { } . tap do | hash | attributes . each do | key , value | hash [ self . class . salesforce_sync_attribute_mapping [ key . to_s ] . to_sym ] = value if self . class . salesforce_sync_attribute_mapping . include? ( key . to_s ) && self . respond_to? ( "#{self.class.s...
An internal method used to get a hash of values that we are going to set from a Salesforce outbound message hash
10,576
def salesforce_process_update ( attributes = { } ) attributes_to_update = salesforce_attributes_to_set ( self . new_record? ? attributes : salesforce_empty_attributes . merge ( attributes ) ) attributes_to_update . each_pair do | k , v | self . send ( "#{k}=" , v ) end self . salesforce_skip_sync = true self . save! en...
Gets passed the Salesforce outbound message hash of changed values and updates the corresponding model
10,577
def system_mod_stamp hash = JSON . parse ( SF_CLIENT . http_get ( "/services/data/v#{SF_CLIENT.version}/query" , :q => "SELECT SystemModstamp FROM #{salesforce_object_name} WHERE Id = '#{salesforce_id}'" ) . body ) hash [ "records" ] . first . try ( :[] , "SystemModstamp" ) end
def salesforce_object_exists? return salesforce_object_exists_method if respond_to? salesforce_exists_method return salesforce_object_exists_default end Finds a salesforce record by its Id and returns nil or its SystemModstamp
10,578
def salesforce_attributes_to_update ( include_all = false ) { } . tap do | hash | self . class . salesforce_sync_attribute_mapping . each do | key , value | if self . respond_to? ( value ) attribute_value = self . send ( value ) if is_boolean? ( value ) && attribute_value . nil? attribute_value = false end hash [ key ]...
create a hash of updates to send to salesforce
10,579
def salesforce_perform_async_call? return false if salesforce_attributes_to_update . empty? || self . class . salesforce_async_attributes . empty? salesforce_attributes_to_update . keys . all? { | key | self . class . salesforce_async_attributes . include? ( key ) } && salesforce_id . present? end
if attributes specified in the async_attributes array are the only attributes being modified then sync the data via delayed_job
10,580
def salesforce_sync return if self . salesforce_skip_sync? if salesforce_perform_async_call? Delayed :: Job . enqueue ( SalesforceArSync :: SalesforceObjectSync . new ( self . class . salesforce_web_class_name , salesforce_id , salesforce_attributes_to_update ) , :priority => 50 ) else if salesforce_object_exists? sale...
sync model data to Salesforce adding any Salesforce validation errors to the models errors
10,581
def validate_ip_ranges raise ActionController :: RoutingError . new ( 'Not Found' ) unless SalesforceArSync :: IPConstraint . new . matches? ( request ) end
to be used in a before_filter checks ip ranges specified in configuration and renders a 404 unless the request matches
10,582
def request ( method , path , options = { } ) options = options . dup raw = raw? || options . delete ( :raw ) params ( options ) response = connection . send method , path , ( @raw_body || @params ) , @headers raw ? response : @scopeable . parse ( response ) end
Low - level connection methods
10,583
def payload payload = @random_generator . payload errors = validation_errors_for ( payload ) raise InvalidContentGenerated , error_message ( payload , errors ) if errors . any? if block_given? payload = yield ( payload ) errors = validation_errors_for ( payload ) raise InvalidContentGenerated , error_message ( payload ...
Return a content item merged with a hash and with the excluded fields removed . If the resulting content item isn t valid against the schema an error will be raised .
10,584
def decode ( elements ) elements . each do | element | if ! TAGS . include? ( element . name ) || ( element [ "style" ] && element [ "style" ] =~ / / ) element . children . remove elsif element [ "class" ] decoys . each do | decoy | element . children . remove if decoy . include? ( element [ "class" ] ) end end end ele...
Receives an array of elements and returns another without invisibles .
10,585
def count ( & block ) return keys . count unless block_given? proxy = HashProxy . new keys . inject ( 0 ) do | count , key | proxy . with ( mapper [ key ] , & block ) ? count . succ : count end end
With no block returns the number of keys . If a block is given counts the number of elements yielding a true value .
10,586
def center ( intervals ) i = intervals . reduce ( [ intervals . first . first , intervals . first . last ] ) { | acc , int | [ [ acc . first , int . first ] . min , [ acc . last , int . last ] . max ] } i . first + ( i . last - i . first ) / 2 end
augmented tree using a start point as resresentative value of the node
10,587
def method_missing ( symbol ) if hash . key? ( symbol ) hash [ symbol ] elsif hash . key? ( symbol . to_s ) hash [ symbol . to_s ] else raise NoMethodError end end
Allows accessing a hash attribute as a method .
10,588
def [] ( key ) if hash . key? ( key ) then hash [ key ] elsif hash . key? ( key . to_sym ) then hash [ key . to_sym ] elsif hash . key? ( key . to_s ) then hash [ key . to_s ] end end
Allows accessing a hash attribute as hash key either a string or symbol .
10,589
def []= ( key , value ) @lock . synchronize do @indexes = { } if value . id_changed? hash . delete value . to_id ( true ) end saved = hash [ key ] = value . to_hash . freeze adapter . save_database if @options [ :sync ] saved end end
Sets a hash by key .
10,590
def authorize_and_capture resp = StdClass . new if self . financial_status == Invoice :: FINANCIAL_STATUS_CAPTURED resp . error = "Funds for this invoice have already been captured." else sc = self . site . store_config case sc . pp_name when StoreConfig :: PAYMENT_PROCESSOR_STRIPE Stripe . api_key = sc . stripe_secret...
Authorize and capture funds
10,591
def void resp = StdClass . new t = InvoiceTransaction . where ( :invoice_id => self . id , :transaction_type => InvoiceTransaction :: TYPE_AUTHORIZE , :success => true ) . first if self . financial_status == Invoice :: FINANCIAL_STATUS_CAPTURED resp . error = "This invoice has already been captured, you will need to re...
Void an authorized invoice
10,592
def add_tags ( host ) host [ :host_tags ] . merge ( 'beaker_version' => Beaker :: Version :: STRING , 'jenkins_build_url' => @options [ :jenkins_build_url ] , 'department' => @options [ :department ] , 'project' => @options [ :project ] , 'created_by' => @options [ :created_by ] , 'name' => host . name , 'roles' => hos...
Override host tags with presets
10,593
def create_invoices self . calculate_date_started_full if self . date_started_full . nil? v = self . variant interval = case v . subscription_interval when Variant :: SUBSCRIPTION_INTERVAL_MONTHLY then 1 . month when Variant :: SUBSCRIPTION_INTERVAL_YEARLY then 1 . year end sc = v . product . site . store_config unit_p...
Verify invoices exist for the entire subscription period up until today
10,594
def activemerchant_package sc = self . invoice . site . store_config weight = 0.0 self . line_items . each { | li | weight = weight + ( li . variant . weight * li . quantity ) } weight = weight * 0.035274 if sc . weight_unit == StoreConfig :: WEIGHT_UNIT_METRIC sp = self . shipping_package dimensions = [ sp . outside_l...
Gets the activemerchant package based on the shipping package
10,595
def boxes ( rigid_variants ) stackable = { } nonstackable = [ ] rigid_variants . each do | v | sgid = v . product . stackable_group_id if sgid stackable [ sgid ] = [ ] if stackable [ sgid ] . nil? stackable [ sgid ] << v else nonstackable << [ v . length , v . width , v . height ] end end stackable . each do | sgid , a...
Gets the 3d dimensions of the variants after they re stacked
10,596
def init_cart create_new_invoice = false if session [ :cart_id ] @invoice = Caboose :: Invoice . where ( :id => session [ :cart_id ] ) . first create_new_invoice = true if @invoice . nil? || @invoice . status != 'cart' else create_new_invoice = true end if create_new_invoice @invoice = Caboose :: Invoice . new @invoice...
Initialize the cart in the session
10,597
def parse_url_params return if ! Caboose . use_url_params url = "#{request.fullpath}" url [ 0 ] = "" if url . starts_with? ( '/' ) url = url . split ( '?' ) [ 0 ] if url . include? ( '?' ) arr = url . split ( '/' ) i = arr . count - 1 while i >= 1 do k = arr [ i - 1 ] v = arr [ i ] if v && v . length > 0 v = v . gsub (...
Parses any parameters in the URL and adds them to the params
10,598
def login_user ( user , remember = false ) session [ "app_user" ] = Caboose :: StdClass . new ( { :id => user . id , :site_id => user . site_id , :first_name => user . first_name , :last_name => user . last_name , :username => user . username , :email => user . email } ) cookies . permanent [ :caboose_user_id ] = user ...
Logs in a user
10,599
def logged_in? validate_token validate_cookie return true if ! session [ "app_user" ] . nil? && session [ "app_user" ] != false && session [ "app_user" ] . id != - 1 && session [ "app_user" ] . id != User . logged_out_user_id ( @site . id ) return false end
Returns whether or not a user is logged in