idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
17,200 | def redefine_command ( obj , command ) cmd_block = redefine_command_block ( obj , command ) @no_option_commands << command if command . options . nil? [ command . name , command . alias ] . compact . each { | e | obj . singleton_class . send ( :define_method , e , cmd_block ) } rescue Error warn "Error: #{$!.message}" ... | Redefines an object s method with a Command of the same name . |
17,201 | def redefine_command_block ( obj , command ) object_methods ( obj ) [ command . name ] ||= begin obj . method ( command . name ) rescue NameError raise Error , "No method exists to redefine command '#{command.name}'." end lambda { | * args | Scientist . analyze ( obj , command , args ) { | args | Scientist . object_met... | The actual method which redefines a command s original method |
17,202 | def analyze ( obj , command , args , & block ) @global_options , @command , @original_args = { } , command , args . dup @args = translate_args ( obj , args ) return run_help_option ( @command ) if @global_options [ :help ] during_analyze ( & block ) rescue OptionParser :: Error , Error raise if Boson . in_shell warn "E... | Runs a command given its object and arguments |
17,203 | def formatted_usage return "" if @opt_types . empty? @opt_types . map do | opt , type | val = respond_to? ( "usage_for_#{type}" , true ) ? send ( "usage_for_#{type}" , opt ) : "#{opt}=:#{type}" "[" + val + "]" end . join ( " " ) end | Generates one - line usage of all options . |
17,204 | def print_usage_table ( options = { } ) fields = get_usage_fields options [ :fields ] fields , opts = get_fields_and_options ( fields , options ) render_table ( fields , opts , options ) end | More verbose option help in the form of a table . |
17,205 | def indifferent_hash Hash . new { | hash , key | hash [ key . to_sym ] if String === key } end | Creates a Hash with indifferent access |
17,206 | def load load_source_and_set_module module_callbacks if @module yield if block_given? detect_additions { load_commands } if load_commands? set_library_commands loaded_correctly? && ( @loaded = true ) end | Loads a library and its dependencies and returns true if library loads correctly . |
17,207 | def detect_additions ( options = { } , & block ) Util . detect ( options , & block ) . tap do | detected | @commands . concat detected [ :methods ] . map ( & :to_s ) end end | Wraps around module loading for unexpected additions |
17,208 | def load_commands @module = @module ? Util . constantize ( @module ) : Util . create_module ( Boson :: Commands , clean_name ) before_load_commands check_for_method_conflicts unless @force actual_load_commands rescue MethodConflictError => err handle_method_conflict_error err end | Prepares for command loading loads commands and rescues certain errors . |
17,209 | def deep_symbolize_keys return each_with_object ( { } ) { | memo , ( k , v ) | memo [ k . to_sym ] = v . deep_symbolize_keys } if self . is_a? ( Hash ) return each_with_object ( [ ] ) { | memo , v | memo << v . deep_symbolize_keys } if self . is_a? ( Array ) self end | Symbolizes keys of a hash |
17,210 | def ensure_description_newlines ( buffer ) return if description . empty? if description [ - 1 , 1 ] != '\n' buffer << '\n\n' elsif description . length > 1 && description [ - 2 , 1 ] != '\n' buffer << '\n' end end | Ensure the input string buffer ends with two newlines . |
17,211 | def filter_collection ( ignore_keys ) return @collection if ignore_keys . blank? @collection . select { | kv_item | ! ignore_keys . include? ( kv_item . keys . first ) } end | Filter collection keys |
17,212 | def command_objects ( names = self . commands , command_array = Boson . commands ) command_array . select { | e | names . include? ( e . name ) && e . lib == self . name } end | Command objects of library s commands |
17,213 | def create_module ( base_module , name ) desired_class = camelize ( name ) possible_suffixes = [ '' ] + %w{ 1 2 3 4 5 6 7 8 9 10 } if suffix = possible_suffixes . find { | e | ! base_module . const_defined? ( desired_class + e ) } base_module . const_set ( desired_class + suffix , Module . new ) end end | Creates a module under a given base module and possible name . If the module already exists it attempts to create one with a number appended to the name . |
17,214 | def call ( env ) request = Rack :: Request . new ( env . dup ) request . params @app . call ( env ) rescue ArgumentError => e raise unless e . message =~ / / @logger . info "Bad request. Returning 400 due to #{e.message} from " + "request with env #{request.inspect}" error_response end | Called by Rack when a request comes through |
17,215 | def connection @connection ||= Faraday . new ( conn_opts ) do | http | http . url_prefix = endpoint if @access_token http . authorization :Bearer , @access_token end end end | HTTP connection for the Particle API |
17,216 | def new_method_added ( mod , meth ) self . current_module = mod store [ :temp ] ||= { } METHODS . each do | e | store [ e ] [ meth . to_s ] = store [ :temp ] [ e ] if store [ :temp ] [ e ] end if store [ :temp ] [ :option ] ( store [ :options ] [ meth . to_s ] ||= { } ) . merge! store [ :temp ] [ :option ] end during_n... | The method_added used while scraping method attributes . |
17,217 | def parse ( args ) if args . size == 1 && args [ 0 ] . is_a? ( String ) args = Shellwords . shellwords ( args [ 0 ] ) if ! Boson . in_shell global_opt , parsed_options , args = parse_options args elsif args . size > 1 && args [ - 1 ] . is_a? ( String ) temp_args = Boson . in_shell ? args : Shellwords . shellwords ( arg... | Parses arguments and returns global options local options and leftover arguments . |
17,218 | def modify_args ( args ) if @command . default_option && @command . numerical_arg_size? && @command . arg_size <= 1 && ! args [ 0 ] . is_a? ( Hash ) && args [ 0 ] . to_s [ / / ] != '-' && ! args . join . empty? args [ 0 ] = "--#{@command.default_option}=#{args[0]}" end end | modifies args for edge cases |
17,219 | def check_argument_size ( args ) if @command . numerical_arg_size? && args . size != @command . arg_size command_size , args_size = args . size > @command . arg_size ? [ @command . arg_size , args . size ] : [ @command . arg_size - 1 , args . size - 1 ] raise CommandArgumentError , "wrong number of arguments (#{args_si... | raises CommandArgumentError if argument size is incorrect for given args |
17,220 | def add_default_args ( args , obj ) if @command . args && args . size < @command . arg_size - 1 @command . args . slice ( 0 .. - 2 ) . each_with_index { | arr , i | next if args . size >= i + 1 break if arr . size != 2 begin args [ i ] = @command . file_parsed_args ? obj . instance_eval ( arr [ 1 ] ) : arr [ 1 ] rescue... | Adds default args as original method would |
17,221 | def delete ( options = { :hard => false } ) if options [ :hard ] self . class . delete ( self . id , options ) else return if new_record? or destroyed? update_column kakurenbo_column , current_time_from_proper_timezone end end | delete record . |
17,222 | def destroy ( options = { :hard => false } ) if options [ :hard ] with_transaction_returning_status do hard_destroy_associated_records self . reload . hard_destroy end else return true if destroyed? with_transaction_returning_status do destroy_at = Time . now run_callbacks ( :destroy ) { update_column kakurenbo_column ... | destroy record and run callbacks . |
17,223 | def restore ( options = { :recursive => true } ) return false unless destroyed? with_transaction_returning_status do run_callbacks ( :restore ) do restore_associated_records if options [ :recursive ] update_column kakurenbo_column , nil self end end end | restore record . |
17,224 | def dependent_association_scopes self . class . reflect_on_all_associations . select { | reflection | reflection . options [ :dependent ] == :destroy and reflection . klass . paranoid? } . map { | reflection | self . association ( reflection . name ) . tap { | assoc | assoc . reset_scope } . scope } end | All Scope of dependent association . |
17,225 | def altitude_mode = ( mode ) allowed_modes = %w( clampToGround relativeToGround absolute ) if allowed_modes . include? ( mode ) @altitude_mode = mode else raise ArgumentError , "Must be one of the allowed altitude modes: #{allowed_modes.join(',')}" end end | Set the altitude mode |
17,226 | def render ( xm = Builder :: XmlMarkup . new ( :indent => 2 ) ) [ :name , :visibility , :address ] . each do | a | xm . __send__ ( a , self . __send__ ( a ) ) unless self . __send__ ( a ) . nil? end xm . description { xm . cdata! ( description ) } unless description . nil? xm . open ( self . open ) unless open . nil? x... | Render the object and all of its sub - elements . |
17,227 | def perform_saved_searches_actions ( context , params = { } ) get_saved_searches ( context ) save_or_update_saved_search ( params . merge ( context : context ) ) get_params_to_search ( context ) end | Perform saved searches actions to provide full functionality with one method |
17,228 | def get_params_to_search ( context ) if params [ :saved_search ] . present? @saved_search = SavedSearch . find_by ( id : params [ :saved_search ] , context : context ) end return params [ :q ] if params [ :use_search_params ] . present? params [ :q ] = @saved_search . try ( :search_params ) || params [ :q ] end | Return params of Saved Search or search form params |
17,229 | def save_or_update_saved_search ( params ) if params [ :save_new_search ] . present? || params [ :save_search ] . present? if params [ :save_new_search ] . present? @saved_search = new_saved_search ( params ) elsif params [ :save_search ] . present? && params [ :saved_search ] . present? @saved_search = update_saved_se... | Save or update Saved Search |
17,230 | def start! Sudo :: System . check @sudo_pid = spawn ( "#{SUDO_CMD} -E #{RUBY_CMD} -I#{LIBDIR} #{@ruby_opts} #{SERVER_SCRIPT} #{@socket} #{Process.uid}" ) Process . detach ( @sudo_pid ) if @sudo_pid finalizer = Finalizer . new ( pid : @sudo_pid , socket : @socket ) ObjectSpace . define_finalizer ( self , finalizer ) if ... | Start the sudo - ed Ruby process . |
17,231 | def load_gems load_paths prospective_gems . each do | prospect | gem_name = prospect . dup begin loaded = @proxy . proxy ( Kernel , :require , gem_name ) rescue LoadError , NameError => e old_gem_name = gem_name . dup gem_name . gsub! ( '-' , '/' ) retry if old_gem_name != gem_name end end end | Load needed libraries in the DRb server . Usually you don t need |
17,232 | def add ( config = { } ) config . each do | key , value | define_setting key . to_sym , value end end | = > Facilitate Dynamic Addition of Configuration Values |
17,233 | def delete ( node ) return 'Node not found on Chef Server' unless Node . exists? ( node ) admin_api_client Client . delete ( node ) Node . delete ( node ) 'Client/Node Deleted from Chef Server' end | = > Delete a Node Object |
17,234 | def run unless opts [ :action ] usage exit 255 end @config = { } if opts [ :config ] @config = YAML . load_file ( opts [ :config ] ) substitute_relative_paths! ( @config , File . dirname ( opts [ :config ] ) ) load_plugins ( @config [ "plugins" ] ) if @config . key? ( "plugins" ) end @config [ :options ] = { } opts . e... | Run method . Call this to run the octofacts updater with the object that was previously construcuted . |
17,235 | def index_file @index_file ||= begin if config . fetch ( "index" , { } ) [ "file" ] return config [ "index" ] [ "file" ] if File . file? ( config [ "index" ] [ "file" ] ) raise Errno :: ENOENT , "Index file (#{config['index']['file'].inspect}) does not exist" end raise ArgumentError , "No index file specified on comman... | Get the index file from the options or configuration file . Raise error if it does not exist or was not specified . |
17,236 | def print_or_write ( data ) if opts [ :output_file ] File . open ( opts [ :output_file ] , "w" ) { | f | f . write ( data ) } else puts data end end | Print or write to file depending on whether or not the output file was set . |
17,237 | def ensure_headers missing = missing_headers return if missing . size == 0 message = "Compilation cannot proceed as the following header files are missing:\n" + missing . join ( "\n" ) raise Error . new ( message ) end | Raises an error if there are missing headers |
17,238 | def source_files return @source_files if @source_files old_dir = Dir . pwd Dir . chdir @rakefile_path @source_files = Rake :: Path . find_files ( @source_search_paths , source_file_extension ) . uniq . sort Dir . chdir old_dir @source_files end | Source files found in source_search_paths |
17,239 | def _set_attribute_as_deprecated ( attribute ) original_attribute_method = instance_method ( attribute . to_sym ) klass = self define_method attribute . to_sym do | * args | backtrace_cleaner = ActiveSupport :: BacktraceCleaner . new backtrace = backtrace_cleaner . clean ( caller ) klass . _notify_deprecated_attribute_... | Wrap the original attribute method with appropriate notification while leaving the functionality of the original method unchanged . |
17,240 | def reindex ( facts_to_index , fixtures ) @index_data = { } facts_to_index . each { | fact | add ( fact , fixtures ) } set_top_level_nodes_fact ( fixtures ) end | Rebuild an index with a specified list of facts . This will remove any indexed facts that are not on the list of facts to use . |
17,241 | def write_file ( filename = nil ) filename ||= @filename unless filename . is_a? ( String ) raise ArgumentError , "Called write_file() for fact_index without a filename" end File . open ( filename , "w" ) { | f | f . write ( to_yaml ) } end | Write the fact index out to a YAML file . |
17,242 | def perform_async ( * args ) self . class . run_hooks_for ( :before_publish , * args ) @chore_publisher ||= self . class . options [ :publisher ] @chore_publisher . publish ( self . class . prefixed_queue_name , self . class . job_hash ( args ) ) self . class . run_hooks_for ( :after_publish , * args ) end | Use the current configured publisher to send this job into a queue . |
17,243 | def response_indicates_valid? ( response ) REXML :: Document . new ( response . body ) . root . get_elements ( '//m:validity' ) . first . text == 'true' end | The feed validator uses a different response type so we have to override these here . |
17,244 | def method_missing ( name , * args , & block ) if Octofacts :: Manipulators . run ( self , name , * args , & block ) @facts_manipulated = true return self end if facts . respond_to? ( name , false ) if args [ 0 ] . is_a? ( String ) || args [ 0 ] . is_a? ( Symbol ) args [ 0 ] = string_or_symbolized_key ( args [ 0 ] ) en... | Missing method - this is used to dispatch to manipulators or to call a Hash method in the facts . |
17,245 | def run ( argv = ARGV ) cli = Options . new cli . parse_options ( argv ) default = Config . options json_config = Util . parse_json_config ( cli . config [ :config_file ] || Config . config_file ) config = [ default , json_config , cli . config ] . compact . reduce ( :merge ) Config . setup do | cfg | cfg . config_file... | = > Launch the Application |
17,246 | def auth_by_user ( operator_id , user_name , password , endpoint ) endpoint = API_BASE_URL if endpoint . nil? res = RestClient . post endpoint + '/auth' , { operatorId : operator_id , userName : user_name , password : password } , 'Content-Type' => 'application/json' , 'Accept' => 'application/json' result = JSON . par... | authenticate by operator_id and user_name and password |
17,247 | def set_value ( new_value , name_in = nil ) if name_in . nil? if new_value . is_a? ( Proc ) return @value = new_value . call ( @value ) end return @value = new_value end parts = if name_in . is_a? ( String ) name_in . split ( "::" ) elsif name_in . is_a? ( Array ) name_in . map do | item | if item . is_a? ( String ) it... | Set the value of the fact . If the name is specified this will dig into a structured fact to set the value within the structure . |
17,248 | def set_structured_value ( subhash , parts , value ) return if subhash . nil? raise ArgumentError , "Cannot set structured value at #{parts.first.inspect}" unless subhash . is_a? ( Hash ) raise ArgumentError , "parts must be an Array, got #{parts.inspect}" unless parts . is_a? ( Array ) matching_keys = subhash . keys .... | Set a value in the data structure of a structured fact . This is intended to be called recursively . |
17,249 | def diff_dirs ( dir1 , dir2 ) mattching_dir_files ( dir1 , dir2 ) . each do | file | a = File . join ( dir1 , file ) b = File . join ( dir2 , file ) diff_files ( a , b ) end end | Recursively diff common files between dir1 and dir2 |
17,250 | def dir_files ( dir ) Find . find ( dir ) . to_a . reject! { | f | File . directory? ( f ) } end | Find all files in a given directory |
17,251 | def unique_files ( dir , dir_files , common_files ) unique = dir_files - common_files if ! unique . empty? @test_failures << yellowit ( "\nMissing from directory #{dir}:\n" ) unique . each do | f | failure = " - #{f}" failure << "\n" if unique . last == f @test_failures << failure end end end | Find files which aren t common to both directories |
17,252 | def to_yaml sorted_facts = @facts . sort . to_h facts_hash_with_expanded_values = Hash [ sorted_facts . collect { | k , v | [ k , v . value ] } ] YAML . dump ( facts_hash_with_expanded_values ) end | YAML representation of the fact fixture . |
17,253 | def covariance2 ( xs , ys ) raise "Length xs and ys must be equal" unless xs . length == ys . length ev_x , ev_y = mean ( xs ) , mean ( ys ) xs . zip ( ys ) . map { | x , y | ( x - ev_x ) * ( y - ev_y ) } . inject ( 0 ) { | sum , x | sum += x } / xs . length end | Another way to implement covariance |
17,254 | def get_file_name ( latitude , longitude ) north_south = latitude >= 0 ? 'N' : 'S' east_west = longitude >= 0 ? 'E' : 'W' lat = latitude . floor . to_i . abs . to_s . rjust ( 2 , '0' ) lon = longitude . floor . to_i . abs . to_s . rjust ( 3 , '0' ) "#{north_south}#{lat}#{east_west}#{lon}.hgt" end | Return the file name no matter if the actual SRTM file exists . |
17,255 | def get_elevation ( latitude , longitude ) if ! ( @latitude <= latitude && latitude < @latitude + 1 ) raise "Invalid latitude #{latitude} for file #{@file_name}" end if ! ( @longitude <= longitude && longitude < @longitude + 1 ) raise "Invalid longitude #{longitude} for file #{@file_name}" end row , column = get_row_an... | If approximate is True then only the points from SRTM grid will be used otherwise a basic aproximation of nearby points will be calculated . |
17,256 | def get_value_at_file_position ( position ) @file . seek ( 4 + position * 4 ) bytes = @file . read ( 4 ) begin value = bytes [ 0 ] . ord * 256 ** 0 + bytes [ 1 ] . ord * 256 ** 1 + bytes [ 2 ] . ord * 256 ** 2 + bytes [ 3 ] . ord * 256 ** 3 result = unpack ( value ) rescue result = 0 end result end | Loads a value from the n - th position in the EGM file . Every position is a 4 - byte real number . |
17,257 | def unpack ( n ) sign = n >> 31 exponent = ( n >> ( 32 - 9 ) ) & 0b11111111 value = n & 0b11111111111111111111111 resul = nil if 1 <= exponent and exponent <= 254 result = ( - 1 ) ** sign * ( 1 + value * 2 ** ( - 23 ) ) * 2 ** ( exponent - 127 ) elsif exponent == 0 result = ( - 1 ) ** sign * value * 2 ** ( - 23 ) * 2 *... | Unpacks a number from the EGM file |
17,258 | def add_state ( node , user , params ) ( n = { } ) && ( n [ :name ] = node ) n [ :created ] = DateTime . now n [ :creator ] = user n [ :type ] = params [ 'type' ] if params [ 'type' ] update_state ( n ) find_state ( node ) end | = > Add Node to the State |
17,259 | def delete_state ( node ) existing = find_state ( node ) return 'Node not present in state' unless existing state . delete ( existing ) write_state existing end | = > Remove Node from the State |
17,260 | def replace_character ( string , & block ) string . gsub ( character_pattern ) do | character | block . call ( find_by_character ( character ) , character ) end end | Replaces emoji characters in a given string with a given block result |
17,261 | def replace_code ( string , & block ) string . gsub ( code_pattern ) do | matched_string | block . call ( find_by_code ( :: Regexp . last_match ( 1 ) ) , matched_string ) end end | Replaces emoji codes in a given string with a given block result |
17,262 | def search_by_code ( pattern ) self . class . new ( select do | emoji | pattern === emoji . code || emoji . aliases . any? do | alias_code | pattern === alias_code end end ) end | Searches emojis that match with given pattern |
17,263 | def inject ( object ) trip . object = object object . send :scorpion_hunt= , self object . injected_attributes . each do | attr | next if object . send "#{ attr.name }?" next if attr . lazy? object . send :inject_dependency , attr , fetch ( attr . contract ) end object . send :on_injected object end | Inject given object with its expected dependencies . |
17,264 | def define_attribute ( name , contract , ** options ) attributes [ name . to_sym ] = Attribute . new name , contract , options end | Define a single attribute with the given name that expects food that will satisfy the contract . |
17,265 | def plugins_map ( type ) @plugins_map ||= { } type = type . to_s @plugins_map [ type ] ||= Hash [ @plugins [ type ] . map do | plugin | [ class2name ( plugin ) , plugin ] end ] end | provide extra map of plugins with symbolized names as keys |
17,266 | def run! ( runtime_config = { } ) @websocket_config . merge! runtime_config EM . run do if @websocket_config [ :tick_interval ] EM . add_periodic_timer ( @websocket_config [ :tick_interval ] ) do socket_trigger ( :on_tick , @socket_connected ) end end EventMachine :: WebSocket . run ( host : @websocket_config [ :socket... | start the socket server and the web server and launch a browser to fetch the view from the web server |
17,267 | def first_class! ( type , klass ) @plugins [ type ] or raise Pluginator :: MissingType . new ( type , @plugins . keys ) klass = string2class ( klass ) plugins_map ( type ) [ klass ] or raise Pluginator :: MissingPlugin . new ( type , klass , plugins_map ( type ) . keys ) end | Find first plugin whose class matches the given name . Behaves like first_class but throws exceptions if can not find anything . |
17,268 | def process_response response without_root = response . body . values . first case when without_root . is_a? ( Array ) then process_array ( response , without_root ) when without_root . is_a? ( Hash ) then from_response ( response , without_root ) else without_root end end | Removes the root from the response and hands it off to the class to process it Processes an array response by delegating to the includer s self . from_response |
17,269 | def inject_from ( dependencies , overwrite = false ) injected_attributes . each do | attr | next unless dependencies . key? attr . name if overwrite || ! send ( "#{ attr.name }?" ) send ( "#{ attr.name }=" , dependencies [ attr . name ] ) end end dependencies end | Feed dependencies from a hash into their associated attributes . |
17,270 | def inject_from! ( dependencies , overwrite = false ) injected_attributes . each do | attr | next unless dependencies . key? attr . name val = dependencies . delete ( attr . name ) if overwrite || ! send ( "#{ attr.name }?" ) send ( "#{ attr.name }=" , val ) end end dependencies end | Injects dependenices from the hash and removes them from the hash . |
17,271 | def method_missing mtd , * args if mtd . to_s . chars . to_a . last == '=' raise ArgumentError , "Invalid number of arguments (#{args.length} for 1)" if args . length != 1 attributes [ mtd . to_s . slice ( 0 , mtd . to_s . length - 1 ) ] = args . first else raise ArgumentError , "Invalid number of arguments (#{args.len... | Allows method - style access to the attributes . |
17,272 | def run_on_change ( callback , mv_change = 10 , interval = 0.01 , repeats = nil ) AIN :: run_on_change ( callback , @pin , mv_change , interval , repeats ) end | Runs a callback after voltage changes by specified amount . This creates a new thread that runs in the background and polls at specified interval . |
17,273 | def run_on_threshold ( callback , mv_lower , mv_upper , mv_reset = 10 , interval = 0.01 , repeats = nil ) AIN :: run_on_threshold ( callback , @pin , mv_lower , mv_upper , mv_reset , interval , repeats ) end | Runs a callback after voltage changes beyond a certain threshold . This creates a new thread that runs in the background and polls at specified interval . When the voltage crosses the specified thresholds the callback is run . |
17,274 | def run_once_on_threshold ( callback , mv_lower , mv_upper , mv_reset = 10 , interval = 0.01 ) AIN :: run_once_on_threshold ( callback , @pin , mv_lower , mv_upper , mv_reset , interval ) end | Runs a callback once after voltage crosses a specified threshold . Convenience method for run_on_threshold |
17,275 | def validate ( context_name = default_validation_context ) errors . clear validation_violations ( context_name ) . each { | v | errors . add ( v ) } self end | Command a resource to populate its ViolationSet with any violations of its validation Rules in + context_name + |
17,276 | def register_plugin ( type , klass ) type = type . to_s @plugins [ type ] ||= [ ] @plugins [ type ] . push ( klass ) unless @plugins [ type ] . include? ( klass ) end | Register a new plugin can be used to load custom plugins |
17,277 | def find_dependency ( hunt ) dependency = dependency_map . find ( hunt . contract ) dependency ||= parent . find_dependency ( hunt ) if parent dependency end | Find any explicitly defined dependencies that can satisfy the hunt . |
17,278 | def first_ask! ( type , method_name , * params ) @plugins [ type ] or raise Pluginator :: MissingType . new ( type , @plugins . keys ) try_to_find ( type , method_name , params ) or raise Pluginator :: MissingPlugin . new ( type , "first_ask: #{method_name}" , plugins_map ( type ) . keys ) end | Call a method on plugin and return first one that returns true . Behaves like first_ask but throws exceptions if can not find anything . |
17,279 | def run_on_edge ( callback , edge , timeout = nil , repeats = nil ) GPIO :: run_on_edge ( callback , @pin , edge , timeout , repeats ) end | Runs a callback on an edge trigger event . This creates a new thread that runs in the background |
17,280 | def default_resource_name result = self . to_s . split ( "::" ) . last . gsub ( / / , '_\1' ) . downcase result . slice 1 , result . length end | Default Resource Name |
17,281 | def offset_simple ( offsets ) raise ArgumentError . new ( "offsets should have ndims elements" ) unless offsets . size == ndims basic_offset_simple ( @id , offsets . ffi_mem_pointer_hsize_t ) end | Set the offset of the dataspace . offsets should be an ndims - sized array of zero - based integer offsets . |
17,282 | def api_token_header ( options , path = nil ) return nil if path == '/j_security_check' unless @api_token fail Error :: MissingCredentials , 'Please set a api_token for user' end options [ :headers ] = { } if options [ :headers ] . nil? options [ :headers ] . merge! ( 'X-Rundeck-Auth-Token' => @api_token ) end | Sets a PRIVATE - TOKEN header for requests . |
17,283 | def name2class ( name ) klass = Kernel name . to_s . split ( %r{ } ) . each do | part | klass = klass . const_get ( part . capitalize . gsub ( / / ) { | match | match [ 1 ] . upcase } ) end klass end | full_name = > class |
17,284 | def sting! ( object ) return object unless scorpion if object assign_scorpion object assign_scorpion_to_enumerable object end object end | Sting an object so that it will be injected with the scorpion and use it to resolve all dependencies . |
17,285 | def matching ( type , list ) list . map do | plugin | ( plugins_map ( type ) || { } ) [ string2class ( plugin ) ] end end | Map array of names to available plugins . |
17,286 | def matching! ( type , list ) @plugins [ type ] or raise Pluginator :: MissingType . new ( type , @plugins . keys ) list . map do | plugin | plugin = string2class ( plugin ) plugins_map ( type ) [ plugin ] or raise Pluginator :: MissingPlugin . new ( type , plugin , plugins_map ( type ) . keys ) end end | Map array of names to available plugins . Behaves like matching but throws exceptions if can not find anything . |
17,287 | def objectify ( result ) if result . is_a? ( Hash ) ObjectifiedHash . new ( result ) elsif result . is_a? ( Array ) result . map { | e | ObjectifiedHash . new ( e ) } elsif result . nil? nil else fail Error :: Parsing , "Couldn't parse a response body" end end | Turn a hash into an object for easy accessibility . |
17,288 | def convert object return { resource_name => object } if object . is_a? Hash { resource_name => object . to_hash } end | Converts a resource object to a hash . |
17,289 | def sort self . records . sort! do | x , y | comp = x [ :request ] [ :symbolized_path ] <=> y [ :request ] [ :symbolized_path ] comp . zero? ? ( x [ :title ] <=> y [ :title ] ) : comp end end | sorts records alphabetically |
17,290 | def read_response_headers ( response ) raw_headers = response . headers headers = { } EXCLUDE_RESPONSE_HEADER_PATTERNS . each do | pattern | raw_headers = raw_headers . reject { | h | h if h . starts_with? pattern } end raw_headers . each do | key , val | headers . merge! ( cleanup_header ( key ) => val ) end headers e... | read and cleanup response headers returns Hash |
17,291 | def get_symbolized_path ( request ) request_path = ( request . env [ 'REQUEST_URI' ] || request . path ) . dup request_params = request . env [ 'action_dispatch.request.parameters' ] || request . env [ 'rack.request.form_hash' ] || request . env [ 'rack.request.query_hash' ] if request_params request_params . except ( ... | replace each first occurrence of param s value in the request path |
17,292 | def capture ( contract , ** options , & builder ) active_dependency_set . unshift Dependency :: CapturedDependency . new ( define_dependency ( contract , options , & builder ) ) end | Captures a single dependency and returns the same instance fore each request for the resource . |
17,293 | def replicate_from ( other_map ) other_map . each do | dependency | if replica = dependency . replicate dependency_set << replica end end self end | Replicates the dependency in other_map into this map . |
17,294 | def xfer ( tx_data , readbytes = 0 , speed = nil , delay = nil , bpw = nil ) SPI :: xfer ( @spi , tx_data , readbytes , speed , delay , bpw ) end | Initialize an SPI device . Returns an SPIDevice object |
17,295 | def options VALID_OPTIONS_KEYS . reduce ( { } ) do | option , key | option . merge! ( key => send ( key ) ) end end | Creates a hash of options and their values . |
17,296 | def check_replies _path_url = '/v1/replies' _query_builder = Configuration . base_uri . dup _query_builder << _path_url _query_url = APIHelper . clean_url _query_builder _headers = { 'accept' => 'application/json' } _request = @http_client . get ( _query_url , headers : _headers ) AuthManager . apply ( _request , _path... | Check for any replies that have been received . Replies are messages that have been sent from a handset in response to a message sent by an application or messages that have been sent from a handset to a inbound number associated with an account known as a dedicated inbound number ( contact <support |
17,297 | def heartrate_time_series ( start_date : nil , end_date : nil , period : nil ) warn '[DEPRECATION] `heartrate_time_series` is deprecated. Please use `hr_series_for_date_range` or `hr_series_for_period` instead.' regular_time_series_guard ( start_date : start_date , end_date : end_date , period : period ) second = peri... | retrieve heartrate time series |
17,298 | def intraday_heartrate_time_series ( start_date : nil , end_date : nil , detail_level : nil , start_time : nil , end_time : nil ) intraday_series_guard ( start_date : start_date , end_date : end_date , detail_level : detail_level , start_time : start_time , end_time : end_time ) end_date = format_date ( end_date ) || '... | retrieve intraday series for heartrate |
17,299 | def execute_as_string ( http_request ) response = @connection . send ( http_request . http_method . downcase , http_request . query_url ) do | request | request . headers = http_request . headers unless http_request . parameters . empty? request . body = http_request . parameters end end convert_response ( response ) e... | The constructor . Method overridden from HttpClient . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.