123456789_123456789_123456789_123456789_123456789_

Class: YARD::Server::HTTPUtils::FormData

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::String
Instance Chain:
self, ::String
Inherits: String
  • Object
Defined in: lib/yard/server/http_utils.rb

Overview

Stores multipart form data. FormData objects are created when WEBrick::HTTPUtils.parse_form_data is called.

Since:

  • 0.6.0

Constant Summary

Class Method Summary

Instance Attribute Summary

  • #filename rw

    The filename of the form data part.

  • #name rw

    The name of the form data part.

Instance Method Summary

::String - Inherited

#shell_split

Splits text into tokens the way a shell would, handling quoted text as a single token.

Constructor Details

.new(*args) ⇒ FormData

Creates a new FormData object.

args is an ::Array of form data entries. One FormData will be created for each entry.

This is called by WEBrick::HTTPUtils.parse_form_data for you

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 267

def initialize(*args)
  @name = @filename = @next_data = nil
  if args.empty?
    @raw_header = []
    @header = nil
    super("")
  else
    @raw_header = EmptyRawHeader
    @header = EmptyHeader
    super(args.shift)
    unless args.empty?
      @next_data = self.class.new(*args)
    end
  end
end

Instance Attribute Details

#filename (rw)

The filename of the form data part

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 254

attr_accessor :filename

#name (rw)

The name of the form data part

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 249

attr_accessor :name

Instance Method Details

#<<(str)

Adds str to this FormData which may be the body, a header or a header entry.

This is called by WEBrick::HTTPUtils.parse_form_data for you

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 300

def <<(str)
  if @header
    super
  elsif str == CRLF
    @header = HTTPUtils::parse_header(@raw_header.join)
    if cd = self['content-disposition']
      if /\s+name="(.*?)"/ =~ cd then @name = $1 end
      if /\s+filename="(.*?)"/ =~ cd then @filename = $1 end
    end
  else
    @raw_header << str
  end
  self
end

#[](*key)

Retrieves the header at the first entry in key

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 286

def [](*key)
  begin
    @header[key[0].downcase].join(", ")
  rescue StandardError, NameError
    super
  end
end

#append_data(data)

Adds data at the end of the chain of entries

This is called by WEBrick::HTTPUtils.parse_form_data for you.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 320

def append_data(data)
  tmp = self
  while tmp
    unless tmp.next_data
      tmp.next_data = data
      break
    end
    tmp = tmp.next_data
  end
  self
end

#each_data

Yields each entry in this FormData

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 335

def each_data
  tmp = self
  while tmp
    next_data = tmp.next_data
    yield(tmp)
    tmp = next_data
  end
end

#list Also known as: #to_ary

Returns all the FormData as an ::Array

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 347

def list
  ret = []
  each_data{|data|
    ret << data.to_s
  }
  ret
end

#to_ary

A FormData will behave like an ::Array

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 358

alias :to_ary :list

#to_s

This FormData's body

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/http_utils.rb', line 363

def to_s
  String.new(self)
end