idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
16,700
def get_task_list ( userid = nil , since = nil , delegated = nil , task_types = nil , task_statuses = nil ) magic_parameters = { action : 'GetTaskList' , userid : userid , parameter1 : since , parameter2 : task_types , parameter3 : task_statuses , parameter4 : delegated } response = magic ( magic_parameters ) unless re...
delegated is an undocumented parameter
16,701
def perform_actions ( change_list , comment = nil ) xml_str = gen_change_xml ( change_list , comment ) @conn . request ( @conn . base_url + @host_url + "/rrset" , "POST" , xml_str ) end
For modifying multiple or single records within a single transaction
16,702
def process_options @options . verbose = false if @options . quiet @options . file = ( user_home + "/.route53" ) if @options . file . nil? if @options . setup setup end load_config @config [ 'access_key' ] = @options . access unless @options . access . nil? @config [ 'secret_key' ] = @options . secret unless @options ....
Performs post - parse processing on options
16,703
def process_arguments if @options . new_zone new_zone elsif @options . delete_zone delete_zone elsif @options . create_record create_record elsif @options . remove_record remove_record elsif @options . change_record change_record else list end end
Setup the arguments
16,704
def as_json_partial ( options = { } ) options ||= { } if options [ :properties ] && ! all_json_properties . member? ( options [ :properties ] ) fail ArgumentError . new ( "Unknown properties option: #{options[:properties]}" ) end keys , partial_json = self . class . materialize_json ( { properties : :short , is_top_lev...
Return a partial JSON without resolved references and all the keys .
16,705
def as_json_cached ( options = { } ) keys , json = as_json_partial ( options ) Mongoid :: CachedJson . materialize_json_references_with_read_multi ( keys , json ) end
Fetch the partial JSON and materialize all JSON references .
16,706
def expire_cached_json all_json_properties . each do | properties | [ true , false ] . each do | is_top_level_json | all_json_versions . each do | version | Mongoid :: CachedJson . config . cache . delete ( self . class . cached_json_key ( { properties : properties , is_top_level_json : is_top_level_json , version : ve...
Expire all JSON entries for this class .
16,707
def setup @log . debug "using journalfile: " + self . settings [ 'journalfile' ] journalfile = self . settings [ 'journalfile' ] store = YAML :: Store . new ( journalfile , true ) store . ultra_safe = true return store end
Create a new journal file or load an existing one if it already exists .
16,708
def validate_uuid ( uuid ) unless uuid . is_a? ( String ) @log . error "UUID is not a string" return false end unless ! ! / \S \S \S \S \S / . match ( uuid . to_s ) @log . error "UUID is not a valid V4 UUID" return false end return true end
Verify that a string is a V4 UUID
16,709
def << ( commit ) return self if key? commit . id if @additions . nil? && empty? && commit . line_stats? @additions = commit . additions @deletions = commit . deletions elsif ! @additions . nil? @additions += commit . additions @deletions += commit . deletions end super end
Creates a new collection with the given commits
16,710
def activity activity = { } return activity if empty? commit_count = values . size active_days = { } each do | commit | date = commit . committed_date . utc day = Time . utc ( date . year , date . month , date . day ) . send :to_date if active_days . key? day active_days [ day ] += 1 else active_days [ day ] = 1 end en...
Calculate some predefined activity statistics for the commits in this collection
16,711
def authors ( commit_id = nil ) authors = ActorCollection . new if commit_id . nil? each { | commit | authors << commit . author } elsif key? commit_id authors << self [ commit_id ] . author end authors end
Returns the authors of all or a specific commit in this collection
16,712
def before ( date ) date = Time . parse date if date . is_a? String commits = CommitCollection . new each do | commit | commits << commit if commit . committed_date < date end commits end
Returns the commits in this collection that have been committed before the given time
16,713
def by ( * author_ids ) author_ids = author_ids . flatten . map do | author_id | author_id . is_a? ( Actor ) ? author_id . id : author_id end commits = CommitCollection . new each do | commit | commits << commit if author_ids . include? commit . author . id end commits end
Returns the list of commits that have been authored by the given authors
16,714
def changing ( * files ) support! :file_stats commits = CommitCollection . new each do | commit | commit_files = commit . added_files + commit . deleted_files + commit . modified_files commits << commit unless ( commit_files & files ) . empty? end commits end
Returns the commits in this collection that change any of the given files
16,715
def committers ( commit_id = nil ) committers = ActorCollection . new if commit_id . nil? each { | commit | committers << commit . committer } elsif key? commit_id committers << self [ commit_id ] . committer end committers end
Returns the committers of all or a specific commit in this collection
16,716
def line_history support! :line_stats history = { :additions => [ ] , :deletions => [ ] } values . reverse . each do | commit | history [ :additions ] << commit . additions history [ :deletions ] << - commit . deletions end history end
This evaluates the changed lines in each commit of this collection
16,717
def most_significant ( count = 10 ) support! :line_stats commits = CommitCollection . new sort_by { | commit | - commit . modifications } . each do | commit | commits << commit break if commits . size == count end commits end
Returns the given number of commits with most line changes on the repository
16,718
def with_impact ( line_count ) support! :line_stats commits = CommitCollection . new each do | commit | commits << commit if commit . modifications >= line_count end commits end
Returns the commits in this collection that change at least the given number of lines
16,719
def load_line_stats @additions = 0 @deletions = 0 return if empty? line_stats = nil if @range . nil? ids = values . reject { | c | c . line_stats? } . map { | c | c . id } line_stats = first . repo . load_line_stats ids unless ids . empty? else line_stats = first . repo . load_line_stats @range end unless line_stats . ...
Loads the line stats for the commits in this collection
16,720
def render ( * args ) begin features = self . class . send :class_variable_get , :@@required_features super if features . all? { | feature | repository . supports? feature } rescue Metior :: UnsupportedError end end
This checks if all required VCS features of this view are available for this report s repository
16,721
def search engine = BentoSearch . get_engine ( params [ :engine_id ] ) @engine = engine unless engine . configuration . allow_routable_results == true raise AccessDenied . new ( "engine needs to be registered with :allow_routable_results => true" ) end @results = engine . search safe_search_args ( engine , params ) @pa...
returns partial HTML results suitable for AJAX to insert into DOM . arguments for engine . search are taken from URI request params whitelisted
16,722
def current_branch branch = @grit_repo . head return branch . name unless branch . nil? commit = @grit_repo . commit ( 'HEAD' ) commit . id unless commit . nil? end
Creates a new Git repository based on the given path
16,723
def load_line_stats ( ids ) if ids . is_a? Range if ids . first == '' range = ids . last else range = '%s..%s' % [ ids . first , ids . last ] end options = { :numstat => true , :timeout => false } output = @grit_repo . git . native :log , options , range commit_stats = :: Grit :: CommitStats . list_from_string @grit_re...
Loads the line stats for the commits given by a set of commit IDs
16,724
def load_branches Hash [ @grit_repo . branches . map { | b | [ b . name , b . commit . id ] } ] end
Loads all branches and the corresponding commit IDs of this repository
16,725
def load_commits ( range ) if range . first == '' base_commit = nil range = range . last else base_commit = @grit_repo . commit ( range . first ) range = '%s..%s' % [ range . first , range . last ] end options = { :pretty => 'raw' , :timeout => false } output = @grit_repo . git . native :rev_list , options , range comm...
This method uses Grit to load all commits from the given commit range
16,726
def load_name_and_description description = @grit_repo . description if description . start_with? 'Unnamed repository' @name = '' @description = '' else description = description . lines . to_a @name = description . shift . strip @description = description . join ( "\n" ) . strip end end
Loads both the name and description of the project contained in the repository from the description file in GIT_DIR . The first line of that file is used as the project s name the remaining text is used as a description of the project .
16,727
def load_tags Hash [ @grit_repo . tags . map { | b | [ b . name , b . commit . id ] } ] end
Loads all tags and the corresponding commit IDs of this repository
16,728
def area ( name , content = nil , & block ) content = capture ( & block ) if block_given? append name , content render_area name end
Defines an area of content in your layout that can be modified or replaced by child layouts that extend it . You can optionally add content to an area using either a String or a block .
16,729
def render_area ( name ) [ ] . tap do | output | @_area_for . fetch ( name , [ ] ) . reverse_each do | method_name , content | output . public_send method_name , content end end . join . html_safe end
Take the instructions we ve gathered for the area and replay them one after the other on an empty array . These instructions will push unshift or replace items into our output array which we then join and mark as html_safe .
16,730
def hash_to_item ( item_response ) v_info = item_response [ "volumeInfo" ] || { } item = ResultItem . new item . unique_id = item_response [ "id" ] item . title = format_title ( v_info ) item . publisher = v_info [ "publisher" ] item . link = v_info [ "previewLink" ] || v_info [ "canonicalVolumeLink" ] item . abstract ...
take a hash from Google json response representing a single item return a ResultItem obj . Used internally .
16,731
def args_to_search_url ( arguments ) query = if arguments [ :query ] . kind_of? Hash arguments [ :query ] . collect { | field , query_value | fielded_query ( query_value , field ) } . join ( " " ) elsif arguments [ :search_field ] fielded_query ( arguments [ :query ] , arguments [ :search_field ] ) else arguments [ :qu...
Our own implementation code
16,732
def render_authors_list parts = [ ] first_three = self . authors . slice ( 0 , 3 ) first_three . each_with_index do | author , index | parts << _h . content_tag ( "span" , :class => "author" ) do self . author_display ( author ) end if ( index + 1 ) < first_three . length parts << "; " end end if self . authors . lengt...
display multiple authors with HTML markup returns html_safe string . experimentally trying this as a decorator helper method rather than a view partial not sure which is best .
16,733
def render_citation_details result_elements = [ ] result_elements . push ( "#{I18n.t('bento_search.volume')}\u00A0#{volume}" ) if volume . present? result_elements . push ( "#{I18n.t('bento_search.issue')}\u00A0#{issue}" ) if issue . present? if ( ! start_page . blank? ) && ( ! end_page . blank? ) result_elements . pus...
volume issue and page numbers . With prefixed labels from I18n . That s it .
16,734
def render_summary summary = nil max_chars = ( self . display_configuration . try { | h | h [ "summary_max_chars" ] } ) || 280 if self . snippets . length > 0 && ! ( self . display_configuration . try { | h | h [ "prefer_abstract_as_summary" ] } && self . abstract ) summary = self . snippets . first self . snippets . s...
A summary . If config . for_dispaly . prefer_snippets_as_summary is set to true then prefers that otherwise abstract .
16,735
def configfile @log . debug "Finding config file" @config_file_paths . each { | file | @log . debug "Checking if file '#{file}' exists" if File . file? ( file ) @log . debug "Reading config file from: " + file config_file = File . read ( file ) parsed_config_file = YAML . load ( config_file ) @log . debug "configuratio...
Locate the configuration file parse it from INI - format and return the results as a hash . Returns an empty hash if no config file is found .
16,736
def validate_config_file ( configfile = location ) @log . debug "validating config file" unless File . file? ( configfile ) @log . error "configuration file not found at: #{configfile}" raise Autosign :: Exceptions :: NotFound end if File . world_readable? ( configfile ) or File . world_writable? ( configfile ) @log . ...
Validate configuration file Raises an exception if the config file cannot be validated
16,737
def format_author_name ( author ) if author . last . present? && author . first . present? str = "#{author.last}, #{author.first}" if author . middle . present? middle = author . middle middle += "." if middle . length == 1 str += " #{middle}" end return str elsif author . display . present? return author . display els...
RIS wants Last First M . we ll do what we can .
16,738
def send_email ( email_id , to , options = { } ) if email_id . nil? raise SendWithUs :: ApiNilEmailId , 'email_id cannot be nil' end payload = { email_id : email_id , recipient : to } if options [ :data ] && options [ :data ] . any? payload [ :email_data ] = options [ :data ] end if options [ :from ] && options [ :from...
Sends the specified email with any optional arguments
16,739
def enable_resource_duplication_via_form action_item ( * compatible_action_item_parameters ) do if controller . action_methods . include? ( 'new' ) && authorized? ( ActiveAdmin :: Auth :: CREATE , active_admin_config . resource_class ) link_to ( I18n . t ( :duplicate_model , default : "Duplicate %{model}" , scope : [ :...
Enables resource duplication via new form .
16,740
def enable_resource_duplication_via_save action_item ( * compatible_action_item_parameters ) do if controller . action_methods . include? ( 'new' ) && authorized? ( ActiveAdmin :: Auth :: CREATE , active_admin_config . resource_class ) link_to ( I18n . t ( :duplicate_model , default : "Duplicate %{model}" , scope : [ :...
Enables resource duplication via save .
16,741
def enable_resource_duplication_via_custom_method ( method ) action_item ( * compatible_action_item_parameters ) do if controller . action_methods . include? ( 'new' ) && authorized? ( ActiveAdmin :: Auth :: CREATE , active_admin_config . resource_class ) link_to ( I18n . t ( :duplicate_model , default : "Duplicate %{m...
Enables resource duplication via a custom method
16,742
def check_errors ( raw : false ) return if @err_array . empty? command = '' rest = '' @semaphore . synchronize do command = @err_array . first rest = @err_array [ 1 .. - 1 ] . join ( '; ' ) @err_array . clear end message = if raw "#{command};#{rest}}" else "Error in previous command (\"#{command}\"): \"#{rest}\"" end f...
Check if there were errors in previous commands . Throws GnuplotError in case of any errors .
16,743
def handle_stderr ( stream ) @err_array = [ ] @semaphore = Mutex . new Thread . new do until ( line = stream . gets ) . nil? line . strip! @semaphore . synchronize { @err_array << line if line . size > 3 } end end end
Start new thread that will read stderr given as stream and add errors into
16,744
def option ( key , * value ) if value . empty? value = options [ key ] value = value [ 0 ] if value && value . size == 1 value else options ( key => value ) end end
Return current option value if no value given . Create new object with given option set if value given .
16,745
def put ( needle , ref , weight = 0 ) check_valid_needle ( needle ) check_valid_ref ( ref ) raise ( ArgumentError , "WEIGHT value must be in #{WEIGHT_RANGE}" ) unless WEIGHT_RANGE . include? ( weight ) cmd = [ "PUT" , @db_name , needle , ref , weight ] send_cmd_and_get_results ( cmd ) return end
Index a given record .
16,746
def lock_content ( content ) content = content . to_smash content . merge! ( :sfn_lock_enabled => true ) safe = SfnParameters :: Safe . build ( config . fetch ( :sfn_parameters , :safe , Smash . new ) ) safe . lock ( dump_json ( content ) ) end
Lock the given content
16,747
def unlock_content ( content ) content = content . to_smash if content [ :sfn_parameters_lock ] safe = SfnParameters :: Safe . build ( config . fetch ( :sfn_parameters , :safe , Smash . new ) ) load_json ( safe . unlock ( content ) ) . to_smash . merge ( :sfn_lock_enabled => true ) else content end end
Unlock given content
16,748
def balance xml = Clockwork :: XML :: Balance . build ( self ) response = Clockwork :: HTTP . post ( Clockwork :: API :: BALANCE_URL , xml , @use_ssl ) balance = Clockwork :: XML :: Balance . parse ( response ) end
Check the remaining credit for this account .
16,749
def mix_options ( options ) all_options = @options . merge ( options ) specific_options , plot_options = all_options . partition { | key , _value | specific_option? ( key ) } yield ( plot_options , default_options . merge ( specific_options ) ) end
Takes all options and splits them into specific and others . Requires a block where this two classes should be mixed .
16,750
def generate ( params = { } ) raise "You need to specify at least 1 team" if @teams . nil? || @teams . empty? raise "You need to specify at least 1 rule" if @rules . nil? || @rules . empty? arrange_flights init_stats @gamedays = [ ] ; @rounds = [ ] @flights . each_with_index do | teams , flight_id | current_cycle = cur...
This will generate the schedule based on the various parameters
16,751
def to_s res = "" res << "#{self.gamedays.size.to_s} gamedays\n" self . gamedays . each do | gd | res << gd . date . strftime ( "%Y-%m-%d" ) + "\n" res << "==========\n" gd . games . sort { | g1 , g2 | g1 . gt == g2 . gt ? g1 . ps <=> g2 . ps : g1 . gt <=> g2 . gt } . each do | g | res << "#{g.ta.to_s} VS #{g.tb.to_s} ...
human readable schedule
16,752
def next_game_date ( dt , wday ) dt += 1 until wday == dt . wday && ! self . exclude_dates . include? ( dt ) dt end
get the next gameday
16,753
def face_to_face ( team_a , team_b ) res = [ ] self . gamedays . each do | gd | res << gd . games . select { | g | ( g . team_a == team_a && g . team_b == team_b ) || ( g . team_a == team_b && g . team_b == team_a ) } end res . flatten end
return matchups between two teams
16,754
def gt = ( gt ) @gt = Array ( gt ) . empty? ? [ "7:00 PM" ] : Array ( gt ) @gt . collect! do | gt | begin DateTime . parse ( gt ) rescue raise "game times must be valid time representations in the string form (e.g. 3:00 PM, 11:00 AM, 18:20, etc)" end end end
Array of game times where games are played . Must be valid DateTime objects in the string form
16,755
def options_hash_to_string ( options ) result = '' options . sort_by { | key , _ | OPTION_ORDER . find_index ( key ) || - 1 } . each do | key , value | if value result += "set #{OptionHandling.option_to_string(key, value)}\n" else result += "unset #{key}\n" end end result end
Convert given options to gnuplot format .
16,756
def forwardDeg! ( point ) point . x *= Proj4 :: DEG_TO_RAD point . y *= Proj4 :: DEG_TO_RAD forward! ( point ) end
Convenience function for calculating a forward projection with degrees instead of radians . This version works in - place i . e . the point objects content is overwritten .
16,757
def inverseDeg! ( point ) inverse! ( point ) point . x *= Proj4 :: RAD_TO_DEG point . y *= Proj4 :: RAD_TO_DEG point end
Convenience function for calculating an inverse projection with the result in degrees instead of radians . This version works in - place i . e . the point objects content is overwritten .
16,758
def transform_all! ( otherProjection , collection ) collection . each do | point | transform! ( otherProjection , point ) end collection end
Transforms all points in a collection in place from one projection to another . The + collection + object must implement the + each + method for this to work .
16,759
def call ( env ) @app . call ( env ) . on_complete do | response_env | datetime = sunset_header ( response_env . response_headers ) report_deprecated_usage ( env , datetime ) unless datetime . nil? end end
Initialize the middleware
16,760
def update ( data = nil , ** options ) if data && @type == :datablock new_datablock = @data . update ( data ) if new_datablock == @data update_options ( options ) else self . class . new ( new_datablock , options ) end else update_options ( options ) end end
Create new dataset with updated data and merged options .
16,761
def options_to_string options . sort_by { | key , _ | OPTION_ORDER . find_index ( key . to_s ) || 999 } . map { | key , value | OptionHandling . option_to_string ( key , value ) } . join ( ' ' ) end
Create string from own options
16,762
def init_string ( data , options ) @type , @data = File . exist? ( data ) ? [ :datafile , "'#{data}'" ] : [ :math_function , data . clone ] @options = Hamster . hash ( options ) end
Initialize Dataset from given String
16,763
def get_daru_columns ( data , cnt ) new_opt = ( 2 .. cnt ) . to_a . join ( ':' ) if data . index [ 0 ] . is_a? ( DateTime ) || data . index [ 0 ] . is_a? ( Numeric ) "1:#{new_opt}" else "#{new_opt}:xtic(1)" end end
Create new value for using option based on column count
16,764
def provide_with_datetime_format ( data , using ) return unless defined? ( Daru ) return unless data . is_a? ( Daru :: DataFrame ) || data . is_a? ( Daru :: Vector ) return unless data . index . first . is_a? ( DateTime ) return if using [ 0 .. 1 ] != '1:' @options = Hamster :: Hash . new ( xdata : 'time' , timefmt : '...
Checks several conditions and set options needed to handle DateTime indexes properly .
16,765
def dataset_from_any ( source ) ds = case source when ( defined? ( Daru ) ? Daru :: Vector : nil ) Dataset . new ( source ) when Dataset source . clone else Dataset . new ( * source ) end data = source . is_a? ( Array ) ? source [ 0 ] : source provide_with_datetime_format ( data , ds . using ) ds end
Check if given args is a dataset and returns it . Creates new dataset from given args otherwise .
16,766
def send_headers raise "sent headers already" if @sent_headers @sent_headers = true fixup_headers ary = [ ] ary << "HTTP/1.1 #{@status || 200} #{@status_string || '...'}\r\n" ary += generate_header_lines ( @headers ) ary << "\r\n" send_data ary . join end
Send the headers out in alpha - sorted order . This will degrade performance to some degree and is intended only to simplify the construction of unit tests .
16,767
def headers new_h = { } headers_orig . each_pair do | k , v | if v . is_a? ( Array ) && v . size == 1 v = v [ 0 ] end new_h [ k . downcase ] = v end new_h end
Provide a headers_orig method in your wrapper to allow this to work
16,768
def plot ( path = nil , ** options ) options [ :output ] ||= path plot_options = mix_options ( options ) do | plot_opts , anim_opts | plot_opts . merge ( term : [ 'gif' , anim_opts ] ) end . to_h need_output = plot_options [ :output ] . nil? plot_options [ :output ] = Dir :: Tmpname . make_tmpname ( 'anim' , 0 ) if nee...
This method creates a gif animation where frames are plots already contained by Animation object .
16,769
def specific_keys %w( animate size background transparent enhanced rounded butt linewidth dashlength tiny small medium large giant font fontscale crop ) end
This plot have some specific options which should be handled different way than others . Here are keys of this options .
16,770
def fit ( data , function : 'a2*x*x+a1*x+a0' , initials : { a2 : 1 , a1 : 1 , a0 : 1 } , term_options : { } , ** options ) dataset = data . is_a? ( Dataset ) ? Dataset . new ( data . data ) : Dataset . new ( data ) opts_str = OptionHandling . ruby_class_to_gnuplot ( options ) output = gnuplot_fit ( function , dataset ,...
Fit given data with function .
16,771
def wait_for_output ( term , variables ) start = Time . now output = '' until output_ready? ( output , variables ) begin term . check_errors ( raw : true ) rescue GnuplotRB :: GnuplotError => e output += e . message end if Time . now - start > Settings . max_fit_delay fail GnuplotError , "Seems like there is an error i...
It takes some time to produce output so here we need to wait for it .
16,772
def gnuplot_fit ( function , data , options , initials , term_options ) variables = initials . keys term = Terminal . new term . set ( term_options ) initials . each { | var_name , value | term . stream_puts "#{var_name} = #{value}" } command = "fit #{function} #{data.to_s(term, without_options: true)} " "#{options} vi...
Make fit command and send it to gnuplot
16,773
def swapper_map ( index ) array = ( 0 .. 9 ) . to_a 10 . times . collect . with_index do | i | array . rotate! ( index + i ^ spin ) . pop end end
We want a unique map for each place in the original number
16,774
def unscatter scattered_array = @working_array sum_of_digits = scattered_array . inject ( :+ ) . to_i @working_array = [ ] @working_array . tap do | unscatter | 10 . times do unscatter . push scattered_array . pop unscatter . rotate! ( sum_of_digits ^ spin ) * - 1 end end end
Reverse the scatter
16,775
def to_camelback_keys ( value = self ) case value when Array value . map { | v | to_camelback_keys ( v ) } when Hash Hash [ value . map { | k , v | [ camelize_key ( k , false ) , to_camelback_keys ( v ) ] } ] else value end end
Recursively converts Rubyish snake_case hash keys to camelBack JSON - style hash keys suitable for use with a JSON API .
16,776
def to_camel_keys ( value = self ) case value when Array value . map { | v | to_camel_keys ( v ) } when Hash Hash [ value . map { | k , v | [ camelize_key ( k ) , to_camel_keys ( v ) ] } ] else value end end
Recursively converts Rubyish snake_case hash keys to CamelCase JSON - style hash keys suitable for use with a JSON API .
16,777
def next_state ( event_name ) transition = transitions . select { | t | t . is_transition_for? ( event_name , @subject . send ( state_method ) ) } . first transition ? transition . to : nil end
Returns the next state for the subject for event_name
16,778
def error_state ( event_name , error ) transition = transitions . select { | t | t . is_error_transition_for? ( event_name , error ) } . first transition ? transition . to : nil end
Returns the error state for the subject for event_name and error
16,779
def transition ( event_name ) clear_raised_error if to = next_state ( event_name ) begin result = yield rescue => e error_state = error_state ( event_name , e ) || state_machine_definition . default_error_state if error_state @raised_error = e @subject . send ( "#{state_method}=" , error_state ) return result else rais...
Transitions to the next state if next_state exists . When an error occurs it uses the error to determine next state . If no next state can be determined it transitions to the default error state if defined otherwise the error is re - raised . Calls illegal_event_callback event_name if no next_state is found
16,780
def bind_inum ( column , enum_class , options = { } ) options = { prefix : column } . merge ( options ) options [ :prefix ] = options [ :prefix ] ? "#{options[:prefix]}_" : '' self . class_eval do define_method ( column ) do enum_class . parse ( read_attribute ( column ) ) end define_method ( "#{column}=" ) do | value ...
Define compare method in class .
16,781
def receive ( type = nil ) check_connected data = @socket . read 14 magic , len , recv_type = unpack_header ( data ) raise WrongMagicString . new ( magic ) unless MAGIC_STRING . eql? magic type && ( raise WrongType . new ( type , recv_type ) unless type == recv_type ) @socket . read ( len ) end
Receives message from i3 - ipc server socket .
16,782
def is_error_transition_for? ( event_name , error ) is_same_event? ( event_name ) && from . is_a? ( Class ) && error . is_a? ( from ) end
returns true if it s a error transition for event_name and error
16,783
def normalize ( input ) input_length = input . jlength in_ptr = UCharPointer . from_string ( input ) needed_length = capacity = 0 out_ptr = UCharPointer . new ( needed_length ) retried = false begin Lib . check_error do | error | needed_length = Lib . unorm2_normalize ( @instance , in_ptr , input_length , out_ptr , cap...
support for newer ICU normalization API
16,784
def validates_formatting_of ( attribute , options = { } ) validation = Method . find ( attribute , options ) options . reverse_merge! ( :with => validation . regex , :message => validation . message ) self . validates_format_of ( attribute , options ) end
Using validates_formatting_of is as simple as using Rails built - in validation methods in models .
16,785
def call worker , msg , queue @statsd . batch do | b | begin worker_name = worker . class . name . gsub ( '::' , '.' ) b . time prefix ( worker_name , 'processing_time' ) do yield end b . increment prefix ( worker_name , 'success' ) rescue => e b . increment prefix ( worker_name , 'failure' ) raise e ensure if @options...
Initializes the middleware with options .
16,786
def control_command_select_string ( title , text , control , string ) command 'ControlCommand' , [ title , text , control , 'SelectString' , string ] end
Sets selection according to string in a ListBox or ComboBox
16,787
def control_set_text ( title , text , control , value ) command_validate 'ControlSetText' , [ title , text , control , value ] end
Sets text of a control . Sends a string of characters to a control .
16,788
def control_click ( title , text , control , button , clicks , x , y ) command_validate ( 'ControlClick' , [ title , text , control , button , clicks , x , y ] ) end
Sends a mouse click command to a given control .
16,789
def control_command_set_current_selection ( title , text , control , occurrance ) command ( 'ControlCommand' , [ title , text , control , 'SetCurrentSelection' , occurrance ] ) end
Sets selection to occurrence ref in a ListBox or ComboBox .
16,790
def process_ie_conditional_comments ( out ) out . gsub / \[ \] \] \s \S \[ \] \] \s / do m = $1 comment = $2 comment_compressed = Html . new . press ( comment ) m . gsub! ( comment , comment_compressed ) reserve m end end
IE conditional comments
16,791
def process_pres ( out ) out . gsub / \b \s \S \/ \s /i do pre = $2 m = $1 pre_compressed = pre . lines . map { | l | l . gsub ( / \s / , '' ) } . join ( "\n" ) pre_compressed = HtmlPress . entities_compressor pre_compressed m . gsub! ( pre , pre_compressed ) reserve m end end
replace PREs with placeholders
16,792
def process_block_elements ( out ) re = '\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' + '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' + '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' + '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h|r|foot|itle)' + '|ul)\\b[^>]*>)' re =...
remove whitespaces outside of block elements
16,793
def address_to_oa_address ( btc_address ) begin btc_hex = decode_base58 ( btc_address ) btc_hex = '0' + btc_hex if btc_hex . size == 47 address = btc_hex [ 0 .. - 9 ] named_addr = OA_NAMESPACE . to_s ( 16 ) + address oa_checksum = checksum ( named_addr ) encode_base58 ( named_addr + oa_checksum ) rescue ArgumentError n...
convert bitcoin address to open assets address
16,794
def oa_address_to_address ( oa_address ) decode_address = decode_base58 ( oa_address ) btc_addr = decode_address [ 2 .. - 9 ] btc_checksum = checksum ( btc_addr ) encode_base58 ( btc_addr + btc_checksum ) end
convert open assets address to bitcoin address
16,795
def valid_asset_id? ( asset_id ) return false if asset_id . nil? || asset_id . length != 34 decoded = decode_base58 ( asset_id ) return false if decoded [ 0 , 2 ] . to_i ( 16 ) != oa_version_byte p2pkh_script_hash = decoded [ 2 .. - 9 ] address = hash160_to_address ( p2pkh_script_hash ) valid_address? ( address ) end
validate asset ID
16,796
def read_var_integer ( data , offset = 0 ) raise ArgumentError , "data is nil." unless data packed = [ data ] . pack ( 'H*' ) return [ nil , 0 ] if packed . bytesize < 1 + offset bytes = packed . bytes [ offset .. ( offset + 9 ) ] first_byte = bytes [ 0 ] if first_byte < 0xfd [ first_byte , offset + 1 ] elsif first_byt...
read variable integer
16,797
def read_leb128 ( data , offset = 0 ) bytes = [ data ] . pack ( 'H*' ) . bytes result = 0 shift = 0 while true return [ nil , offset ] if bytes . length < 1 + offset byte = bytes [ offset .. ( offset + 1 ) ] [ 0 ] result |= ( byte & 0x7f ) << shift break if byte & 0x80 == 0 shift += 7 offset += 1 end [ result , offset ...
read leb128 value
16,798
def to_array self . instance_variables . map do | var | if var == :@hosts self . instance_variable_get ( var ) . map { | host | host . to_array } else self . instance_variable_get ( var ) end end end
Create a new scan report passing in every attribute . The best way to do this is with the ScanResultProcessor module .
16,799
def get_updates ( offset : nil , limit : nil , timeout : nil ) result = call ( :getUpdates , offset : offset , limit : limit , timeout : timeout ) result . map { | update_hash | Update . new ( update_hash ) } end
Use this method to receive incoming updates using long polling . An Array of Update objects is returned .