idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
13,100
def validate_version! Docker . info true rescue Docker :: Error :: DockerError raise Docker :: Error :: VersionError , "Expected API Version: #{API_VERSION}" end
When the correct version of Docker is installed returns true . Otherwise raises a VersionError .
13,101
def create_mock_project @project_path = File . join ( "spec" , "data" , "test-project" ) Tetra :: Project . init ( @project_path , false ) @project = Tetra :: Project . new ( @project_path ) end
creates a minimal tetra project
13,102
def create_mock_executable ( executable_name ) Dir . chdir ( @project_path ) do dir = mock_executable_dir ( executable_name ) FileUtils . mkdir_p ( dir ) executable_path = mock_executable_path ( executable_name ) File . open ( executable_path , "w" ) { | io | io . puts "echo $0 $*>test_out" } File . chmod ( 0777 , exec...
creates an executable in kit that will print its parameters in a test_out file for checking . Returns mocked executable full path
13,103
def get_pom_from_jar ( file ) log . debug ( "Attempting unpack of #{file} to find a POM" ) begin Zip :: File . foreach ( file ) do | entry | if entry . name =~ %r{ } log . info ( "pom.xml found in #{file}##{entry.name}" ) return entry . get_input_stream . read , :found_in_jar end end rescue Zip :: Error log . warn ( "#...
returns a pom embedded in a jar file
13,104
def get_pom_from_sha1 ( file ) log . debug ( "Attempting SHA1 POM lookup for #{file}" ) begin if File . file? ( file ) site = MavenWebsite . new sha1 = Digest :: SHA1 . hexdigest File . read ( file ) results = site . search_by_sha1 ( sha1 ) . select { | result | result [ "ec" ] . include? ( ".pom" ) } result = results ...
returns a pom from search . maven . org with a jar sha1 search
13,105
def get_pom_from_heuristic ( filename ) begin log . debug ( "Attempting heuristic POM search for #{filename}" ) site = MavenWebsite . new filename = cleanup_name ( filename ) version_matcher = VersionMatcher . new my_artifact_id , my_version = version_matcher . split_version ( filename ) log . debug ( "Guessed artifact...
returns a pom from search . maven . org with a heuristic name search
13,106
def _to_script ( project ) project . from_directory do script_lines = [ "#!/bin/bash" , "set -xe" , "PROJECT_PREFIX=`readlink -e .`" , "cd #{project.latest_dry_run_directory}" ] + aliases ( project ) + project . build_script_lines new_content = script_lines . join ( "\n" ) + "\n" result_dir = File . join ( project . pa...
returns a build script for this package
13,107
def aliases ( project ) kit = Tetra :: Kit . new ( project ) aliases = [ ] ant_path = kit . find_executable ( "ant" ) ant_commandline = Tetra :: Ant . commandline ( "$PROJECT_PREFIX" , ant_path ) aliases << "alias ant='#{ant_commandline}'" mvn_path = kit . find_executable ( "mvn" ) mvn_commandline = Tetra :: Mvn . comm...
setup aliases for adjusted versions of the packaging tools
13,108
def template_files ( include_bundled_software ) result = { "kit" => "." , "packages" => "." , "src" => "." } if include_bundled_software Dir . chdir ( TEMPLATE_PATH ) do Dir . glob ( File . join ( "bundled" , "*" ) ) . each do | file | result [ file ] = "kit" end end end result end
returns a hash that maps filenames that should be copied from TEMPLATE_PATH to the value directory
13,109
def commit_source_archive ( file , message ) from_directory do result_dir = File . join ( packages_dir , name ) FileUtils . mkdir_p ( result_dir ) result_path = File . join ( result_dir , File . basename ( file ) ) FileUtils . cp ( file , result_path ) @git . commit_file ( result_path , "Source archive added" ) unarchi...
adds a source archive at the project both in original and unpacked forms
13,110
def http_get ( port , host_header , path , timeout_sec = 10 , protocol = 'http' , bypass_ssl_verify = false ) Http_Get . new ( port , host_header , path , timeout_sec , protocol , bypass_ssl_verify ) end
ServerSpec Type wrapper for http_get
13,111
def generate ( template_name , object_binding ) erb = ERB . new ( File . read ( File . join ( template_path , template_name ) ) , nil , "<>" ) erb . result ( object_binding ) end
generates content from an ERB template and an object binding
13,112
def log ( severity , message , time : nil ) time ||= Time . now m = SumologicCloudSyslog :: Message . new m . structured_data << @default_structured_data m . header = @default_header . dup m . header . severity = severity m . header . timestamp = time yield m . header if block_given? m . msg = message transport . write...
Send log message with severity to Sumologic
13,113
def shelljoin ( cmd , whitelist : SHELLJOIN_WHITELIST ) cmd . map do | str | if whitelist . any? { | pat | str =~ pat } str else Shellwords . shellescape ( str ) end end . join ( ' ' ) end
An improved version of Shellwords . shelljoin that doesn t escape a few things .
13,114
def absolute_command ( cmd , path : nil ) was_array = cmd . is_a? ( Array ) cmd = if was_array cmd . dup else Shellwords . split ( cmd ) end if cmd . first && ! cmd . first . start_with? ( '-' ) && ! cmd . first . include? ( :: File :: SEPARATOR ) cmd [ 0 ] = which ( cmd . first , path : path ) || cmd . first end cmd =...
Convert the executable in a string or array command to an absolute path .
13,115
def then ( body , & setup ) new_step = WorkflowStep . new new_step . body = body @workflow_builder . add_step ( new_step ) new_builder = StepBuilder . new ( @workflow_builder , new_step ) if body . kind_of? ( Class ) new_step . name = body . name end if setup setup . call ( new_builder ) end new_outcome = StepOutcome ....
Adds a new step to the workflow
13,116
def input ( step_property , & value ) mapping = IOMapping . new mapping . property = step_property mapping . value = value @step . inputs << mapping self end
Map workflow instance data to a property on the step
13,117
def decrypt ( encrypted ) fail ArgumentError , 'No cipher text supplied.' if encrypted . nil? || encrypted . empty? matches = CIPHER_PATTERN . match ( encrypted ) fail ArgumentError , 'Cipher text has an unsupported format.' if matches . nil? cipher = self . class . cipher cipher . decrypt cipher . key = Base64 . decod...
This method expects a base64 encoded cipher text and decrypts it .
13,118
def logger ( tag ) @loggers [ tag ] ||= new_logger ( tag ) if @loggers [ tag ] . closed? @loggers [ tag ] = new_logger ( tag ) end @loggers [ tag ] end
Get logger for given tag
13,119
def add_role name if allowed_role? name return if has_role? name role = Role . find_by ( name : name . to_s ) roles << role end end
These methods are included in all User instances
13,120
def tidy_bytes ( force = false ) if force return unpack ( "C*" ) . map do | b | tidy_byte ( b ) end . flatten . compact . pack ( "C*" ) . unpack ( "U*" ) . pack ( "U*" ) end bytes = unpack ( "C*" ) conts_expected = 0 last_lead = 0 bytes . each_index do | i | byte = bytes [ i ] is_ascii = byte < 128 is_cont = byte > 127...
Attempt to replace invalid UTF - 8 bytes with valid ones . This method naively assumes if you have invalid UTF8 bytes they are either Windows CP - 1252 or ISO8859 - 1 . In practice this isn t a bad assumption but may not always work .
13,121
def setup ( * methods , & block ) methods . each do | method | if method . to_s =~ / / prepend_before { __send__ method } else before { __send__ method } end end before ( & block ) if block end
Wraps setup calls from within Rails testing framework in before hooks .
13,122
def parse if @config [ "rows" ] . nil? || @config [ "rows" ] . to_i < 0 @row_count = 100 else @row_count = @config [ "rows" ] . to_i end @fields = [ ] if @config [ "fields" ] . nil? || @config [ "fields" ] . empty? raise "need 'fields' in the config file and at least 1 field in it" end @config [ "fields" ] . each do | ...
prepare the json config and generate the fields
13,123
def parse_server_attributes ( value ) parts = value . to_s . split ( / \s / ) current_name = nil pairs = parts . each_with_object ( { } ) { | part , attrs | if SERVER_ATTRIBUTE_NAMES . include? ( part ) current_name = part attrs [ current_name ] = [ ] elsif current_name . nil? raise "Invalid server attribute: #{part}" ...
Parses server attributes from the server value . I couldn t manage to get treetop to do this .
13,124
def clean_parsed_server_attributes ( pairs ) pairs . each do | k , v | pairs [ k ] = if v . empty? true else v . join ( " " ) end end end
Converts attributes with no values to true and combines everything else into space - separated strings .
13,125
def parse ( substatement = nil , token_index = 0 ) p_token = nil if substatement c_token , c_token_value = substatement [ token_index ] else c_token , c_token_value = @scanner . get_token end parenth = 0 until c_token . nil? if substatement token_index += 1 n_token , n_token_value = substatement [ token_index ] else @s...
Parse the input string one token at a time a contruct the call stack
13,126
def get_token return nil if @token_index >= @arguments . size begin case chr ( @arguments [ @token_index ] ) when "[" return "statement" , gen_substatement when "]" return "]" when "(" return "(" , "(" when ")" return ")" , ")" when "n" if ( chr ( @arguments [ @token_index + 1 ] ) == "o" ) && ( chr ( @arguments [ @toke...
Scans the input string and identifies single language tokens
13,127
def << ( arg ) case arg when PositionalArgument , KeywordArgument , FlagArgument , RestArgument if @arguments [ arg . key ] raise ArgumentError , "An argument with key '#{arg.key}' has already been defined" end if arg . short_key && @short_keys [ arg . short_key ] raise ArgumentError , "The short key '#{arg.short_key}'...
Adds the specified argument to the command - line definition .
13,128
def positional_arg ( key , desc , opts = { } , & block ) self << ArgParser :: PositionalArgument . new ( key , desc , opts , & block ) end
Add a positional argument to the set of arguments in this command - line argument definition .
13,129
def keyword_arg ( key , desc , opts = { } , & block ) self << ArgParser :: KeywordArgument . new ( key , desc , opts , & block ) end
Add a keyword argument to the set of arguments in this command - line argument definition .
13,130
def flag_arg ( key , desc , opts = { } , & block ) self << ArgParser :: FlagArgument . new ( key , desc , opts , & block ) end
Add a flag argument to the set of arguments in this command - line argument definition .
13,131
def rest_arg ( key , desc , opts = { } , & block ) self << ArgParser :: RestArgument . new ( key , desc , opts , & block ) end
Add a rest argument to the set of arguments in this command - line argument definition .
13,132
def validate_requirements ( args ) errors = [ ] @require_set . each do | req , sets | sets . each do | set | count = set . count { | arg | args . has_key? ( arg . key ) && args [ arg . key ] } case req when :one if count == 0 errors << "No argument has been specified for one of: #{set.join(', ')}" elsif count > 1 error...
Validates the supplied + args + Hash object verifying that any argument set requirements have been satisfied . Returns an array of error messages for each set requirement that is not satisfied .
13,133
def show_usage ( out = STDERR , width = 80 ) lines = [ '' ] pos_args = positional_args opt_args = size - pos_args . size usage_args = pos_args . map ( & :to_use ) usage_args << ( requires_some? ? 'OPTIONS' : '[OPTIONS]' ) if opt_args > 0 usage_args << rest_args . to_use if rest_args? lines . concat ( wrap_text ( "USAGE...
Generates a usage display string
13,134
def show_help ( out = STDOUT , width = 80 ) lines = [ '' , '' ] lines << title lines << title . gsub ( / / , '=' ) lines << '' if purpose lines . concat ( wrap_text ( purpose , width ) ) lines << '' end if copyright lines . concat ( wrap_text ( "Copyright (c) #{copyright}" , width ) ) lines << '' end lines << 'USAGE' l...
Generates a more detailed help screen .
13,135
def wrap_text ( text , width ) if width > 0 && ( text . length > width || text . index ( "\n" ) ) lines = [ ] start , nl_pos , ws_pos , wb_pos , end_pos = 0 , 0 , 0 , 0 , text . rindex ( / \s / ) while start < end_pos last_start = start nl_pos = text . index ( "\n" , start ) ws_pos = text . rindex ( / / , start + width...
Utility method for wrapping lines of + text + at + width + characters .
13,136
def parse ( tokens = ARGV ) @show_usage = nil @show_help = nil @errors = [ ] begin pos_vals , kw_vals , rest_vals = classify_tokens ( tokens ) args = process_args ( pos_vals , kw_vals , rest_vals ) unless @show_help rescue NoSuchArgumentError => ex self . errors << ex . message @show_usage = true end ( @show_usage || @...
Instantiates a new command - line parser with the specified command - line definition . A Parser instance delegates unknown methods to the Definition so its possible to work only with a Parser instance to both define and parse a command - line .
13,137
def process_arg_val ( arg , val , hsh , is_default = false ) if is_default && arg . required? && ( val . nil? || val . empty? ) self . errors << "No value was specified for required argument '#{arg}'" return end if ! is_default && val . nil? && KeywordArgument === arg if arg . value_optional? val = arg . value_optional...
Process a single argument value
13,138
def method_missing ( name , * args , & block ) return @info [ name . to_s ] if @info . key? name . to_s return @info [ name ] if @info . key? name super . method_missing name end
allow accessing info values with dot notation
13,139
def prune_dead_workers all_workers = self . class . all return if all_workers . empty? known_workers = JRUBY ? worker_thread_ids : [ ] pids = nil , hostname = self . hostname all_workers . each do | worker | host , pid , thread , queues = self . class . split_id ( worker . id ) next if host != hostname next if known_wo...
similar to the original pruning but accounts for thread - based workers
13,140
def worker_thread_ids thread_group = java . lang . Thread . currentThread . getThreadGroup threads = java . lang . reflect . Array . newInstance ( java . lang . Thread . java_class , thread_group . activeCount ) thread_group . enumerate ( threads ) threads . map do | thread | thread && thread . getName . index ( WORKER...
returns worker thread names that supposely belong to the current application
13,141
def update_native_thread_name thread = JRuby . reference ( Thread . current ) set_thread_name = Proc . new do | prefix , suffix | self . class . with_global_lock do count = self . class . system_registered_workers . size thread . native_thread . name = "#{prefix}##{count}#{suffix}" end end if ! name = thread . native_t...
so that we can later identify a live worker thread
13,142
def system_unregister_worker self . class . with_global_lock do workers = self . class . system_registered_workers workers . delete ( self . id ) self . class . store_global_property ( WORKERS_KEY , workers . join ( ',' ) ) end end
unregister a worked id globally
13,143
def parse_ngannotate_options opt = config . options . clone if ENV [ 'NG_OPT' ] opt_str = ENV [ 'NG_OPT' ] if opt_str opt = Hash [ opt_str . split ( ',' ) . map { | e | e . split ( '=' ) } ] opt . symbolize_keys! end end regexp = ENV [ 'NG_REGEXP' ] if regexp opt [ :regexp ] = regexp end opt end
Parse extra options for ngannotate
13,144
def validate ( command , allknifes ) return if allknifes . index { | x | x . start_with? ( "knife #{command}" ) } STDERR . puts "ERROR: 'knife #{command}' is not a currently supported command for knife." exit ( - 1 ) end
test that the knife command exists
13,145
def document_to_model ( document ) identity_map . retrieve_or_store model_class , document . key do model = model_class . new ( document . to_h ) model . key = document . key model . rev = document . revision handle_related_documents ( model ) model end end
Map a document to a model
13,146
def model_to_document ( model ) document = model . attributes . dup . except ( :key , :rev ) handle_embedded_models ( model , document ) handle_related_models ( document ) document end
Map a model to a document
13,147
def initialize_metal Rails :: Rack :: Metal . requested_metals = configuration . metals Rails :: Rack :: Metal . metal_paths = [ "#{TRUSTY_CMS_ROOT}/app/metal" ] Rails :: Rack :: Metal . metal_paths += plugin_loader . engine_metal_paths Rails :: Rack :: Metal . metal_paths += extension_loader . paths ( :metal ) Rails :...
Overrides the Rails initializer to load metal from TRUSTY_CMS_ROOT and from radiant extensions .
13,148
def initialize_i18n radiant_locale_paths = Dir [ File . join ( TRUSTY_CMS_ROOT , 'config' , 'locales' , '*.{rb,yml}' ) ] configuration . i18n . load_path = radiant_locale_paths + extension_loader . paths ( :locale ) super end
Extends the Rails initializer to add locale paths from TRUSTY_CMS_ROOT and from radiant extensions .
13,149
def validate_run_list ( node , run_list , cookbooks , roles ) run_list . split ( "," ) . each do | item | if item . start_with? ( "recipe[" ) cb = item . split ( / \[ \] / ) [ 1 ] . split ( ":" ) [ 0 ] unless cookbooks . member? ( cb ) STDERR . puts "ERROR: '#{node}' run list cookbook '#{cb}' is missing from the list o...
ensure run_list contents are listed previously .
13,150
def validate_options ( node , options , environments ) if options =~ / / env = options . split ( "-E" ) [ 1 ] . split [ 0 ] unless environments . member? ( env ) STDERR . puts "ERROR: '#{node}' environment '#{env}' is missing from the list of environments in the manifest." exit ( - 1 ) end end end
for now just check that - E is legit
13,151
def validate_node_file ( name ) node = Chef :: JSONCompat . from_json ( IO . read ( "nodes/#{name}.json" ) ) return unless node [ "name" ] != name STDERR . puts "ERROR: Node '#{name}' listed in the manifest does not match the name '#{node['name']}' within the nodes/#{name}.json file." exit ( - 1 ) end
validate individual node files
13,152
def process_providers ( names , count , name , options , run_list , create_command_options , knifecommands ) provider = names [ 0 ] validate_provider ( provider , names , count , options , knifecommands ) unless Spiceweasel :: Config [ :novalidation ] provided_names = [ ] if name . nil? && options . split . index ( "-N...
manage all the provider logic
13,153
def validate_provider ( provider , names , _count , options , knifecommands ) unless knifecommands . index { | x | x . start_with? ( "knife #{provider}" ) } STDERR . puts "ERROR: 'knife #{provider}' is not a currently installed plugin for knife." exit ( - 1 ) end return unless provider . eql? ( "google" ) return unless...
check that the knife plugin is installed
13,154
def chef_client_search ( name , run_list , environment ) search = [ ] search . push ( "name:#{name}" ) if name search . push ( "chef_environment:#{environment}" ) if environment run_list . split ( "," ) . each do | item | item . sub! ( / \[ / , ":" ) item . chop! item . sub! ( / / , '\:\:' ) search . push ( item ) end ...
create the knife ssh chef - client search pattern
13,155
def validate_metadata ( cookbook , version ) metadata = @loader . cookbooks_by_name [ cookbook ] . metadata Spiceweasel :: Log . debug ( "validate_metadata: #{cookbook} #{metadata.name} #{metadata.version}" ) if metadata . name . empty? Spiceweasel :: Log . warn ( "No cookbook name in the #{cookbook} metadata.rb." ) el...
check the metadata for versions and gather deps
13,156
def validate_dependencies Spiceweasel :: Log . debug ( "cookbook validate_dependencies: '#{@dependencies}'" ) @dependencies . each do | dep | unless member? ( dep ) STDERR . puts "ERROR: Cookbook dependency '#{dep}' is missing from the list of cookbooks in the manifest." exit ( - 1 ) end end end
compare the list of cookbook deps with those specified
13,157
def generate! changelog = extraction_stratagy . extract changelog . version = version changelog . date = options [ 'release_date' ] writer . write! ( changelog ) end
Create the change log
13,158
def perfom_query ( iterator_with_mapping , & block ) iterator = perform_mapping? ? iterator_with_mapping : iterator_without_mapping ( & block ) connection . execute ( aql_string , options ) . each ( & iterator ) end
Executes an AQL query with bind parameters
13,159
def cluster_process_nodes ( cluster , environment , cookbooks , environments , roles , knifecommands , rootoptions ) Spiceweasel :: Log . debug ( "cluster::cluster_process_nodes '#{environment}' '#{cluster[environment]}'" ) cluster [ environment ] . each do | node | node_name = node . keys . first options = node [ node...
configure the individual nodes within the cluster
13,160
def activate_extensions initializer . initialize_views ordered_extensions = [ ] configuration = TrustyCms :: Application . config if configuration . extensions . first == :all ordered_extensions = extensions else configuration . extensions . each { | name | ordered_extensions << select_extension ( name ) } end ordered_...
Activates all enabled extensions and makes sure that any newly declared subclasses of Page are recognised . The admin UI and views have to be reinitialized each time to pick up changes and avoid duplicates .
13,161
def source_partial_exists? if @site . respond_to? ( :in_source_dir ) File . exists? @site . in_source_dir ( "_app.yaml" ) else File . exists? Jekyll . sanitized_path ( @site . source , "_app.yaml" ) end end
Checks if a optional _app . yaml partial already exists
13,162
def document_overrides ( document ) if document . respond_to? ( :data ) and document . data . has_key? ( "app_engine" ) document . data . fetch ( "app_engine" ) else { } end end
Document specific app . yaml configuration provided in yaml frontmatter
13,163
def app_yaml_exists? if @site . respond_to? ( :in_source_dir ) File . exists? @site . in_source_dir ( "app.yaml" ) else File . exists? Jekyll . sanitized_path ( @site . source , "app.yaml" ) end end
Checks if a app . yaml already exists in the site source
13,164
def validate_item ( db , item ) unless File . exist? ( "data_bags/#{db}/#{item}.json" ) STDERR . puts "ERROR: data bag '#{db}' item '#{item}' file 'data_bags/#{db}/#{item}.json' does not exist" exit ( - 1 ) end f = File . read ( "data_bags/#{db}/#{item}.json" ) begin itemfile = JSON . parse ( f ) rescue JSON :: ParserE...
validate the item to be loaded
13,165
def initialize_coercer ( klass ) coercers [ klass ] = begin coercer = Coercer :: Object . determine_type ( klass ) || Coercer :: Object args = [ self ] args << config_for ( coercer ) if coercer . respond_to? ( :config_name ) coercer . new ( * args ) end end
Initialize a new coercer instance for the given type
13,166
def write_collections edge_collections . flat_map do | target_state | [ target_state . edge_collection_name ] + ( target_state . from_vertices + target_state . to_vertices ) . map ( & :collection ) end . uniq . compact end
A list of collections we will write to
13,167
def transaction transaction = database . create_transaction ( transaction_code , write : write_collections , read : read_collections ) transaction . wait_for_sync = true transaction end
A transaction instance from the database
13,168
def decode16bit data , length data . split ( '' ) . in_groups_of ( 4 ) . collect ( ) double_octets = data . split ( '' ) . in_groups_of ( 4 ) . map ( & :join ) . map { | x | x . to_i ( 16 ) } [ 0 , length / 2 ] double_octets . collect do | o | [ o ] . pack ( 'S' ) end . join . force_encoding ( 'utf-16le' ) . encode ( '...
Decodes 16bit UTF - 16 string into UTF - 8 string
13,169
def each ( & block ) return to_enum ( __callee__ ) unless block_given? perfom_query -> ( document ) { block . call mapper . document_to_model ( document ) } , & block end
Create a new Query
13,170
def perfom_query ( iterator , & block ) if example connection . by_example ( example , options ) . each ( & iterator ) else connection . all ( options ) . each ( & iterator ) end end
Performs the query against the database connection .
13,171
def style ( name ) style = Mapnik :: Style . new yield style styles [ name ] = style end
Creates and yeilds a new style object then adds that style to the map s collection of styles under the name passed in . Makes no effort to de - dupe style name collisions .
13,172
def layer ( name , srs = nil ) layer = Mapnik :: Layer . new ( name , srs ) layer . map = self yield layer layers << layer end
Creates and yields a new layer object then adds that layer to the map s collection of layers . If the srs is not provided in the initial call it will need to be provided in the block .
13,173
def render_to_file ( filename , format = nil ) if format __render_to_file_with_format__ ( filename , format ) else __render_to_file__ ( filename ) end return File . exists? ( filename ) end
Renders the map to a file . Returns true or false depending if the render was successful . The image type is inferred from the filename .
13,174
def getError ( code , message = nil ) klass = find_by_code ( code ) message = build_message ( klass , code , message ) error = klass . new ( code , message ) error end
This method returns the appropriate FileMaker object depending on the error code passed to it . It also accepts an optional message .
13,175
def request ( method , path , opts = { } ) raise ClientError , 'Access token missing' unless @access_token opts [ :headers ] = { } if opts [ :headers ] . nil? opts [ :headers ] [ 'Accept' ] = 'application/json' opts [ :headers ] [ 'Content-Type' ] = 'application/json' unless method == :get opts [ :headers ] [ 'User-Age...
Send a request to the Mondo API servers
13,176
def connect ( action , args , options = { } ) post = args . merge ( expand_options ( options ) ) . merge ( { action => '' } ) http_fetch ( "/fmi/xml/fmresultset.xml" , post ) end
Performs a raw FileMaker action . You will generally not call this method directly but it is exposed in case you need to do something under the hood .
13,177
def available_locales cached_locales = cache . keys . map { | key | key . split ( '.' ) . first } ( cached_locales + super ) . uniq . map { | locale | locale . to_sym } end
Returns locales availabile for this Copycopter project .
13,178
def create! rar_process = IO . popen command_line _ , status = Process . wait2 rar_process . pid if status . exitstatus > 1 if message = ExitCodeMessages [ status . exitstatus ] raise CommandLineError , message else raise CommandLineError , "Unknown exit status: #{status}" end else true end end
Create the final archive .
13,179
def upload ( data ) connect do | http | response = http . post ( uri ( 'draft_blurbs' ) , data . to_json , 'Content-Type' => 'application/json' ) check response log 'Uploaded missing translations' end end
Uploads the given hash of blurbs as draft content .
13,180
def deploy connect do | http | response = http . post ( uri ( 'deploys' ) , '' ) check response log 'Deployed' end end
Issues a deploy marking all draft content as published for this project .
13,181
def nodes return @nodes if @nodes @nodes = sweep . map do | k , v | Node . new ( ip : k , mac : Hooray :: Local . arp_table [ k . to_s ] , ports : v ) end end
Map results to
13,182
def ping_class return Net :: Ping :: External unless ports return Net :: Ping :: TCP unless @protocol =~ / / Net :: Ping . const_get ( @protocol . upcase ) end
Decide how to ping
13,183
def scan_bot ( ip ) ( ports || [ nil ] ) . each do | port | Thread . new do if ping_class . new ( ip . to_s , port , TIMEOUT ) . ping? @scan [ ip ] << port print '.' end end end end
Creates a bot per port on IP
13,184
def sweep network . to_range . each do | ip | @scan [ ip ] = [ ] scan_bot ( ip ) end Thread . list . reject { | t | t == Thread . current } . each ( & :join ) @scan . reject! { | _k , v | v . empty? } end
fast - > - sn - PA
13,185
def export keys = { } lock do @blurbs . sort . each do | ( blurb_key , value ) | current = keys yaml_keys = blurb_key . split ( '.' ) 0 . upto ( yaml_keys . size - 2 ) do | i | key = yaml_keys [ i ] unless current [ key ] . class == Hash current [ key ] = { } end current = current [ key ] end current [ yaml_keys . last...
Yaml representation of all blurbs
13,186
def wait_for_download if pending? logger . info 'Waiting for first download' if logger . respond_to? :flush logger . flush end while pending? sleep 0.1 end end end
Waits until the first download has finished .
13,187
def validate missing_parameters = [ ] required_fields . each do | param | missing_parameters << param . to_s unless self . send ( param ) end raise RTurk :: MissingParameters , "Parameters: '#{missing_parameters.join(', ')}'" unless missing_parameters . empty? end
More complicated validation run before request
13,188
def default_class if collection . respond_to? ( :proxy_reflection ) collection . proxy_reflection . klass elsif ! collection . empty? collection . first . class end end
Finds the class representing the objects within the collection
13,189
def undef_cell ( name ) method_name = name . gsub ( '-' , '_' ) klass = class << self ; self ; end klass . class_eval do remove_method ( method_name ) end end
Removes the definition for the given cell
13,190
def cell ( name , * args ) name = name . to_s if name options = args . last . is_a? ( Hash ) ? args . pop : { } options [ :namespace ] = table . object_name args << options cell = Cell . new ( name , * args ) cells [ name ] = cell builder . define_cell ( name ) if name cell end
Creates a new cell with the given name and generates shortcut accessors for the method .
13,191
def column ( * names ) unless @customized @customized = true clear end options = names . last . is_a? ( Hash ) ? names . pop : { } content = names . last . is_a? ( String ) ? names . pop : nil args = [ content , options ] . compact names . collect! do | name | column = row . cell ( name , * args ) column . content_type...
Creates one or more to columns in the header . This will clear any pre - existing columns if it is being customized for the first time after it was initially created .
13,192
def html html_options = @html_options . dup html_options [ :style ] = 'display: none;' if table . empty? && hide_when_empty content_tag ( tag_name , content , html_options ) end
Creates and returns the generated html for the header
13,193
def gen_request_parameters method , params params . merge! self . service . default_parameters params . merge! self . options params [ :Action ] = method . to_s params [ :Timestamp ] = Time . now . utc . iso8601 params [ :SignatureNonce ] = SecureRandom . uuid params [ :Signature ] = compute_signature params params end
generate the parameters
13,194
def compute_signature params if $DEBUG puts "keys before sorted: #{params.keys}" end sorted_keys = params . keys . sort if $DEBUG puts "keys after sorted: #{sorted_keys}" end canonicalized_query_string = "" canonicalized_query_string = sorted_keys . map { | key | "%s=%s" % [ safe_encode ( key . to_s ) , safe_encode ( p...
compute the signature of the parameters String
13,195
def calculate_signature key , string_to_sign hmac = HMAC :: SHA1 . new ( key ) hmac . update ( string_to_sign ) signature = Base64 . encode64 ( hmac . digest ) . gsub ( "\n" , '' ) if $DEBUG puts "Signature #{signature}" end signature end
calculate the signature
13,196
def encode_dump ( dump ) dump = dump . read unless dump . is_a? ( String ) enc = CharlockHolmes :: EncodingDetector . detect ( dump ) if enc [ :encoding ] != 'UTF-8' puts "Converting `#{enc[:encoding]}` to `UTF-8`" . yellow dump = CharlockHolmes :: Converter . convert dump , enc [ :encoding ] , 'UTF-8' end dump end
Force subtitles to be UTF - 8
13,197
def create ( params = { } ) fail Error , 'Create parent first' unless parent . id assoc_params = default_params . merge ( params ) add_instance ( member_class . create ( assoc_params ) ) end
Initialize a collection member and save it
13,198
def retrieve ( id ) each do | item | return item if item . id . eql? ( id ) end add_instance ( member_class . retrieve ( id ) ) end
Retrieve a collection member by its id
13,199
def parent_id? ( item ) parent . id && item . send ( foreign_key ) . eql? ( parent . id ) end
Check if parent_id is defined on item