idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
8,200 | def render ( context , options , block ) super rescue CellHandling => e CellUtils . render context , e . message , options [ :locals ] , & block end | When a type partial is found it works as usual . |
8,201 | def find_partial ( * ) super . tap do | partial | raise CellHandling , partial . inspect if CellUtils . cell? partial . inspect end end | Override origin method to stop rendering when a cell is found . |
8,202 | def filter_types types = [ ] wrap_with_rewind ( @filtered_data ) do scanline_positions . each do | pos | @filtered_data . pos = pos byte = @filtered_data . read 1 types << byte . unpack ( 'C' ) . first end end types end | Returns an array of each scanline s filter type value . |
8,203 | def compress ( level = Zlib :: DEFAULT_COMPRESSION , window_bits = Zlib :: MAX_WBITS , mem_level = Zlib :: DEF_MEM_LEVEL , strategy = Zlib :: DEFAULT_STRATEGY ) wrap_with_rewind ( @compressed_data , @filtered_data ) do z = Zlib :: Deflate . new level , window_bits , mem_level , strategy until @filtered_data . eof? do b... | Re - compress the filtered data . |
8,204 | def each_scanline return enum_for :each_scanline unless block_given? prev_filters = self . filter_types is_refilter_needed = false filter_codecs = [ ] wrap_with_rewind ( @filtered_data ) do at = 0 scanline_positions . push ( @filtered_data . size ) . inject do | pos , delimit | scanline = Scanline . new @filtered_data ... | Process each scanline . |
8,205 | def width = w @head_data . pos = 8 while bytes = @head_data . read ( 8 ) length , type = bytes . unpack 'Na*' if type == 'IHDR' @head_data << [ w ] . pack ( 'N' ) @head_data . pos -= 4 data = @head_data . read length @head_data << [ Zlib . crc32 ( data , Zlib . crc32 ( type ) ) ] . pack ( 'N' ) break end end @head_data... | Rewrites the width value . |
8,206 | def height = h @head_data . pos = 8 while bytes = @head_data . read ( 8 ) length , type = bytes . unpack 'Na*' if type == 'IHDR' @head_data . pos += 4 @head_data << [ h ] . pack ( 'N' ) @head_data . pos -= 8 data = @head_data . read length @head_data << [ Zlib . crc32 ( data , Zlib . crc32 ( type ) ) ] . pack ( 'N' ) @... | Rewrites the height value . |
8,207 | def save file wrap_with_rewind ( @head_data , @tail_data , @compressed_data ) do open ( file , 'wb' ) do | io | io << @head_data . read chunk_size = @idat_chunk_size || @compressed_data . size type = 'IDAT' until @compressed_data . eof? do data = @compressed_data . read ( chunk_size ) io << [ data . size ] . pack ( 'N'... | Save to the + file + . |
8,208 | def wrap_with_rewind * io , & block io . each do | i | i . rewind end yield io . each do | i | i . rewind end end | Rewinds given IOs before and after the block . |
8,209 | def scanline_positions scanline_pos = [ 0 ] amount = @filtered_data . size @interlace_pass_count = [ ] if self . interlaced? v = 1 + ( @width / 8.0 ) . ceil * @sample_size ( @height / 8.0 ) . ceil . times do scanline_pos << scanline_pos . last + v end @interlace_pass_count << scanline_pos . size v = 1 + ( ( @width - 4 ... | Calculate positions of scanlines |
8,210 | def register_filter_encoder encoder = nil , & block if ! encoder . nil? && encoder . is_a? ( Proc ) @filter_codec [ :encoder ] = encoder elsif block_given? @filter_codec [ :encoder ] = block end save end | Registers a custom filter function to encode data . |
8,211 | def register_filter_decoder decoder = nil , & block if ! decoder . nil? && decoder . is_a? ( Proc ) @filter_codec [ :decoder ] = decoder elsif block_given? @filter_codec [ :decoder ] = block end save end | Registers a custom filter function to decode data . |
8,212 | def save pos = @io . pos @io . pos = @start_at @io << [ Filter . guess ( @filter_type ) ] . pack ( 'C' ) @io << self . data . slice ( 0 , @data_size ) . ljust ( @data_size , "\0" ) @io . pos = pos @callback . call ( self ) unless @callback . nil? self end | Save the changes . |
8,213 | def variance ( measurements ) return 0 if measurements . empty? avg = average ( measurements ) total = measurements . reduce ( 0 ) do | sum , x | sum + ( x - avg ) ** 2 end total . to_f / measurements . size end | Calculate variance of measurements |
8,214 | def assert_perform_under ( threshold , options = { } , & work ) actual , _ = ExecutionTime . run ( options , & work ) actual <= threshold end | Run given work and gather time statistics |
8,215 | def assert_perform_ips ( iterations , options = { } , & work ) mean , stddev , _ = Iteration . run ( options , & work ) iterations <= ( mean + 3 * stddev ) end | Assert work is performed within expected iterations per second |
8,216 | def run request_config if @options [ :reauth ] if @options [ :changelog ] system %[ more "#{File.join(File.dirname(__FILE__), '../../CHANGELOG.markdown')}" ] exit end begin if @command if command? @command result = send @command , * @args if not result . nil? if result . respond_to? :join , include_all = false puts res... | Start the application . |
8,217 | def time2float time_string if time_string =~ / / hours , minutes = time_string . split ( ':' ) hours . to_f + ( minutes . to_f / 60.0 ) else time_string . to_f end end | Convert from a time span in hour or decimal format to a float . |
8,218 | def append_note http , new_notes ( self . notes << "\n#{new_notes}" ) . lstrip! http . post "daily/update/#{id}" , notes : notes , hours : hours end | Append a string to the notes for this task . |
8,219 | def status result = Faraday . new ( "http://kccljmymlslr.statuspage.io/api/v2" ) do | f | f . adapter Faraday . default_adapter end . get ( 'status.json' ) . body json = Yajl :: Parser . parse result , symbolize_keys : true status = json [ :status ] [ :description ] updated_at = DateTime . parse ( json [ :page ] [ :upd... | Show the network status of the Harvest service . |
8,220 | def shelves ( user_id , options = { } ) options = options . merge ( user_id : user_id , v : 2 ) data = request ( "/shelf/list.xml" , options ) shelves = data [ "shelves" ] shelves = data [ "shelves" ] [ "user_shelf" ] . map do | s | Hashie :: Mash . new ( { id : s [ "id" ] , name : s [ "name" ] , book_count : s [ "book... | Lists shelves for a user |
8,221 | def shelf ( user_id , shelf_name , options = { } ) options = options . merge ( shelf : shelf_name , v : 2 ) data = request ( "/review/list/#{user_id}.xml" , options ) reviews = data [ "reviews" ] [ "review" ] books = [ ] unless reviews . nil? reviews = [ reviews ] unless reviews . instance_of? ( Array ) books = reviews... | Get books from a user s shelf |
8,222 | def add_to_shelf ( book_id , shelf_name , options = { } ) options = options . merge ( book_id : book_id , name : shelf_name , v : 2 ) data = oauth_request_method ( :post , "/shelf/add_to_shelf.xml" , options ) shelves = data [ "my_review" ] [ "shelves" ] [ "shelf" ] shelves = [ shelves ] unless shelves . instance_of? (... | Add book to a user s shelf |
8,223 | def request ( path , params = { } ) if oauth_configured? oauth_request ( path , params ) else http_request ( path , params ) end end | Perform an API request using API key or OAuth token |
8,224 | def http_request ( path , params ) token = api_key || Goodreads . configuration [ :api_key ] fail ( Goodreads :: ConfigurationError , "API key required." ) if token . nil? params . merge! ( format : API_FORMAT , key : token ) url = "#{API_URL}#{path}" resp = RestClient . get ( url , params : params ) do | response , re... | Perform an API request using API key |
8,225 | def oauth_request_method ( http_method , path , params = { } ) fail "OAuth access token required!" unless @oauth_token headers = { "Accept" => "application/xml" } resp = if http_method == :get || http_method == :delete if params url_params = params . map { | k , v | "#{k}=#{v}" } . join ( "&" ) path = "#{path}?#{url_pa... | Perform an OAuth API request . Goodreads must have been initialized with a valid OAuth access token . |
8,226 | def group ( group_id ) data = request ( "/group/show" , id : group_id ) Hashie :: Mash . new ( data [ "group" ] ) end | Get group details |
8,227 | def group_list ( user_id , sort = "my_activity" ) data = request ( "/group/list" , id : user_id , sort : sort ) Hashie :: Mash . new ( data [ "groups" ] [ "list" ] ) end | Get list of groups a given user is a member of |
8,228 | def user ( id ) data = request ( "/user/show" , id : id ) Hashie :: Mash . new ( data [ "user" ] ) end | Get user details |
8,229 | def friends ( user_id , options = { } ) data = oauth_request ( "/friend/user/#{user_id}" , options ) Hashie :: Mash . new ( data [ "friends" ] ) end | Get the specified user s friends |
8,230 | def recent_reviews ( params = { } ) skip_cropped = params . delete ( :skip_cropped ) || false data = request ( "/review/recent_reviews" , params ) return unless data [ "reviews" ] && data [ "reviews" ] . key? ( "review" ) reviews = data [ "reviews" ] [ "review" ] . map { | r | Hashie :: Mash . new ( r ) } reviews = rev... | Recent reviews from all members . |
8,231 | def review ( id ) data = request ( "/review/show" , id : id ) Hashie :: Mash . new ( data [ "review" ] ) end | Get review details |
8,232 | def reviews ( params = { } ) data = request ( "/review/list" , params . merge ( v : "2" ) ) reviews = data [ "reviews" ] [ "review" ] if reviews . present? reviews . map { | review | Hashie :: Mash . new ( review ) } else [ ] end end | Get list of reviews |
8,233 | def user_review ( user_id , book_id , params = { } ) data = request ( '/review/show_by_user_and_book.xml' , params . merge ( v : "2" , user_id : user_id , book_id : book_id ) ) Hashie :: Mash . new ( data [ "review" ] ) end | Get a user s review for a given book |
8,234 | def create_review ( book_id , params = { } ) params = params . merge ( book_id : book_id , v : "2" ) params [ :read_at ] = params [ :read_at ] . strftime ( '%Y-%m-%d' ) if params [ :read_at ] . is_a? ( Time ) params [ :' ' ] = params . delete ( :review ) if params [ :review ] params [ :' ' ] = params . delete ( :rating... | Add review for a book |
8,235 | def edit_review ( review_id , params = { } ) params = params . merge ( v : "2" ) params [ :read_at ] = params [ :read_at ] . strftime ( '%Y-%m-%d' ) if params [ :read_at ] . is_a? ( Time ) params [ :' ' ] = params . delete ( :review ) if params [ :review ] params [ :' ' ] = params . delete ( :rating ) if params [ :rati... | Edit review for a book |
8,236 | def search_books ( query , params = { } ) params [ :q ] = query . to_s . strip data = request ( "/search/index" , params ) Hashie :: Mash . new ( data [ "search" ] ) end | Search for books |
8,237 | def author ( id , params = { } ) params [ :id ] = id data = request ( "/author/show" , params ) Hashie :: Mash . new ( data [ "author" ] ) end | Get author details |
8,238 | def author_by_name ( name , params = { } ) params [ :id ] = name name_encoded = URI . encode ( name ) data = request ( "/api/author_url/#{name_encoded}" , params ) Hashie :: Mash . new ( data [ "author" ] ) end | Search for an author by name |
8,239 | def insert ( prev , protocol , options = { } ) klass = check_protocol ( protocol ) nxt = prev . body header = klass . new ( options . merge! ( packet : self ) ) add_header header , previous_header : prev idx = headers . index ( prev ) + 1 headers [ idx , 0 ] = header header [ :body ] = nxt self end | Insert a header in packet |
8,240 | def encapsulate ( other , parsing : false ) other . headers . each_with_index do | h , i | add_header h , parsing : ( i > 0 ) || parsing end end | Encapulate another packet in + self + |
8,241 | def decapsulate ( * hdrs ) hdrs . each do | hdr | idx = headers . index ( hdr ) raise FormatError , 'header not in packet!' if idx . nil? prev_hdr = idx > 0 ? headers [ idx - 1 ] : nil next_hdr = ( idx + 1 ) < headers . size ? headers [ idx + 1 ] : nil headers . delete_at ( idx ) add_header ( next_hdr , previous_header... | Remove headers from + self + |
8,242 | def parse ( binary_str , first_header : nil ) headers . clear if first_header . nil? first_header = guess_first_header ( binary_str ) if first_header . nil? raise ParseError , 'cannot identify first header in string' end end add first_header headers [ - 1 , 1 ] = last_header . read ( binary_str ) decode_bottom_up self ... | Parse a binary string and populate Packet from it . |
8,243 | def inspect str = Inspect . dashed_line ( self . class ) headers . each do | header | str << header . inspect end str << Inspect . inspect_body ( body ) end | Get packet as a pretty formatted string . |
8,244 | def check_protocol ( protocol ) klass = Header . get_header_class_by_name ( protocol ) raise ArgumentError , "unknown #{protocol} protocol" if klass . nil? klass end | check if protocol is known |
8,245 | def add_header ( header , previous_header : nil , parsing : false ) prev_header = previous_header || last_header if prev_header bindings = prev_header . class . known_headers [ header . class ] bindings = prev_header . class . known_headers [ header . class . superclass ] if bindings . nil? if bindings . nil? msg = "#{... | Add a header to packet |
8,246 | def guess_first_header ( binary_str ) first_header = nil Header . all . each do | hklass | hdr = hklass . new ( packet : self ) hdr = hdr . read ( binary_str ) next unless hdr . parse? first_header = hklass . to_s . gsub ( / / , '' ) if search_upper_header ( hdr ) break unless first_header . nil? end first_header end | Try to guess header from + binary_str + |
8,247 | def decode_bottom_up loop do last_known_hdr = last_header break if ! last_known_hdr . respond_to? ( :body ) || last_known_hdr . body . empty? nh = search_upper_header ( last_known_hdr ) break if nh . nil? nheader = nh . new ( packet : self ) nheader = nheader . read ( last_known_hdr . body ) next unless nheader . parse... | Decode packet bottom up |
8,248 | def search_upper_header ( hdr ) hdr . class . known_headers . each do | nh , bindings | return nh if bindings . check? ( hdr ) end nil end | Search a upper header for + hdr + |
8,249 | def dependent_operations ( operation ) operations . select do | top | top . dependencies . select do | dp | dp [ 'id' ] == operation . template . id && dp [ 'statuses' ] . include? ( operation . status ) end . present? end end | here we calculate template operations that depends on given process operation status and template id |
8,250 | def target @target ||= begin parent = context [ :parent ] if parent . is_a? RailsWorkflow :: Operation parent . becomes ( RailsWorkflow :: Operation ) elsif parent . is_a? RailsWorkflow :: Process parent . becomes ( RailsWorkflow :: Process ) end end end | Changing custom process or operation classes to default classes . If we store error with a custom class and somebody will delete or rename this class - we will not be able to load error . |
8,251 | def method_missing ( attr_name ) member_sym = attr_name . id2name . to_sym self [ member_sym ] rescue ArgumentError raise ( NoMethodError . new ( "undefined method '#{attr_name}' for #{self}" ) ) end | Provides accessor methods for the members of the MeCab struct . |
8,252 | def parse ( text , constraints = { } ) if text . nil? raise ArgumentError . new 'Text to parse cannot be nil' elsif constraints [ :boundary_constraints ] if ! ( constraints [ :boundary_constraints ] . is_a? ( Regexp ) || constraints [ :boundary_constraints ] . is_a? ( String ) ) raise ArgumentError . new 'boundary cons... | Initializes the wrapped Tagger instance with the given options . |
8,253 | def truncate ( str , length , options = { } ) text = str . dup options [ :omission ] ||= "..." length_with_room_for_omission = length - options [ :omission ] . length stop = options [ :separator ] ? ( text . rindex ( options [ :separator ] , length_with_room_for_omission ) || length_with_room_for_omission ) : length_wi... | copied from ActiveSupport |
8,254 | def process_notification ( notification ) Flapjack . logger . debug { "Processing notification: #{notification.inspect}" } check = notification . check check_name = check . name alerts = alerts_for ( notification , check , :time => Time . now ) if alerts . nil? || alerts . empty? Flapjack . logger . info { "No alerts" ... | takes an event for which messages should be generated works out the type of notification updates the notification history in redis generates the notifications |
8,255 | def setup_signals Kernel . trap ( 'INT' ) { Thread . new { @shutdown . call ( Signal . list [ 'INT' ] ) } . join } Kernel . trap ( 'TERM' ) { Thread . new { @shutdown . call ( Signal . list [ 'TERM' ] ) } . join } unless RbConfig :: CONFIG [ 'host_os' ] =~ / /i Kernel . trap ( 'HUP' ) { Thread . new { @reload . call } ... | the global nature of this seems at odds with it calling stop within a single coordinator instance . Coordinator is essentially a singleton anyway ... |
8,256 | def build_from_hash ( attributes ) return nil unless attributes . is_a? ( Hash ) self . class . swagger_types . each_pair do | key , type | if type =~ / /i if attributes [ self . class . attribute_map [ key ] ] . is_a? ( Array ) self . send ( "#{key}=" , attributes [ self . class . attribute_map [ key ] ] . map { | v |... | build the object from hash |
8,257 | def to_hash hash = { } attributes = self . class . attribute_map . sort_by { | key , value | key } attributes . each { | attr , param | value = self . send ( attr ) next if value . nil? if value . is_a? ( Array ) hash [ param ] = value . compact . map { | v | _to_hash ( v ) } else hash [ param ] = _to_hash ( value ) en... | return the object in the form of hash |
8,258 | def run ( * parameters ) name = parameters . shift if name . nil? || name == 'help' if command_name = parameters . first command = @commands [ command_name ] command . usage else usage end else command = @commands [ name ] if command . nil? @output . write ( "There is no command called '#{name}'.\n" ) else command . ru... | Instantiate a CLI for an API described by a JSON schema . |
8,259 | def run ( * parameters ) resource_name = @link_schema . resource_name name = @link_schema . name result = @client . send ( resource_name ) . send ( name , * parameters ) result = result . to_a if result . instance_of? ( Enumerator ) if result && ! result . instance_of? ( String ) result = MultiJson . dump ( result , pr... | Run the command and write the results to the output stream . |
8,260 | def run ( * parameters ) path , body = @link_schema . format_path ( parameters ) path = "#{@path_prefix}#{path}" unless @path_prefix == '/' headers = @default_headers if body case @link_schema . method when :put , :post , :patch headers = headers . merge ( { 'Content-Type' => @link_schema . content_type } ) body = @lin... | Instantiate a link . |
8,261 | def unpack_url ( url ) root_url = [ ] path_prefix = '' parts = URI . split ( url ) root_url << "#{parts[0]}://" root_url << "#{parts[1]}@" unless parts [ 1 ] . nil? root_url << "#{parts[2]}" root_url << ":#{parts[3]}" unless parts [ 3 ] . nil? path_prefix = parts [ 5 ] return root_url . join ( '' ) , path_prefix end | Unpack the URL and split it into a root URL and a path prefix if one exists . |
8,262 | def method_missing ( name ) name = name . to_s resource = @resources [ name ] if resource . nil? name = Heroics . ruby_name ( name ) resource = @resources [ name ] if resource . nil? raise NoMethodError . new ( "undefined method `#{name}' for #{to_s}" ) end end resource end | Instantiate an HTTP client . |
8,263 | def method_missing ( name , * parameters ) link = @links [ name . to_s ] if link . nil? address = "<#{self.class.name}:0x00#{(self.object_id << 1).to_s(16)}>" raise NoMethodError . new ( "undefined method `#{name}' for ##{address}" ) end link . run ( * parameters ) end | Find a link and invoke it . |
8,264 | def resource ( name ) if @schema [ 'definitions' ] . has_key? ( name ) ResourceSchema . new ( @schema , name ) else raise SchemaError . new ( "Unknown resource '#{name}'." ) end end | Get a schema for a named resource . |
8,265 | def example_body if body_schema = link_schema [ 'schema' ] definitions = @schema [ 'definitions' ] [ @resource_name ] [ 'definitions' ] Hash [ body_schema [ 'properties' ] . keys . map do | property | if definitions . has_key? ( property ) example = definitions [ property ] [ 'example' ] else example = '' end [ propert... | Get an example request body . |
8,266 | def format_path ( parameters ) path = link_schema [ 'href' ] parameter_size = path . scan ( PARAMETER_REGEX ) . size too_few_parameters = parameter_size > parameters . size too_many_parameters = parameter_size < ( parameters . size - 1 ) if too_few_parameters || too_many_parameters raise ArgumentError . new ( "wrong nu... | Inject parameters into the link href and return the body if it exists . |
8,267 | def resolve_parameters ( parameters ) properties = @schema [ 'definitions' ] [ @resource_name ] [ 'properties' ] return [ '' ] if properties . nil? definitions = Hash [ properties . each_pair . map do | key , value | [ value [ '$ref' ] , key ] end ] parameters . map do | parameter | definition_name = URI . unescape ( p... | Get the names of the parameters this link expects . |
8,268 | def resolve_parameter_details ( parameters ) parameters . map do | parameter | parameter = URI . unescape ( parameter [ 2 .. - 3 ] ) path = parameter . split ( '/' ) [ 1 .. - 1 ] info = lookup_parameter ( path , @schema ) resource_name = path [ 1 ] . gsub ( '-' , '_' ) if info . has_key? ( 'anyOf' ) ParameterChoice . n... | Get the parameters this link expects . |
8,269 | def unpack_multiple_parameters ( parameters ) parameters . map do | info | parameter = info [ '$ref' ] path = parameter . split ( '/' ) [ 1 .. - 1 ] info = lookup_parameter ( path , @schema ) resource_name = path . size > 2 ? path [ 1 ] . gsub ( '-' , '_' ) : nil name = path [ - 1 ] Parameter . new ( resource_name , na... | Unpack an anyOf or oneOf multi - parameter blob . |
8,270 | def lookup_parameter ( path , schema ) key = path [ 0 ] remaining = path [ 1 .. - 1 ] if remaining . empty? return schema [ key ] else lookup_parameter ( remaining , schema [ key ] ) end end | Recursively walk the object hierarchy in the schema to resolve a given path . This is used to find property information related to definitions in link hrefs . |
8,271 | def format_parameter ( parameter ) formatted_parameter = parameter . instance_of? ( Time ) ? iso_format ( parameter ) : parameter . to_s WEBrick :: HTTPUtils . escape formatted_parameter end | Convert a path parameter to a format suitable for use in a path . |
8,272 | def method_signature @parameters . map { | info | info . name == 'body' ? "body = {}" : Heroics . ruby_name ( info . name ) } . join ( ', ' ) end | list of parameters for method signature body is optional |
8,273 | def option ( short , long , desc , argument : :forbidden , multiple : false , hidden : false , default : nil , transform : nil , & block ) @command . option_definitions << Cri :: OptionDefinition . new ( short : short &. to_s , long : long &. to_s , desc : desc , argument : argument , multiple : multiple , hidden : hid... | Adds a new option to the command . If a block is given it will be executed when the option is successfully parsed . |
8,274 | def param ( name , transform : nil ) if @command . explicitly_no_params? raise AlreadySpecifiedAsNoParams . new ( name , @command ) end @command . parameter_definitions << Cri :: ParamDefinition . new ( name : name , transform : transform , ) end | Defines a new parameter for the command . |
8,275 | def required ( short , long , desc , params = { } , & block ) params = params . merge ( argument : :required ) option ( short , long , desc , params , & block ) end | Adds a new option with a required argument to the command . If a block is given it will be executed when the option is successfully parsed . |
8,276 | def run @running = true while running? e = @unprocessed_arguments_and_options . shift break if e . nil? if e == '--' handle_dashdash ( e ) elsif e =~ / / && ! @no_more_options handle_dashdash_option ( e ) elsif e =~ / / && ! @no_more_options handle_dash_option ( e ) else add_argument ( e ) end end add_defaults self ens... | Parses the command - line arguments into options and arguments . |
8,277 | def wrap_and_indent ( str , width , indentation , first_line_already_indented = false ) indented_width = width - indentation indent = ' ' * indentation paragraphs = to_paragraphs ( str ) text = paragraphs . map do | paragraph | lines = [ ] line = '' paragraph . split ( / \s / ) . each do | word | if ( line + ' ' + word... | Word - wraps and indents the string . |
8,278 | def render text = + '' append_summary ( text ) append_usage ( text ) append_description ( text ) append_subcommands ( text ) append_options ( text ) text end | Creates a new help renderer for the given command . |
8,279 | def modify ( & block ) dsl = Cri :: CommandDSL . new ( self ) if [ - 1 , 0 ] . include? block . arity dsl . instance_eval ( & block ) else yield ( dsl ) end self end | Modifies the command using the DSL . |
8,280 | def define_command ( name = nil , & block ) dsl = Cri :: CommandDSL . new dsl . name name unless name . nil? if [ - 1 , 0 ] . include? block . arity dsl . instance_eval ( & block ) else yield ( dsl ) end cmd = dsl . command add_command ( cmd ) cmd end | Defines a new subcommand for the current command using the DSL . |
8,281 | def commands_named ( name ) @commands . each do | cmd | found = cmd . name == name || cmd . aliases . include? ( name ) return [ cmd ] if found end @commands . select do | cmd | cmd . name [ 0 , name . length ] == name end end | Returns the commands that could be referred to with the given name . If the result contains more than one command the name is ambiguous . |
8,282 | def run ( opts_and_args , parent_opts = { } , hard_exit : true ) stuff = partition ( opts_and_args ) opts_before_subcmd , subcmd_name , opts_and_args_after_subcmd = * stuff if subcommands . empty? || ( subcmd_name . nil? && ! block . nil? ) run_this ( opts_and_args , parent_opts ) else handle_options ( opts_before_subc... | Runs the command with the given command - line arguments possibly invoking subcommands and passing on the options and arguments . |
8,283 | def run_this ( opts_and_args , parent_opts = { } ) if all_opts_as_args? args = opts_and_args global_opts = parent_opts else parser = Cri :: Parser . new ( opts_and_args , global_option_definitions , parameter_definitions , explicitly_no_params? , ) handle_errors_while { parser . run } local_opts = parser . options glob... | Runs the actual command with the given command - line arguments not invoking any subcommands . If the command does not have an execution block an error ir raised . |
8,284 | def parse_error ( error ) case error when SocketError PuppetDebugger :: Exception :: ConnectError . new ( message : "Unknown host: #{Puppet[:server]}" ) when Net :: HTTPError PuppetDebugger :: Exception :: AuthError . new ( message : error . message ) when Errno :: ECONNREFUSED PuppetDebugger :: Exception :: ConnectErr... | parses the error type into a more useful error message defined in errors . rb returns new error object or the original if error cannot be parsed |
8,285 | def puppet_repl_lib_dir File . expand_path ( File . join ( File . dirname ( File . dirname ( File . dirname ( __FILE__ ) ) ) , 'lib' ) ) end | this is the lib directory of this gem in order to load any puppet functions from this gem we need to add the lib path of this gem |
8,286 | def do_initialize Puppet . initialize_settings Puppet [ :parser ] = 'future' Puppet [ :trusted_node_data ] = true rescue ArgumentError => e rescue Puppet :: DevError => e end | this is required in order to load things only when we need them |
8,287 | def key_words variables = scope . to_hash . keys scoped_vars = variables . map { | k , _v | scope . compiler . topscope . exist? ( k ) ? "$::#{k}" : "$#{k}" } funcs = function_map . keys . map { | k | "#{k.split('::').last}()" } PuppetDebugger :: InputResponders :: Datatypes . instance . debugger = self ( scoped_vars +... | returns a cached list of key words |
8,288 | def to_resource_declaration ( type ) if type . respond_to? ( :type_name ) && type . respond_to? ( :title ) title = type . title type_name = type . type_name elsif type_result = / \w \[ \w \] / . match ( type . to_s ) title = type_result [ 2 ] type_name = type_result [ 1 ] else return type end res = scope . catalog . re... | looks up the type in the catalog by using the type and title and returns the resource in ral format |
8,289 | def expand_resource_type ( types ) output = [ types ] . flatten . map do | t | if t . class . to_s =~ / / to_resource_declaration ( t ) else t end end output end | returns a formatted array |
8,290 | def handle_input ( input ) raise ArgumentError unless input . instance_of? ( String ) begin output = '' case input . strip when PuppetDebugger :: InputResponders :: Commands . command_list_regex args = input . split ( ' ' ) command = args . shift plugin = PuppetDebugger :: InputResponders :: Commands . plugin_from_comm... | this method handles all input and expects a string of text . |
8,291 | def read_loop line_number = 1 full_buffer = '' while buf = Readline . readline ( "#{line_number}:#{extra_prompt}>> " , true ) begin full_buffer += buf unless PuppetDebugger :: InputResponders :: Commands . command_list_regex . match ( buf ) line_number = line_number . next begin parser . parse_string ( full_buffer ) re... | reads input from stdin since readline requires a tty we cannot read from other sources as readline requires a file object we parse the string after each input to determine if the input is a multiline_input entry . If it is multiline we run through the loop again and concatenate the input |
8,292 | def http_get ( uri , options = { } ) found = false remaining_redirects = options [ :max_redirects ] ? options [ :max_redirects ] . to_i : 4 until found http = Net :: HTTP . new ( uri . host , uri . port ) http . use_ssl = uri . scheme == 'https' http . verify_mode = OpenSSL :: SSL :: VERIFY_PEER http . read_timeout = h... | Given a URI make an HTTP request |
8,293 | def cast_with_puppet_resource ( object , type ) cast = cast_without_puppet_resource ( object , type ) if defined? ( :: Puppet :: Type ) && ( object . class < :: Puppet :: Type ) cast = :puppet_type elsif defined? ( :: Puppet :: Pops :: Types ) && ( object . class < :: Puppet :: Pops :: Types ) cast = :puppet_type elsif... | this tells ap how to cast our object so we can be specific about printing different puppet objects |
8,294 | def initialize_copy ( orig ) hooks_dup = @hooks . dup @hooks . each do | k , v | hooks_dup [ k ] = v . dup end @hooks = hooks_dup end | Ensure that duplicates have their |
8,295 | def add_hook ( event_name , hook_name , callable = nil , & block ) event_name = event_name . to_s if hook_exists? ( event_name , hook_name ) && ! hook_name . nil? raise ArgumentError , "Hook with name '#{hook_name}' already defined!" end if ! block && ! callable raise ArgumentError , "Must provide a block or callable."... | Add a new hook to be executed for the event_name event . |
8,296 | def exec_hook ( event_name , * args , & block ) @hooks [ event_name . to_s ] . map do | hook_name , callable | begin callable . call ( * args , & block ) rescue PuppetDebugger :: Exception :: Error , :: RuntimeError => e errors << e e end end . last end | Execute the list of hooks for the event_name event . |
8,297 | def task_status ( task_id ) current_path = "/api/v1/wip/task/#{task_id}/status" res = @conn . get ( current_path ) raise InvalidDataError , "No wip task returned for task id #{task_id}" if res [ 'wip_task' ] . nil? raise InvalidDataError , "No task status returned for task id #{task_id}" if res [ 'wip_task' ] [ 'status... | Get the status of a wip task by id . |
8,298 | def find_task_ids ( limit = nil , page = nil , group = nil , klass = nil , status = nil ) res = find_tasks limit : limit , page : page , group : group , klass : klass , status : status task_ids = [ ] i = 0 res . each do | task | task_ids [ i ] = task [ 'id' ] i += 1 end task_ids end | Find a set of task ids . |
8,299 | def find_tasks ( datum = nil ) current_path = '/api/v1/tasks' pb = SFRest :: Pathbuilder . new @conn . get URI . parse ( pb . build_url_query ( current_path , datum ) ) . to_s end | Find a set of tasks . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.