idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
4,800 | def parse_compound_selector ( value , name = nil , allow_parent_ref = false ) assert_type value , :String , name selector = parse_selector ( value , name , allow_parent_ref ) seq = selector . members . first sseq = seq . members . first if selector . members . length == 1 && seq . members . length == 1 && sseq . is_a? ... | Parses a user - provided compound selector . |
4,801 | def normalize_selector ( value , name ) if ( str = selector_to_str ( value ) ) return str end err = "#{value.inspect} is not a valid selector: it must be a string,\n" + "a list of strings, or a list of lists of strings" err = "$#{name.to_s.tr('_', '-')}: #{err}" if name raise ArgumentError . new ( err ) end | Converts a user - provided selector into string form or throws an ArgumentError if it s in an invalid format . |
4,802 | def selector_to_str ( value ) return value . value if value . is_a? ( Sass :: Script :: String ) return unless value . is_a? ( Sass :: Script :: List ) if value . separator == :comma return value . to_a . map do | complex | next complex . value if complex . is_a? ( Sass :: Script :: String ) return unless complex . is_... | Converts a user - provided selector into string form or returns nil if it s in an invalid format . |
4,803 | def backtrace return nil if super . nil? return super if sass_backtrace . all? { | h | h . empty? } sass_backtrace . map do | h | "#{h[:filename] || '(sass)'}:#{h[:line]}" + ( h [ :mixin ] ? ":in `#{h[:mixin]}'" : "" ) end + super end | Returns the standard exception backtrace including the Sass backtrace . |
4,804 | def sass_backtrace_str ( default_filename = "an unknown file" ) lines = message . split ( "\n" ) msg = lines [ 0 ] + lines [ 1 .. - 1 ] . map { | l | "\n" + ( " " * "Error: " . size ) + l } . join "Error: #{msg}" + sass_backtrace . each_with_index . map do | entry , i | "\n #{i == 0 ? 'on' : 'from'} line #{entry... | Returns a string representation of the Sass backtrace . |
4,805 | def fetch ( key , cache_options , & block ) if defined? ( Rails ) Rails . cache . fetch ( key , cache_options , & block ) else @cache [ key ] ||= yield end end | Fetch given a key and options and a fallback block attempts to find the key in the cache and stores the block result in there if no key is found . |
4,806 | def map_cache_key_to_engine ( engine ) if cache_key = cache_key_for ( engine ) result_cache_key = ActiveSupport :: Cache . expand_cache_key ( cache_key , :rabl ) @cache_key_to_engine [ result_cache_key ] = engine disable_cache_read_on_render ( engine ) end end | Maps a cache key to an engine |
4,807 | def read_cache_results @cache_results ||= begin mutable_keys = @cache_key_to_engine . keys . map { | k | k . dup } if mutable_keys . empty? { } else Rabl . configuration . cache_engine . read_multi ( * mutable_keys ) end end end | Returns the items that were found in the cache |
4,808 | def replace_engines_with_cache_results @cache_results . each do | key , value | engine = @cache_key_to_engine [ key ] builder = @engine_to_builder [ engine ] builder . replace_engine ( engine , value ) if value end end | Maps the results from the cache back to the builders |
4,809 | def process_source ( source ) return source if source . is_a? ( String ) && source =~ / \n / source , _ = engine . fetch_source ( source , { :view_path => options [ :view_path ] } ) source end | Returns the source given a relative template path |
4,810 | def determine_object_root ( data_token , data_name = nil , include_root = true ) return if object_root_name == false root_name = data_name . to_s if include_root if is_object? ( data_token ) || data_token . nil? root_name elsif is_collection? ( data_token ) object_root_name || ( root_name . singularize if root_name ) e... | Returns the object rootname based on if the root should be included Can be called with data as a collection or object determine_object_root ( |
4,811 | def is_collection? ( obj , follow_symbols = true ) data_obj = follow_symbols ? data_object ( obj ) : obj data_obj && data_obj . is_a? ( Enumerable ) && ! ( data_obj . is_a? ( Struct ) || defined? ( Hashie :: Mash ) && data_obj . is_a? ( Hashie :: Mash ) ) end | Returns true if the obj is a collection of items is_collection? ( |
4,812 | def object_to_engine ( object , options = { } , & block ) return if object . nil? options . reverse_merge! ( { :format => "hash" . freeze , :view_path => view_path , :root => ( options [ :root ] || false ) } ) Engine . new ( options [ :source ] , options ) . apply ( context_scope , :object => object , :locals => option... | Returns an Engine based representation of any data object given ejs template block object_to_engine ( |
4,813 | def template_cache_configured? if defined? ( Rails ) defined? ( ActionController :: Base ) && ActionController :: Base . perform_caching else Rabl . configuration . perform_caching end end | Returns true if the cache has been enabled for the application |
4,814 | def object ( template_data ) current_data = ( @_locals [ :object ] . nil? || template_data == false ) ? template_data : @_locals [ :object ] @_data_object = data_object ( current_data ) @_root_name_data = template_data . is_a? ( Hash ) && ! current_data . is_a? ( Hash ) ? template_data : current_data @_root_name_data =... | Sets the object to be used as the data source for this template object ( |
4,815 | def collection ( data , options = { } ) @_collection_name = options [ :root ] if options [ :root ] @_collection_name ||= data . values . first if data . is_a? ( Hash ) @_object_root_name = options [ :object_root ] if options . has_key? ( :object_root ) object ( data_object ( data ) || [ ] ) end | Sets the object as a collection casted to a simple array collection |
4,816 | def default_object return unless context_scope . respond_to? ( :controller ) controller_name = context_scope . controller . controller_name stripped_name = controller_name . split ( %r{ \/ } ) . last ivar_object = instance_variable_get ( "@#{stripped_name}" ) ivar_object if is_object? ( ivar_object ) end | Returns a guess at the default object for this template default_object = > |
4,817 | def request_format format = request_params [ :format ] if format . nil? && context_scope . respond_to? ( :request ) request = context_scope . request format = request . format . to_sym . to_s if request . respond_to? ( :format ) end format = "json" unless format && respond_to? ( "to_#{format}" ) format end | Returns a guess at the format in this context_scope request_format = > xml |
4,818 | def method_missing ( name , * args , & block ) context_scope . respond_to? ( name , true ) ? context_scope . __send__ ( name , * args , & block ) : super end | Supports calling helpers defined for the template context_scope using method_missing hook |
4,819 | def fetch_padrino_source ( file , options = { } ) view_path = Array ( options [ :view_path ] || context_scope . settings . views ) file_path , _ = context_scope . instance_eval { resolve_template ( file ) } File . join ( view_path . first . to_s , ( file_path . to_s + ".rabl" ) ) end | Returns the rabl template path for padrino views using configured views |
4,820 | def fetch_rails_source ( file , options = { } ) source_format = request_format if defined? ( request_format ) if source_format && context_scope . respond_to? ( :lookup_context ) lookup_proc = lambda do | partial | if ActionPack :: VERSION :: MAJOR == 3 && ActionPack :: VERSION :: MINOR < 2 context_scope . lookup_contex... | Returns the rabl template path for Rails including special lookups for Rails 2 and 3 |
4,821 | def fetch_sinatra_source ( file , options = { } ) view_path = Array ( options [ :view_path ] || context_scope . settings . views ) fetch_manual_template ( view_path , file ) end | Returns the rabl template path for sinatra views using configured views |
4,822 | def child ( data , options = { } , & block ) return unless data . present? && resolve_condition ( options ) name = is_name_value? ( options [ :root ] ) ? options [ :root ] : data_name ( data ) object = data_object ( data ) engine_options = @options . slice ( :child_root ) engine_options [ :root ] = is_collection? ( obj... | Creates a child node that is included in json output child ( |
4,823 | def glue ( data , options = { } , & block ) return unless data . present? && resolve_condition ( options ) object = data_object ( data ) engine = object_to_engine ( object , :root => false , & block ) engines << engine if engine end | Glues data from a child node to the json_output glue ( |
4,824 | def permit? ( privilege , options = { } ) if permit! ( privilege , options . merge ( :bang => false ) ) yield if block_given? true else false end end | Calls permit! but doesn t raise authorization errors . If no exception is raised permit? returns true and yields to the optional block . |
4,825 | def roles_for ( user ) user ||= Authorization . current_user raise AuthorizationUsageError , "User object doesn't respond to roles (#{user.inspect})" if ! user . respond_to? ( :role_symbols ) and ! user . respond_to? ( :roles ) Rails . logger . info ( "The use of user.roles is deprecated. Please add a method " + "role... | Returns the role symbols of the given user . |
4,826 | def flatten_privileges ( privileges , context = nil , flattened_privileges = Set . new ) raise AuthorizationUsageError , "No context given or inferable from object" unless context privileges . reject { | priv | flattened_privileges . include? ( priv ) } . each do | priv | flattened_privileges << priv flatten_privileges... | Returns the privilege hierarchy flattened for given privileges in context . |
4,827 | def obligation ( attr_validator , hash = nil ) hash = ( hash || @conditions_hash ) . clone hash . each do | attr , value | if value . is_a? ( Hash ) hash [ attr ] = obligation ( attr_validator , value ) elsif value . is_a? ( Array ) and value . length == 2 hash [ attr ] = [ value [ 0 ] , attr_validator . evaluate ( val... | resolves all the values in condition_hash |
4,828 | def obligation ( attr_validator , hash_or_attr = nil , path = [ ] ) hash_or_attr ||= @attr_hash case hash_or_attr when Symbol @context ||= begin rule_model = attr_validator . context . to_s . classify . constantize context_reflection = self . class . reflection_for_path ( rule_model , path + [ hash_or_attr ] ) if conte... | may return an array of obligations to be OR ed |
4,829 | def parse! ( obligation ) @current_obligation = obligation @join_table_joins = Set . new obligation_conditions [ @current_obligation ] ||= { } follow_path ( obligation ) rebuild_condition_options! rebuild_join_options! end | Consumes the given obligation converting it into scope join and condition options . |
4,830 | def follow_path ( steps , past_steps = [ ] ) if steps . is_a? ( Hash ) steps . each do | step , next_steps | path_to_this_point = [ past_steps , step ] . flatten reflection = reflection_for ( path_to_this_point ) rescue nil if reflection follow_path ( next_steps , path_to_this_point ) else follow_comparison ( next_step... | Parses the next step in the association path . If it s an association we advance down the path . Otherwise it s an attribute and we need to evaluate it as a comparison operation . |
4,831 | def add_obligation_condition_for ( path , expression ) raise "invalid expression #{expression.inspect}" unless expression . is_a? ( Array ) && expression . length == 3 add_obligation_join_for ( path ) obligation_conditions [ @current_obligation ] ||= { } ( obligation_conditions [ @current_obligation ] [ path ] ||= Set ... | Adds the given expression to the current obligation s indicated path s conditions . |
4,832 | def model_for ( path ) reflection = reflection_for ( path ) if Authorization . is_a_association_proxy? ( reflection ) if Rails . version < "3.2" reflection . proxy_reflection . klass else reflection . proxy_association . reflection . klass end elsif reflection . respond_to? ( :klass ) reflection . klass else reflection... | Returns the model associated with the given path . |
4,833 | def reflection_for ( path , for_join_table_only = false ) @join_table_joins << path if for_join_table_only and ! reflections [ path ] reflections [ path ] ||= map_reflection_for ( path ) end | Returns the reflection corresponding to the given path . |
4,834 | def map_reflection_for ( path ) raise "reflection for #{path.inspect} already exists" unless reflections [ path ] . nil? reflection = path . empty? ? top_level_model : begin parent = reflection_for ( path [ 0 .. - 2 ] ) if ! Authorization . is_a_association_proxy? ( parent ) and parent . respond_to? ( :klass ) parent .... | Attempts to map a reflection for the given path . Raises if already defined . |
4,835 | def map_table_alias_for ( path ) return "table alias for #{path.inspect} already exists" unless table_aliases [ path ] . nil? reflection = reflection_for ( path ) table_alias = reflection . table_name if table_aliases . values . include? ( table_alias ) max_length = reflection . active_record . connection . table_alias... | Attempts to map a table alias for the given path . Raises if already defined . |
4,836 | def permitted_to? ( privilege , options = { } , & block ) options = { :user => Authorization . current_user , :object => self } . merge ( options ) Authorization :: Engine . instance . permit? ( privilege , { :user => options [ :user ] , :object => options [ :object ] } , & block ) end | If the user meets the given privilege permitted_to? returns true and yields to the optional block . |
4,837 | def has_role? ( * roles , & block ) user_roles = authorization_engine . roles_for ( current_user ) result = roles . all? do | role | user_roles . include? ( role ) end yield if result and block_given? result end | While permitted_to? is used for authorization in some cases content should only be shown to some users without being concerned with authorization . E . g . to only show the most relevant menu options to a certain group of users . That is what has_role? should be used for . |
4,838 | def has_any_role? ( * roles , & block ) user_roles = authorization_engine . roles_for ( current_user ) result = roles . any? do | role | user_roles . include? ( role ) end yield if result and block_given? result end | Intended to be used where you want to allow users with any single listed role to view the content in question |
4,839 | def has_role_with_hierarchy? ( * roles , & block ) user_roles = authorization_engine . roles_with_hierarchy_for ( current_user ) result = roles . all? do | role | user_roles . include? ( role ) end yield if result and block_given? result end | As has_role? except checks all roles included in the role hierarchy |
4,840 | def has_any_role_with_hierarchy? ( * roles , & block ) user_roles = authorization_engine . roles_with_hierarchy_for ( current_user ) result = roles . any? do | role | user_roles . include? ( role ) end yield if result and block_given? result end | As has_any_role? except checks all roles included in the role hierarchy |
4,841 | def save ensure_name_metadata_set redis . pipelined do redis . hmset ( "id:#{id}" , * metadata . to_a . flatten ) redis . set ( "name:#{name}" , id ) end end | Generates a + Fixnum + hash value for this user object . Implemented to support equality . |
4,842 | def join ( room ) room_object = find_room ( room ) if room_object redis . sadd ( "persisted_rooms" , room_object . id ) adapter . join ( room_object . id ) else adapter . join ( room ) end end | Makes the robot join a room with the specified ID . |
4,843 | def part ( room ) room_object = find_room ( room ) if room_object redis . srem ( "persisted_rooms" , room_object . id ) adapter . part ( room_object . id ) else adapter . part ( room ) end end | Makes the robot part from the room with the specified ID . |
4,844 | def send_messages_with_mention ( target , * strings ) return send_messages ( target , * strings ) if target . private_message? mention_name = target . user . mention_name prefixed_strings = strings . map do | s | "#{adapter.mention_format(mention_name).strip} #{s}" end send_messages ( target , * prefixed_strings ) end | Sends one or more messages to a user or room . If sending to a room prefixes each message with the user s mention name . |
4,845 | def trigger ( event_name , payload = { } ) handlers . each do | handler | next unless handler . respond_to? ( :trigger ) handler . trigger ( self , event_name , payload ) end end | Triggers an event instructing all registered handlers to invoke any methods subscribed to the event and passing them a payload hash of arbitrary data . |
4,846 | def load_adapter adapter_name = config . robot . adapter adapter_class = adapters [ adapter_name . to_sym ] unless adapter_class logger . fatal I18n . t ( "lita.robot.unknown_adapter" , adapter : adapter_name ) abort end adapter_class . new ( self ) end | Loads the selected adapter . |
4,847 | def run_app http_config = config . http @server_thread = Thread . new do @server = Puma :: Server . new ( app ) begin @server . add_tcp_listener ( http_config . host , http_config . port . to_i ) rescue Errno :: EADDRINUSE , Errno :: EACCES => e logger . fatal I18n . t ( "lita.http.exception" , message : e . message , ... | Starts the web server . |
4,848 | def register_route ( http_method , path , callback , options ) route = new_route ( http_method , path , callback , options ) route . to ( HTTPCallback . new ( handler_class , callback ) ) handler_class . http_routes << route end | Adds a new HTTP route for the handler . |
4,849 | def new_route ( http_method , path , callback , options ) route = ExtendedRoute . new route . path = path route . name = callback . method_name route . add_match_with ( options ) route . add_request_method ( http_method ) route . add_request_method ( "HEAD" ) if http_method == "GET" route end | Creates and configures a new HTTP route . |
4,850 | def save mention_name = metadata [ :mention_name ] || metadata [ "mention_name" ] current_keys = metadata . keys redis_keys = redis . hkeys ( "id:#{id}" ) delete_keys = ( redis_keys - current_keys ) redis . pipelined do redis . hdel ( "id:#{id}" , * delete_keys ) if delete_keys . any? redis . hmset ( "id:#{id}" , * met... | Saves the user record to Redis overwriting any previous data for the current ID and user name . |
4,851 | def reply_privately ( * strings ) private_source = source . clone private_source . private_message! @robot . send_messages ( private_source , * strings ) end | Replies by sending the given strings back to the user who sent the message directly even if the message was sent in a room . |
4,852 | def validate ( type , plugin , attributes , attribute_namespace = [ ] ) attributes . each do | attribute | if attribute . children? validate ( type , plugin , attribute . children , attribute_namespace . clone . push ( attribute . name ) ) elsif attribute . required? && attribute . value . nil? registry . logger . fata... | Validates an array of attributes recursing if any nested attributes are encountered . |
4,853 | def adapters_config adapters = registry . adapters root . config :adapters do adapters . each do | key , adapter | combine ( key , adapter . configuration_builder ) end end end | Builds config . adapters |
4,854 | def handlers_config handlers = registry . handlers root . config :handlers do handlers . each do | handler | if handler . configuration_builder . children? combine ( handler . namespace , handler . configuration_builder ) end end end end | Builds config . handlers |
4,855 | def http_config root . config :http do config :host , type : String , default : "0.0.0.0" config :port , type : [ Integer , String ] , default : 8080 config :min_threads , type : [ Integer , String ] , default : 0 config :max_threads , type : [ Integer , String ] , default : 16 config :middleware , type : MiddlewareReg... | Builds config . http |
4,856 | def robot_config root . config :robot do config :name , type : String , default : "Lita" config :mention_name , type : String config :alias , type : String config :adapter , types : [ String , Symbol ] , default : :shell config :locale , types : [ String , Symbol ] , default : I18n . locale config :log_level , types : ... | Builds config . robot |
4,857 | def config ( * args , ** kwargs , & block ) if block configuration_builder . config ( * args , ** kwargs , & block ) else configuration_builder . config ( * args , ** kwargs ) end end | Sets a configuration attribute on the plugin . |
4,858 | def config ( name , types : nil , type : nil , required : false , default : nil , & block ) attribute = self . class . new attribute . name = name attribute . types = types || type attribute . required = required attribute . value = default attribute . instance_exec ( & block ) if block children << attribute end | Declares a configuration attribute . |
4,859 | def build_leaf ( object ) this = self run_validator = method ( :run_validator ) check_types = method ( :check_types ) object . instance_exec do define_singleton_method ( this . name ) { this . value } define_singleton_method ( "#{this.name}=" ) do | value | run_validator . call ( value ) check_types . call ( value ) th... | Finalize a nested object . |
4,860 | def build_nested ( object ) this = self nested_object = Configuration . new children . each { | child | child . build ( nested_object ) } object . instance_exec { define_singleton_method ( this . name ) { nested_object } } object end | Finalize the root builder or any builder with children . |
4,861 | def check_types ( value ) if types &. none? { | type | type === value } Lita . logger . fatal ( I18n . t ( "lita.config.type_error" , attribute : name , types : types . join ( ", " ) ) ) raise ValidationError end end | Check s the value s type from inside the finalized object . |
4,862 | def recognize ( env ) env [ "lita.robot" ] = robot recognized_routes_for ( env ) . map { | match | match . route . name } end | Finds the first route that matches the request environment if any . Does not trigger the route . |
4,863 | def compile robot . handlers . each do | handler | next unless handler . respond_to? ( :http_routes ) handler . http_routes . each { | route | router . add_route ( route ) } end end | Registers routes in the router for each handler s defined routes . |
4,864 | def user_in_group? ( user , group ) group = normalize_group ( group ) return user_is_admin? ( user ) if group == "admins" redis . sismember ( group , user . id ) end | Checks if a user is in an authorization group . |
4,865 | def user_is_admin? ( user ) Array ( robot . config . robot . admins ) . include? ( user . id ) end | Checks if a user is an administrator . |
4,866 | def groups_with_users groups . reduce ( { } ) do | list , group | list [ group ] = redis . smembers ( group ) . map do | user_id | User . find_by_id ( user_id ) end list end end | Returns a hash of authorization group names and the users in them . |
4,867 | def passes_route_hooks? ( route , message , robot ) robot . hooks [ :validate_route ] . all? do | hook | hook . call ( handler : handler , route : route , message : message , robot : robot ) end end | Allow custom route hooks to reject the route |
4,868 | def authorized? ( robot , user , required_groups ) required_groups . nil? || required_groups . any? do | group | robot . auth . user_in_group? ( user , group ) end end | User must be in auth group if route is restricted . |
4,869 | def context_binding ( variables ) context = TemplateEvaluationContext . new helpers . each { | helper | context . extend ( helper ) } variables . each do | k , v | context . instance_variable_set ( "@#{k}" , v ) end context . __get_binding end | Create an empty object to use as the ERB context and set any provided variables in it . |
4,870 | def start check_ruby_verison check_default_handlers begin Bundler . require rescue Bundler :: GemfileNotFound say I18n . t ( "lita.cli.no_gemfile_warning" ) , :red abort end Lita . run ( options [ :config ] ) end | Starts Lita . |
4,871 | def validate check_ruby_verison check_default_handlers begin Bundler . require rescue Bundler :: GemfileNotFound say I18n . t ( "lita.cli.no_gemfile_warning" ) , :red abort end Lita . load_config ( options [ :config ] ) end | Outputs detailed stacktrace when there is a problem or exit 0 when OK . You can use this as a pre - check script for any automation |
4,872 | def merge! ( schema ) if schema . is_a? ( Schema ) @data . merge! ( schema . data ) else @data . merge! ( schema ) end end | Merge schema data with provided schema |
4,873 | def to_json new_json = JSON . pretty_generate ( @data ) new_json = new_json . split ( "\n" ) . reject ( & :empty? ) . join ( "\n" ) + "\n" new_json end | Convert Schema to JSON |
4,874 | def common_header ( frame ) header = [ ] unless FRAME_TYPES [ frame [ :type ] ] fail CompressionError , "Invalid frame type (#{frame[:type]})" end if frame [ :length ] > @max_frame_size fail CompressionError , "Frame size is too large: #{frame[:length]}" end if frame [ :length ] < 0 fail CompressionError , "Frame size ... | Initializes new framer object . |
4,875 | def read_common_header ( buf ) frame = { } len_hi , len_lo , type , flags , stream = buf . slice ( 0 , 9 ) . unpack ( HEADERPACK ) frame [ :length ] = ( len_hi << FRAME_LENGTH_HISHIFT ) | len_lo frame [ :type ] , _ = FRAME_TYPES . find { | _t , pos | type == pos } if frame [ :type ] frame [ :flags ] = FRAME_FLAGS [ fra... | Decodes common 9 - byte header . |
4,876 | def send_data ( frame = nil , encode = false ) @send_buffer . push frame unless frame . nil? while @remote_window > 0 && ! @send_buffer . empty? frame = @send_buffer . shift sent , frame_size = 0 , frame [ :payload ] . bytesize if frame_size > @remote_window payload = frame . delete ( :payload ) chunk = frame . dup fra... | Buffers outgoing DATA frames and applies flow control logic to split and emit DATA frames based on current flow control window . If the window is large enough the data is sent immediately . Otherwise the data is buffered until the flow control window is updated . |
4,877 | def send_connection_preface return unless @state == :waiting_connection_preface @state = :connected emit ( :frame , CONNECTION_PREFACE_MAGIC ) payload = @local_settings . reject { | k , v | v == SPEC_DEFAULT_CONNECTION_SETTINGS [ k ] } settings ( payload ) end | Emit the connection preface if not yet |
4,878 | def receive ( frame ) transition ( frame , false ) case frame [ :type ] when :data update_local_window ( frame ) emit ( :data , frame [ :payload ] ) unless frame [ :ignore ] calculate_window_update ( @local_window_max_size ) when :headers emit ( :headers , frame [ :payload ] ) unless frame [ :ignore ] when :push_promis... | Processes incoming HTTP 2 . 0 frames . The frames must be decoded upstream . |
4,879 | def send ( frame ) process_priority ( frame ) if frame [ :type ] == :priority case frame [ :type ] when :data send_data ( frame ) when :window_update manage_state ( frame ) do @local_window += frame [ :increment ] emit ( :frame , frame ) end else manage_state ( frame ) do emit ( :frame , frame ) end end end | Processes outgoing HTTP 2 . 0 frames . Data frames may be automatically split and buffered based on maximum frame size and current stream flow control window size . |
4,880 | def headers ( headers , end_headers : true , end_stream : false ) flags = [ ] flags << :end_headers if end_headers flags << :end_stream if end_stream send ( type : :headers , flags : flags , payload : headers ) end | Sends a HEADERS frame containing HTTP response headers . All pseudo - header fields MUST appear in the header block before regular header fields . |
4,881 | def data ( payload , end_stream : true ) max_size = @connection . remote_settings [ :settings_max_frame_size ] if payload . bytesize > max_size payload = chunk_data ( payload , max_size ) do | chunk | send ( type : :data , flags : [ ] , payload : chunk ) end end flags = [ ] flags << :end_stream if end_stream send ( typ... | Sends DATA frame containing response payload . |
4,882 | def chunk_data ( payload , max_size ) total = payload . bytesize cursor = 0 while ( total - cursor ) > max_size yield payload . byteslice ( cursor , max_size ) cursor += max_size end payload . byteslice ( cursor , total - cursor ) end | Chunk data into max_size yield each chunk then return final chunk |
4,883 | def promise ( * args , & callback ) parent , headers , flags = * args promise = new_stream ( parent : parent ) promise . send ( type : :push_promise , flags : flags , stream : parent . id , promise_stream : promise . id , payload : headers . to_a , ) callback . call ( promise ) end | Handle locally initiated server - push event emitted by the stream . |
4,884 | def add_listener ( event , & block ) fail ArgumentError , 'must provide callback' unless block_given? listeners ( event . to_sym ) . push block end | Subscribe to all future events for specified type . |
4,885 | def emit ( event , * args , & block ) listeners ( event ) . delete_if do | cb | cb . call ( * args , & block ) == :delete end end | Emit event with provided arguments . |
4,886 | def new_stream ( ** args ) fail ConnectionClosed if @state == :closed fail StreamLimitExceeded if @active_stream_count >= @remote_settings [ :settings_max_concurrent_streams ] stream = activate_stream ( id : @stream_id , ** args ) @stream_id += 2 stream end | Allocates new stream for current connection . |
4,887 | def ping ( payload , & blk ) send ( type : :ping , stream : 0 , payload : payload ) once ( :ack , & blk ) if blk end | Sends PING frame to the peer . |
4,888 | def goaway ( error = :no_error , payload = nil ) last_stream = if ( max = @streams . max ) max . first else 0 end send ( type : :goaway , last_stream : last_stream , error : error , payload : payload ) @state = :closed @closed_since = Time . now end | Sends a GOAWAY frame indicating that the peer should stop creating new streams for current connection . |
4,889 | def settings ( payload ) payload = payload . to_a connection_error if validate_settings ( @local_role , payload ) @pending_settings << payload send ( type : :settings , stream : 0 , payload : payload ) @pending_settings << payload end | Sends a connection SETTINGS frame to the peer . The values are reflected when the corresponding ACK is received . |
4,890 | def encode ( frame ) frames = if frame [ :type ] == :headers || frame [ :type ] == :push_promise encode_headers ( frame ) else [ frame ] end frames . map { | f | @framer . generate ( f ) } end | Applies HTTP 2 . 0 binary encoding to the frame . |
4,891 | def validate_settings ( role , settings ) settings . each do | key , v | case key when :settings_header_table_size when :settings_enable_push case role when :server return ProtocolError . new ( "invalid #{key} value" ) unless v . zero? when :client unless v . zero? || v == 1 return ProtocolError . new ( "invalid #{key}... | Validate settings parameters . See sepc Section 6 . 5 . 2 . |
4,892 | def connection_settings ( frame ) connection_error unless frame [ :type ] == :settings && ( frame [ :stream ] ) . zero? settings , side = if frame [ :flags ] . include? ( :ack ) [ @pending_settings . shift , :local ] else connection_error ( check ) if validate_settings ( @remote_role , frame [ :payload ] ) [ frame [ :p... | Update connection settings based on parameters set by the peer . |
4,893 | def decode_headers ( frame ) if frame [ :payload ] . is_a? Buffer frame [ :payload ] = @decompressor . decode ( frame [ :payload ] ) end rescue CompressionError => e connection_error ( :compression_error , e : e ) rescue ProtocolError => e connection_error ( :protocol_error , e : e ) rescue StandardError => e connectio... | Decode headers payload and update connection decompressor state . |
4,894 | def encode_headers ( frame ) payload = frame [ :payload ] payload = @compressor . encode ( payload ) unless payload . is_a? Buffer frames = [ ] while payload . bytesize > 0 cont = frame . dup cont [ :type ] = :continuation cont [ :flags ] = [ ] cont [ :payload ] = payload . slice! ( 0 , @remote_settings [ :settings_max... | Encode headers payload and update connection compressor state . |
4,895 | def activate_stream ( id : nil , ** args ) connection_error ( msg : 'Stream ID already exists' ) if @streams . key? ( id ) stream = Stream . new ( { connection : self , id : id } . merge ( args ) ) stream . once ( :active ) { @active_stream_count += 1 } stream . once ( :close ) do @active_stream_count -= 1 @streams_rec... | Activates new incoming or outgoing stream and registers appropriate connection managemet callbacks . |
4,896 | def connection_error ( error = :protocol_error , msg : nil , e : nil ) goaway ( error ) unless @state == :closed || @state == :new @state , @error = :closed , error klass = error . to_s . split ( '_' ) . map ( & :capitalize ) . join msg ||= e && e . message backtrace = ( e && e . backtrace ) || [ ] fail Error . const_g... | Emit GOAWAY error indicating to peer that the connection is being aborted and once sent raise a local exception . |
4,897 | def build_for ( commit , user , room_id = nil , compare = nil ) if compare . nil? && build = commit . last_build compare = build . compare end room_id = room_id . to_s if room_id . empty? || room_id == "0" room_id = repository . room_id end builds . create! ( :compare => compare , :user => user , :commit => commit , :r... | Create a build for the given commit . |
4,898 | def head_build_for ( room_id , user ) sha_to_build = GitHub . branch_head_sha ( repository . nwo , name ) return if ! sha_to_build commit = repository . commit_for_sha ( sha_to_build ) current_sha = current_build ? current_build . sha1 : "#{sha_to_build}^" compare_url = repository . github_url ( "compare/#{current_sha}... | Fetch the HEAD commit of this branch using the GitHub API and create a build and commit record . |
4,899 | def status if current_build && current_build . building? "building" elsif build = completed_builds . first if build . green? "green" elsif build . red? "red" end elsif completed_builds . empty? || builds . empty? "no build" else raise Error , "unexpected branch status: #{id.inspect}" end end | Human readable status of this branch |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.