idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
13,300 | def load_dependencies_to_classpath jars = dependencies_classpath . split ( File :: PATH_SEPARATOR ) Naether :: Java . load_jars ( jars ) jars end | Load dependencies to Classpath |
13,301 | def to_local_paths ( notations ) if Naether . platform == 'java' Naether :: Java . convert_to_ruby_array ( Naether :: Java . exec_static_method ( 'com.tobedevoured.naether.util.Notation' , 'getLocalPaths' , [ local_repo_path , notations ] , [ 'java.lang.String' , 'java.util.List' ] ) ) else paths = Naether :: Java . ex... | Convert notations to local paths of artifacts |
13,302 | def deploy_artifact ( notation , file_path , url , opts = { } ) artifact = Naether :: Java . create ( "com.tobedevoured.naether.deploy.DeployArtifact" ) artifact . setRemoteRepo ( url ) artifact . setNotation ( notation ) artifact . setFilePath ( file_path ) if opts [ :pom_path ] artifact . setPomPath ( opts [ :pom_pat... | Deploy artifact to remote repo url |
13,303 | def read_int_sval ( s ) s = s . downcase if s . match ( / / ) return s . to_i ( 16 ) end if s . match ( / / ) return s . to_i ( 2 ) end if s . match ( / / ) return s . to_i ( 8 ) end s . to_i ( 10 ) end | Max of long |
13,304 | def synced_attributes_as_hash ( attributes ) return attributes if attributes . is_a? ( Hash ) Hash [ Array . wrap ( attributes ) . map { | name | [ name , name ] } ] end | On a Hash returns the same Hash On an Array returns a Hash with identical corresponding keys and values Used for mapping local - remote attributes |
13,305 | def read_from_string ( buf ) @lexer . stream_stash ( [ FileIO . new ( StringIO . new ( buf ) , "-" ) ] ) parse . each do | toplevel_ast | @gen . emit_toplevel ( toplevel_ast ) end @lexer . stream_unstash end | Reads from a string as if the string is a content of input file . Convenient for evaluating small string snippet contaiing preprocessor macros . |
13,306 | def run begin unless self . symbology . nil? unless self . options [ :ascii ] Barcodes :: Renderer :: Pdf . new ( Barcodes . create ( self . symbology , self . options ) ) . render ( self . target ) else Barcodes :: Renderer :: Ascii . new ( Barcodes . create ( self . symbology , self . options ) ) . render ( self . ta... | Creates a new instance with given command line arguments and options Runs the command and renders barcode |
13,307 | def _init_parser @parser ||= OptionParser . new do | opts | opts . banner = "Usage: barcodes [OPTIONS] symbology target" opts . separator "" opts . on ( '-D' , '--data [DATA]' , 'The barcode data to encode (0123456789)' ) { | v | @options [ :data ] = v ||= '0123456789' } opts . on ( '-s' , '--start_character [START_CHA... | Initializes the option parser instance |
13,308 | def _parse! begin self . parser . parse! ( self . argv ) rescue puts self . parser . help exit 1 end @symbology = self . argv . shift @target = self . argv . shift end | Parses the command line arguments |
13,309 | def list print_template = lambda { | path | puts " #{File.basename(path)}" } say "Builtin templates:" , :green Config . builtin_templates ( & print_template ) say "Installed templates:" , :green Config . installed_templates ( & print_template ) end | Lists builtin and installed templates . |
13,310 | def remove ( name ) name = File . basename ( name ) path = File . join ( Config :: TEMPLATES_DIR , name ) unless File . exists? ( path ) say "Unknown template: #{name}" , :red exit - 1 end FileUtils . rm_rf ( path ) end | Removes a previously installed template . |
13,311 | def generate self . destination_root = path enable_templates! initialize_variables! extend Template :: Helpers :: MARKUP . fetch ( @markup ) unless options . quiet? say "Generating #{self.destination_root}" , :green end generate_directories! generate_files! initialize_scm! end | Generates a new project . |
13,312 | def enable_template ( name ) name = name . to_sym return false if @enabled_templates . include? ( name ) unless ( template_dir = Template . templates [ name ] ) say "Unknown template #{name}" , :red exit - 1 end new_template = Template :: Directory . new ( template_dir ) @enabled_templates << name new_template . enable... | Enables a template adding it to the generator . |
13,313 | def disable_template ( name ) name = name . to_sym return false if @disabled_templates . include? ( name ) if ( template_dir = Template . templates [ name ] ) source_paths . delete ( template_dir ) @templates . delete_if { | template | template . path == template_dir } @enabled_templates . delete ( name ) end @disabled... | Disables a template in the generator . |
13,314 | def enable_templates! @templates = [ ] @enabled_templates = Set [ ] @disabled_templates = Set [ ] enable_template :gem Options :: DEFAULT_TEMPLATES . each do | name | if ( Template . template? ( name ) && options [ name ] ) enable_template ( name ) end end options . each do | name , value | if ( Template . template? ( ... | Enables templates . |
13,315 | def initialize_variables! @root = destination_root @project_dir = File . basename ( @root ) @name = ( options . name || @project_dir ) @scm = if File . directory? ( File . join ( @root , '.git' ) ) then :git elsif File . directory? ( File . join ( @root , '.hg' ) ) then :hg elsif File . directory? ( File . join ( @root... | Initializes variables for the templates . |
13,316 | def generate_files! @templates . reverse_each do | template | template . each_file ( @markup ) do | dest , file | generate_file dest , file end template . each_template ( @markup ) do | dest , file | generate_file dest , file , template : true end end @generated_files . each_value do | path | dir = path . split ( File ... | Copies static files and renders templates in the template directories . |
13,317 | def initialize_scm! in_root do case @scm when :git unless File . directory? ( '.git' ) run 'git init' run 'git add .' run 'git commit -m "Initial commit."' end when :hg unless File . directory? ( '.hg' ) run 'hg init' run 'hg add .' run 'hg commit -m "Initial commit."' end when :svn @ignore . each do | pattern | run "s... | Initializes the project repository and commits all files . |
13,318 | def init_config ( options = { } ) options = options . to_symbol_keys if ! options [ :method ] abort "Please provide a deployment method. e.g. #{METHODS.keys}" end @options = DEFAULT_OPTIONS . deep_merge ( options ) write_config check_gitignore end | Create a config file |
13,319 | def generate_result ( * args ) start_symbol , rules_map = map_default_args ( * args ) Result . new ( @registry . evaluate ( start_symbol , rules_map ) ) end | Produces a generated result from evaluating the grammar . |
13,320 | def service_snapshots ( service_id ) return unless service_id res = client . hgetall ( redis_key ( service_id ) ) res . values . map { | v | Yajl :: Parser . parse ( v ) } end | Get all snapshots related to a service instance |
13,321 | def snapshot_details ( service_id , snapshot_id ) return unless service_id && snapshot_id res = client . hget ( redis_key ( service_id ) , snapshot_id ) raise ServiceError . new ( ServiceError :: NOT_FOUND , "snapshot #{snapshot_id}" ) unless res Yajl :: Parser . parse ( res ) end | Get detail information for a single snapshot |
13,322 | def filter_keys ( snapshot ) return unless snapshot . is_a? Hash snapshot . select { | k , v | FILTER_KEYS . include? k . to_s } end | filter internal keys of a given snapshot object return a new snapshot object in canonical format |
13,323 | def generate_dir ( dest ) return if @generated_dirs . has_key? ( dest ) path = interpolate ( dest ) empty_directory path @generated_dirs [ dest ] = path return path end | Generates an empty directory . |
13,324 | def generate_file ( dest , file , options = { } ) return if @generated_files . has_key? ( dest ) path = interpolate ( dest ) if options [ :template ] @current_template_dir = File . dirname ( dest ) template file , path @current_template_dir = nil else copy_file file , path end @generated_files [ dest ] = path return pa... | Generates a file . |
13,325 | def convert_assessments ( quizzes , choices , feedbacks , questionnaires ) assessment_converter = Moodle2CC :: Moodle2Converter :: AssessmentConverter . new assessments = [ ] assessments += quizzes . map { | quiz | assessment_converter . convert_quiz ( quiz ) } assessments += choices . map { | choice | assessment_conve... | convert quizzes to assessments |
13,326 | def convert_question_banks ( question_categories ) bank_converter = Moodle2CC :: Moodle2Converter :: QuestionBankConverter . new question_categories . map { | category | bank_converter . convert ( category ) } end | convert question categories to question banks |
13,327 | def build ( template , options = { } ) args = [ 'build' , '-machine-readable' ] args << '-force' if options . key? ( :force ) args << "-except=#{options[:except].join(',')}" if options . key? ( :except ) args << "-only=#{options[:only].join(',')}" if options . key? ( :only ) args << "-parallel=#{options[:parallel]}" if... | Executes + packer build + . |
13,328 | def inspect_template ( template ) args = [ 'inspect' , '-machine-readable' , template ] Packer :: Output :: Inspect . new ( command ( args ) ) end | Excutes + packer inspect + |
13,329 | def push ( template , options = { } ) args = [ 'push' ] args << "-message=#{options[:message]}" if options . key? ( :message ) args << "-name=#{options[:name]}" if options . key? ( :name ) args << "-token=#{options[:token]}" if options . key? ( :token ) args << "-var-file=#{options[:var_file]}" if options . key? ( :var... | Executes + packer push + . |
13,330 | def validate ( template , options = { } ) args = [ 'validate' ] args << '-syntax-only' if options . key? ( :syntax_only ) args << "-except=#{options[:except].join(',')}" if options . key? ( :except ) args << "-only=#{options[:only].join(',')}" if options . key? ( :only ) args << "-var-file=#{options[:var_file]}" if opt... | Executes + packer validate + |
13,331 | def update_name ( service_id , snapshot_id , name ) return unless service_id && snapshot_id && name verify_input_name ( name ) key = self . class . redis_key ( service_id ) client . watch ( key ) snapshot = client . hget ( redis_key ( service_id ) , snapshot_id ) return nil unless snapshot snapshot = Yajl :: Parser . p... | Update the name of given snapshot . This function is not protected by redis lock so a optimistic lock is applied to prevent concurrent update . |
13,332 | def transform ( name , value ) if respond_to? ( name ) send ( name , value ) elsif value . respond_to? ( name ) value . send ( name ) else value end end | Transforms an output string by delegating to the given output function . |
13,333 | def load query = ( arguments or self ) . info_sql Squirm . exec ( query , [ name , schema ] ) do | result | validate result set_values_from result end self end | Loads meta info about the stored procedure . |
13,334 | def call ( * args , & block ) Squirm . exec query , arguments . format ( * args ) do | result | if block_given? yield result elsif return_type =~ / \A / result . to_a else result . getvalue ( 0 , 0 ) end end end | Invokes the procedure . |
13,335 | def validate ( result ) if result . ntuples == 0 raise NotFound elsif result . ntuples > 1 raise TooManyChoices end end | Checks the number of values returned when looking up meta info about the procedure . |
13,336 | def merge! ( points = { } ) raise ArgumentError , "key points must be a Hash object" unless points . is_a? Hash points . each do | key , value | raise ArgumentError , "found a point key that is not a Numeric object: #{key.inspect}" unless key . is_a? Numeric end @points . merge! ( points ) normalize_data self end | merges the given key points with the original points |
13,337 | def at ( point , & block ) if @sorted . empty? return nil elsif @sorted . size == 1 return @sorted . first . last end if point <= @min_point return @sorted . first . last elsif point >= @max_point return @sorted . last . last end left = 0 right = @sorted . length - 2 low_point = nil low_value = nil high_point = nil hig... | returns the interpolated value at the Numeric point specified optionally using a given block as the blending function |
13,338 | def find_children_banks ( all_banks , visited_banks = [ ] ) visited_banks << self children = [ ] sub_children = [ ] all_banks . each do | bank | children << bank if bank . parent_id && bank . parent_id == self . original_id && ! visited_banks . include? ( bank ) end children . each do | child | sub_children += child . ... | recursively find all banks that belong to this one |
13,339 | def module_of ( word ) if COMMON_NAMESPACES . has_key? ( word ) COMMON_NAMESPACES [ word ] elsif COMMON_ABBREVIATIONS . has_key? ( word ) COMMON_ABBREVIATIONS [ word ] else word . capitalize end end | Guesses the module name for a word within a project name . |
13,340 | def modules_of ( name ) names_in ( name ) . map do | words | words . split ( '_' ) . map { | word | module_of ( word ) } . join end end | Guesses the module names from a project name . |
13,341 | def convert @assets . each do | asset | finished = false while finished == false klass = JAPR :: Converter . klass ( asset . filename ) if klass . nil? finished = true else convert_asset ( klass , asset ) end end end end | Convert assets based on the file extension if converter is defined |
13,342 | def bundle content = @assets . map ( & :content ) . join ( "\n" ) hash = JAPR :: Pipeline . hash ( @source , @manifest , @options ) @assets = [ JAPR :: Asset . new ( content , "#{@prefix}-#{hash}#{@type}" ) ] end | Bundle multiple assets into a single asset |
13,343 | def write_asset_file ( directory , asset ) FileUtils . mkpath ( directory ) unless File . directory? ( directory ) begin File . open ( File . join ( directory , asset . filename ) , 'w' ) do | file | file . write ( asset . content ) end rescue StandardError => se puts "Asset Pipeline: Failed to save '#{asset.filename}'... | Write asset file to disk |
13,344 | def markup display_path = @options [ 'display_path' ] || @options [ 'output_path' ] @html = @assets . map do | asset | klass = JAPR :: Template . klass ( asset . filename ) html = klass . new ( display_path , asset . filename ) . html unless klass . nil? html end . join end | Generate html markup pointing to assets |
13,345 | def four_number @four_number ||= begin fn = ip . split ( "." ) . map ( & :to_i ) raise "ip is no valid" if fn . length != 4 || fn . any? { | d | d < 0 || d > 255 } fn end end | Initialize IP object |
13,346 | def build_meta_fields ( mod ) fields = { } %w{ mod_type assignment_type } . each do | key | fields [ key ] = mod . send ( key ) if mod . respond_to? ( key ) end if mod . grade_item Moodle2CC :: Moodle :: GradeItem :: PROPERTIES . each do | key | fields [ key ] = mod . grade_item . send ( key ) if mod . grade_item . res... | Common Cartridge doesn t have anywhere to put assignment meta data like this So add them as HTML meta fields in the HTML file |
13,347 | def connect ( options = { } ) return @pool = options [ :pool ] if options [ :pool ] options = options . dup timeout = options . delete ( :timeout ) || 5 pool_size = options . delete ( :pool_size ) || 1 @pool = Squirm :: Pool . new ( timeout ) pool_size . times do conn = PGconn . open ( options ) yield conn if block_giv... | Establishes a connection pool . |
13,348 | def exec ( * args , & block ) if current = Thread . current [ :squirm_connection ] current . exec ( * args , & block ) else use { | conn | conn . exec ( * args , & block ) } end end | Executes the query and passes the result to the block you specify . |
13,349 | def use ( conn = nil ) conn_given = ! ! conn conn = conn_given ? conn : @pool . checkout begin yield Thread . current [ :squirm_connection ] = conn ensure Thread . current [ :squirm_connection ] = nil @pool . checkin conn unless conn_given end end | Uses a connection for all database access inside the given block . If no connection is given then one will be checked out from the pool for use inside the block and then checked back in when the method returns . |
13,350 | def manifest = ( hash ) return unless hash raise "Input should be Hash" unless hash . is_a? Hash @manifest . merge! VCAP . symbolize_keys ( hash ) end | add + hash + to manifest file . |
13,351 | def pack ( force = nil ) if File . exists? @zipfile if force File . delete @zipfile else raise "File #{@zipfile} already exists." end end dirname = File . dirname ( @zipfile ) raise "Dir #{dirname} is not exists." unless File . exists? dirname raise "Dir #{dirname} is not writable." unless File . writable? dirname Zip ... | package files and manifest in + zipfile + . If + force + is true we ll try to delete the target + zipfile + if it already exists . |
13,352 | def unpack path raise "File #{@zipfile} not exists." unless File . exists? @zipfile raise "unpack path: #{path} not found." unless Dir . exists? path raise "unpack path: #{path} is not writable." unless File . writable? path files = [ ] Zip :: ZipFile . foreach ( @zipfile ) do | entry | next if entry . to_s == MANIFEST... | unpack the content to + path + and return extraced file list . |
13,353 | def load_manifest zf = Zip :: ZipFile . open ( @zipfile ) @manifest = VCAP . symbolize_keys ( Yajl :: Parser . parse ( zf . read ( MANIFEST_FILE ) ) ) rescue Errno :: ENOENT => e raise ServiceError . new ( ServiceError :: BAD_SERIALIZED_DATAFILE , "request. Missing manifest." ) end | read manifest in a zip file |
13,354 | def filter ( name , callable = nil , & block ) if block_given? transforms [ name . to_sym ] = block else transforms [ name . to_sym ] = callable end end | Registers the given block as a string filter . |
13,355 | def define_rule ( name , trace , productions ) rules [ name . to_sym ] = Rule . new ( name . to_sym , construct_rule ( productions ) , trace ) end | Defines a static rule in the grammar . |
13,356 | def define_context_rule ( name , trace , productions ) productions = [ productions ] unless productions . is_a? ( Enumerable ) context [ name . to_sym ] = Rule . new ( name . to_sym , construct_rule ( productions ) , trace ) end | Defines a rule in the temporary evaluation context . |
13,357 | def expand ( symbol ) expansion = rules [ symbol ] || context [ symbol ] if expansion . nil? if @options . strict? raise Errors :: UndefinedRule . new ( @last_expansion , symbol ) else expansion = Production :: Terminal . new ( '' ) end end @last_expansion = expansion expansion end | Expands the given symbol to its rule . |
13,358 | def transform ( name , value ) if transforms . key? ( name ) transforms [ name ] . call ( value ) else modifiers . transform ( name , value ) end end | Applies the given modifier function to the given value to transform it . |
13,359 | def unique_expansion ( symbol ) pending = true uniques [ symbol ] = [ ] if uniques [ symbol ] . nil? while pending if uniques [ symbol ] . size == expand ( symbol ) . size uniques [ symbol ] = [ ] pending = false end result = expand ( symbol ) . evaluate ( @options ) unless uniques [ symbol ] . include? ( result ) uniq... | Expands a unique rule symbol by evaluating it and checking that it hasn t previously been selected . |
13,360 | def evaluate ( start_symbol = :start , rules_map = { } ) reset_evaluation_context rules_map . each do | key , value | if rules . key? ( key . to_sym ) raise Errors :: DuplicateRule . new ( key ) end define_context_rule ( key , caller_locations . last , value ) end [ start_symbol , expand ( start_symbol ) . evaluate ( @... | Evaluates the grammar defined in this registry combining it with rules from the passed in context . |
13,361 | def make_logger logger = Logger . new ( STDOUT ) logger . level = Logger :: ERROR logger end | Options for lock name - The uuid of the lock timeout - The time that waits to acquire the lock default 20 seconds expiration - Lock expires in given seconds if not refreshed default 10 seconds logger - The logger .. ttl - The max time that a thread can acquire the lock default 600 seconds . Lock raise + JOB_TIMEOUT + e... |
13,362 | def validate_incoming_request unless request . media_type == Rack :: Mime . mime_type ( '.json' ) error_msg = ServiceError . new ( ServiceError :: INVALID_CONTENT ) . to_hash logger . error ( "Validation failure: #{error_msg.inspect}, request media type: #{request.media_type} is not json" ) abort_request ( error_msg ) ... | Validate the incoming request |
13,363 | def perform begin required_options :service_id , :snapshot_id @name = options [ "service_id" ] @snapshot_id = options [ "snapshot_id" ] @logger . info ( "Launch job: #{self.class} for #{name}" ) lock = create_lock @snapshot_files = [ ] lock . lock do dump_path = get_dump_path ( name , snapshot_id ) package_file = "#{sn... | workflow template Subclass implement execute method which returns true for a successful rollback |
13,364 | def enhance_method ( method , callbacks ) _method = ( PREFIX + method . to_s ) . to_sym alias_method _method , method self . send ( :define_method , method ) do | * args , & blk | [ callbacks , _method ] . flatten . each do | callback | break unless self . send ( callback , * args , & blk ) end end end | enhance single method with callbacks |
13,365 | def convert_rating_question ( moodle_question , canvas_question ) choices = create_rating_choices ( moodle_question ) canvas_question . responses = [ ] moodle_question . choices . each_with_index do | answer , answer_idx | response = { :id => "response#{answer_idx + 1}" , :choices => [ ] } canvas_question . material = ... | For l .. x rating questions |
13,366 | def enumerator Enumerator . new do | yielder | response = get_initial_response loop do items = response . records break if items . empty? items . each { | item | yielder << item } @params ||= { } @params [ :page ] ||= 1 @params [ :page ] += 1 response = @service . list ( ** @params ) end end . lazy end | Get a lazy enumerable for listing data from the API |
13,367 | def static_role! role_name raise ArgumentError , "Take a single role name, was: #{role_name}" if ! role_name || ! role_name . kind_of_label? troles_config . add_valid_roles role_name if set_roles role_name define_method :static_roles? do true end end end | Do we need a static_roles! method? I think so! |
13,368 | def set_roles * roles roles_to_set = make_valid_roles ( * roles ) . flat_uniq return false if ! roles_to_set || roles_to_set . empty? store . set_roles ( roles_to_set ) end | Sets new roles for the subject |
13,369 | def untranslated? return false if obsolete? || fuzzy? return @msgstr . map ( & :str ) . join . empty? if @msgstr . is_a? Array @msgstr . nil? || @msgstr . str . empty? end | Checks if the entry is untraslated |
13,370 | def to_h instance_variables . each_with_object ( { } ) do | label , hash | object = instance_variable_get ( label ) if object . is_a? ( Array ) object . each do | entry | hash [ entry . type ] = entry . to_s unless entry . nil? end else hash [ object . type ] = object . to_s unless object . nil? end end end | Convert entry to a hash key value |
13,371 | def to_s LABELS . each_with_object ( [ ] ) do | label , arr | object = instance_variable_get ( "@#{label}" . to_sym ) if object . is_a? ( Array ) arr . push ( * object . map { | entry | entry . to_s ( true ) } . compact ) else arr << object . to_s ( true ) unless object . nil? end end . join end | Convert entry to a string |
13,372 | def params_hash %i[ opcode ] . push ( * ATTRIBUTES ) . map { | a | [ a , send ( a ) . to_s ] } . to_h . reject { | _k , v | v . nil? || v . empty? } end | Builds hash with meaningful params only |
13,373 | def request_params params_hash . tap do | params | params [ :sign ] = Signature . new ( params , credentials . secret ) . sign end end | Builds and signs request parameters |
13,374 | def set_roles * roles raise ArgumentError , "A single role strategy can only allow setting a single role, was: #{roles}" if ( roles . size > 1 ) set_role roles . flat_uniq . first end | saves the role for the user in the data store |
13,375 | def set_role role num = bitmask . write role set_ds_field ( num == 1 ? false : true ) end | saves the role for the role subject in the data store |
13,376 | def to_h { } . tap do | h | ALLOWED_PARAMS . each { | p | h [ p ] = send ( p ) } h [ :txn_status_message ] = txn_status_message h [ :txn_type_message ] = txn_type_message end end | Converts confirmation data to hash |
13,377 | def calculated_sign params = SIGN_PARAMS . each_with_object ( { } ) do | p , h | h [ p ] = send ( p ) . tap { | v | v ? v . to_s : nil } end Signature . new ( params , @secret ) . sign . upcase end | Calculates signature for parameters |
13,378 | def set_role new_role value = make_valid_role new_role return false if ! value store . set_role ( value ) end | Set the role of the subject to a new role |
13,379 | def to_hex ( sep_bytes = false ) hx = @bytes . unpack ( 'H*' ) [ 0 ] . upcase if sep_bytes sep = "" ( 0 ... hx . size ) . step ( 2 ) do | i | sep << " " unless i == 0 sep << hx [ i , 2 ] end hx = sep end hx end | return an hex representation of a byte string |
13,380 | def reverse_byte_nibbles! w = "" w . force_encoding ( "BINARY" ) if w . respond_to? ( :force_encoding ) @bytes . each_byte do | b | w << ( ( b >> 4 ) | ( ( b & 0xF ) << 4 ) ) end @bytes = w __setobj__ @bytes self end | Reverse the order of the nibbles in each byte . |
13,381 | def reverse_byte_pairs! w = "" w . force_encoding ( "BINARY" ) if w . respond_to? ( :force_encoding ) ( 0 ... @bytes . size ) . step ( 2 ) do | i | w << @bytes [ i + 1 ] w << @bytes [ i ] end @bytes = w __setobj__ @bytes self end | reverse the order of bytes in 16 - bit words |
13,382 | def to_bitfields ( lens , byte_endianness = :little_endian , bits_little_endian = false ) fields = [ ] i = to_i ( byte_endianness , bits_little_endian ) for len in lens mask = ( 1 << len ) - 1 fields << ( i & mask ) i >>= len end fields end | convert a byte string to separate fixed - width bit - fields as integers |
13,383 | def each @model . transaction do begin declare_cursor if @join_dependency rows = Array . new last_id = nil while row = fetch_forward instantiated_row = @join_dependency . instantiate ( [ row ] , @join_dependency . aliases ) . first current_id = instantiated_row [ @join_dependency . join_root . primary_key ] last_id ||=... | Calls block once for each record in the cursor passing that record as a parameter . |
13,384 | def map_sorted ( hash ) hash . keys . sort_by ( & :to_sym ) . map { | k | yield k , hash [ k ] } end | Maps hash yielding key - value pairs ordered by key |
13,385 | def merge_to_previous_string ( array ) array . each_with_index do | key , index | next unless key . length == 1 array [ index - 1 ] [ 1 ] += key [ 0 ] array . delete_at ( index ) end end | Sometimes long lines are wrapped into new lines this function join them back |
13,386 | def get ( path : , params : { } ) params ||= { } if feed_password && ! feed_password . empty? params = params . merge ( feedPassword : feed_password ) end response = make_request ( :get , path , params ) SPOT :: ApiResponse . new ( response ) end | Make a GET request to the SPOT API |
13,387 | def auto_config? name return auto_config [ name ] if ! auto_config [ name ] . nil? Troles :: Config . auto_config? ( name ) end | is a certain type of auto configuration enabled? |
13,388 | def main_field = field_name name = field_name . to_s . alpha_numeric . to_sym raise ArgumentException , "Not a valid field name: #{field_name}" if ! valid_field_name? ( name ) @main_field ||= name end | Set the main field of the behavior |
13,389 | def configure_relation case strategy when :ref_many has_many_for subject_class , :role , :through => join_key belongs_to_for join_model , subject_class belongs_to_for join_model , object_model has_many_for role , subject_class , :through => join_key when :embed_many embeds_many subject_class , object_model end end | more likely strategy should be part of configuration options directly when Config object is created! |
13,390 | def set_rolegroups * rolegroups rolegroups_to_set = make_valid_rolegroups ( * rolegroups ) . flat_uniq return false if ! rolegroups_to_set || rolegroups_to_set . empty? group_store . set_rolegroups ( rolegroups_to_set ) end | Sets new rolegroups for the subject |
13,391 | def add ( entry ) return import_hash ( entry ) if entry . is_a? ( Hash ) return import_array ( entry ) if entry . is_a? ( Array ) raise ArgumentError , 'Must be a hash or an array of hashes' end | add new entries to po file |
13,392 | def delete ( entry ) raise ( ArgumentError , 'Must be an Entry' ) unless entry . is_a? ( PoParser :: Entry ) @entries . delete ( entry ) end | Delete entry from po file |
13,393 | def stats untranslated_size = untranslated . size translated_size = translated . size fuzzy_size = fuzzy . size { translated : percentage ( translated_size ) , untranslated : percentage ( untranslated_size ) , fuzzy : percentage ( fuzzy_size ) , } end | Shows statistics and status of the provided file in percentage . |
13,394 | def save_file raise ArgumentError , 'Need a Path to save the file' if @path . nil? File . open ( @path , 'w' ) { | file | file . write ( to_s ) } end | Saves the file to the provided path |
13,395 | def xsd_file ( filename ) xsd_file_location = File . join ( DineroMailIpn . resources_path , "/validation/xsd/#{filename}" ) xsd_file = File . read ( xsd_file_location ) xsd_file end | Locates an XSD file . |
13,396 | def execute ( cmd , options = { } ) options = { :directory => nil , :outstream => nil , :raise_on_failure => true , :set_env_vars => nil , :clear_env_vars => nil , :logger => default_logger , :timeout => nil , :keep_alive_interval => nil , :keep_alive_timeout => nil } . merge ( options ) outstream = options [ :outstrea... | Implements execute interface . |
13,397 | def output_for ( cmd , options = { } ) output = StringIO . new execute ( cmd , options . merge ( :outstream => output ) ) output . string end | Implements output_for interface . |
13,398 | def configure_executioner ( executioner , options ) sev = options [ :set_env_vars ] if ( sev && ! sev . empty? ) executioner = lambda do | e | lambda { set_env_vars ( sev ) { e . call } } end . call ( executioner ) end cev = options [ :clear_env_vars ] if ( cev && ! cev . empty? ) executioner = lambda do | e | lambda {... | Encapsulates the given executioner with child - process - modifying behavior based on options . Builds the executioner as a series of callbacks . |
13,399 | def set_env_vars ( variables ) save_vars = { } variables . each do | k , v | k = k . to_s save_vars [ k ] = ENV [ k ] ENV [ k ] = v . nil? ? v : v . to_s end begin yield ensure variables . each_key do | k | k = k . to_s ENV [ k ] = save_vars [ k ] end end true end | Sets the given list of environment variables while executing the given block . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.