idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
1,700 | def add_cell ( value = '' , options = { } ) c = Cell . new ( self , value , options ) self << c worksheet . send ( :update_column_info , self , [ ] ) c end | Adds a single cell to the row based on the data provided and updates the worksheet s autofit data . |
1,701 | def color = ( color ) each_with_index do | cell , index | cell . color = color . is_a? ( Array ) ? color [ index ] : color end end | sets the color for every cell in this row |
1,702 | def style = ( style ) each_with_index do | cell , index | cell . style = style . is_a? ( Array ) ? style [ index ] : style end end | sets the style for every cell in this row |
1,703 | def array_to_cells ( values , options = { } ) DataTypeValidator . validate :array_to_cells , Array , values types , style , formula_values = options . delete ( :types ) , options . delete ( :style ) , options . delete ( :formula_values ) values . each_with_index do | value , index | options [ :style ] = style . is_a? ( Array ) ? style [ index ] : style if style options [ :type ] = types . is_a? ( Array ) ? types [ index ] : types if types options [ :formula_value ] = formula_values [ index ] if formula_values . is_a? ( Array ) self [ index ] = Cell . new ( self , value , options ) end end | Converts values types and style options into cells and associates them with this row . A new cell is created for each item in the values array . If value option is defined and is a symbol it is applied to all the cells created . If the value option is an array cell types are applied by index for each cell If the style option is defined and is an Integer it is applied to all cells created . If the style option is an array style is applied by index for each cell . |
1,704 | def add_image ( options = { } ) if options [ :end_at ] TwoCellAnchor . new ( self , options ) . add_pic ( options ) else OneCellAnchor . new ( self , options ) end @anchors . last . object end | Creates a new Drawing object |
1,705 | def add_chart ( chart_type , options = { } ) TwoCellAnchor . new ( self , options ) @anchors . last . add_chart ( chart_type , options ) end | Adds a chart to the drawing . |
1,706 | def charts charts = @anchors . select { | a | a . object . is_a? ( GraphicFrame ) } charts . map { | a | a . object . chart } end | An array of charts that are associated with this drawing s anchors |
1,707 | def hyperlinks links = self . images . select { | a | a . hyperlink . is_a? ( Hyperlink ) } links . map { | a | a . hyperlink } end | An array of hyperlink objects associated with this drawings images |
1,708 | def images images = @anchors . select { | a | a . object . is_a? ( Pic ) } images . map { | a | a . object } end | An array of image objects that are associated with this drawing s anchors |
1,709 | def relationships r = Relationships . new child_objects . each { | child | r << child . relationship } r end | The drawing s relationships . |
1,710 | def to_xml_string ( str = '' ) update_properties str << "<sheetPr #{serialized_attributes}>" tab_color . to_xml_string ( str , 'tabColor' ) if tab_color outline_pr . to_xml_string ( str ) if @outline_pr page_setup_pr . to_xml_string ( str ) str << "</sheetPr>" end | Serialize the object |
1,711 | def to_xml_string ( str = '' ) super ( str ) do str << '<c:pie3DChart>' str << ( '<c:varyColors val="' << vary_colors . to_s << '"/>' ) @series . each { | ser | ser . to_xml_string ( str ) } d_lbls . to_xml_string ( str ) if @d_lbls str << '</c:pie3DChart>' end end | Creates a new pie chart object |
1,712 | def to_xml_string ( str = '' ) return if empty? str << "<bookViews>" each { | view | view . to_xml_string ( str ) } str << '</bookViews>' end | creates the book views object Serialize to xml |
1,713 | def update_width ( cell , fixed_width = nil , use_autowidth = true ) if fixed_width . is_a? Numeric self . width = fixed_width elsif use_autowidth cell_width = cell . autowidth self . width = cell_width unless ( width || 0 ) > ( cell_width || 0 ) end end | updates the width for this col based on the cells autowidth and an optionally specified fixed width |
1,714 | def parse_symbol attr_name , xpath v = parse_value xpath v = v . to_sym unless v . nil? send ( "#{attr_name}=" , v ) end | parse convert and assign node text to symbol |
1,715 | def parse_integer attr_name , xpath v = parse_value xpath v = v . to_i if v . respond_to? ( :to_i ) send ( "#{attr_name}=" , v ) end | parse convert and assign note text to integer |
1,716 | def parse_float attr_name , xpath v = parse_value xpath v = v . to_f if v . respond_to? ( :to_f ) send ( "#{attr_name}=" , v ) end | parse convert and assign node text to float |
1,717 | def parse_value xpath node = parser_xml . xpath ( xpath ) return nil if node . empty? node . text . strip end | return node text based on xpath |
1,718 | def add_chart ( chart_type , options ) @drawing ||= Drawing . new worksheet drawing . add_chart ( chart_type , options ) end | adds a chart to the drawing object |
1,719 | def add_range ( cells ) sqref = if cells . is_a? ( String ) cells elsif cells . is_a? ( SimpleTypedList ) || cells . is_a? ( Array ) Axlsx :: cell_range ( cells , false ) end self << ProtectedRange . new ( :sqref => sqref , :name => "Range#{size}" ) last end | Adds a protected range |
1,720 | def to_xml_string ( str = '' ) return if empty? str << '<protectedRanges>' each { | range | range . to_xml_string ( str ) } str << '</protectedRanges>' end | Serializes the protected ranges |
1,721 | def add_column ( col_id , filter_type , options = { } ) columns << FilterColumn . new ( col_id , filter_type , options ) columns . last end | Adds a filter column . This is the recommended way to create and manage filter columns for your autofilter . In addition to the require id and type parameters options will be passed to the filter column during instantiation . |
1,722 | def apply first_cell , last_cell = range . split ( ':' ) start_point = Axlsx :: name_to_indices ( first_cell ) end_point = Axlsx :: name_to_indices ( last_cell ) rows = worksheet . rows [ ( start_point . last + 1 ) .. end_point . last ] || [ ] column_offset = start_point . first columns . each do | column | rows . each do | row | next if row . hidden column . apply ( row , column_offset ) end end end | actually performs the filtering of rows who s cells do not match the filter . |
1,723 | def delete ( v ) return unless include? v raise ArgumentError , "Item is protected and cannot be deleted" if protected? index ( v ) @list . delete v end | delete the item from the list |
1,724 | def []= ( index , v ) DataTypeValidator . validate :SimpleTypedList_insert , @allowed_types , v raise ArgumentError , "Item is protected and cannot be changed" if protected? index @list [ index ] = v v end | positional assignment . Adds the item at the index specified |
1,725 | def serialized_tag ( tagname , str , additional_attributes = { } , & block ) str << "<#{tagname} " serialized_attributes ( str , additional_attributes ) if block_given? str << '>' yield str << "</#{tagname}>" else str << '/>' end end | creates a XML tag with serialized attributes |
1,726 | def serialized_attributes ( str = '' , additional_attributes = { } ) attributes = declared_attributes . merge! additional_attributes attributes . each do | key , value | str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" " end str end | serializes the instance values of the defining object based on the list of serializable attributes . |
1,727 | def declared_attributes instance_values . select do | key , value | value != nil && self . class . xml_attributes . include? ( key . to_sym ) end end | A hash of instance variables that have been declared with seraialized_attributes and are not nil . This requires ruby 1 . 9 . 3 or higher |
1,728 | def serialized_element_attributes ( str = '' , additional_attributes = [ ] , & block ) attrs = self . class . xml_element_attributes + additional_attributes values = instance_values attrs . each do | attribute_name | value = values [ attribute_name . to_s ] next if value . nil? value = yield value if block_given? element_name = Axlsx . camel ( attribute_name , false ) str << "<#{element_name}>#{value}</#{element_name}>" end str end | serialized instance values at text nodes on a camelized element of the attribute name . You may pass in a block for evaluation against non nil values . We use an array for element attributes becuase misordering will break the xml and 1 . 8 . 7 does not support ordered hashes . |
1,729 | def to_xml_string ( str = '' ) validate_attributes_for_chart_type str << '<c:dLbls>' %w( d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines ) . each do | key | next unless instance_values . keys . include? ( key ) && instance_values [ key ] != nil str << "<c:#{Axlsx::camel(key, false)} val='#{instance_values[key]}' />" end str << '</c:dLbls>' end | serializes the data labels |
1,730 | def node_name path = self . class . to_s if i = path . rindex ( '::' ) path = path [ ( i + 2 ) .. - 1 ] end path [ 0 ] = path [ 0 ] . chr . downcase path end | The node name to use in serialization . As LineChart is used as the base class for Liine3DChart we need to be sure to serialize the chart based on the actual class type and not a fixed node name . |
1,731 | def to_xml_string ( str = '' ) str << '<?xml version="1.0" encoding="UTF-8"?>' str << ( '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">' ) instance_values . each do | key , value | node_name = Axlsx . camel ( key ) str << "<#{node_name}>#{value}</#{node_name}>" end str << '</Properties>' end | Serialize the app . xml document |
1,732 | def merge ( target ) start , stop = if target . is_a? ( String ) [ self . r , target ] elsif ( target . is_a? ( Cell ) ) Axlsx . sort_cells ( [ self , target ] ) . map { | c | c . r } end self . row . worksheet . merge_cells "#{start}:#{stop}" unless stop . nil? end | Merges all the cells in a range created between this cell and the cell or string name for a cell provided |
1,733 | def autowidth return if is_formula? || value . nil? if contains_rich_text? string_width ( '' , font_size ) + value . autowidth elsif styles . cellXfs [ style ] . alignment && styles . cellXfs [ style ] . alignment . wrap_text max_width = 0 value . to_s . split ( / \r \n / ) . each do | line | width = string_width ( line , font_size ) max_width = width if width > max_width end max_width else string_width ( value , font_size ) end end | Attempts to determine the correct width for this cell s content |
1,734 | def cell_type_from_value ( v ) if v . is_a? ( Date ) :date elsif v . is_a? ( Time ) :time elsif v . is_a? ( TrueClass ) || v . is_a? ( FalseClass ) :boolean elsif v . to_s =~ Axlsx :: NUMERIC_REGEX :integer elsif v . to_s =~ Axlsx :: FLOAT_REGEX :float elsif v . to_s =~ Axlsx :: ISO_8601_REGEX :iso_8601 elsif v . is_a? RichText :richtext else :string end end | Determines the cell type based on the cell value . |
1,735 | def cast_value ( v ) return v if v . is_a? ( RichText ) || v . nil? case type when :date self . style = STYLE_DATE if self . style == 0 v when :time self . style = STYLE_DATE if self . style == 0 if ! v . is_a? ( Time ) && v . respond_to? ( :to_time ) v . to_time else v end when :float v . to_f when :integer v . to_i when :boolean v ? 1 : 0 when :iso_8601 v else v . to_s end end | Cast the value into this cells data type . |
1,736 | def apply ( cell ) return false unless cell filter_items . each do | filter | return false if cell . value == filter . val end true end | Tells us if the row of the cell provided should be filterd as it does not meet any of the specified filter_items or date_group_items restrictions . |
1,737 | def to_xml_string ( str = '' ) str << "<filters #{serialized_attributes}>" filter_items . each { | filter | filter . to_xml_string ( str ) } date_group_items . each { | date_group_item | date_group_item . to_xml_string ( str ) } str << '</filters>' end | Serialize the object to xml |
1,738 | def date_group_items = ( options ) options . each do | date_group | raise ArgumentError , "date_group_items should be an array of hashes specifying the options for each date_group_item" unless date_group . is_a? ( Hash ) date_group_items << DateGroupItem . new ( date_group ) end end | Date group items are date group filter items where you specify the date_group and a value for that option as part of the auto_filter |
1,739 | def create_password_hash ( password ) encoded_password = encode_password ( password ) password_as_hex = [ encoded_password ] . pack ( "v" ) password_as_string = password_as_hex . unpack ( "H*" ) . first . upcase password_as_string [ 2 .. 3 ] + password_as_string [ 0 .. 1 ] end | Creates a password hash for a given password |
1,740 | def data = ( values = [ ] ) @tag_name = values . first . is_a? ( Cell ) ? :numCache : :numLit values . each do | value | value = value . is_formula? ? 0 : value . value if value . is_a? ( Cell ) @pt << NumVal . new ( :v => value ) end end | Creates the val objects for this data set . I am not overly confident this is going to play nicely with time and data types . |
1,741 | def name = ( v ) DataTypeValidator . validate :table_name , [ String ] , v if v . is_a? ( String ) @name = v end end | The name of the Table . |
1,742 | def to_xml_string ( str = '' ) str << '<cfRule ' serialized_attributes str str << '>' str << ( '<formula>' << [ * self . formula ] . join ( '</formula><formula>' ) << '</formula>' ) if @formula @color_scale . to_xml_string ( str ) if @color_scale && @type == :colorScale @data_bar . to_xml_string ( str ) if @data_bar && @type == :dataBar @icon_set . to_xml_string ( str ) if @icon_set && @type == :iconSet str << '</cfRule>' end | Serializes the conditional formatting rule |
1,743 | def ref = ( cell_reference ) cell_reference = cell_reference . r if cell_reference . is_a? ( Cell ) Axlsx :: validate_string cell_reference @ref = cell_reference end | Sets the cell location of this hyperlink in the worksheet |
1,744 | def to_xml_string ( str = '' ) str << '<?xml version="1.0" encoding="UTF-8"?>' str << ( '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" ' ) str << ( 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ' ) str << ( 'xmlns:xsi="' << CORE_NS_XSI << '">' ) str << ( '<dc:creator>' << self . creator << '</dc:creator>' ) str << ( '<dcterms:created xsi:type="dcterms:W3CDTF">' << ( created || Time . now ) . strftime ( '%Y-%m-%dT%H:%M:%S' ) << 'Z</dcterms:created>' ) str << '<cp:revision>0</cp:revision>' str << '</cp:coreProperties>' end | serializes the core . xml document |
1,745 | def add ( cells ) self << if cells . is_a? ( String ) cells elsif cells . is_a? ( Array ) Axlsx :: cell_range ( cells , false ) elsif cells . is_a? ( Row ) Axlsx :: cell_range ( cells , false ) end end | creates a new MergedCells object |
1,746 | def search_geocode_ban_fr_params ( query ) params = { q : query . sanitized_text } unless ( limit = query . options [ :limit ] ) . nil? || ! limit_param_is_valid? ( limit ) params [ :limit ] = limit . to_i end unless ( autocomplete = query . options [ :autocomplete ] ) . nil? || ! autocomplete_param_is_valid? ( autocomplete ) params [ :autocomplete ] = autocomplete . to_s end unless ( type = query . options [ :type ] ) . nil? || ! type_param_is_valid? ( type ) params [ :type ] = type . downcase end unless ( postcode = query . options [ :postcode ] ) . nil? || ! code_param_is_valid? ( postcode ) params [ :postcode ] = postcode . to_s end unless ( citycode = query . options [ :citycode ] ) . nil? || ! code_param_is_valid? ( citycode ) params [ :citycode ] = citycode . to_s end params end | SEARCH GEOCODING PARAMS |
1,747 | def reverse_geocode_ban_fr_params ( query ) lat_lon = query . coordinates params = { lat : lat_lon . first , lon : lat_lon . last } unless ( type = query . options [ :type ] ) . nil? || ! type_param_is_valid? ( type ) params [ :type ] = type . downcase end params end | REVERSE GEOCODING PARAMS |
1,748 | def classify_name ( filename ) filename . to_s . split ( "_" ) . map { | i | i [ 0 ... 1 ] . upcase + i [ 1 .. - 1 ] } . join end | Convert an underscore version of a name into a class version . |
1,749 | def configured_service! if s = configuration [ :service ] and services . keys . include? ( s ) return s else raise ( Geocoder :: ConfigurationError , "When using MaxMind you MUST specify a service name: " + "Geocoder.configure(:maxmind => {:service => ...}), " + "where '...' is one of: #{services.keys.inspect}" ) end end | Return the name of the configured service or raise an exception . |
1,750 | def [] ( url ) interpret case when store . respond_to? ( :[] ) store [ key_for ( url ) ] when store . respond_to? ( :get ) store . get key_for ( url ) when store . respond_to? ( :read ) store . read key_for ( url ) end end | Read from the Cache . |
1,751 | def []= ( url , value ) case when store . respond_to? ( :[]= ) store [ key_for ( url ) ] = value when store . respond_to? ( :set ) store . set key_for ( url ) , value when store . respond_to? ( :write ) store . write key_for ( url ) , value end end | Write to the Cache . |
1,752 | def full_error ( attribute_name , options = { } ) options = options . dup options [ :error_prefix ] ||= if object . class . respond_to? ( :human_attribute_name ) object . class . human_attribute_name ( attribute_name . to_s ) else attribute_name . to_s . humanize end error ( attribute_name , options ) end | Return the error but also considering its name . This is used when errors for a hidden field need to be shown . |
1,753 | def lookup_model_names @lookup_model_names ||= begin child_index = options [ :child_index ] names = object_name . to_s . scan ( / \d \w / ) . flatten names . delete ( child_index ) if child_index names . each { | name | name . gsub! ( '_attributes' , '' ) } names . freeze end end | Extract the model names from the object_name mess ignoring numeric and explicit child indexes . |
1,754 | def lookup_action @lookup_action ||= begin action = template . controller && template . controller . action_name return unless action action = action . to_s ACTIONS [ action ] || action end end | The action to be used in lookup . |
1,755 | def find_input ( attribute_name , options = { } , & block ) column = find_attribute_column ( attribute_name ) input_type = default_input_type ( attribute_name , column , options ) if block_given? SimpleForm :: Inputs :: BlockInput . new ( self , attribute_name , column , input_type , options , & block ) else find_mapping ( input_type ) . new ( self , attribute_name , column , input_type , options ) end end | Find an input based on the attribute name . |
1,756 | def valid_elf_file? ( path ) File . open ( path ) { | f | ELFTools :: ELFFile . new ( f ) . each_segments . first } true rescue ELFTools :: ELFError false end | Checks if the file of given path is a valid ELF file . |
1,757 | def build_id_of ( path ) File . open ( path ) { | f | ELFTools :: ELFFile . new ( f ) . build_id } end | Get the Build ID of target ELF . |
1,758 | def colorize ( str , sev : :normal_s ) return str unless color_enabled? cc = COLOR_CODE color = cc . key? ( sev ) ? cc [ sev ] : '' "#{color}#{str.sub(cc[:esc_m], color)}#{cc[:esc_m]}" end | Wrap string with color codes for pretty inspect . |
1,759 | def url_request ( url ) uri = URI . parse ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) http . use_ssl = true http . verify_mode = :: OpenSSL :: SSL :: VERIFY_NONE request = Net :: HTTP :: Get . new ( uri . request_uri ) response = http . request ( request ) raise ArgumentError , "Fail to get response of #{url}" unless %w[ 200 302 ] . include? ( response . code ) response . code == '302' ? response [ 'location' ] : response . body rescue NoMethodError , SocketError , ArgumentError => e OneGadget :: Logger . error ( e . message ) nil end | Get request . |
1,760 | def architecture ( file ) return :invalid unless File . exist? ( file ) f = File . open ( file ) str = ELFTools :: ELFFile . new ( f ) . machine { 'Advanced Micro Devices X86-64' => :amd64 , 'Intel 80386' => :i386 , 'ARM' => :arm , 'AArch64' => :aarch64 , 'MIPS R3000' => :mips } [ str ] || :unknown rescue ELFTools :: ELFError :invalid ensure f &. close end | Fetch the ELF archiecture of + file + . |
1,761 | def find_objdump ( arch ) [ which ( 'objdump' ) , which ( arch_specific_objdump ( arch ) ) ] . find { | bin | objdump_arch_supported? ( bin , arch ) } end | Find objdump that supports architecture + arch + . |
1,762 | def stack_register? ( reg ) %w[ esp ebp rsp rbp sp x29 ] . include? ( reg ) end | Checks if the register is a stack - related pointer . |
1,763 | def ask_update ( msg : '' ) name = 'one_gadget' cmd = OneGadget :: Helper . colorize ( "gem update #{name} && gem cleanup #{name}" ) OneGadget :: Logger . info ( msg + "\n" + "Update with: $ #{cmd}" + "\n" ) end | Show the message of ask user to update gem . |
1,764 | def work ( argv ) @options = DEFAULT_OPTIONS . dup parser . parse! ( argv ) return show ( "OneGadget Version #{OneGadget::VERSION}" ) if @options [ :version ] return info_build_id ( @options [ :info ] ) if @options [ :info ] libc_file = argv . pop build_id = @options [ :build_id ] level = @options [ :level ] return error ( 'Either FILE or BuildID can be passed' ) if libc_file && @options [ :build_id ] return show ( parser . help ) && false unless build_id || libc_file gadgets = if build_id OneGadget . gadgets ( build_id : build_id , details : true , level : level ) else OneGadget . gadgets ( file : libc_file , details : true , force_file : @options [ :force_file ] , level : level ) end handle_gadgets ( gadgets , libc_file ) end | Main method of CLI . |
1,765 | def handle_gadgets ( gadgets , libc_file ) return false if gadgets . empty? return handle_script ( gadgets , @options [ :script ] ) if @options [ :script ] return handle_near ( libc_file , gadgets , @options [ :near ] ) if @options [ :near ] display_gadgets ( gadgets , @options [ :raw ] ) end | Decides how to display fetched gadgets according to options . |
1,766 | def info_build_id ( id ) result = OneGadget :: Gadget . builds_info ( id ) return false if result . nil? OneGadget :: Logger . info ( "Information of #{id}:\n#{result.join("\n")}" ) true end | Displays libc information given BuildID . |
1,767 | def parser @parser ||= OptionParser . new do | opts | opts . banner = USAGE opts . on ( '-b' , '--build-id BuildID' , 'BuildID[sha1] of libc.' ) do | b | @options [ :build_id ] = b end opts . on ( '-f' , '--[no-]force-file' , 'Force search gadgets in file instead of build id first.' ) do | f | @options [ :force_file ] = f end opts . on ( '-l' , '--level OUTPUT_LEVEL' , Integer , 'The output level.' , 'OneGadget automatically selects gadgets with higher successful probability.' , 'Increase this level to ask OneGadget show more gadgets it found.' , 'Default: 0' ) do | l | @options [ :level ] = l end opts . on ( '-n' , '--near FUNCTIONS/FILE' , 'Order gadgets by their distance to the given functions' ' or to the GOT functions of the given file.' ) do | n | @options [ :near ] = n end opts . on ( '-r' , '--[no-]raw' , 'Output gadgets offset only, split with one space.' ) do | v | @options [ :raw ] = v end opts . on ( '-s' , '--script exploit-script' , 'Run exploit script with all possible gadgets.' , 'The script will be run as \'exploit-script $offset\'.' ) do | s | @options [ :script ] = s end opts . on ( '--info BuildID' , 'Show version information given BuildID.' ) do | b | @options [ :info ] = b end opts . on ( '--version' , 'Current gem version.' ) do | v | @options [ :version ] = v end end end | The option parser . |
1,768 | def display_gadgets ( gadgets , raw ) if raw show ( gadgets . map ( & :offset ) . join ( ' ' ) ) else show ( gadgets . map ( & :inspect ) . join ( "\n" ) ) end end | Writes gadgets to stdout . |
1,769 | def logger ( logger , level = :info , format = :apache ) default_options [ :logger ] = logger default_options [ :log_level ] = level default_options [ :log_format ] = format end | Turns on logging |
1,770 | def http_proxy ( addr = nil , port = nil , user = nil , pass = nil ) default_options [ :http_proxyaddr ] = addr default_options [ :http_proxyport ] = port default_options [ :http_proxyuser ] = user default_options [ :http_proxypass ] = pass end | Allows setting http proxy information to be used |
1,771 | def default_params ( h = { } ) raise ArgumentError , 'Default params must be an object which responds to #to_hash' unless h . respond_to? ( :to_hash ) default_options [ :default_params ] ||= { } default_options [ :default_params ] . merge! ( h ) end | Allows setting default parameters to be appended to each request . Great for api keys and such . |
1,772 | def headers ( h = nil ) if h raise ArgumentError , 'Headers must be an object which responds to #to_hash' unless h . respond_to? ( :to_hash ) default_options [ :headers ] ||= { } default_options [ :headers ] . merge! ( h . to_hash ) else default_options [ :headers ] || { } end end | Allows setting HTTP headers to be used for each request . |
1,773 | def connection_adapter ( custom_adapter = nil , options = nil ) if custom_adapter . nil? default_options [ :connection_adapter ] else default_options [ :connection_adapter ] = custom_adapter default_options [ :connection_adapter_options ] = options end end | Allows setting a custom connection_adapter for the http connections |
1,774 | def get ( path , options = { } , & block ) perform_request Net :: HTTP :: Get , path , options , & block end | Allows making a get request to a url . |
1,775 | def post ( path , options = { } , & block ) perform_request Net :: HTTP :: Post , path , options , & block end | Allows making a post request to a url . |
1,776 | def patch ( path , options = { } , & block ) perform_request Net :: HTTP :: Patch , path , options , & block end | Perform a PATCH request to a path |
1,777 | def put ( path , options = { } , & block ) perform_request Net :: HTTP :: Put , path , options , & block end | Perform a PUT request to a path |
1,778 | def delete ( path , options = { } , & block ) perform_request Net :: HTTP :: Delete , path , options , & block end | Perform a DELETE request to a path |
1,779 | def move ( path , options = { } , & block ) perform_request Net :: HTTP :: Move , path , options , & block end | Perform a MOVE request to a path |
1,780 | def copy ( path , options = { } , & block ) perform_request Net :: HTTP :: Copy , path , options , & block end | Perform a COPY request to a path |
1,781 | def head ( path , options = { } , & block ) ensure_method_maintained_across_redirects options perform_request Net :: HTTP :: Head , path , options , & block end | Perform a HEAD request to a path |
1,782 | def options ( path , options = { } , & block ) perform_request Net :: HTTP :: Options , path , options , & block end | Perform an OPTIONS request to a path |
1,783 | def mkcol ( path , options = { } , & block ) perform_request Net :: HTTP :: Mkcol , path , options , & block end | Perform a MKCOL request to a path |
1,784 | def flat_pmap ( enumerable ) return to_enum ( :flat_pmap , enumerable ) unless block_given? pmap ( enumerable , & Proc . new ) . flatten ( 1 ) end | Returns a new array with the concatenated results of running block once for every element in enumerable . If no block is given an enumerator is returned instead . |
1,785 | def pmap ( enumerable ) return to_enum ( :pmap , enumerable ) unless block_given? if enumerable . count == 1 enumerable . collect { | object | yield ( object ) } else enumerable . collect { | object | Thread . new { yield ( object ) } } . collect ( & :value ) end end | Returns a new array with the results of running block once for every element in enumerable . If no block is given an enumerator is returned instead . |
1,786 | def query_string_to_hash ( query_string ) query = CGI . parse ( URI . parse ( query_string ) . query ) Hash [ query . collect { | key , value | [ key . to_sym , value . first ] } ] end | Converts query string to a hash |
1,787 | def created_at time = @attrs [ :created_at ] return if time . nil? time = Time . parse ( time ) unless time . is_a? ( Time ) time . utc end | Time when the object was created on Twitter |
1,788 | def as_json ( _options = { } ) { resource_owner_id : resource_owner_id , scope : scopes , expires_in : expires_in_seconds , application : { uid : application . try ( :uid ) } , created_at : created_at . to_i , } end | JSON representation of the Access Token instance . |
1,789 | def secret_matches? ( input ) return false if input . nil? || secret . nil? return true if secret_strategy . secret_matches? ( input , secret ) if fallback_secret_strategy fallback_secret_strategy . secret_matches? ( input , secret ) else false end end | Check whether the given plain text secret matches our stored secret |
1,790 | def validate_reuse_access_token_value strategy = token_secret_strategy return if ! reuse_access_token || strategy . allows_restoring_secrets? :: Rails . logger . warn ( "You have configured both reuse_access_token " "AND strategy strategy '#{strategy}' that cannot restore tokens. " "This combination is unsupported. reuse_access_token will be disabled" ) @reuse_access_token = false end | Determine whether + reuse_access_token + and a non - restorable + token_secret_strategy + have both been activated . |
1,791 | def ssl_context openssl_verify_mode = settings [ :openssl_verify_mode ] if openssl_verify_mode . kind_of? ( String ) openssl_verify_mode = OpenSSL :: SSL . const_get ( "VERIFY_#{openssl_verify_mode.upcase}" ) end context = Net :: SMTP . default_ssl_context context . verify_mode = openssl_verify_mode if openssl_verify_mode context . ca_path = settings [ :ca_path ] if settings [ :ca_path ] context . ca_file = settings [ :ca_file ] if settings [ :ca_file ] context end | Allow SSL context to be configured via settings for Ruby > = 1 . 9 Just returns openssl verify mode for Ruby 1 . 8 . x |
1,792 | def [] ( index_value ) if index_value . is_a? ( Integer ) self . fetch ( index_value ) else self . select { | a | a . filename == index_value } . first end end | Returns the attachment by filename or at index . |
1,793 | def find ( options = nil , & block ) options = validate_options ( options ) start do | pop3 | mails = pop3 . mails pop3 . reset mails . sort! { | m1 , m2 | m2 . number <=> m1 . number } if options [ :what ] == :last mails = mails . first ( options [ :count ] ) if options [ :count ] . is_a? Integer if options [ :what ] . to_sym == :last && options [ :order ] . to_sym == :desc || options [ :what ] . to_sym == :first && options [ :order ] . to_sym == :asc || mails . reverse! end if block_given? mails . each do | mail | new_message = Mail . new ( mail . pop ) new_message . mark_for_delete = true if options [ :delete_after_find ] yield new_message mail . delete if options [ :delete_after_find ] && new_message . is_marked_for_delete? end else emails = [ ] mails . each do | mail | emails << Mail . new ( mail . pop ) mail . delete if options [ :delete_after_find ] end emails . size == 1 && options [ :count ] == 1 ? emails . first : emails end end end | Find emails in a POP3 mailbox . Without any options the 5 last received emails are returned . |
1,794 | def delete_all start do | pop3 | unless pop3 . mails . empty? pop3 . delete_all pop3 . finish end end end | Delete all emails from a POP3 server |
1,795 | def addresses list = element . addresses . map { | a | a . address } Mail :: AddressContainer . new ( self , list ) end | Returns the address string of all the addresses in the address list |
1,796 | def formatted list = element . addresses . map { | a | a . format } Mail :: AddressContainer . new ( self , list ) end | Returns the formatted string of all the addresses in the address list |
1,797 | def display_names list = element . addresses . map { | a | a . display_name } Mail :: AddressContainer . new ( self , list ) end | Returns the display name of all the addresses in the address list |
1,798 | def decoded_group_addresses groups . map { | k , v | v . map { | a | a . decoded } } . flatten end | Returns a list of decoded group addresses |
1,799 | def encoded_group_addresses groups . map { | k , v | v . map { | a | a . encoded } } . flatten end | Returns a list of encoded group addresses |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.