idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
23,200 | def delete ( key ) request_data = { :key => key } . to_json request = prepare_request :DELETE , request_data Response . new ( execute_request ( request ) ) end | Delete data at a given SAM key |
23,201 | def get ( key , expected_checksum = nil ) request_data = { :key => key } . to_json request = prepare_request :GET , request_data response = execute_request ( request ) verify_checksum ( response [ "data" ] , expected_checksum ) unless expected_checksum . nil? Response . new ( response ) end | Recover data stored at a given SAM key |
23,202 | def get_file ( key , type = :file , expected_checksum = nil ) response = get ( key , expected_checksum ) response = Response . new ( 'key' => response . key , 'checksum' => response . checksum , 'filename' => response . data [ 'filename' ] , 'file' => Base64 . decode64 ( response . data [ type . to_s ] ) , 'deleted' => response . deleted? ) end | Recover a file stored at a given SAM key |
23,203 | def update ( key , value ) request_data = { :key => key , :value => value } request_data [ :expire ] = @expire if @expire request = prepare_request :PUT , request_data . to_json Response . new ( execute_request ( request ) ) end | Update data stored at a given SAM key |
23,204 | def update_file ( key , type = :file , new_content , filename ) encoded = Base64 . encode64 ( new_content ) update ( key , type => encoded , filename : filename ) end | Update file stored at a given SAM key |
23,205 | def configure ( * ) if options [ :help ] invoke :help , [ 'configure' ] else require_relative 'commands/configure' RubyEdit :: Commands :: Configure . new ( options ) . execute end end | Set and view configuration options |
23,206 | def call! ( env ) if ( request = Request . new ( env ) ) . for_asset_file? Response . new ( env , request . asset_file ) . to_rack else @app . call ( env ) end end | The real Rack call interface . if an asset file is being requested this is an endpoint - otherwise call on up to the app as normal |
23,207 | def find_all ( short , options = { } ) return to_enum ( :find_all , short , options ) unless block_given? short = :: Pathname . new ( short ) options = DEFAULT_FIND_OPTIONS . merge ( options ) @paths . reverse . each do | path | joined = path_join ( path , short , options ) yield joined if ( options [ :file ] && joined . file? ) || joined . exist? end nil end | Finds all versions of the short path name in the paths in the path sets . If no block is given it returns an enumerable ; otherwise if a block is given it yields the joined path if it exists . |
23,208 | def get_compiled_file_content ( path ) begin Tilt . new ( path . to_s ) . render ( { } , { :spec => spec } ) rescue RuntimeError File . read ( path ) end end | Given a path run it through tilt and return the compiled version . If there s no known engine for it just return the content verbatim . If we know the type buy are missing the gem raise an exception . |
23,209 | def simple_compile_directory ( directory ) if directory . is_a? ( String ) from_directory = ( directory [ / \/ / ] ? '' : 'src/' ) + directory directory = { :from => from_directory , :as => directory } end directory [ :use_tilt ] |= true Dir [ @base_dir . join ( directory [ :from ] , '**/*' ) ] . each do | path | file_in_path = Pathname . new ( path ) next unless file_in_path . file? file_out_path = remap_path_to_build_directory ( path , directory ) if directory [ :use_tilt ] content = get_compiled_file_content ( file_in_path ) file_out_path = asset_output_filename ( file_out_path , Tilt . mappings . keys ) else content = File . read ( file_in_path ) end FileUtils . mkdir_p ( file_out_path . dirname ) File . open ( file_out_path , 'w' ) do | f | f . write content end end end | Copy all the files from a directory to the output compiling them if they are familiar to us . Does not do any sprocketing . |
23,210 | def compile_files ( files ) files . each do | base_path | Dir [ @base_dir . join ( 'src' , base_path + '*' ) ] . each do | path | path = Pathname . new ( path ) . relative_path_from ( @base_dir . join ( 'src' ) ) file_in_path = @base_dir . join ( 'src' , path ) file_out_path = asset_output_filename ( @output_dir . join ( path ) , @sprockets . engines . keys ) if @sprockets . extensions . include? ( path . extname ) content = @sprockets [ file_in_path ] . to_s else content = File . read ( file_in_path ) end FileUtils . mkdir_p ( file_out_path . dirname ) File . open ( file_out_path , 'w' ) do | f | f . write content end end end end | Process all the files in the directory through sprockets before writing them to the output directory |
23,211 | def write_manifest generator = ManifestGenerator . new ( spec ) File . open ( @output_dir . join ( 'manifest.json' ) , 'w' ) do | f | f . write JSON . pretty_generate ( generator . spec_as_json ) end end | Generate the manifest from the spec and write it to disk |
23,212 | def create_sprockets_environment @sprockets = Sprockets :: Environment . new @sprockets . append_path ( @base_dir . join ( 'src/javascripts' ) . to_s ) @sprockets . append_path ( @base_dir . join ( 'src/templates' ) . to_s ) @sprockets . append_path ( @base_dir . join ( 'src/stylesheets' ) . to_s ) @sprockets . append_path ( @base_dir . join ( 'src' ) . to_s ) @sprockets . append_path ( @base_dir . to_s ) end | Set up the sprockets environment for munging all the things |
23,213 | def deliver ( jid , message , type = :chat ) contacts ( jid ) do | friend | unless subscribed_to? friend add ( friend . jid ) return deliver_deferred ( friend . jid , message , type ) end if message . kind_of? ( Jabber :: Message ) msg = message msg . to = friend . jid else msg = Message . new ( friend . jid ) msg . type = type msg . body = message end send! ( msg ) end end | Send a message to jabber user jid . |
23,214 | def status ( presence , message ) @presence = presence @status_message = message stat_msg = Presence . new ( @presence , @status_message ) send! ( stat_msg ) end | Set your presence with a message . |
23,215 | def send! ( msg ) attempts = 0 begin attempts += 1 client . send ( msg ) rescue Errno :: EPIPE , IOError => e sleep 1 disconnect reconnect retry unless attempts > 3 raise e rescue Errno :: ECONNRESET => e sleep ( attempts ^ 2 ) * 60 + 60 disconnect reconnect retry unless attempts > 3 raise e end end | Send a Jabber stanza over - the - wire . |
23,216 | def deliver_deferred ( jid , message , type ) msg = { :to => jid , :message => message , :type => type } queue ( :pending_messages ) << [ msg ] end | Queue messages for delivery once a user has accepted our authorization request . Works in conjunction with the deferred delivery thread . |
23,217 | def start_deferred_delivery_thread Thread . new { loop { messages = [ queue ( :pending_messages ) . pop ] . flatten messages . each do | message | if subscribed_to? ( message [ :to ] ) deliver ( message [ :to ] , message [ :message ] , message [ :type ] ) else queue ( :pending_messages ) << message end end } } end | This thread facilitates the delivery of messages to users who haven t yet accepted an invitation from us . When we attempt to deliver a message if the user hasn t subscribed we place the message in a queue for later delivery . Once a user has accepted our authorization request we deliver any messages that have been queued up in the meantime . |
23,218 | def create ( options ) status , body = key_create ( options ) if status save_message ( 'Key' : [ 'created!' ] ) true else save_message ( body ) false end end | Creates a new key on the local client |
23,219 | def key_create ( options ) ssh_key = key_generation ( options ) ssh_private_key_file = options [ :private_key ] ssh_public_key_file = "#{ssh_private_key_file}.pub" File . write ( ssh_private_key_file , ssh_key . private_key ) File . chmod ( 0o600 , ssh_private_key_file ) File . write ( ssh_public_key_file , ssh_key . ssh_public_key ) File . chmod ( 0o600 , ssh_public_key_file ) [ true , 'Key' : [ 'creation failed' ] ] end | Sends a post request with json from the command line key |
23,220 | def key_generation ( options ) SSHKey . generate ( type : options [ :type ] , bits : options [ :bits ] , comment : 'ssh@fenton_shell' , passphrase : options [ :passphrase ] ) end | Generates the SSH key pair |
23,221 | def metadata log "retrieving containers metadata from #{storage_path}" response = storage_client . head ( storage_path ) { :containers => response [ "X-Account-Container-Count" ] . to_i , :objects => response [ "X-Account-Object-Count" ] . to_i , :bytes => response [ "X-Account-Bytes-Used" ] . to_i } end | Return metadata on all containers |
23,222 | def setctxopt name , value length = 4 pointer = LibC . malloc length pointer . write_int value rc = LibXS . xs_setctxopt @context , name , pointer , length LibC . free ( pointer ) unless pointer . nil? || pointer . null? rc end | Initialize context object Sets options on a context . |
23,223 | def socket type sock = nil begin sock = Socket . new @context , type rescue ContextError => e sock = nil end sock end | Allocates a socket for context |
23,224 | def publish publisher . publish ( 'instance' , added : info ) do | redis | redis . setex "instance_#{ @id }" , Attention . options [ :ttl ] , JSON . dump ( info ) end heartbeat end | Creates an Instance |
23,225 | def given_a ( factory_name , args = { } ) Given "a #{factory_name} #{humanize args}" do args . each do | key , value | if value . is_a? Symbol instance_var_named_value = instance_variable_get ( "@#{value}" ) args [ key ] = instance_var_named_value if instance_var_named_value end end model = Factory ( factory_name . to_sym , args ) instance_variable_set ( "@#{factory_name}" , model ) end end | Creates an object using a factory_girl factory and creates a Given step that reads like Given a gi_joe with a name of Blowtorch and habit of swearing |
23,226 | def setup_notification_categories templates = Octo . get_config ( :push_templates ) if templates templates . each do | t | args = { enterprise_id : self . _id , category_type : t [ :name ] , template_text : t [ :text ] , active : true } Octo :: Template . new ( args ) . save! end Octo . logger . info ( "Created templates for Enterprise: #{ self.name }" ) end end | Setup the notification categories for the enterprise |
23,227 | def setup_intelligent_segments segments = Octo . get_config ( :intelligent_segments ) if segments segments . each do | seg | args = { enterprise_id : self . _id , name : seg [ :name ] , type : seg [ :type ] . constantize , dimensions : seg [ :dimensions ] . collect ( & :constantize ) , operators : seg [ :operators ] . collect ( & :constantize ) , values : seg [ :values ] . collect ( & :constantize ) , active : true , intelligence : true , } Octo :: Segment . new ( args ) . save! end Octo . logger . info "Created segents for Enterprise: #{ self.name }" end end | Setup the intelligent segments for the enterprise |
23,228 | def forgot_password klass = params [ :type ] || 'FastExt::MPerson' @user = klass . constantize . where ( username : params [ :username ] ) random_password = Array . new ( 10 ) . map { ( 65 + rand ( 58 ) ) . chr } . join @user . password = random_password @user . save! end | assign them a random one and mail it to them asking them to change it |
23,229 | def except ( * keys ) self . reject { | k , v | keys . include? ( k || k . to_sym ) } end | Filter keys out of a Hash . |
23,230 | def only ( * keys ) self . reject { | k , v | ! keys . include? ( k || k . to_sym ) } end | Returns a Hash with only the pairs identified by + keys + . |
23,231 | def build ( which = :all ) return to_enum ( :build , which ) unless block_given? select_forms ( which ) . each { | f | yield proc { f . build ( self ) } } end | Given a set of forms to build it yields blocks that can be called to build a form . |
23,232 | def roots @_roots ||= :: Hash . new do | h , k | h [ k ] = nil h [ k ] = parse_from ( k ) end end | A cache for all of the root nodes . This is a regular hash ; however upon attempt to access an item that isn t already in the hash it first parses the file at that item and stores the result in the hash returning the root node in the file . This is to cache files so that they do not get reparsed multiple times . |
23,233 | def parse_from ( path , short = path . relative_path_from ( root ) ) contents = path . read digest = Digest :: SHA2 . digest ( contents ) cache . fetch ( digest ) do scanner = Scanner . new ( contents , short , options ) parser = Parser . new ( scanner . call ) parser . call . tap { | r | cache [ digest ] = r } end end | Parses a file . This bypasses the filename cache . |
23,234 | def execute ( * bind_values ) t = Time . now @executor . execute ( * bind_values ) . tap do | rs | rs . info [ :execution_time ] ||= Time . now - t if logger . debug? logger . debug ( "(%.6f) %s %s" % [ rs . execution_time , command , ( "<Bind: #{bind_values.inspect}>" unless bind_values . empty? ) ] ) end end rescue RDO :: Exception => e logger . fatal ( e . message ) if logger . fatal? raise end | Initialize a new Statement wrapping the given StatementExecutor . |
23,235 | def attributes attrs = { } attribute_names . each { | name | attrs [ name ] = read_attribute ( name ) } attrs end | Returns a hash of all the attributes with their names as keys and the values of the attributes as values . |
23,236 | def EQL? ( sample ) @it . eql? ( sample ) && sample . eql? ( @it ) && ( @it . hash == sample . hash ) && ( { @it => true } . has_key? sample ) end | true if can use for hash - key |
23,237 | def CATCH ( exception_klass , & block ) block . call rescue :: Exception if $! . instance_of? exception_klass pass else failure ( "Faced a exception, that instance of #{exception_klass}." , "Faced a exception, that instance of #{$!.class}." , 2 ) end else failure ( "Faced a exception, that instance of #{exception_klass}." , 'The block was not faced any exceptions.' , 2 ) ensure _declared! end | pass if occured the error is just a own instance |
23,238 | def process_push factory = "::#{object_type}" . constantize local_object = factory . find ( object_local_id ) syncer = factory . synchronizer syncer . push_object ( local_object ) self . state = 'done' self . save end | Processes queued item of type push |
23,239 | def process_pull factory = "::#{object_type}" . constantize syncer = factory . synchronizer syncer . pull_object ( self . object_remote_id ) self . state = 'done' self . save end | Processes queued item of type pull |
23,240 | def attribute ( name , type = Object ) name = name . to_sym raise NameError , "attribute `#{name}` already created" if members . include? ( name ) raise TypeError , "second argument, type, must be a Class but got `#{type.inspect}` insted" unless type . is_a? ( Class ) raise TypeError , "directly converting to Bignum is not supported, use Integer instead" if type == Bignum new_attribute ( name , type ) end | Create attribute accesors for the included class Also validations and coercions for the type specified |
23,241 | def new_attribute ( name , type ) attributes [ name ] = type define_attr_reader ( name ) define_attr_writer ( name , type ) name end | Add new attribute for the tiny object modeled |
23,242 | def define_attr_writer ( name , type ) define_method ( "#{name}=" ) do | value | unless value . kind_of? ( type ) value = coerce ( value , to : type ) unless value . kind_of? ( type ) raise TypeError , "Attribute `#{name}` only accepts `#{type}` but got `#{value}`:`#{value.class}` instead" end end instance_variable_set ( "@#{name}" , value ) end end | Define attr_writer method for the new attribute with the added feature of validations and coercions . |
23,243 | def validate! logger . debug "Starting validation for #{description}" raise NotFound . new name , connection unless exists? logger . info "Successfully validated #{description}" self end | Initializes a new VirtualMachine for a connection and name |
23,244 | def execute! ( command , options ) arguments = [ command , name , * arguments_for ( command ) ] arguments << "--color" if options [ :color ] if options [ :provider ] arguments << "--provider" arguments << options [ :provider ] end if options [ :log_mode ] arguments << { :mode => options [ :log_mode ] } end block = options [ :log ] ? shell_log_block : nil connection . execute! * arguments , & block end | Executes a command on the connection for this VM |
23,245 | def total_coverage return 0.0 if lines . size . zero? ran_lines . size . to_f / lines . size . to_f end | Gives a real number between 0 and 1 indicating how many lines have been executed . |
23,246 | def code_coverage return 0.0 if code_lines . size . zero? ran_lines . size . to_f / code_lines . size . to_f end | Gives a real number between 0 and 1 indicating how many lines of code have been executed . It ignores all lines that can not be executed such as comments . |
23,247 | def []= ( key , value ) if StackableFlash . stacking super ( key , StackableFlash :: FlashStack . new . replace ( value . kind_of? ( Array ) ? value : Array . new ( 1 , value ) ) ) else super ( key , value ) end end | Make an array at the key while providing a seamless upgrade to existing flashes |
23,248 | def add ( severity , message = nil , progname = nil , & block ) return if @level > severity message = ( message || ( block && block . call ) || progname ) . to_s message = formatter . call ( formatter . number_to_severity ( severity ) , Time . now . utc , progname , message ) message = "#{message}\n" unless message [ - 1 ] == ?\n buffer << message auto_flush message end | We need to overload the add method . Basibally it is the same as the original one but we add our own log format to it . |
23,249 | def load_chunk ( client , idx , cache , orig_last_modified ) url = generate_loader_url ( idx , orig_last_modified ) feed = client . get ( url ) . to_xml feed . elements . each ( 'entry' ) do | entry | process_entry ( cache , entry ) end feed . elements . count end | Load the next chuck of data from GMail into the cache . |
23,250 | def process_entry ( cache , entry ) gmail_id = entry . elements [ 'id' ] . text if entry . elements [ 'gd:deleted' ] cache . delete ( gmail_id ) else addrs = [ ] entry . each_element ( 'gd:email' ) { | a | addrs << a . attributes [ 'address' ] } cache . update ( gmail_id , entry . elements [ 'title' ] . text || '' , addrs ) end end | Process a Gmail contact updating the cache appropriately . |
23,251 | def generate_loader_url ( idx , cache_last_modified ) url = "https://www.google.com/m8/feeds/contacts/#{@user}/thin" url += '?orderby=lastmodified' url += '&showdeleted=true' url += "&max-results=#{@fetch_size}" url += "&start-index=#{idx}" if cache_last_modified url += "&updated-min=#{CGI.escape(cache_last_modified)}" end url end | Generate the URL to retrieve the next chunk of data from GMail . |
23,252 | def walk ( mode = :pre , & block ) raise ArgumentError , "Unknown walk mode #{mode.inspect}. Use either :pre, :post or :leaves" unless MODES . include? mode return to_enum ( :walk , mode ) unless block case ( mode ) when :pre then walk_pre ( & block ) when :post then walk_post ( & block ) when :leaves then walk_leaves ( & block ) end end | works like each but recursive |
23,253 | def verify_callback ( _ , cert ) pem = cert . current_cert . public_key . to_pem sha256 = OpenSSL :: Digest :: SHA256 . new hash = sha256 . digest ( pem ) . unpack ( "H*" ) hash [ 0 ] . casecmp ( @hash ) . zero? end | Connect to the server OpenSSL verify callback used by initialize when optional callback argument isn t set . |
23,254 | def login_with_token ( bot , name , token ) send Common :: Login . new ( bot , name , nil , token ) end | Sends the login packet with specific token . Read the result with read . |
23,255 | def send ( packet ) id = Common . packet_to_id ( packet ) data = [ id , [ packet . to_a ] ] . to_msgpack @stream . write Common . encode_u16 ( data . length ) @stream . write data end | Transmit a packet over the connection |
23,256 | def read ( ) size_a = @stream . read 2 size = Common . decode_u16 ( size_a ) data = @stream . read size data = MessagePack . unpack data class_ = Common . packet_from_id data [ 0 ] class_ . new * data [ 1 ] [ 0 ] end | Read a packet from the connection |
23,257 | def create ( store_data ) auth_by_platform_token! response = self . class . post ( '/stores' , { body : store_data . to_json } ) data = JSON . parse ( response . body ) rescue nil { status : response . code , data : data , } end | Call create store api |
23,258 | def push_order ( order_data ) body = Utils . build_push_order_data ( order_data ) auth_by_store_token! response = self . class . post ( "/stores/#{Config.store_id}/orders" , { body : body . to_json } ) data = JSON . parse ( response . body ) rescue nil { status : response . code , data : data } end | Call order api |
23,259 | def load_store ( url ) auth_by_platform_token! response = self . class . get ( "/stores" , { query : { url : url } } ) data = JSON . parse ( response . body ) rescue nil { status : response . code , data : data , } end | Call store lookup api |
23,260 | def calculate_averages ( results ) Array . new ( results . first . size ) do | require_number | samples = results . map { | r | r [ require_number ] } first_sample = samples . first average = initialize_average_with_copied_fields ( first_sample ) AVERAGED_FIELDS . map do | field | next unless first_sample . key? ( field ) average [ field ] = calculate_average ( samples . map { | s | s [ field ] } ) end average end end | Take corresponding results array values and compare them |
23,261 | def md_el ( node_type , children = [ ] , meta = { } , al = nil ) if ( e = children . first ) . kind_of? ( MDElement ) and e . node_type == :ial then if al al += e . ial else al = e . ial end children . shift end e = MDElement . new ( node_type , children , meta , al ) e . doc = @doc return e end | if the first is a md_ial it is used as such |
23,262 | def find_root_with_flag ( flag , default = nil ) root_path = self . called_from [ 0 ] while root_path && :: File . directory? ( root_path ) && ! :: File . exist? ( "#{root_path}/#{flag}" ) parent = :: File . dirname ( root_path ) root_path = parent != root_path && parent end root = :: File . exist? ( "#{root_path}/#{flag}" ) ? root_path : default raise "Could not find root path for #{self}" unless root RbConfig :: CONFIG [ 'host_os' ] =~ / / ? Pathname . new ( root ) . expand_path : Pathname . new ( root ) . realpath end | i steal this from rails |
23,263 | def ilabel ( object_name , method , content_or_options = nil , options = nil , & block ) options ||= { } content_is_options = content_or_options . is_a? ( Hash ) if content_is_options || block_given? options . merge! ( content_or_options ) if content_is_options text = nil else text = content_or_options end ActionView :: Helpers :: InstanceTag . new ( object_name , method , self , options . delete ( :object ) ) . to_ilabel_tag ( text , options , & block ) end | module_eval << - EOV |
23,264 | def get_private_channel ( user ) @users . keys . map { | channel | @channels [ channel ] } . compact . find { | channel | channel . private } end | Search for a private channel with user |
23,265 | def get_recipient_unchecked ( channel_id ) @users . values . find { | user | user . modes . keys . any { | channel | channel == channel_id } } end | Search for the recipient in a private channel . If the channel isn t private it returns the first user it can find that has a special mode in that channel . So you should probably make sure it s private first . |
23,266 | def _init_requester if circuit_breaker_enabled? @_requester = Utils :: CircuitBreaker . new ( threshold : error_threshold , retry_period : retry_period ) { | * args | _request ( * args ) } @_requester . on_open do logger . error ( "circuit opened for #{name}" ) end @_requester . on_close do logger . info ( "circuit closed for #{name}" ) end else @_requester = proc { | * args | _request ( * args ) } end end | Sets up the circuit breaker for making requests to the service . |
23,267 | def _request ( verb , path , params ) Rester . wrap_request do Rester . request_info [ :producer_name ] = name Rester . request_info [ :path ] = path Rester . request_info [ :verb ] = verb logger . info ( 'sending request' ) _set_default_headers start_time = Time . now . to_f begin response = adapter . request ( verb , path , params ) _process_response ( start_time , verb , path , * response ) rescue Errors :: TimeoutError logger . error ( 'timed out' ) raise end end end | Add a correlation ID to the header and send the request to the adapter |
23,268 | def parse ( file_path ) require 'nokogiri' @doc = Nokogiri :: XML ( File . open ( file_path ) ) @total_count = @doc . xpath ( '//testsuite' ) . map { | x | x . attr ( 'tests' ) . to_i } . inject ( 0 ) { | sum , x | sum + x } @skipped_count = @doc . xpath ( '//testsuite' ) . map { | x | x . attr ( 'skipped' ) . to_i } . inject ( 0 ) { | sum , x | sum + x } @executed_count = @total_count - @skipped_count @failed_count = @doc . xpath ( '//testsuite' ) . map { | x | x . attr ( 'failures' ) . to_i } . inject ( 0 ) { | sum , x | sum + x } @failures = @doc . xpath ( '//failure' ) return @failed_count <= 0 end | Parses tests . |
23,269 | def put ( document_uri , document ) validate_uri ( document_uri ) res = put_document ( document_uri , document , "application/xml" ) res . success? ? res : handle_error ( res ) end | Puts the given document content at the specified URI |
23,270 | def delete ( document_uri ) validate_uri ( document_uri ) res = HTTParty . delete ( document_uri , @default_opts ) res . success? ? res : handle_error ( res ) end | Deletes the document at the specified URI from the store |
23,271 | def query ( query , opts = { } ) body = EasyExist :: QueryRequest . new ( query , opts ) . body res = HTTParty . post ( "" , @default_opts . merge ( { body : body , headers : { 'Content-Type' => 'application/xml' , 'Content-Length' => body . length . to_s } } ) ) res . success? ? res . body : handle_error ( res ) end | Runs the given XQuery against the store and returns the results |
23,272 | def store_query ( query_uri , query ) validate_uri ( query_uri ) res = put_document ( query_uri , query , "application/xquery" ) res . success? ? res : handle_error ( res ) end | Stores the given query at the specified URI |
23,273 | def put_document ( uri , document , content_type ) HTTParty . put ( uri , @default_opts . merge ( { body : document , headers : { "Content-Type" => content_type } , } ) ) end | Stores a document at the specified URI and with the specified content type |
23,274 | def set_required_attributes ( code , name ) missing_arguments = [ ] missing_arguments << :code if code . nil? missing_arguments << :name if name . nil? raise ArgumentError . new ( "Cannot create the Institution based on the given arguments (:code => #{code.inspect}, :name => #{name.inspect}).\n" + "The following arguments cannot be nil: #{missing_arguments.inspect}" ) unless missing_arguments . empty? @code , @name = code . to_sym , name end | Creates a new Institution object from the given code name and hash . |
23,275 | def build_table_body data . each_with_index do | row , i | output << ",\n" if i > 0 build_row ( row ) end output << "\n" end | Uses the Row controller to build up the table body . |
23,276 | def build_row ( data = self . data ) values = data . to_a keys = self . data . column_names . to_a hash = { } values . each_with_index do | val , i | key = ( keys [ i ] || i ) . to_s hash [ key ] = val end line = hash . to_json . to_s output << " #{line}" end | Renders individual rows for the table . |
23,277 | def build_grouping_body arr = [ ] data . each do | _ , group | arr << render_group ( group , options ) end output << arr . join ( ",\n" ) end | Generates the body for a grouping . Iterates through the groups and renders them using the group controller . |
23,278 | def users ( options = { } ) response = connection . get do | req | req . url "users" , options end return_error_or_body ( response ) end | Get a list of all users for the authenticating client . |
23,279 | def create_user ( options = { } ) response = connection . post do | req | req . url "users" , options end return_error_or_body ( response ) end | Create a user in the checkd . in system tied to the authenticating client . |
23,280 | def create_user_authentication ( id , options = { } ) response = connection . post do | req | req . url "users/#{id}/authentications" , options end return_error_or_body ( response ) end | Create an authentication for a user |
23,281 | def blacklisted ( options = { } ) response = connection . get do | req | req . url "users/blacklisted" , options end return_error_or_body ( response ) end | Get a list of all blacklisted users for the authenticating client . |
23,282 | def view_user_full_description ( id ) response = connection . get do | req | req . url "users/#{id}/full" end return_error_or_body ( response ) end | View a full user s description |
23,283 | def write ( temp_object , opts = { } ) temp_object . file do | fd | File . new . tap do | file | file . metadata = temp_object . meta file . data = fd file . save! return file . id . to_s end end end | + temp_object + should respond to + data + and + meta + |
23,284 | def update kwargs = { } ignore_cksum = kwargs . arg :ignore_cksum , false ignore_sigs = kwargs . arg :ignore_sigs , false cmd = 'aptly mirror update' cmd += ' -ignore-checksums' if ignore_cksum cmd += ' -ignore-signatures' if ignore_sigs cmd += " #{@name.quote}" Aptly :: runcmd cmd end | Updates a repository syncing in all packages which have not already been downloaded and caches them locally . |
23,285 | def delete ( key ) node = find_node ( key ) return false if node . nil? node . value = nil node . prune true end | Delete a key |
23,286 | def match_count ( data , list = { } ) return nil if @root == nil i = 0 while ( i < data . length ) node = @root . find_forward ( data , i , data . length - i ) if ( node! = nil && node . value! = nil ) if ( ! list . has_key? ( node ) ) list [ node ] = 1 else list [ node ] += 1 end i += node . length else i += 1 end end list end | Return a Hash of terminating nodes to Integer counts for a given String data i . e . Find the count of instances of each String in the tree in the given data . |
23,287 | def find_node ( key ) return nil if @root == nil node = @root . find_vertical ( key ) ( node . nil? || node . value . nil? ? nil : node ) end | Find a node by its key |
23,288 | def migrate_to_database ( & block ) tm = Jinx :: Stopwatch . measure { execute_save ( & block ) } . elapsed logger . debug { format_migration_time_log_message ( tm ) } end | Creates a new Migrator with the given options . |
23,289 | def archive_attributes_utc ( attribute , start_time = DEFAULT_DAYS_START . ago , end_time = DEFAULT_DAYS_END . ago ) archived_attribute_base ( attribute , start_time , end_time ) do | hsh , obj | hsh [ obj . send ( archived_time_attribute ) . to_i ] = obj . send ( attribute ) hsh end end | temp method for prototyping |
23,290 | def archive_attributes_by_time ( attribute , start_time = DEFAULT_DAYS_START . ago , end_time = DEFAULT_DAYS_END . ago ) archived_attribute_base ( attribute , start_time , end_time ) do | hsh , obj | hsh [ obj . send ( archived_time_attribute ) ] = obj . send ( attribute ) hsh end end | temp method for prototyping save as above except the keys are Time objects |
23,291 | def add_child key , page = nil if key . is_a? Page page , key = key , ( self . keys . length + 1 ) . to_sym end page . parent = self page . url = key self [ key ] = page end | Add a child page . You will seldom need to call this directly . Instead use add_blog or add_article |
23,292 | def check_password ( password ) return false unless key key == self . class . hash_password ( password , key . split ( '|' , 2 ) . first ) end | Compares a plain - text password against the password hash in this credential . |
23,293 | def password = ( new_password ) @password = new_password salt = self . class . random_salt self . key = new_password && self . class . hash_password ( new_password , salt ) end | Password virtual attribute . |
23,294 | def should_have_markup ( column , options = { } ) options = HasMarkup :: default_has_markup_options . merge ( options ) should_have_instance_methods "#{column}_html" should_require_markup column if options [ :required ] should_cache_markup column if options [ :cache_html ] end | Ensure that the model has markup . Accepts all the same options that has_markup does . |
23,295 | def send_request ( method , args ) request = API :: Request . new ( method , build_url ( method , args ) , config . api_key ) do | r | r . data = args [ :json ] if args [ :json ] r . ref = args [ :ref ] if args [ :ref ] end request . perform end | Initialize and return a new Client instance . Optionally configure options for the instance by passing a Configuration object . If no custom configuration is provided the configuration options from Orchestrate . config will be used . |
23,296 | def build_url ( method , args ) API :: URL . new ( method , config . base_url , args ) . path end | Builds the URL for each HTTP request to the orchestrate . io api . |
23,297 | def add_variables ( * vars ) bound_vars = vars . collect do | v | BoundVariable . new v , self end keys = vars . collect ( & :name ) append_hash = Hash [ keys . zip ( bound_vars ) ] @variables_hash . merge! ( append_hash ) do | key , oldval , newval | oldval end end | add variables . doesn t check for uniqueness does not overwrite existing |
23,298 | def set ( var_hash ) var_hash . each do | variable_name , value | throw :MissingVariable unless @variables_hash . has_key? variable_name bv = @variables_hash [ variable_name ] bv . value = value end end | Use to set the value for a variety of variables |
23,299 | def calculate_rain_and_snow @snow_metar = 0 @rain_metar = 0 self . specials . each do | s | new_rain = 0 new_snow = 0 coefficient = 1 case s [ :precipitation ] when 'drizzle' then new_rain = 5 when 'rain' then new_rain = 10 when 'snow' then new_snow = 10 when 'snow grains' then new_snow = 5 when 'ice crystals' then new_snow = 1 new_rain = 1 when 'ice pellets' then new_snow = 2 new_rain = 2 when 'hail' then new_snow = 3 new_rain = 3 when 'small hail/snow pellets' then new_snow = 1 new_rain = 1 end case s [ :intensity ] when 'in the vicinity' then coefficient = 1.5 when 'heavy' then coefficient = 3 when 'light' then coefficient = 0.5 when 'moderate' then coefficient = 1 end snow = new_snow * coefficient rain = new_rain * coefficient if @snow_metar < snow @snow_metar = snow end if @rain_metar < rain @rain_metar = rain end end real_world_coefficient = 0.5 * 25.4 / 10.0 @snow_metar *= real_world_coefficient @rain_metar *= real_world_coefficient end | Calculate precipitation in self defined units and aproximated real world units |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.