idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
15,600 | def parse_component_values ( input = @tokens ) input = TokenScanner . new ( input ) unless input . is_a? ( TokenScanner ) tokens = [ ] while token = consume_component_value ( input ) tokens << token end tokens end | Parses a list of component values and returns an array of parsed tokens . |
15,601 | def parse_declaration ( input = @tokens ) input = TokenScanner . new ( input ) unless input . is_a? ( TokenScanner ) while input . peek && input . peek [ :node ] == :whitespace input . consume end if input . peek . nil? return create_node ( :error , :value => 'empty' ) elsif input . peek [ :node ] != :ident return crea... | Parses a single declaration and returns it . |
15,602 | def parse_declarations ( input = @tokens , options = { } ) input = TokenScanner . new ( input ) unless input . is_a? ( TokenScanner ) consume_declarations ( input , options ) end | Parses a list of declarations and returns them . |
15,603 | def parse_rule ( input = @tokens ) input = TokenScanner . new ( input ) unless input . is_a? ( TokenScanner ) while input . peek && input . peek [ :node ] == :whitespace input . consume end if input . peek . nil? return create_node ( :error , :value => 'empty' ) elsif input . peek [ :node ] == :at_keyword rule = consum... | Parses a single rule and returns it . |
15,604 | def parse_value ( nodes ) nodes = [ nodes ] unless nodes . is_a? ( Array ) string = String . new nodes . each do | node | case node [ :node ] when :comment , :semicolon next when :at_keyword , :ident string << node [ :value ] when :function if node [ :value ] . is_a? ( String ) string << node [ :value ] string << '(' e... | Returns the unescaped value of a selector name or property declaration . |
15,605 | def consume_bad_url text = String . new until @s . eos? if valid_escape? text << consume_escaped elsif valid_escape? ( @s . peek ( 2 ) ) @s . consume text << consume_escaped else char = @s . consume if char == ')' break else text << char end end end text end | Consumes the remnants of a bad URL and returns the consumed text . |
15,606 | def consume_comments if @s . peek ( 2 ) == '/*' @s . consume @s . consume if text = @s . scan_until ( RE_COMMENT_CLOSE ) text . slice! ( - 2 , 2 ) else text = @s . consume_rest end return create_token ( :comment , :value => text ) end nil end | Consumes comments and returns them or nil if no comments were consumed . |
15,607 | def consume_escaped return "\ufffd" if @s . eos? if hex_str = @s . scan ( RE_HEX ) @s . consume if @s . peek =~ RE_WHITESPACE codepoint = hex_str . hex if codepoint == 0 || codepoint . between? ( 0xD800 , 0xDFFF ) || codepoint > 0x10FFFF return "\ufffd" else return codepoint . chr ( Encoding :: UTF_8 ) end end @s . con... | Consumes an escaped code point and returns its unescaped value . |
15,608 | def consume_ident value = consume_name if @s . peek == '(' @s . consume if value . downcase == 'url' @s . consume while @s . peek ( 2 ) =~ RE_WHITESPACE_ANCHORED if @s . peek ( 2 ) =~ RE_QUOTED_URL_START create_token ( :function , :value => value ) else consume_url end else create_token ( :function , :value => value ) ... | Consumes an ident - like token and returns it . |
15,609 | def consume_name result = String . new until @s . eos? if match = @s . scan ( RE_NAME ) result << match next end char = @s . consume if valid_escape? result << consume_escaped elsif char == '*' && @options [ :preserve_hacks ] result << @s . consume else @s . reconsume return result end end result end | Consumes a name and returns it . |
15,610 | def consume_numeric number = consume_number if start_identifier? ( @s . peek ( 3 ) ) create_token ( :dimension , :repr => number [ 0 ] , :type => number [ 2 ] , :unit => consume_name , :value => number [ 1 ] ) elsif @s . peek == '%' @s . consume create_token ( :percentage , :repr => number [ 0 ] , :type => number [ 2 ]... | Consumes a numeric token and returns it . |
15,611 | def consume_string ( ending = nil ) ending = @s . current if ending . nil? value = String . new until @s . eos? case char = @s . consume when ending break when "\n" @s . reconsume return create_token ( :bad_string , :error => true , :value => value ) when '\\' case @s . peek when '' next when "\n" @s . consume else val... | Consumes a string token that ends at the given character and returns the token . |
15,612 | def consume_unicode_range value = @s . scan ( RE_HEX ) || String . new while value . length < 6 break unless @s . peek == '?' value << @s . consume end range = { } if value . include? ( '?' ) range [ :start ] = value . gsub ( '?' , '0' ) . hex range [ :end ] = value . gsub ( '?' , 'F' ) . hex return create_token ( :uni... | Consumes a Unicode range token and returns it . Assumes the initial u + or U + has already been consumed . |
15,613 | def consume_url value = String . new @s . scan ( RE_WHITESPACE ) until @s . eos? case char = @s . consume when ')' break when RE_WHITESPACE @s . scan ( RE_WHITESPACE ) if @s . eos? || @s . peek == ')' @s . consume break else return create_token ( :bad_url , :value => value + consume_bad_url ) end when '"' , "'" , '(' ,... | Consumes a URL token and returns it . Assumes the original url ( has already been consumed . |
15,614 | def convert_string_to_number ( str ) matches = RE_NUMBER_STR . match ( str ) s = matches [ :sign ] == '-' ? - 1 : 1 i = matches [ :integer ] . to_i f = matches [ :fractional ] . to_i d = matches [ :fractional ] ? matches [ :fractional ] . length : 0 t = matches [ :exponent_sign ] == '-' ? - 1 : 1 e = matches [ :exponen... | Converts a valid CSS number string into a number and returns the number . |
15,615 | def preprocess ( input ) input = input . to_s . encode ( 'UTF-8' , :invalid => :replace , :undef => :replace ) input . gsub! ( / \r \n \r \f / , "\n" ) input . gsub! ( "\u0000" , "\ufffd" ) input end | Preprocesses _input_ to prepare it for the tokenizer . |
15,616 | def start_identifier? ( text = nil ) text = @s . current + @s . peek ( 2 ) if text . nil? case text [ 0 ] when '-' nextChar = text [ 1 ] ! ! ( nextChar == '-' || nextChar =~ RE_NAME_START || valid_escape? ( text [ 1 , 2 ] ) ) when RE_NAME_START true when '\\' valid_escape? ( text [ 0 , 2 ] ) else false end end | Returns true if the given three - character _text_ would start an identifier . If _text_ is nil the current and next two characters in the input stream will be checked but will not be consumed . |
15,617 | def start_number? ( text = nil ) text = @s . current + @s . peek ( 2 ) if text . nil? case text [ 0 ] when '+' , '-' ! ! ( text [ 1 ] =~ RE_DIGIT || ( text [ 1 ] == '.' && text [ 2 ] =~ RE_DIGIT ) ) when '.' ! ! ( text [ 1 ] =~ RE_DIGIT ) when RE_DIGIT true else false end end | Returns true if the given three - character _text_ would start a number . If _text_ is nil the current and next two characters in the input stream will be checked but will not be consumed . |
15,618 | def assign! ( field ) options = self . class . incrementing_fields [ field ] fail AutoIncrementsError if options [ :auto ] fail AlreadyAssignedError if send ( field ) . present? increment! ( field , options ) end | Manually assign the next number to the passed autoinc field . |
15,619 | def update_auto_increments self . class . incrementing_fields . each do | field , options | increment! ( field , options ) if options [ :auto ] end && true end | Sets autoincrement values for all autoincrement fields . |
15,620 | def increment! ( field , options ) options = options . dup model_name = ( options . delete ( :model_name ) || self . class . model_name ) . to_s options [ :scope ] = evaluate_scope ( options [ :scope ] ) if options [ :scope ] options [ :step ] = evaluate_step ( options [ :step ] ) if options [ :step ] write_attribute (... | Set autoincrement value for the passed autoincrement field using the passed options |
15,621 | def evaluate_scope ( scope ) return send ( scope ) if scope . is_a? Symbol return instance_exec ( & scope ) if scope . is_a? Proc fail ArgumentError , 'scope is not a Symbol or a Proc' end | Asserts the validity of the passed scope |
15,622 | def evaluate_step ( step ) return step if step . is_a? Integer return evaluate_step_proc ( step ) if step . is_a? Proc fail ArgumentError , 'step is not an Integer or a Proc' end | Returns the number to add to the current increment |
15,623 | def evaluate_step_proc ( step_proc ) result = instance_exec ( & step_proc ) return result if result . is_a? Integer fail 'step Proc does not evaluate to an Integer' end | Executes a proc and returns its + Integer + value |
15,624 | def same_namespace? ( node_1 , node_2 ) args = [ node_1 , node_2 ] if args . all? { | node | not node . is_namespaced? } or args . any? { | node | node . is_character_data? } return true end href1 = node_1 . namespace_uri || '' href2 = node_2 . namespace_uri || '' return href1 == href2 end | Determine if two nodes are in the same effective Namespace |
15,625 | def generate_captcha if EasyCaptcha . cache FileUtils . mkdir_p ( EasyCaptcha . cache_temp_dir ) files = Dir . glob ( EasyCaptcha . cache_temp_dir + "*.png" ) unless files . size < EasyCaptcha . cache_size file = File . open ( files . at ( Kernel . rand ( files . size ) ) ) session [ :captcha ] = File . basename ( file... | generate captcha image and return it as blob |
15,626 | def generate_speech_captcha raise RuntimeError , "espeak disabled" unless EasyCaptcha . espeak? if EasyCaptcha . cache File . read ( speech_captcha_cache_path ( current_captcha_code ) ) else wav_file = Tempfile . new ( "#{current_captcha_code}.wav" ) EasyCaptcha . espeak . generate ( current_captcha_code , wav_file . p... | generate speech by captcha from session |
15,627 | def generate_captcha_code session [ :captcha ] = EasyCaptcha . length . times . collect { EasyCaptcha . chars [ rand ( EasyCaptcha . chars . size ) ] } . join end | generate captcha code save in session and return |
15,628 | def captcha_valid? ( code ) return false if session [ :captcha ] . blank? or code . blank? session [ :captcha ] . to_s . upcase == code . to_s . upcase end | validate given captcha code and re |
15,629 | def captcha_tag ( * args ) options = { :alt => 'captcha' , :width => EasyCaptcha . image_width , :height => EasyCaptcha . image_height } options . merge! args . extract_options! image_tag ( captcha_url ( :i => Time . now . to_i ) , options ) end | generate an image_tag for captcha image |
15,630 | def source_photos return [ ] unless sources . kind_of? Array @source_photos ||= sources . map do | source | RGallery :: Photo . new source . src , options . merge ( :sizing => source . sizing ) end end | A photo can contain a source set of other photos! |
15,631 | def sources = sources = [ ] return unless sources . kind_of? Array @sources = sources . map { | source | Hashie :: Mash . new source } end | make sure that sources are wrapped as Hashies to allow method access |
15,632 | def modules modules = @modules . dup modules << @authentication_strategy modules << :db_password modules << :password_reset modules << :trackable modules << :timeoutable if @timeout_in modules << :lifetimed if @max_session_lifetime modules << :brute_force if @max_consecutive_bad_logins_allowed modules end | List of symbols naming modules to load . |
15,633 | def login ( user ) @current_user = user @current_user . generate_session_token if user . present? message = catch ( :failure ) do Authenticate . lifecycle . run_callbacks ( :after_set_user , @current_user , self , event : :authentication ) Authenticate . lifecycle . run_callbacks ( :after_authentication , @current_user... | Initialize an Authenticate session . |
15,634 | def require_login debug "!!!!!!!!!!!!!!!!!! controller#require_login " unauthorized unless logged_in? message = catch ( :failure ) do current_user = authenticate_session . current_user Authenticate . lifecycle . run_callbacks ( :after_set_user , current_user , authenticate_session , event : :set_user ) end unauthorized... | Use this filter as a before_action to control access to controller actions limiting to logged in users . |
15,635 | def unauthorized ( msg = t ( 'flashes.failure_when_not_signed_in' ) ) authenticate_session . logout respond_to do | format | format . any ( :js , :json , :xml ) { head :unauthorized } format . any { redirect_unauthorized ( msg ) } end end | User is not authorized bounce em to sign in |
15,636 | def method_missing ( name , * args , & block ) return super if block case args . size when 0 if name =~ / \A \w \? \z / ! ! ( respond_to? ( $1 ) ? send ( $1 ) : instance_variable_get ( "@#{ $1 }" ) ) elsif name =~ / \A \w \z / instance_variable_get ( "@#{ $1 }" ) else super end when 1 if name =~ / \A \w \z / instance_v... | Allows to dynamically set config attributes . |
15,637 | def to_hash instance_variables . each_with_object ( { } ) do | var , h | h [ var [ 1 .. - 1 ] . to_sym ] = instance_variable_get ( var ) end end | Transforms config to the hash with all keys symbolized . |
15,638 | def prepare_options ( options ) options = engine . config . to_hash . merge ( options ) options . keys . each { | k | options [ k . to_s . gsub ( / / ) { $1 . upcase } . to_sym ] = options [ k ] } options . delete_if { | k , v | v . nil? } end | Responds for preparing compilation options . |
15,639 | def read_compiler_source ( path ) raise engine :: CompilerError , "Couldn't read compiler source: #{ path }" unless File . readable? ( path ) File . read ( path ) end | Reads the compiler source from a file and returns it . |
15,640 | def version stdout , exit_status = Open3 . capture2 "node" , "--eval" , "console.log(require(#{ JSON.dump(File.join(npm_package_path, "package.json")) }).version)" if exit_status . success? stdout . strip else raise engine :: CompilerError , %{Failed to get #{ engine.name } version. Perhaps, the problem with Node.js ru... | Returns version of engine installed system - wide . |
15,641 | def check_npm_package! exit_status = Open3 . capture2 ( "node" , "--eval" , npm_package_require_snippet ) [ 1 ] unless exit_status . success? raise engine :: CompilerError , %{No #{ engine.name } NPM package has been found in your system. } + %{Have you forgotten to "npm install --global #{ npm_package_name }"?} end ni... | Checks if engine NPM package is installed . |
15,642 | def loadstring_and_call ( s , bndng , filename , lineno ) bottom = stack_top chunk = filename ? "#{filename}:#{lineno}" : 'line' err = Lib . luaL_loadbuffer ( @pointer , s , s . bytesize , chunk ) fail_if_error ( 'eval:compile' , err , bndng , filename , lineno ) pcall ( bottom , 0 , bndng , filename , lineno ) end | This method holds the eval mechanism . |
15,643 | def stack_to_s s = ( 1 .. stack_top ) . inject ( [ ] ) { | a , i | type , tname = stack_type_at ( i ) val = if type == TSTRING "\"#{stack_fetch(i)}\"" elsif SIMPLE_TYPES . include? ( type ) stack_fetch ( i ) . to_s elsif type == TTABLE "(# is #{Lib.lua_objlen(@pointer, i)})" else '' end a << "#{i} : #{tname} (#{type}) ... | Returns a string representation of the state s stack . |
15,644 | def stack_push ( o ) return stack_push ( o . to_lua ) if o . respond_to? ( :to_lua ) case o when NilClass then Lib . lua_pushnil ( @pointer ) when TrueClass then Lib . lua_pushboolean ( @pointer , 1 ) when FalseClass then Lib . lua_pushboolean ( @pointer , 0 ) when Integer then Lib . lua_pushinteger ( @pointer , o ) wh... | Given a Ruby instance will attempt to push it on the Lua stack . |
15,645 | def stack_push_hash ( h ) Lib . lua_createtable ( @pointer , 0 , h . size ) h . each do | k , v | stack_push ( k ) stack_push ( v ) Lib . lua_settable ( @pointer , - 3 ) end end | Pushes a hash on top of the Lua stack . |
15,646 | def stack_push_array ( a ) Lib . lua_createtable ( @pointer , a . size , 0 ) a . each_with_index do | e , i | stack_push ( i + 1 ) stack_push ( e ) Lib . lua_settable ( @pointer , - 3 ) end end | Pushes an array on top of the Lua stack . |
15,647 | def set_read_only_connection_for_block ( action ) read_pool_method = nil if session read_pool_method = session [ :next_request_db_connection ] session . delete ( :next_request_db_connection ) if session [ :next_request_db_connection ] end read_pool_method ||= seamless_database_pool_options [ action . to_sym ] || seamle... | Set the read only connection for a block . Used to set the connection for a controller action . |
15,648 | def call ( * args ) bottom = stack_top load_onto_stack args . each { | arg | stack_push ( arg ) } pcall ( bottom , args . length , nil , nil , nil ) end | Calls the Lua function . |
15,649 | def resume ( * args ) bottom = stack_top fetch_library_method ( 'coroutine.resume' ) . load_onto_stack load_onto_stack args . each { | arg | stack_push ( arg ) } pcall ( bottom , args . length + 1 , nil , nil , nil ) end | Resumes the coroutine |
15,650 | def []= ( k , v ) load_onto_stack stack_push ( k ) stack_push ( v ) Lib . lua_settable ( @pointer , - 3 ) v end | Sets a value in the table |
15,651 | def to_h load_onto_stack table_pos = stack_top Lib . lua_pushnil ( @pointer ) h = { } while Lib . lua_next ( @pointer , table_pos ) != 0 do value = stack_fetch ( - 1 ) value . load_onto_stack if value . is_a? ( Ref ) key = stack_fetch ( - 2 ) key . load_onto_stack if key . is_a? ( Ref ) stack_unstack h [ key ] = value ... | Returns a Ruby Hash instance representing this Lua table . |
15,652 | def to_a ( pure = true ) h = self . to_h pure && h . keys . find { | k | not [ Float ] . include? ( k . class ) } && fail ( 'cannot turn hash into array, some keys are not numbers' ) a_keys = ( 1 .. objlen ) . to_a . collect { | k | k . to_f } keys = a_keys + ( h . keys - a_keys ) keys . inject ( [ ] ) { | a , k | a <<... | Returns a Ruby Array instance representing this Lua table . |
15,653 | def sweetalert ( text , title = '' , opts = { } ) opts = { showConfirmButton : false , timer : 2000 , allowOutsideClick : true , confirmButtonText : 'OK' } . merge ( opts ) opts [ :text ] = text opts [ :title ] = title if opts [ :button ] opts [ :showConfirmButton ] = true opts [ :confirmButtonText ] = opts [ :button ]... | Display an alert with a text and an optional title Default without an specific type |
15,654 | def flash_config ( opts ) if opts [ :title ] . blank? opts [ :title ] = opts [ :text ] opts . delete ( :text ) end flash [ :sweetify ] = opts . to_json end | Flash the configuration as json If no title is specified use the text as the title |
15,655 | def to_xml ( options = { } ) doc = Nokogiri :: XML :: Document . new root = doc . create_element ( tag_name ) self . class . keys . each do | name | value = read_attribute ( name ) next if value . blank? root [ name . to_s . camelize ] = value end self . class . elements . each do | name , field | next if options [ :on... | Builds XML from elements and attributes |
15,656 | def insert ( index , middleware , * args , & block ) index = self . index ( index ) unless index . is_a? ( Integer ) raise "no such middleware to insert before: #{index.inspect}" unless index stack . insert ( index , [ middleware , args , block ] ) end | Inserts a middleware at the given index or directly before the given middleware object . |
15,657 | def replace ( index , middleware , * args , & block ) if index . is_a? ( Integer ) delete ( index ) insert ( index , middleware , * args , & block ) else insert_before ( index , middleware , * args , & block ) delete ( index ) end end | Replaces the given middleware object or index with the new middleware . |
15,658 | def reload if new_record? false else reloaded_element = self . class . find ( self . id ) @attributes = reloaded_element . attributes reset_modifications true end end | Reloads the + Element + attributes from Exchanger . |
15,659 | def to_xml ( value , options = { } ) if value . is_a? ( Exchanger :: Element ) value . tag_name = tag_name value . to_xml ( options ) else doc = Nokogiri :: XML :: Document . new root = doc . create_element ( tag_name ) case value when Array value . each do | sub_value | root << sub_field . to_xml ( sub_value , options... | Convert Ruby value to XML |
15,660 | def value_from_xml ( node ) if type . respond_to? ( :new_from_xml ) type . new_from_xml ( node ) elsif type . is_a? ( Array ) node . children . map do | sub_node | sub_field . value_from_xml ( sub_node ) end elsif type == Boolean node . text == "true" elsif type == Integer node . text . to_i unless node . text . empty?... | Convert XML to Ruby value |
15,661 | def reset_attribute! ( name ) value = attribute_was ( name ) if value @attributes [ name ] = value modifications . delete ( name ) end end | Resets a changed field back to its old value . |
15,662 | def accessed ( name , value ) @accessed ||= { } @accessed [ name ] = value . dup if ( value . is_a? ( Array ) || value . is_a? ( Hash ) ) && ! @accessed . has_key? ( name ) value end | Audit the original value for a field that can be modified in place . |
15,663 | def modifications @accessed . each_pair do | field , value | current = @attributes [ field ] if current != value || ( current . is_a? ( Array ) && current . any? { | v | v . respond_to? ( :changed? ) && v . changed? } ) @modifications [ field ] = [ value , current ] end end @accessed . clear @modifications end | Get all normal modifications plus in place potential changes . Also checks changes in array attributes with + Element + objects . |
15,664 | def modify ( name , old_value , new_value ) @attributes [ name ] = new_value if @modifications && ( old_value != new_value ) original = @modifications [ name ] . first if @modifications [ name ] @modifications [ name ] = [ ( original || old_value ) , new_value ] end end | Audit the change of a field s value . |
15,665 | def method_missing ( name , * args ) attr = name . to_s . sub ( "=" , "" ) return super unless attributes . has_key? ( attr ) if name . to_s . ends_with? ( "=" ) write_attribute ( attr , * args ) else read_attribute ( attr ) end end | Used for allowing accessor methods for dynamic attributes |
15,666 | def request ( post_body , headers ) response = @client . post ( endpoint , post_body , headers ) return { :status => response . status , :body => response . content , :content_type => response . contenttype } end | Does the actual HTTP level interaction . |
15,667 | def bind conn = Net :: LDAP . new :host => @config [ :server ] , :port => @config [ :port ] , :base => @config [ :base ] if @config [ :encryption ] conn . encryption @config [ :encryption ] end raise "Anonymous Bind is disabled" if @config [ :password ] == "" && ! ( @config [ :anonymous_bind ] ) conn . auth "#{@config[... | Attempts to bind to Active Directory |
15,668 | def request ( method , path , params = nil , body = nil , depth = nil , destination = nil , raw = false ) response = Net :: HTTP . start ( @url . host , @url . port , use_ssl : @url . scheme == "https" ) do | http | req = Kernel . const_get ( "Net::HTTP::#{method.capitalize}" ) . new ( @url . request_uri + path ) req [... | Gathers credentials for communicating with Nextcloud instance |
15,669 | def parse_with_meta ( doc , xpath ) groups = [ ] doc . xpath ( xpath ) . each do | prop | groups << prop . text end meta = get_meta ( doc ) groups . send ( :define_singleton_method , :meta ) do meta end groups end | Makes an array out of repeated elements |
15,670 | def get_meta ( doc ) meta = doc . xpath ( "//meta/*" ) . each_with_object ( { } ) do | node , meta | meta [ node . name ] = node . text end end | Parses meta information returned by API may include a status status code and a message |
15,671 | def doc_to_hash ( doc , xpath = "/" ) h = Hash . from_xml ( doc . xpath ( xpath ) . to_xml ) h end | Converts document to hash |
15,672 | def add_meta ( doc , obj ) meta = get_meta ( doc ) obj . define_singleton_method ( :meta ) { meta } && obj end | Adds meta method to an object |
15,673 | def parse_dav_response ( doc ) doc . remove_namespaces! if doc . at_xpath ( "//error" ) { exception : doc . xpath ( "//exception" ) . text , message : doc . xpath ( "//message" ) . text } elsif doc . at_xpath ( "//status" ) { status : doc . xpath ( "//status" ) . text } else { status : "ok" } end end | Shows errors or success message |
15,674 | def has_dav_errors ( doc ) doc . remove_namespaces! if doc . at_xpath ( "//error" ) { exception : doc . xpath ( "//exception" ) . text , message : doc . xpath ( "//message" ) . text } else false end end | Shows error or returns false |
15,675 | def handle_field ( field ) case field when Symbol then return return_symbol_value ( field ) when Array then return @ldap_object . try ( field . first ) . try ( :collect , & field . last ) end end | Handle the output for the given field |
15,676 | def cn_groups_nested @cn_groups_nested = cn_groups cn_groups . each do | group | ado = Adauth :: AdObjects :: Group . where ( 'name' , group ) . first if ado groups = convert_to_objects ado . cn_groups groups . each do | g | @cn_groups_nested . push g if ! ( @cn_groups_nested . include? ( g ) ) end end end return @cn_g... | The same as cn_groups but with the parent groups included |
15,677 | def ous unless @ous @ous = [ ] @ldap_object . dn . split ( / / ) . each do | entry | @ous . push Adauth :: AdObjects :: OU . where ( 'name' , entry . gsub ( / / , '' ) ) . first if entry =~ / / end end @ous end | Returns all the ous the object is in |
15,678 | def modify ( operations ) Adauth . logger . info ( self . class . inspect ) { "Attempting modify operation" } unless Adauth . connection . modify :dn => @ldap_object . dn , :operations => operations Adauth . logger . fatal ( self . class . inspect ) { "Modify Operation Failed! Code: #{Adauth.connection.get_operation_re... | Runs a modify action on the current object takes an aray of operations |
15,679 | def members unless @members @members = [ ] [ Adauth :: AdObjects :: Computer , Adauth :: AdObjects :: OU , Adauth :: AdObjects :: User , Adauth :: AdObjects :: Group ] . each do | object | object . all . each do | entity | @members . push entity if entity . is_a_member? ( self ) end end end @members end | Returns an array of member objects for this object |
15,680 | def run_and_collect_multiple_changes ( monitor , times , directory , * flags , & block ) watch_and_run ( monitor , times , false , directory , * flags , & block ) end | Runs the monitor and collects changes for the specified amount of times on the given directory . It stops the monitor afterwards . |
15,681 | def run ( monitor , directory , * flags , & block ) result = watch_and_run ( monitor , 1 , false , directory , * flags , & block ) result . changes [ 0 ] . directory = result . directory result . changes [ 0 ] end | Helper method for running the monitor one time . |
15,682 | def run_with_fixture ( monitor , * flags , & block ) fixture do | f | run ( monitor , f , * flags , & block ) end end | Helper method for using the run method with the fixture helper . |
15,683 | def run_recursively_and_collect_multiple_changes ( monitor , times , directory , * flags , & block ) watch_and_run ( monitor , times , true , directory , * flags , & block ) end | Runs the monitor recursively and collects changes for the specified amount of times on the given directory . It stops the monitor afterwards . |
15,684 | def run_recursively ( monitor , directory , * flags , & block ) result = watch_and_run ( monitor , 1 , true , directory , * flags , & block ) result . changes [ 0 ] . directory = result . directory result . changes [ 0 ] end | Helper method for running the monitor recursively one time . |
15,685 | def run_recursively_with_fixture ( monitor , * flags , & block ) fixture do | f | run_recursively ( monitor , f , * flags , & block ) end end | Helper method for using the run method recursively with the fixture helper . |
15,686 | def watch_and_run ( monitor , times , recursively , directory , * flags ) result = OpenStruct . new ( directory : directory , changes : [ ] ) i = 0 result . changes [ i ] = OpenStruct . new ( called : false ) can_return = false callback = Proc . new do | change | next if can_return result . changes [ i ] . called = tru... | Very customizable method to watch directories and then run the monitor |
15,687 | def fixture pwd = FileUtils . pwd path = File . expand_path ( File . join ( pwd , "spec/.fixtures/#{rand(99999)}" ) ) FileUtils . mkdir_p ( path ) FileUtils . cd ( path ) yield ( path ) ensure FileUtils . cd pwd FileUtils . rm_rf ( path ) if File . exists? ( path ) end | Prepares the temporary fixture directory and cleans it afterwards . |
15,688 | def to_term ( color_model = 256 ) term = case color_model when 256 then PryTheme :: RGB :: TABLE . index ( @value ) when 16 then PryTheme :: RGB :: SYSTEM . index ( @value ) when 8 then PryTheme :: RGB :: LINUX . index ( @value ) else raise ArgumentError , "invalid value for PryTheme::HEX#to_term(): #{ @value }" end te... | Converts the RGB to a terminal colour equivalent . |
15,689 | def validate_array ( ary ) correct_size = ary . size . equal? ( 3 ) correct_vals = ary . all? { | val | val . is_a? ( Integer ) && val . between? ( 0 , 255 ) } return true if correct_size && correct_vals raise ArgumentError , %|invalid value for PryTheme::RGB#validate_array(): "#{ ary }"| end | Checks whether the + ary + has correct number of elements and these elements are valid RGB numbers . |
15,690 | def nearest_term_256 ( byte ) for i in 0 .. 4 lower , upper = BYTEPOINTS_256 [ i ] , BYTEPOINTS_256 [ i + 1 ] next unless byte . between? ( lower , upper ) distance_from_lower = ( lower - byte ) . abs distance_from_upper = ( upper - byte ) . abs closest = distance_from_lower < distance_from_upper ? lower : upper end cl... | Approximates the given + byte + to a terminal colour value within range of 256 colours . |
15,691 | def find_among_term_colors ( term , color_model ) rgb = @value . map { | byte | nearest_term_256 ( byte ) } term = PryTheme :: RGB :: TABLE . index ( rgb ) approximate ( term , color_model ) end | Finds an approximated + term + colour among the colour numbers within the given + color_model + . |
15,692 | def approximate ( term , color_model ) needs_approximation = ( term > color_model - 1 ) if needs_approximation case color_model when 16 then nearest_term_16 ( term ) when 8 then nearest_term_8 ( term ) end else term end end | Approximates + term + in correspondence with + color_model + |
15,693 | def endpoint_parameter ( name , description , how_to_pass , required , type , params = { } ) parameters = settings . swagger_current_endpoint_parameters check_if_not_duplicate ( name , parameters , 'Parameter' ) parameters [ name ] = Sinatra :: SwaggerExposer :: Configuration :: SwaggerEndpointParameter . new ( name , ... | Define parameter for the endpoint |
15,694 | def endpoint ( params ) params . each_pair do | param_name , param_value | case param_name when :summary endpoint_summary param_value when :description endpoint_description param_value when :tags endpoint_tags * param_value when :produces endpoint_produces * param_value when :path endpoint_path param_value when :parame... | Define fluent endpoint dispatcher |
15,695 | def response_header ( name , type , description ) settings . swagger_response_headers . add_response_header ( name , type , description ) end | Declare a response header |
15,696 | def endpoint_response ( code , type = nil , description = nil , headers = [ ] ) responses = settings . swagger_current_endpoint_responses check_if_not_duplicate ( code , responses , 'Response' ) responses [ code ] = Sinatra :: SwaggerExposer :: Configuration :: SwaggerEndpointResponse . new ( type , description , setti... | Declare a response |
15,697 | def route ( verb , path , options = { } , & block ) no_swagger = options [ :no_swagger ] options . delete ( :no_swagger ) if ( verb == 'HEAD' ) || no_swagger super ( verb , path , options , & block ) else request_processor = create_request_processor ( verb . downcase , path , options ) super ( verb , path , options ) d... | Override Sinatra route method |
15,698 | def create_request_processor ( type , path , opts ) current_endpoint_info = settings . swagger_current_endpoint_info current_endpoint_parameters = settings . swagger_current_endpoint_parameters current_endpoint_responses = settings . swagger_current_endpoint_responses endpoint = Sinatra :: SwaggerExposer :: Configurati... | Call for each endpoint declaration |
15,699 | def check_if_not_duplicate ( key , values , name ) if values . key? key raise SwaggerInvalidException . new ( "#{name} already exist for #{key} with value [#{values[key]}]" ) end end | Check if a value does not exist in a hash and throw an Exception |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.