Class: Ronin::Web::Browser::CookieFile

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/web/browser/cookie_file.rb

Overview

Represents a file of cookies.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CookieFile

Initializes a cookie file.

Parameters:

  • path (String)

    The path to the cookie file.



44
45
46
# File 'lib/ronin/web/browser/cookie_file.rb', line 44

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathString (readonly)

The path to the file.

Returns:

  • (String)


36
37
38
# File 'lib/ronin/web/browser/cookie_file.rb', line 36

def path
  @path
end

Class Method Details

.save(path, cookies) ⇒ Object

Writes the cookies to the cookie file.

Parameters:

  • path (String)

    The path to the cookie file to write to.

  • cookies (Array<Cookie>, Enumerator<Cookie>)

    The cookies to write.



57
58
59
60
61
62
63
# File 'lib/ronin/web/browser/cookie_file.rb', line 57

def self.save(path,cookies)
  File.open(path,'w') do |file|
    cookies.each do |cookie|
      file.puts(cookie)
    end
  end
end

Instance Method Details

#each {|cookie| ... } ⇒ Enumerator

Parses each cookie in the cookie file.

Yields:

  • (cookie)

    The given block will be passed each cookie parsed from each line of the file.

Yield Parameters:

  • cookie (Cookie)

    A cookie parsed from the file.

Returns:

  • (Enumerator)

    If no block is given, then an Enumerator will be returned.



78
79
80
81
82
83
84
85
86
# File 'lib/ronin/web/browser/cookie_file.rb', line 78

def each
  return enum_for(__method__) unless block_given?

  File.open(@path) do |file|
    file.each_line(chomp: true) do |line|
      yield Cookie.parse(line)
    end
  end
end