idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
24,500 | def append_path ( sprocket , path ) path = Pathname . new ( path ) . expand_path ( root ) sprocket . append_path ( path ) if path . exist? end | Appends the given + path + to the given + sprocket + This makes sure the path is relative to the root path or an absolute path pointing somewhere else . It also checks if it exists before appending it . |
24,501 | def append_paths ( sprocket , paths ) paths or return paths . each do | path | append_path sprocket , path end end | Appends the given Array of + paths + to the given + sprocket + . |
24,502 | def js_compressor case config . js_compressor when Crush :: Engine config . js_compressor when Symbol , String JS_COMPRESSORS [ config . js_compressor . to_sym ] else Crush . register_js Tilt [ 'js' ] end end | Returns the Javascript compression engine based on what s set in config . js_compressor . If config . js_compressor is nil let Tilt + Crush decide which one to use . |
24,503 | def css_compressor case config . css_compressor when Crush :: Engine config . css_compressor when Symbol , String CSS_COMPRESSORS [ config . css_compressor . to_sym ] else Crush . register_css Tilt [ 'css' ] end end | Returns the CSS compression engine based on what s set in config . css_compressor . If config . css_compressor is nil let Tilt + Crush decide which one to use . |
24,504 | def granulate ( options = { } ) @request_data = Hash . new if options [ :video_link ] insert_download_data options elsif options [ :sam_uid ] && options [ :filename ] file_data = { :video_uid => options [ :sam_uid ] , :filename => options [ :filename ] } @request_data . merge! file_data elsif options [ :file ] && options [ :filename ] file_data = { :video => options [ :file ] , :filename => options [ :filename ] } @request_data . merge! file_data else raise NSIVideoGranulate :: Errors :: Client :: MissingParametersError end insert_callback_data options request = prepare_request :POST , @request_data . to_json execute_request ( request ) end | Initialize a client to a VideoGranulate node |
24,505 | def grains_keys_for ( video_key ) request = prepare_request :GET , { :video_key => video_key , :grains => true } . to_json execute_request ( request ) . select { | key | [ 'images' , 'videos' ] . include? key } end | Return the keys of the grains of a video |
24,506 | def set_exec_path ( path ) yml = YAML . load_file ( @config_file ) yml [ :exec_path ] = File . expand_path ( path ) File . open ( @config_file , 'w+' ) { | f | f . write ( yml . to_yaml ) } end | set exec path |
24,507 | def call ( env ) now = Time . now . to_i session = env [ 'rack.session' ] window_size = window_size ( env ) previous_timeout = session [ 'aker.last_request_at' ] return @app . call ( env ) unless window_size > 0 env [ 'aker.timeout_at' ] = now + window_size session [ 'aker.last_request_at' ] = now return @app . call ( env ) unless previous_timeout if now >= previous_timeout + window_size env [ 'aker.session_expired' ] = true env [ 'warden' ] . logout end @app . call ( env ) end | Determines whether the incoming request arrived within the timeout window . If it did then the request is passed onto the rest of the Rack stack ; otherwise the user is redirected to the configured logout path . |
24,508 | def build_promise ( depending_job , param_key ) Promise . new . tap do | promise | promise . assign_attributes ( job_id : job . id , hash_field : param_key , result_key : result_key ) depending_job . promise_ids << promise . id end end | Builds promise from this future |
24,509 | def to_hash ( args = { } ) args ||= { } hash = { } self . attributes . each do | name , value | hash [ name ] = if value . is_a? ( :: Array ) value . map { | x | x . respond_to? ( :to_hash ) ? call_method_with_optional_parameters ( x , :to_hash , :nested => true ) : x } elsif value . respond_to? ( :to_hash ) call_method_with_optional_parameters ( value , :to_hash , :nested => true ) elsif value . respond_to? ( :as_json ) value . as_json ( :nested => true ) else value end end hash end | ActiveSupport seemed to cause problems when just using as_json so using to_hash |
24,510 | def call_method_with_optional_parameters ( object , method_name , parameters ) if object . respond_to? ( method_name ) if object . method ( method_name ) . arity == - 1 object . send ( method_name , parameters ) else object . send ( method_name ) end end end | Helper to not call to_hash with the wrong number of arguments |
24,511 | def initialize_from_response_data run_callbacks :initialize_from_response_data do self . class . attribute_options_including_superclasses . each do | name , options | value = if options [ :type ] == :key self [ name ] . blank? ? options [ :default ] : self [ name ] elsif options [ :type ] == :one hash = self [ name . to_s ] hash && hash [ '@type' ] ? self . class . new_from_response_data ( hash ) : nil elsif options [ :type ] == :many response_data [ name ] && response_data [ name ] . map { | hash | self . class . new_from_response_data ( hash ) } || [ ] else raise "Invalid type: #{options[:type]}" end send ( "#{name}=" , value ) end end end | Iterate over the response data and initialize the attributes |
24,512 | def xml h = Element . new ( 'history' ) events . each do | event | h << event . xml end h end | used when creating a new metadata file for a static XML file |
24,513 | def general ( input , convert = [ :all ] ) output = input output = ellipsis ( output ) if ( convert . include? ( :all ) || convert . include? ( :ellipsis ) ) output = multicharacters ( output ) if ( convert . include? ( :all ) || convert . include? ( :characters ) ) output = brackets_whitespace ( output ) if ( convert . include? ( :all ) || convert . include? ( :brackets ) ) output = emdash ( output ) if ( convert . include? ( :all ) || convert . include? ( :dashes ) ) output = endash ( output ) if ( convert . include? ( :all ) || convert . include? ( :dashes ) ) output = name_abbreviations ( output ) if ( convert . include? ( :all ) || convert . include? ( :abbreviations ) ) output = multiplication_sign ( output ) if ( convert . include? ( :all ) || convert . include? ( :multiplication ) ) output = space_between_numbers ( output ) if ( convert . include? ( :all ) || convert . include? ( :numbers ) ) output = units ( output ) if ( convert . include? ( :all ) || convert . include? ( :units ) ) output = widows ( output ) if ( convert . include? ( :all ) || convert . include? ( :widows ) ) output end | Improves basic non - language specific issues in typography . |
24,514 | def brackets_whitespace ( input ) output = input . gsub ( / \( \[ \{ \s / , '\1' ) output = output . gsub ( / \s \] \) \} / , '\1' ) output = output . gsub ( / \s \( \[ \{ \s / , ' \1' ) output = output . gsub ( / \s \] \) \} \s / , '\1 ' ) end | Fixes spaces around various brackets . |
24,515 | def create if text . match ( / \_ / ) require 'organismo/element/quote' Organismo :: Element :: Quote . new ( text , location ) elsif text . match ( / \_ / ) require 'organismo/element/code' Organismo :: Element :: Code . new ( text , location ) elsif text . match ( / \_ / ) require 'organismo/element/example' Organismo :: Element :: Example . new ( text , location ) elsif text . match ( / \* / ) require 'organismo/element/header' Organismo :: Element :: Header . new ( text , location ) elsif text . match ( / \[ \[ \S \. \j \. \] \] / ) require 'organismo/element/image' Organismo :: Element :: Image . new ( text , location ) elsif text . match ( / \[ \[ \S \] \] / ) require 'organismo/element/link' Organismo :: Element :: Link . new ( text , location ) elsif text . match ( / \- / ) require 'organismo/element/plain_list' Organismo :: Element :: PlainList . new ( text , location ) else require 'organismo/element/text' Organismo :: Element :: Text . new ( text , location ) end end | require and initialize different instance depending on string regex |
24,516 | def send ( email , subject , opts = { } ) if email . nil? or subject . nil? raise ArgumentError , 'Email Address or Subject is missing' else message = { from_name : Octo . get_config ( :email_sender ) . fetch ( :name ) , from_email : Octo . get_config ( :email_sender ) . fetch ( :email ) , subject : subject , text : opts . fetch ( 'text' , nil ) , html : opts . fetch ( 'html' , nil ) , to : [ { email : email , name : opts . fetch ( 'name' , nil ) } ] } _mandrill_config = ENV [ 'MANDRILL_API_KEY' ] || Octo . get_config ( :mandrill_api_key ) if _mandrill_config and ! _mandrill_config . empty? enqueue_msg ( message ) end end end | Send Emails using mandrill api |
24,517 | def parse_control_file @control_file_contents . scan ( / \w \n /m ) . each do | entry | field , value = entry @fields [ field . gsub ( "-" , "_" ) . downcase ] = value end @fields [ "installed_size" ] = @fields [ "installed_size" ] . to_i * 1024 unless @fields [ "installed_size" ] . nil? end | Parse the available fields out of the Debian control file . |
24,518 | def method_missing ( method , * args , & block ) if @queue . respond_to? ( method ) proc = @queue . scopes [ method ] instance_exec * args , & proc end end | this allows you to chain scopes the 2 + scopes in the chain will be called on a query object and not on the base object |
24,519 | def document ( data ) document = collaborative_model . find_by_collaborative_key ( data [ 'id' ] ) @documents ||= [ ] @documents << document send_attribute_versions ( document ) stream_from "loose_leaf.documents.#{document.id}.operations" end | Subscribe to changes to a document |
24,520 | def send_attribute_versions ( document ) collaborative_model . collaborative_attributes . each do | attribute_name | attribute = document . collaborative_attribute ( attribute_name ) transmit ( document_id : document . id , action : 'attribute' , attribute : attribute_name , version : attribute . version ) end end | Send out initial versions |
24,521 | def load_files ( file_finder ) if file_finder . options . fetch ( :files ) . empty? file_finder . list ( * options [ :extensions ] ) else file_finder . options . fetch ( :files ) { [ ] } end end | Loads the files to be read |
24,522 | def print_report todos = [ ] finder = FileFinder . new ( path , options ) files = load_files ( finder ) files . each do | file | todos += Todo . within ( File . open ( file ) , :config => @options ) end todos . sort . each . with_index do | todo , num | due_date = if todo . due_date tag_context = " via #{todo.tag}" if todo . tag? Rainbow ( " (due #{todo.due_date.to_date}#{tag_context})" ) . public_send ( todo . due_date . overdue? ? :red : :blue ) else Rainbow ( " (no due date)" ) . red end puts "#{num + 1}. #{todo.task}#{due_date} " + Rainbow ( "(#{todo.relative_path}:#{todo.line_number}:" "#{todo.character_number})" ) . yellow end exit 0 end | Print report of todos in codebase then exit |
24,523 | def []= ( key , value ) h = self [ key ] if h h . value = value else new_header = Redhead :: Header . new ( key , TO_RAW [ key ] , value ) self << new_header end end | If there is a header in the set with a key matching _key_ then set its value to _value_ . If there is no header matching _key_ create a new header with the given key and value . |
24,524 | def delete ( key ) header = self [ key ] @headers . reject! { | header | header . key == key } ? header : nil end | Removes any headers with key names matching _key_ from the set . |
24,525 | def _supply_model_hook tmp = session [ :__reqref ] _struct = nil if tmp arr = tmp . split ( '|' ) _struct = OpenStruct . new ( request_url : arr [ 0 ] . split ( '=' , 2 ) [ 1 ] , referrer_url : minlength_or_nil ( arr [ 1 ] . split ( '=' , 2 ) [ 1 ] ) , visit_count : arr [ 2 ] . split ( '=' , 2 ) [ 1 ] . to_i ) end ActiveRecord :: Base . send ( :define_method , '_get_reqref' , proc { _struct } ) end | The before_filter which processes necessary data for + acts_as_referred + - models |
24,526 | def shutdown ( force = false ) @workforce . mu_synchronize do Thread . pass until @job_queue . empty? unless force while worker = @workforce . shift ; worker . terminate ; end end nil end | Prevents more workers from being created and waits for all jobs to finish . Once the jobs have completed the workers are terminated . |
24,527 | def authenticate ( username , password ) begin options = { authorization : basic_auth_encryption ( username , password ) } url = url_for_path ( '/authenticateduser/' ) client . get ( url , options ) do | response | if response . code == 200 a_hash = parse response Resource :: User . from_coach a_hash else false end end rescue raise 'Error: Could not authenticate user!' end end | Creates a Coach client for the cyber coach webservcie . |
24,528 | def user_exists? ( username ) begin url = url_for_path ( user_path ( username ) ) client . get ( url ) { | response | response . code == 200 } rescue raise 'Error: Could not test user existence!' end end | Tests if the user given its username exists .. |
24,529 | def create_user ( options = { } , & block ) builder = Builder :: User . new ( public_visible : Privacy :: Public ) block . call ( builder ) url = url_for_path ( user_path ( builder . username ) ) begin client . put ( url , builder . to_xml , options ) do | response | a_hash = parse response Resource :: User . from_coach a_hash end rescue => e raise e if debug false end end | Creates a user with public visibility as default . |
24,530 | def delete_user ( user , options = { } ) raise 'Error: Param user is nil!' if user . nil? url = if user . is_a? ( Resource :: User ) url_for_resource ( user ) elsif user . is_a? ( String ) url_for_path ( user_path ( user ) ) else raise 'Error: Invalid parameters!' end begin client . delete ( url , options ) do | response | response . code == 200 end rescue => e raise e if debug end end | Deletes a user . |
24,531 | def create_partnership ( first_user , second_user , options = { } , & block ) raise 'Error: Param first_user is nil!' if first_user . nil? raise 'Error: Param second_user is nil!' if second_user . nil? path = if first_user . is_a? ( Resource :: User ) && second_user . is_a? ( Resource :: User ) partnership_path ( first_user . username , second_user . username ) elsif first_user . is_a? ( String ) && second_user . is_a? ( String ) partnership_path ( first_user , second_user ) else raise 'Error: Invalid parameters!' end url = url_for_path ( path ) builder = Builder :: Partnership . new ( public_visible : Privacy :: Public ) block . call ( builder ) if block_given? begin client . put ( url , builder . to_xml , options ) do | response | a_hash = parse response Resource :: Partnership . from_coach a_hash end rescue => e raise e if debug false end end | Creates a partnership with public visibility as default . |
24,532 | def delete_partnership ( partnership , options = { } ) raise 'Error: Param partnership is nil!' if partnership . nil? url = url_for_resource ( partnership ) begin client . delete ( url , options ) do | response | response . code == 200 end rescue => e raise e if debug false end end | Deletes a partnership |
24,533 | def breakup_between ( first_user , second_user , options = { } ) raise 'Error: Param first_user is nil!' if first_user . nil? raise 'Error: Param second_user is nil!' if second_user . nil? path = if first_user . is_a? ( Resource :: User ) && second_user . is_a? ( Resource :: User ) partnership_path ( first_user . username , second_user . username ) elsif first_user . is_a? ( String ) && second_user . is_a? ( String ) partnership_path ( first_user , second_user ) else raise 'Error: Invalid parameters!' end url = url_for_path ( path ) begin client . delete ( url , options ) do | response | response . code == 200 end rescue => e raise e if debug false end end | Breaks up a partnership between two users . |
24,534 | def create_subscription ( user_partnership , sport , options = { } , & block ) raise 'Error: Param user_partnership is nil!' if user_partnership . nil? raise 'Error: Param sport is nil!' if sport . nil? url = if user_partnership . is_a? ( Resource :: User ) url_for_path ( subscription_user_path ( user_partnership . username , sport ) ) elsif user_partnership . is_a? ( Resource :: Partnership ) first_username = user_partnership . first_user . username second_username = user_partnership . second_user . username url_for_path ( subscription_partnership_path ( first_username , second_username , sport ) ) elsif user_partnership . is_a? ( String ) url_for_uri ( user_partnership ) else raise 'Error: Invalid parameter!' end builder = Builder :: Subscription . new ( public_visible : Privacy :: Public ) block . call ( builder ) if block_given? begin client . put ( url , builder . to_xml , options ) do | response | a_hash = parse response Resource :: Subscription . from_coach a_hash end rescue => e raise e if debug false end end | Creates a subscription with public visibility as default . |
24,535 | def create_entry ( user_partnership , sport , options = { } , & block ) raise 'Error: Param user_partnership is nil!' if user_partnership . nil? raise 'Error: Param sport is nil!' if sport . nil? entry_type = sport . downcase . to_sym builder = Builder :: Entry . builder ( entry_type ) url = if user_partnership . is_a? ( Resource :: Entity ) url_for_resource ( user_partnership ) + sport . to_s elsif user_partnership . is_a? ( String ) url_for_uri ( user_partnership ) + sport . to_s else raise 'Error: Invalid parameter!' end block . call ( builder ) if block_given? begin client . post ( url , builder . to_xml , options ) do | response | if uri = response . headers [ :location ] entry_by_uri ( uri , options ) else false end end rescue => e raise e if debug false end end | Creates an entry with public visibility as default . |
24,536 | def update_entry ( entry , options = { } , & block ) raise 'Error: Param entry is nil!' if entry . nil? url , entry_type = if entry . is_a? ( Resource :: Entry ) [ url_for_resource ( entry ) , entry . type ] else * , type , id = url_for_uri ( entry ) . split ( '/' ) type = type . downcase . to_sym [ url_for_uri ( entry ) , type ] end builder = Builder :: Entry . builder ( entry_type ) block . call ( builder ) begin client . put ( url , builder . to_xml , options ) do | response | a_hash = parse ( response ) Resource :: Entry . from_coach a_hash end rescue => e raise e if debug false end end | Updates an entry . |
24,537 | def delete_entry ( entry , options = { } ) raise 'Error: Param entry is nil!' if entry . nil? url = if entry . is_a? ( Resource :: Entry ) url_for_resource ( entry ) elsif entry . is_a? ( String ) url_for_uri ( entry ) else raise 'Error: Invalid parameter!' end begin client . delete ( url , options ) do | response | response . code == 200 end rescue => e raise e if debug false end end | Deletes an entry .. |
24,538 | def user ( user , options = { } ) raise 'Error: Param user is nil!' if user . nil? url = if user . is_a? ( Resource :: User ) url_for_resource ( user ) elsif user . is_a? ( String ) url_for_path ( user_path ( user ) ) else raise 'Error: Invalid parameter!' end url = append_query_params ( url , options ) client . get ( url , options ) do | response | a_hash = parse ( response ) Resource :: User . from_coach a_hash end end | Retrieves a user by its username . |
24,539 | def user_by_uri ( uri , options = { } ) raise 'Error: Param uri is nil!' if uri . nil? url = url_for_uri ( uri ) url = append_query_params ( url , options ) client . get ( url , options ) do | response | a_hash = parse ( response ) Resource :: User . from_coach a_hash end end | Retrieves a user by its uri . |
24,540 | def users ( options = { query : { } } ) url = url_for_path ( user_path ) url = append_query_params ( url , options ) client . get ( url , options ) do | response | a_hash = parse ( response ) Resource :: Page . from_coach a_hash , Resource :: User end end | Retrieves users . |
24,541 | def partnership_by_uri ( uri , options = { } ) raise 'Error: Param uri is nil!' if uri . nil? url = url_for_uri ( uri ) url = append_query_params ( url , options ) client . get ( url , options ) do | response | a_hash = parse ( response ) Resource :: Partnership . from_coach a_hash end end | Retrieves a partnership by its uri . |
24,542 | def partnership ( first_username , second_username , options = { } ) raise 'Error: Param first_username is nil!' if first_username . nil? raise 'Error: Param second_username is nil!' if second_username . nil? url = url_for_path ( partnership_path ( first_username , second_username ) ) url = append_query_params ( url , options ) client . get ( url , options ) do | response | a_hash = parse ( response ) Resource :: Partnership . from_coach a_hash end end | Retrieves a partnership by the first username and second username . |
24,543 | def partnerships ( options = { query : { } } ) url = url_for_path ( partnership_path ) url = append_query_params ( url , options ) client . get ( url , options ) do | response | a_hash = parse ( response ) Resource :: Page . from_coach a_hash , Resource :: Partnership end end | Retrieves partnerships . |
24,544 | def call ( env ) if env [ 'REQUEST_METHOD' ] == 'GET' && env [ 'PATH_INFO' ] == logout_path ( env ) :: Rack :: Response . new ( login_html ( env , :logged_out => true ) ) do | resp | resp [ 'Content-Type' ] = 'text/html' end . finish else @app . call ( env ) end end | When given GET to the configured logout path builds a Rack response containing the login form with a you have been logged out notification . Otherwise passes the response on . |
24,545 | def render_with_super ( * args , & block ) if args . first == :super last_view = view_stack . last || { :view => instance_variable_get ( :@virtual_path ) . split ( '/' ) . last } options = args [ 1 ] || { } options [ :locals ] ||= { } options [ :locals ] . reverse_merge! ( last_view [ :locals ] || { } ) if last_view [ :templates ] . nil? last_view [ :templates ] = lookup_context . find_all_templates ( last_view [ :view ] , last_view [ :partial ] , options [ :locals ] . keys ) last_view [ :templates ] . shift end options [ :template ] = last_view [ :templates ] . shift view_stack << last_view result = render_without_super options view_stack . pop result else options = args . first if options . is_a? ( Hash ) current_view = { :view => options [ :partial ] , :partial => true } if options [ :partial ] current_view = { :view => options [ :template ] , :partial => false } if current_view . nil? && options [ :template ] current_view [ :locals ] = options [ :locals ] if ! current_view . nil? && options [ :locals ] view_stack << current_view if current_view . present? end result = render_without_super ( * args , & block ) view_stack . pop if current_view . present? result end end | Adds rendering option . |
24,546 | def bind_mounts ret_val = @launcher . bind_mounts ret_val << File . dirname ( @config [ 'listen' ] ) ret_val += valid_web_paths ret_val . uniq end | Find out bind mount paths |
24,547 | def spawn_command [ @launcher . spawn_cmd_path , '-s' , @config [ 'listen' ] , '-U' , listen_uid . to_s , '-G' , listen_gid . to_s , '-M' , '0660' , '-u' , uid . to_s , '-g' , gid . to_s , '-C' , '4' , '-n' ] end | Build the spawn command |
24,548 | def to_uri h = self . attributes . symbolize_keys . slice ( :scheme , :host , :path ) h [ :query ] = self . unobfuscated_query || self . query return Addressable :: URI . new ( h ) end | during a fresh query we need to actually use the unobfuscated_query |
24,549 | def locale_string_for_ip ( ip ) get "/#{ip}/pay/#{price_setting_id}/locale_for_ip" do | data | parts = data [ :locale ] . split ( '-' ) Zaypay :: Util . stringify_locale_hash ( { :country => parts [ 1 ] , :language => parts [ 0 ] } ) end end | Returns the default locale as a string for a given ip_address with the first part representing the language the second part the country |
24,550 | def country_has_been_configured_for_ip ( ip , options = { } ) locale = locale_for_ip ( ip ) country = list_countries ( options ) . select { | c | c . has_value? locale [ :country ] } . first { :country => country , :locale => locale } if country end | Returns a country as a Hash if the country of the given IP has been configured for your Price Setting . |
24,551 | def list_payment_methods ( options = { } ) raise Zaypay :: Error . new ( :locale_not_set , "locale was not set for your price setting" ) if @locale . nil? get "/#{options[:amount]}/#{@locale}/pay/#{price_setting_id}/payments/new" do | data | Zaypay :: Util . arrayify_if_not_an_array ( data [ :payment_methods ] [ :payment_method ] ) end end | Returns an array of payment methods that are available to your Price Setting with a given locale |
24,552 | def create_payment ( options = { } ) raise Zaypay :: Error . new ( :locale_not_set , "locale was not set for your price setting" ) if @locale . nil? raise Zaypay :: Error . new ( :payment_method_id_not_set , "payment_method_id was not set for your price setting" ) if @payment_method_id . nil? query = { :payment_method_id => payment_method_id } query . merge! ( options ) amount = query . delete ( :amount ) post "/#{amount}/#{@locale}/pay/#{price_setting_id}/payments" , query do | data | payment_hash data end end | Creates a payment on the Zaypay platform . |
24,553 | def register ( key , object = nil ) assert_register_args_valid ( object , block_given? ) @container . register ( key ) do | * args | object = yield ( * args ) if block_given? injectable? ( object ) ? inject ( object ) : object end self end | Registers a new dependency with the given key . You can specify either an object or a factory block that creates an object . |
24,554 | def inject ( target ) unless injectable? ( target ) raise ArgumentError , 'The given object does not include Dio module' end loader = @loader_factory . create ( @container , target ) target . __dio_inject__ ( loader ) target end | Inject dependencies to the given object . |
24,555 | def create ( clazz , * args ) raise ArgumentError , "#{clazz} is not a class" unless clazz . is_a? ( Class ) inject ( clazz . new ( * args ) ) end | Creates a new instance of the given class . Dio injects dependencies to the created instance . |
24,556 | def bitmask_scopes ( bitmask ) send ( "values_for_#{bitmask}" ) . each do | value | scope value , send ( "with_#{bitmask}" , value ) scope "not_#{value}" , send ( "without_#{bitmask}" , value ) end end | Setup scopes for Bitmask attributes |
24,557 | def bitmask_virtual_attributes ( bitmask ) send ( "values_for_#{bitmask}" ) . each do | value | define_method ( "#{value}" ) { send ( "#{bitmask}?" , value ) } define_method ( "#{value}=" ) { | arg | send ( "#{bitmask}=" , arg . blank? || arg == "0" ? send ( "#{bitmask}" ) - [ value ] : send ( "#{bitmask}" ) << value ) } end end | Setup virtual attributes for Bitmask attributes |
24,558 | def awesome_hash ( h ) return "{}" if h == { } keys = @options [ :sort_keys ] ? h . keys . sort { | a , b | a . to_s <=> b . to_s } : h . keys data = keys . map do | key | plain_single_line do [ @inspector . awesome ( key ) , h [ key ] ] end end width = data . map { | key , | key . size } . max || 0 width += @indentation if @options [ :indent ] > 0 data = data . map do | key , value | indented do align ( key , width ) + colorize ( " => " , :hash ) + @inspector . awesome ( value ) end end data = limited ( data , width , :hash => true ) if should_be_limited? if @options [ :multiline ] "{\n" + data . join ( ",\n" ) + "\n#{outdent}}" else "{ #{data.join(', ')} }" end end | Format a hash . If |
24,559 | def request ( http_method , uri , options = { } ) response = self . class . __send__ ( http_method , uri , options . merge ( basic_auth ) ) response end | Entry point to HTTP request Set the username of basic auth to the API Key attribute . |
24,560 | def run_setup setup_tcl = File . open ( "/var/tmp/setup-#{@buildtime}" , 'w' ) setup_tcl . write setup setup_tcl . close system "#@ixia_exe /var/tmp/setup-#{@buildtime}" File . delete setup_tcl end | Load IxN file start all protocols and then start traffic |
24,561 | def clear_stats clear_tcl = File . open ( "/var/tmp/clear-#{@buildtime}" , 'w' ) clear_tcl . write clear_traffic_stats clear_tcl . close system "#{@ixia_exe} /var/tmp/clear-#{@buildtime}" File . delete clear_tcl end | Clear all Ixia stats . This removes invalid drops observed |
24,562 | def run_stats_gather stats_tcl = File . open ( "/var/tmp/stats-#{@buildtime}" , 'w' ) stats_tcl . write finish stats_tcl . close system "#@ixia_exe /var/tmp/stats-#{@buildtime}" File . delete stats_tcl ftp = Net :: FTP . new ( @host ) ftp . login file = "#{@csv_file}.csv" Dir . chdir "#{$log_path}/ixia" do ftp . get "Reports/#{file}" end ftp . delete "Reports/#{file}" ftp . delete "Reports/#{file}.columns" ftp . close CSV . read ( "#{$log_path}/ixia/#{file}" , headers : true ) end | Stop Ixia traffic flows and gather Ixia stats |
24,563 | def run_protocols run_proto = File . open ( "/var/tmp/run-proto-#{@buildtime}" , 'w' ) tcl = connect tcl << load_config tcl << start_protocols tcl << disconnect run_proto . write tcl run_proto . close system "#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}" File . delete run_proto end | Just run protocols . Do not start traffic |
24,564 | def assert_version_changed ( info_plist_file_path ) unless File . file? ( info_plist_file_path ) fail "Info.plist at path " + info_plist_file_path + " does not exist." return end unless git . diff_for_file ( info_plist_file_path ) fail "You did not edit your Info.plist file at all. Therefore, you did not change the iOS version." return end git_diff_string = git . diff_for_file ( info_plist_file_path ) . patch assert_version_changed_diff ( git_diff_string ) end | Asserts the version string has been changed in your iOS XCode project . |
24,565 | def _evaluate_params ( params ) unless params . is_a? ( Hash ) raise ArgumentError , 'event parameters must be a hash' end params = params . dup @instance = params . delete ( :instance ) @params = _sanitize_params ( params ) end | Parameter Evaluation Logic |
24,566 | def _sanitize_params ( params ) Hash [ params . map { | key , value | [ key . to_sym , _sanitize_value ( key , value ) ] } ] . freeze end | Sanitize the event params . Prevents passing values that could cause errors later in Announcer . |
24,567 | def _sanitize_array ( key , array ) array . map { | value | _sanitize_value ( key , value ) } . freeze end | Sanitize an array . |
24,568 | def _sanitize_value ( key , value ) case value when String value . dup . freeze when Symbol , Integer , Float , NilClass , TrueClass , FalseClass value when Array _sanitize_array ( key , value ) when Hash _sanitize_params ( value ) else raise Errors :: UnsafeValueError . new ( key , value ) end end | Sanitize an individual value . |
24,569 | def validate @folders . each do | item | if ( item == nil ) || ( item == "" ) || ! Dir . exists? ( item ) puts "a valid folder path is required as argument #{item}" exit end end end | the container for the files that could not be processed initialize the class with the folders to be processed Validates the supplied folders ensuring they exist |
24,570 | def attributes return @attributes if defined? @attributes data = read_file "replay.attributes.events" data . slice! 0 , ( game_version [ :build ] < 17326 ? 4 : 5 ) @attributes = [ ] data . slice! ( 0 , 4 ) . unpack ( "V" ) [ 0 ] . times do @attributes << Attribute . read ( data . slice! ( 0 , 13 ) ) end @attributes end | replay . attributes . events has plenty of handy information . Here we simply deserialize all the attributes taking into account a format change that took place in build 17326 for later processing . |
24,571 | def parse_global_attributes attributes . each do | attr | case attr . id . to_i when 0x07d1 @game_type = attr . sval @game_type = @game_type == 'Cust' ? :custom : @game_type [ 1 , 3 ] . to_sym when 0x0bb8 @game_speed = ATTRIBUTES [ :game_speed ] [ attr . sval ] when 0x0bc1 @category = ATTRIBUTES [ :category ] [ attr . sval ] end end end | Several pieces of information come from replay . attributes . events and finding one of them is about as hard as finding all of them so we just find all of them here when asked . |
24,572 | def push ( opts ) tokens = [ opts [ :tokens ] || opts [ :token ] || opts [ :to ] ] . flatten message = opts [ :message ] || '' data = opts [ :data ] || { } badge_count = opts [ :badge_count ] || 0 return self if message . blank? @_notifications = Array . new . tap do | notifications | tokens . each do | token | notifications << Houston :: Notification . new ( device : token ) . tap do | notification | notification . alert = message notification . badge = badge_count notification . custom_data = data end end end self end | Create apple push notifications to be sent out |
24,573 | def deliver return self if @_push_was_called @_push_was_called = true apn = APNCertificate . instance @_notifications . each do | notification | apn . push ( notification ) end end | Send out the push notifications |
24,574 | def generate create_header unless @fields . empty? @fields . each { | field | create_field ( field ) } end create_footer @dtd << Ox . dump ( @doc ) . strip end | Initialization Create the XML and return XML string |
24,575 | def make_node ( name , value = nil , attributes = { } ) node = Ox :: Element . new ( name ) node << value unless value . nil? attributes . each { | att , val | node [ att ] = val } unless attributes . empty? node end | Make and return a single node |
24,576 | def make_nodes ( nodes , parent_node ) nodes . each do | name , value | if value . kind_of? ( Hash ) node = Ox :: Element . new ( name . to_s ) make_nodes ( value , node ) else node = make_node ( name . to_s , value ) end parent_node << node parent_node end end | Make multiple nodes appending to the parent passed to the method |
24,577 | def create_header nodes = { deploymentStatus : 'Deployed' , description : "A custom object named #{@name}" , enableActivities : 'true' , enableFeeds : 'false' , enableHistory : 'true' , enableReports : 'true' } make_nodes ( nodes , @doc_root ) end | Create the header for an object |
24,578 | def seo_data if @seo_data . nil? Rails . configuration . seo . each do | key , value | regex = Regexp . new ( value [ "regex" ] ) . match ( request . path ) unless regex . nil? data = Rails . configuration . seo [ key ] fallback = data [ "parent" ] . blank? ? seo_default : seo_default . merge ( Rails . configuration . seo [ data [ "parent" ] ] ) unless data [ "model" ] . blank? response = seo_dynamic ( data [ "model" ] , regex [ 1 .. ( regex . size - 1 ) ] ) data = response . nil? ? { } : response end @seo_data = fallback . merge ( data ) end end end @seo_data ||= seo_default end | Returns SEO data as defined in in seo . json |
24,579 | def add_class ( css_class , options = { } ) return { } unless css_class attributes = { :class => css_class } if options . has_key? ( :unless ) return options [ :unless ] ? { } : attributes end if options . has_key? ( :if ) return options [ :if ] ? attributes : { } end attributes end | provides a slick way to add classes inside haml attribute collections |
24,580 | def delete_link ( * args ) options = { :method => :delete , :confirm => "Are you sure you want to delete this?" } . merge ( extract_options_from_args! ( args ) || { } ) args << options link_to ( * args ) end | Wrap a delete link |
24,581 | def metadata warn 'metadata is deprecated. Use column_properties[] instead' @column_properties . inject ( { } ) { | res , ( k , v ) | res . merge! ( { k => v . to_h } ) } end | Returns meta data as Hash with header name as key |
24,582 | def + ( table ) t2 = table . to_a t2_header = t2 . shift raise 'Tables cannot be added due to header mismatch' unless @column_properties . keys == t2_header raise 'Tables cannot be added due to column properties mismatch' unless column_properties_eql? table . column_properties raise 'Tables cannot be added due to table properties mismatch' unless @table_properties . to_h == table . table_properties . to_h TableTransform :: Table . new ( self . to_a + t2 ) end | Add two tables |
24,583 | def add_column ( name , column_properties = { } ) validate_column_absence ( name ) create_column_properties ( name , column_properties ) @data_rows . each { | x | x << ( yield Row . new ( @column_indexes , x ) ) } @column_indexes [ name ] = @column_indexes . size self end | adds a column with given name to the far right of the table |
24,584 | def upload track if track . playlist_id and track . playlist_token response = JSON . parse ( RestClient . post ( UPLOAD_BASE , audioFile : track . file , title : track . title , playlistId : track . playlist_id , playlistUploadToken : track . playlist_token , order : track . order , description : track . description , longitude : track . longitude , latitude : track . latitude ) ) else response = JSON . parse ( RestClient . post ( UPLOAD_BASE , audioFile : track . file , title : track . title , order : track . order , description : track . description , longitude : track . longitude , latitude : track . latitude ) ) end TrackUser . new ( response ) end | uploads a TrackUpload object returns a TrackUser object |
24,585 | def get ( id : ) response = Faraday . get ( "#{API_BASE}/#{id}" ) attributes = JSON . parse ( response . body ) Track . new ( attributes ) end | get song with specific id |
24,586 | def soundwave ( id : ) response = Faraday . get ( "#{API_BASE}/#{id}/soundwave" ) attributes = JSON . parse ( response . body ) Soundwave . new ( attributes ) end | returns a Soundwave object with peak data |
24,587 | def category_list response = Faraday . get ( "#{API_BASE}/categorylist" ) attributes = JSON . parse ( response . body ) result = Array . new attributes . each do | attrs | result << ListItem . new ( attrs ) end result end | returns an array of ListItem objects of categories |
24,588 | def search term response = Faraday . get ( "#{API_BASE}/categorylist/#{term}" ) attributes = JSON . parse ( response . body ) assemble_tracks attributes end | returns 20 tracks from a specified search in an array of Track objects |
24,589 | def featured ( count : 10 ) response = Faraday . get ( "#{API_BASE}/featuredlist/featured?count=#{count}" ) attributes = JSON . parse ( response . body ) assemble_tracks attributes end | returns featured tracks in an array of Track objects |
24,590 | def gurobi_status intptr = FFI :: MemoryPointer . new :pointer ret = Gurobi . GRBgetintattr @ptr , Gurobi :: GRB_INT_ATTR_STATUS , intptr fail if ret != 0 case intptr . read_int when Gurobi :: GRB_OPTIMAL :optimized when Gurobi :: GRB_INFEASIBLE , Gurobi :: GRB_INF_OR_UNBD , Gurobi :: GRB_UNBOUNDED :invalid else :unknown end end | Get the status of the model |
24,591 | def gurobi_objective dblptr = FFI :: MemoryPointer . new :pointer ret = Gurobi . GRBgetdblattr @ptr , Gurobi :: GRB_DBL_ATTR_OBJVAL , dblptr fail if ret != 0 dblptr . read_double end | The value of the objective function |
24,592 | def add_variable ( var ) ret = Gurobi . GRBaddvar @ptr , 0 , nil , nil , var . coefficient , var . lower_bound , var . upper_bound , gurobi_type ( var . type ) , var . name fail if ret != 0 store_variable var end | Add a new variable to the model |
24,593 | def add_constraint ( constr ) terms = constr . expression . terms indexes_buffer = build_pointer_array ( terms . each_key . map do | var | var . index end , :int ) values_buffer = build_pointer_array terms . values , :double ret = Gurobi . GRBaddconstr @ptr , terms . length , indexes_buffer , values_buffer , gurobi_sense ( constr . sense ) , constr . rhs , constr . name fail if ret != 0 constr . model = self constr . index = @constraints . length constr . freeze @constraints << constr end | Add a new constraint to the model |
24,594 | def build_constraint_matrix ( constrs ) cbeg = [ ] cind = [ ] cval = [ ] constrs . each . map do | constr | cbeg << cind . length constr . expression . terms . each do | var , coeff | cind << var . index cval << coeff end end [ cbeg , cind , cval ] end | Construct a matrix of values for the given list of constraints |
24,595 | def array_to_pointers_to_names ( arr ) arr . map do | obj | obj . name . nil? ? nil : FFI :: MemoryPointer . from_string ( obj . name ) end end | Convert an array of objects to an FFI array of memory pointers to the names of each object |
24,596 | def serialize serialized = { } serialized [ :id ] = id serialized [ :title ] = title serialized [ :subtitle ] = subtitle serialized [ :excerpt ] = excerpt serialized [ :content ] = content serialized [ :seo_description ] = seo_description serialized [ :meta_language ] = meta_language serialized [ :meta_permalink ] = meta_permalink serialized [ :meta_status ] = meta_status serialized [ :fields ] = serialize_fields serialized [ :categories ] = serialize_categories serialized [ :tags ] = serialize_tags serialized [ :other_informations ] = serialize_other_informations serialized end | This function serializes a complete version of the post . |
24,597 | def serialize_fields serialized = { } post_fields . visibles . roots . order ( 'position ASC' ) . each do | post_field | serialized [ post_field . key ] = post_field . serialize_base end serialized end | This function serializes the list of fields for the post . |
24,598 | def serialize_categories serialized = { } categories . each do | category | serialized [ category . id ] = category . serialize_base end serialized end | This function serializes the list of categories for the post . |
24,599 | def serialize_tags serialized = { } tags . each do | tag | serialized [ tag . id ] = tag . serialize_base end serialized end | This function serializes the list of tags for the post . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.