idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
7,700 | def typeahead searcher = params [ :searcher ] query = params [ :q ] or '' total = params [ :total ] or 3 if searcher . blank? logger . error "Typeahead request: no searcher param provided" head :bad_request return nil end searcher_string = "QuickSearch::#{searcher.camelize}Searcher" begin klass = searcher_string . cons... | This method should return a list of search suggestions for a given searcher It should return errors if there is no param called searcher if the searcher does not exist or if the searcher doesn t implement the typeahead method Otherwise it should return the result of calling the typeahead method as JSON |
7,701 | def log_search if params [ :query ] . present? && params [ :page ] . present? @session . searches . create ( query : params [ :query ] , page : params [ :page ] ) head :ok else head :bad_request end end | Logs a search to the database |
7,702 | def log_event if params [ :category ] . present? && params [ :event_action ] . present? && params [ :label ] . present? action = params . fetch ( :action_type , 'click' ) @session . events . create ( category : params [ :category ] , item : params [ :event_action ] , query : params [ :label ] [ 0 .. 250 ] , action : ac... | Logs an event to the database . Typically these can be clicks or serves . |
7,703 | def new_session on_campus = on_campus? ( request . remote_ip ) is_mobile = is_mobile? session_expiry = 5 . minutes . from_now session_uuid = SecureRandom . uuid @session = Session . create ( session_uuid : session_uuid , expiry : session_expiry , on_campus : on_campus , is_mobile : is_mobile ) cookies [ :session_id ] =... | Creates a new session and logs it in the database |
7,704 | def update_session session_id = cookies [ :session_id ] @session = Session . find_by session_uuid : session_id @session . expiry = 5 . minutes . from_now @session . save cookies [ :session_id ] = { :value => session_id , :expires => @session . expiry } end | Updates a session s expiration time on cookie and in database |
7,705 | def no_results_link ( service_name , i18n_key , default_i18n_key = nil ) if ( i18n_key . present? && I18n . exists? ( i18n_key ) ) || ( default_i18n_key . present? && I18n . exists? ( default_i18n_key ) ) locale_result = I18n . t ( i18n_key , default : I18n . t ( default_i18n_key ) ) return locale_result if locale_resu... | Returns a String representing the link to use when no results are found for a search . |
7,706 | def xhr_search endpoint = params [ :endpoint ] if params [ :template ] == 'with_paging' template = 'xhr_response_with_paging' else template = 'xhr_response' end @query = params_q_scrubbed @page = page @per_page = per_page ( endpoint ) @offset = offset ( @page , @per_page ) http_client = HTTPClient . new update_searcher... | The following searches for individual sections of the page . This allows us to do client - side requests in cases where the original server - side request times out or otherwise fails . |
7,707 | def private_const_set ( name , const ) unless role_const_defined? ( name ) const = const_set ( name , const ) private_constant name . to_sym end const end | Set a named constant and make it private |
7,708 | def executable ( name ) define_method ( name ) do | * command | Executable . execute_command ( name , Array ( command ) . flatten , false ) end define_method ( name . to_s + '!' ) do | * command | Executable . execute_command ( name , Array ( command ) . flatten , true ) end end | Creates the methods for the executable with the given name . |
7,709 | def fetch_sims device_list = JSON . parse ( list ( [ '-j' , 'devices' ] ) ) [ 'devices' ] unless device_list . is_a? ( Hash ) msg = "Expected devices to be of type Hash but instated found #{device_list.class}" fail Fourflusher :: Informative , msg end device_list . flat_map do | runtime_str , devices | if runtime_str .... | Gets the simulators and transforms the simctl json into Simulator objects |
7,710 | def get_extra_keys ( schema , data ) extra = data . keys - schema . properties . keys if schema . pattern_properties schema . pattern_properties . keys . each do | pattern | extra -= extra . select { | k | k =~ pattern } end end extra end | for use with additionalProperties and strictProperties |
7,711 | def split ( path ) parts = [ ] last_index = 0 while index = path . index ( "/" , last_index ) if index == last_index parts << "" else parts << path [ last_index ... index ] end last_index = index + 1 end parts << path [ last_index .. - 1 ] parts . shift parts end | custom split method to account for blank segments |
7,712 | def build_report options = ReportBuilder . options groups = get_groups options [ :input_path ] json_report_path = options [ :json_report_path ] || options [ :report_path ] if options [ :report_types ] . include? 'JSON' File . open ( json_report_path + '.json' , 'w' ) do | file | file . write JSON . pretty_generate ( gr... | ReportBuilder Main method |
7,713 | def exit_now! ( exit_code , message = nil ) if exit_code . kind_of? ( String ) && message . nil? raise Methadone :: Error . new ( 1 , exit_code ) else raise Methadone :: Error . new ( exit_code , message ) end end | Call this to exit the program immediately with the given error code and message . |
7,714 | def check_and_prepare_basedir! ( basedir , force ) if File . exists? basedir if force rm_rf basedir , :verbose => true , :secure => true else exit_now! 1 , "error: #{basedir} exists, use --force to override" end end mkdir_p basedir end | Checks that the basedir can be used either by not existing or by existing and force is true . In that case we clean it out entirely |
7,715 | def add_to_file ( file , lines , options = { } ) new_lines = [ ] found_line = false File . open ( file ) . readlines . each do | line | line . chomp! if options [ :before ] && options [ :before ] === line found_line = true new_lines += lines end new_lines << line end raise "No line matched #{options[:before]}" if optio... | Add content to a file |
7,716 | def copy_file ( relative_path , options = { } ) options [ :from ] ||= :full relative_path = File . join ( relative_path . split ( / \/ / ) ) template_path = File . join ( template_dir ( options [ :from ] ) , relative_path + ".erb" ) template = ERB . new ( File . open ( template_path ) . readlines . join ( '' ) ) relati... | Copies a file running it through ERB |
7,717 | def parse_string_for_argv ( string ) return [ ] if string . nil? args = [ ] current = 0 next_arg = '' inside_quote = nil last_char = nil while current < string . length char = string . chars . to_a [ current ] case char when / / if inside_quote . nil? inside_quote = char elsif inside_quote == char inside_quote = nil el... | Parses + string + returning an array that can be placed into ARGV or given to OptionParser |
7,718 | def go! setup_defaults opts . post_setup opts . parse! opts . check_args! result = call_main if result . kind_of? Integer exit result else exit 0 end rescue OptionParser :: ParseError => ex logger . error ex . message puts puts opts . help exit 64 end | Start your command - line app exiting appropriately when complete . |
7,719 | def normalize_defaults new_options = { } options . each do | key , value | unless value . nil? new_options [ key . to_s ] = value new_options [ key . to_sym ] = value end end options . merge! ( new_options ) end | Normalized all defaults to both string and symbol forms so the user can access them via either means just as they would for non - defaulted options |
7,720 | def call_main @leak_exceptions = nil unless defined? @leak_exceptions @main_block . call ( * ARGV ) rescue Methadone :: Error => ex raise ex if ENV [ 'DEBUG' ] logger . error ex . message unless no_message? ex ex . exit_code rescue OptionParser :: ParseError raise rescue => ex raise ex if ENV [ 'DEBUG' ] raise ex if @l... | Handle calling main and trapping any exceptions thrown |
7,721 | def check_args! :: Hash [ @args . zip ( :: ARGV ) ] . each do | arg_name , arg_value | if @arg_options [ arg_name ] . include? :required if arg_value . nil? message = "'#{arg_name.to_s}' is required" message = "at least one " + message if @arg_options [ arg_name ] . include? :many raise :: OptionParser :: ParseError , ... | Create the proxy |
7,722 | def arg ( arg_name , * options ) options << :optional if options . include? ( :any ) && ! options . include? ( :optional ) options << :required unless options . include? :optional options << :one unless options . include? ( :any ) || options . include? ( :many ) @args << arg_name @arg_options [ arg_name ] = options opt... | Sets the banner to include these arg names |
7,723 | def sh ( command , options = { } , & block ) sh_logger . debug ( "Executing '#{command}'" ) stdout , stderr , status = execution_strategy . run_command ( command ) process_status = Methadone :: ProcessStatus . new ( status , options [ :expected ] ) sh_logger . warn ( "stderr output of '#{command}': #{stderr}" ) unless ... | Run a shell command capturing and logging its output . If the command completed successfully it s output is logged at DEBUG . If not its output as logged at INFO . In either case its error output is logged at WARN . |
7,724 | def call_block ( block , stdout , stderr , exitstatus ) if block . arity > 0 case block . arity when 1 block . call ( stdout ) when 2 block . call ( stdout , stderr ) else block . call ( stdout , stderr , exitstatus ) end else block . call end end | Safely call our block even if the user passed in a lambda |
7,725 | def relationnal_result ( method_name , * arguments ) self . class . reload_fields_definition ( false ) if self . class . many2one_associations . has_key? ( method_name ) load_m2o_association ( method_name , * arguments ) elsif self . class . polymorphic_m2o_associations . has_key? ( method_name ) load_polymorphic_m2o_a... | fakes associations like much like ActiveRecord according to the cached OpenERP data model |
7,726 | def cast_association ( k ) if self . class . one2many_associations [ k ] if @loaded_associations [ k ] v = @loaded_associations [ k ] . select { | i | i . changed? } v = @associations [ k ] if v . empty? else v = @associations [ k ] end cast_o2m_association ( v ) elsif self . class . many2many_associations [ k ] v = @a... | talk OpenERP cryptic associations API |
7,727 | def on_change ( on_change_method , field_name , field_value , * args ) ids = self . id ? [ id ] : [ ] result = self . class . object_service ( :execute , self . class . openerp_model , on_change_method , ids , * args ) load_on_change_result ( result , field_name , field_value ) end | Generic OpenERP on_change method |
7,728 | def wkf_action ( action , context = { } , reload = true ) self . class . object_service ( :exec_workflow , self . class . openerp_model , action , self . id , context ) reload_fields if reload end | wrapper for OpenERP exec_workflow Business Process Management engine |
7,729 | def load ( attributes ) self . class . reload_fields_definition ( false ) raise ArgumentError , "expected an attributes Hash, got #{attributes.inspect}" unless attributes . is_a? ( Hash ) @associations ||= { } @attributes ||= { } @loaded_associations = { } attributes . each do | key , value | self . send "#{key}=" , va... | Flushes the current object and loads the + attributes + Hash containing the attributes and the associations into the current object |
7,730 | def copy ( defaults = { } , context = { } ) self . class . find ( rpc_execute ( 'copy' , id , defaults , context ) , context : context ) end | OpenERP copy method load persisted copied Object |
7,731 | def perform_validations ( options = { } ) if options . is_a? ( Hash ) options [ :validate ] == false || valid? ( options [ :context ] ) else valid? end end | Real validations happens on OpenERP side only pre - validations can happen here eventually |
7,732 | def stub_model ( model_class , stubs = { } ) model_class . new . tap do | m | m . extend ActiveModelStubExtensions if defined? ( ActiveRecord ) && model_class < ActiveRecord :: Base && model_class . primary_key m . extend ActiveRecordStubExtensions primary_key = model_class . primary_key . to_sym stubs = { primary_key ... | Creates an instance of Model with to_param stubbed using a generated value that is unique to each object . If Model is an ActiveRecord model it is prohibited from accessing the database . |
7,733 | def stop ( reason ) if @pid begin Process . kill ( 'KILL' , @pid ) Process . waitpid ( @pid ) rescue Errno :: ESRCH , Errno :: ECHILD end end @log . info "Killing pid: #{@pid.to_s}. Reason: #{reason}" @pid = nil end | Stop the child process by issuing a kill - 9 . |
7,734 | def mentos ( method , args = [ ] , kwargs = { } , original_code = nil ) start unless alive? begin timeout_time = Integer ( ENV [ "MENTOS_TIMEOUT" ] ) rescue 8 Timeout :: timeout ( timeout_time ) do id = ( 0 ... 8 ) . map { 65 . + ( rand ( 25 ) ) . chr } . join code = add_ids ( original_code , id ) if original_code if c... | Our rpc - ish request to mentos . Requires a method name and then optional args kwargs code . |
7,735 | def handle_header_and_return ( header , id ) if header header = header_to_json ( header ) bytes = header [ :bytes ] res = @out . read ( bytes . to_i ) if header [ :method ] == "highlight" if res . nil? @log . warn "No highlight result back from mentos." stop "No highlight result back from mentos." raise MentosError , "... | Based on the header we receive determine if we need to read more bytes and read those bytes if necessary . |
7,736 | def get_header begin size = @out . read ( 33 ) size = size [ 0 .. - 2 ] if not size_check ( size ) @log . error "Size returned from mentos.py invalid." stop "Size returned from mentos.py invalid." raise MentosError , "Size returned from mentos.py invalid." end header_bytes = size . to_s . to_i ( 2 ) + 1 @log . info "Si... | Read the header via the pipe . |
7,737 | def return_result ( res , method ) unless method == :lexer_name_for || method == :highlight || method == :css res = MultiJson . load ( res , :symbolize_keys => true ) end res = res . rstrip if res . class == String res end | Return the final result for the API . Return Ruby objects for the methods that want them text otherwise . |
7,738 | def header_to_json ( header ) @log . info "[In header: #{header} " header = MultiJson . load ( header , :symbolize_keys => true ) if header [ :error ] @log . error "Failed to convert header to JSON." stop header [ :error ] raise MentosError , header [ :error ] else header end end | Convert a text header into JSON for easy access . |
7,739 | def sql_in_for_flag ( flag , colmn ) val = flag_mapping [ colmn ] [ flag ] flag_value_range_for_column ( colmn ) . select { | bits | bits & val == val } end | returns an array of integers suitable for a SQL IN statement . |
7,740 | def input_format ( & block ) case when block && ! @input_format_block @input_format_block = block when ! block && @input_format_block return @input_format ||= Apipie :: Params :: Description . define ( & @input_format_block ) when block && @input_format_block raise "The input_format has already been defined in #{self.c... | we don t evaluate tbe block immediatelly but postpone it till all the action classes are loaded because we can use them to reference output format |
7,741 | def recursive_to_hash ( * values ) if values . size == 1 value = values . first case value when String , Numeric , Symbol , TrueClass , FalseClass , NilClass , Time value when Hash value . inject ( { } ) { | h , ( k , v ) | h . update k => recursive_to_hash ( v ) } when Array value . map { | v | recursive_to_hash v } e... | recursively traverses hash - array structure and converts all to hashes accepts more hashes which are then merged |
7,742 | def trigger ( action_class , * args ) if uses_concurrency_control trigger_with_concurrency_control ( action_class , * args ) else world . trigger { world . plan_with_options ( action_class : action_class , args : args , caller_action : self ) } end end | Helper for creating sub plans |
7,743 | def current_batch start_position = output [ :planned_count ] size = start_position + batch_size > total_count ? total_count - start_position : batch_size batch ( start_position , size ) end | Returns the items in the current batch |
7,744 | def add_dependencies ( step , action ) action . required_step_ids . each do | required_step_id | @graph [ step . id ] << required_step_id end end | adds dependencies to graph that + step + has based on the steps referenced in its + input + |
7,745 | def reload! @action_classes = @action_classes . map do | klass | begin Utils . constantize ( klass . to_s ) rescue NameError nil end end . compact middleware . clear_cache! calculate_subscription_index end | reload actions classes intended only for devel |
7,746 | def rescue_strategy suggested_strategies = [ ] if self . steps . compact . any? { | step | step . state == :error } suggested_strategies << SuggestedStrategy [ self , rescue_strategy_for_self ] end self . planned_actions . each do | planned_action | rescue_strategy = rescue_strategy_for_planned_action ( planned_action ... | What strategy should be used for rescuing from error in the action or its sub actions |
7,747 | def combine_suggested_strategies ( suggested_strategies ) if suggested_strategies . empty? nil else if suggested_strategies . all? { | suggested_strategy | suggested_strategy . strategy == Skip } return Skip elsif suggested_strategies . all? { | suggested_strategy | suggested_strategy . strategy == Fail } return Fail e... | Override when different approach should be taken for combining the suggested strategies |
7,748 | def build_errors ( type , category = nil , row = nil , column = nil , content = nil , constraints = { } ) @errors << Csvlint :: ErrorMessage . new ( type , category , row , column , content , constraints ) end | Creates a validation error |
7,749 | def parse_contents ( stream , line = nil ) current_line = line . present? ? line : 1 all_errors = [ ] @csv_options [ :encoding ] = @encoding begin row = LineCSV . parse_line ( stream , @csv_options ) rescue LineCSV :: MalformedCSVError => e build_exception_messages ( e , stream , current_line ) end if row if current_li... | analyses the provided csv and builds errors warnings and info messages |
7,750 | def create_order_reference_for_id ( id , id_type , inherit_shipping_address : nil , confirm_now : nil , amount : nil , currency_code : @currency_code , platform_id : nil , seller_note : nil , seller_order_id : nil , store_name : nil , custom_information : nil , supplementary_data : nil , merchant_id : @merchant_id , mw... | Creates an order reference for the given object |
7,751 | def get_billing_agreement_details ( amazon_billing_agreement_id , address_consent_token : nil , access_token : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'GetBillingAgreementDetails' , 'SellerId' => merchant_id , 'AmazonBillingAgreementId' => amazon_billing_agreement_id } optio... | Returns details about the Billing Agreement object and its current state |
7,752 | def set_billing_agreement_details ( amazon_billing_agreement_id , platform_id : nil , seller_note : nil , seller_billing_agreement_id : nil , custom_information : nil , store_name : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'SetBillingAgreementDetails' , 'SellerId' => merchant... | Sets billing agreement details such as a description of the agreement and other information about the seller . |
7,753 | def confirm_billing_agreement ( amazon_billing_agreement_id , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'ConfirmBillingAgreement' , 'SellerId' => merchant_id , 'AmazonBillingAgreementId' => amazon_billing_agreement_id } optional = { 'MWSAuthToken' => mws_auth_token } operation ( par... | Confirms that the billing agreement is free of constraints and all required information has been set on the billing agreement |
7,754 | def validate_billing_agreement ( amazon_billing_agreement_id , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'ValidateBillingAgreement' , 'SellerId' => merchant_id , 'AmazonBillingAgreementId' => amazon_billing_agreement_id } optional = { 'MWSAuthToken' => mws_auth_token } operation ( p... | Validates the status of the BillingAgreement object and the payment method associated with it |
7,755 | def close_billing_agreement ( amazon_billing_agreement_id , closure_reason : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'CloseBillingAgreement' , 'SellerId' => merchant_id , 'AmazonBillingAgreementId' => amazon_billing_agreement_id } optional = { 'ClosureReason' => closure_reas... | Confirms that you want to terminate the billing agreement with the buyer and that you do not expect to create any new order references or authorizations on this billing agreement |
7,756 | def list_order_reference ( query_id , query_id_type , created_time_range_start : nil , created_time_range_end : nil , sort_order : nil , page_size : nil , order_reference_status_list_filter : nil , merchant_id : @merchant_id , mws_auth_token : nil ) payment_domain = payment_domain_hash [ @region ] parameters = { 'Actio... | Allows the search of any Amazon Pay order made using secondary seller order IDs generated manually a solution provider or a custom order fulfillment service . |
7,757 | def get_merchant_account_status ( merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'GetMerchantAccountStatus' , 'SellerId' => merchant_id } optional = { 'MWSAuthToken' => mws_auth_token } operation ( parameters , optional ) end | Returns status of the merchant |
7,758 | def get_order_reference_details ( amazon_order_reference_id , address_consent_token : nil , access_token : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'GetOrderReferenceDetails' , 'SellerId' => merchant_id , 'AmazonOrderReferenceId' => amazon_order_reference_id } optional = { 'A... | Returns details about the Order Reference object and its current state |
7,759 | def set_order_reference_details ( amazon_order_reference_id , amount , currency_code : @currency_code , platform_id : nil , seller_note : nil , seller_order_id : nil , request_payment_authorization : nil , store_name : nil , order_item_categories : nil , custom_information : nil , supplementary_data : nil , merchant_id... | Sets order reference details such as the order total and a description for the order |
7,760 | def set_order_attributes ( amazon_order_reference_id , amount : nil , currency_code : @currency_code , platform_id : nil , seller_note : nil , seller_order_id : nil , payment_service_provider_id : nil , payment_service_provider_order_id : nil , request_payment_authorization : nil , store_name : nil , order_item_categor... | Sets order attributes such as the order total and a description for the order |
7,761 | def confirm_order_reference ( amazon_order_reference_id , success_url : nil , failure_url : nil , authorization_amount : nil , currency_code : @currency_code , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'ConfirmOrderReference' , 'SellerId' => merchant_id , 'AmazonOrderReferenceId' =>... | Confirms that the order reference is free of constraints and all required information has been set on the order reference |
7,762 | def cancel_order_reference ( amazon_order_reference_id , cancelation_reason : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'CancelOrderReference' , 'SellerId' => merchant_id , 'AmazonOrderReferenceId' => amazon_order_reference_id } optional = { 'CancelationReason' => cancelation_... | Cancels a previously confirmed order reference |
7,763 | def get_authorization_details ( amazon_authorization_id , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'GetAuthorizationDetails' , 'SellerId' => merchant_id , 'AmazonAuthorizationId' => amazon_authorization_id } optional = { 'MWSAuthToken' => mws_auth_token } operation ( parameters , o... | Returns the status of a particular authorization and the total amount captured on the authorization |
7,764 | def capture ( amazon_authorization_id , capture_reference_id , amount , currency_code : @currency_code , seller_capture_note : nil , soft_descriptor : nil , provider_credit_details : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'Capture' , 'SellerId' => merchant_id , 'AmazonAutho... | Captures funds from an authorized payment instrument . |
7,765 | def get_capture_details ( amazon_capture_id , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'GetCaptureDetails' , 'SellerId' => merchant_id , 'AmazonCaptureId' => amazon_capture_id } optional = { 'MWSAuthToken' => mws_auth_token } operation ( parameters , optional ) end | Returns the status of a particular capture and the total amount refunded on the capture |
7,766 | def refund ( amazon_capture_id , refund_reference_id , amount , currency_code : @currency_code , seller_refund_note : nil , soft_descriptor : nil , provider_credit_reversal_details : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'Refund' , 'SellerId' => merchant_id , 'AmazonCaptur... | Refunds a previously captured amount |
7,767 | def get_refund_details ( amazon_refund_id , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'GetRefundDetails' , 'SellerId' => merchant_id , 'AmazonRefundId' => amazon_refund_id } optional = { 'MWSAuthToken' => mws_auth_token } operation ( parameters , optional ) end | Returns the status of a particular refund |
7,768 | def close_authorization ( amazon_authorization_id , closure_reason : nil , merchant_id : @merchant_id , mws_auth_token : nil ) parameters = { 'Action' => 'CloseAuthorization' , 'SellerId' => merchant_id , 'AmazonAuthorizationId' => amazon_authorization_id } optional = { 'ClosureReason' => closure_reason , 'MWSAuthToken... | Closes an authorization |
7,769 | def set_provider_credit_details ( provider_credit_details ) member_details = { } provider_credit_details . each_with_index do | val , index | member = index + 1 member_details [ "ProviderCreditList.member.#{member}.ProviderId" ] = val [ :provider_id ] member_details [ "ProviderCreditList.member.#{member}.CreditAmount.A... | This method builds the provider credit details hash that will be combined with either the authorize or capture API call . |
7,770 | def set_provider_credit_reversal_details ( provider_credit_reversal_details ) member_details = { } provider_credit_reversal_details . each_with_index do | val , index | member = index + 1 member_details [ "ProviderCreditReversalList.member.#{member}.ProviderId" ] = val [ :provider_id ] member_details [ "ProviderCreditR... | This method builds the provider credit reversal details hash that will be combined with the refund API call . |
7,771 | def build_post_url @optional . map { | k , v | @parameters [ k ] = v unless v . nil? } @parameters [ 'Timestamp' ] = Time . now . utc . iso8601 unless @parameters . key? ( 'Timestamp' ) @parameters = @default_hash . merge ( @parameters ) post_url = @parameters . sort . map { | k , v | "#{k}=#{custom_escape(v)}" } . joi... | This method combines the required and optional parameters to sign the post body and generate the post url . |
7,772 | def sign ( post_body ) custom_escape ( Base64 . strict_encode64 ( OpenSSL :: HMAC . digest ( OpenSSL :: Digest :: SHA256 . new , @secret_key , post_body ) ) ) end | This method signs the post body that is being sent using the secret key provided . |
7,773 | def post ( mws_endpoint , sandbox_str , post_url ) uri = URI ( "https://#{mws_endpoint}/#{sandbox_str}/#{AmazonPay::API_VERSION}" ) https = Net :: HTTP . new ( uri . host , uri . port , @proxy_addr , @proxy_port , @proxy_user , @proxy_pass ) https . use_ssl = true https . verify_mode = OpenSSL :: SSL :: VERIFY_PEER use... | This method performs the post to the MWS endpoint . It will retry three times after the initial post if the status code comes back as either 500 or 503 . |
7,774 | def charge ( amazon_reference_id , authorization_reference_id , charge_amount , charge_currency_code : @currency_code , charge_note : nil , charge_order_id : nil , store_name : nil , custom_information : nil , soft_descriptor : nil , platform_id : nil , merchant_id : @merchant_id , mws_auth_token : nil ) if order_refer... | This method combines multiple API calls to perform a complete transaction with minimum requirements . |
7,775 | def add ( routes_refine ) routes . deep_merge! routes_refine . routes reverse_routes . merge! routes_refine . reverse_routes end | Add RoutesRefine to Router |
7,776 | def find_nearest_route ( path ) path_parts = path . parts . dup loop do route = routes . navigate ( * path_parts ) &. values &. grep ( Route ) &. first break route if route || path_parts . pop . nil? end end | Find the nearest route by path |
7,777 | def path_of ( route_or_controller , action = nil ) if route_or_controller . is_a? ( Flame :: Router :: Route ) route = route_or_controller controller = route . controller action = route . action else controller = route_or_controller end reverse_routes . dig ( controller . to_s , action ) end | Find the path of route |
7,778 | def render ( cache : true , & block ) @cache = cache return unless @filename tilt = compile_file layout_render tilt . render ( @scope , @locals , & block ) end | Create a new instance from controller by path and with options |
7,779 | def compile_file ( filename = @filename ) cached = @controller . cached_tilts [ filename ] return cached if @cache && cached compiled = Tilt . new ( filename , nil , @tilt_options ) @controller . cached_tilts [ filename ] ||= compiled if @cache compiled end | Compile file with Tilt engine |
7,780 | def find_file ( path ) caller_path = caller_locations ( 4 .. 4 ) . first . path caller_dir = begin File . dirname ( caller_path ) . sub ( views_dir , '' ) if Tilt [ caller_path ] rescue LoadError nil end find_files ( path , controller_dirs | Array ( caller_dir ) ) . find { | file | Tilt [ file ] } end | Find template - file by path |
7,781 | def find_layouts ( path ) find_files ( path , layout_dirs ) . select { | file | Tilt [ file ] } . sort! { | a , b | b . split ( '/' ) . size <=> a . split ( '/' ) . size } end | Find layout - files by path |
7,782 | def controller_dirs parts = @controller . class . underscore . split ( '/' ) . map do | part | %w[ _controller _ctrl ] . find { | suffix | part . chomp! suffix } part end combine_parts ( parts ) . map! { | path | path . join ( '/' ) } end | Find possible directories for the controller |
7,783 | def combine_parts ( parts ) parts . size . downto ( 1 ) . with_object ( [ ] ) do | i , arr | arr . push ( * parts . combination ( i ) . to_a ) end end | Make combinations in order with different sizes |
7,784 | def layout_render ( content ) return content unless @layout layout_files = find_layouts ( @layout ) return content if layout_files . empty? layout_files . each_with_object ( content . dup ) do | layout_file , result | layout = compile_file ( layout_file ) result . replace layout . render ( @scope , @locals ) { result }... | Render the layout with template |
7,785 | def adapt ( ctrl , action ) parameters = ctrl . instance_method ( action ) . parameters parameters . map! do | parameter | parameter_type , parameter_name = parameter path_part = self . class :: Part . new parameter_name , arg : parameter_type path_part unless parts . include? path_part end self . class . new @path . e... | Compare by parts count and the first arg position |
7,786 | def to_routes_with_endpoint endpoint = parts . reduce ( result = Flame :: Router :: Routes . new ) do | hash , part | hash [ part ] ||= Flame :: Router :: Routes . new end [ result , endpoint ] end | Path parts as keys of nested Hashes |
7,787 | def assign_argument ( part , args = { } ) return part unless part . arg? return args . delete ( part [ 2 .. - 1 ] . to_sym ) if part . opt_arg? param = args . delete ( part [ 1 .. - 1 ] . to_sym ) error = Errors :: ArgumentNotAssignedError . new ( @path , part ) raise error if param . nil? param end | Helpers for assign_arguments |
7,788 | def status ( value = nil ) response . status ||= 200 response . headers [ 'X-Cascade' ] = 'pass' if value == 404 value ? response . status = value : response . status end | Acccess to the status of response |
7,789 | def params @params ||= begin request . params . symbolize_keys ( deep : true ) rescue ArgumentError => e raise unless e . message . include? ( 'invalid %-encoding' ) { } end end | Parameters of the request |
7,790 | def dump_error ( error ) error_message = [ "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - " "#{error.class} - #{error.message}:" , * error . backtrace ] . join ( "\n\t" ) @env [ Rack :: RACK_ERRORS ] . puts ( error_message ) end | Add error s backtrace to |
7,791 | def try_options return unless request . http_method == :OPTIONS allow = available_endpoint &. allow halt 404 unless allow response . headers [ 'Allow' ] = allow end | Return response if HTTP - method is OPTIONS |
7,792 | def redirect ( * args ) args [ 0 ] = args . first . to_s if args . first . is_a? URI unless args . first . is_a? String path_to_args_range = 0 .. ( args . last . is_a? ( Integer ) ? - 2 : - 1 ) args [ path_to_args_range ] = path_to ( * args [ path_to_args_range ] ) end response . redirect ( * args ) status end | Redirect for response |
7,793 | def attachment ( filename = nil , disposition = :attachment ) content_dis = 'Content-Disposition' response [ content_dis ] = disposition . to_s return unless filename response [ content_dis ] << "; filename=\"#{File.basename(filename)}\"" ext = File . extname ( filename ) response . content_type = ext unless ext . empt... | Set the Content - Disposition to attachment with the specified filename instructing the user agents to prompt to save and set Content - Type by filename . |
7,794 | def reroute ( * args ) add_controller_class ( args ) ctrl , action = args [ 0 .. 1 ] ctrl_object = ctrl == self . class ? self : ctrl . new ( @dispatcher ) ctrl_object . send :execute , action body end | Execute any action from any controller |
7,795 | def call ( env ) @app . call ( env ) if @app . respond_to? :call Flame :: Dispatcher . new ( self . class , env ) . run! end | Request recieving method |
7,796 | def request ( verb , path , options = { } ) response = connection . request ( verb , path , ** options ) Response . new ( response . status . code , response . headers , response . body . to_s ) end | Create a new client . |
7,797 | def redirect_to_reddit! state = SecureRandom . urlsafe_base64 url = Redd . url ( client_id : @client_id , redirect_uri : @redirect_uri , scope : @scope , duration : @duration , state : state ) @request . session [ :redd_state ] = state [ 302 , { 'Location' => url } , [ ] ] end | Creates a unique state and redirects the user to reddit for authentication . |
7,798 | def after_call env_session = @request . env [ 'redd.session' ] if env_session && env_session . client . access @request . session [ :redd_session ] = env_session . client . access . to_h else @request . session . delete ( :redd_session ) end end | Do any cleanup or changes after calling the application . |
7,799 | def handle_token_error message = nil message = 'invalid_state' if @request . GET [ 'state' ] != @request . session [ :redd_state ] message = @request . GET [ 'error' ] if @request . GET [ 'error' ] raise Errors :: TokenRetrievalError , message if message end | Assigns a single string representing a reddit authentication errors . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.