Class: Watobo::HTTP::Cookies

Inherits:
Object
  • Object
show all
Defined in:
lib/watobo/http/cookies/cookies.rb

Defined Under Namespace

Modules: Mixin

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Cookies

Returns a new instance of Cookies.



53
54
55
56
57
58
59
# File 'lib/watobo/http/cookies/cookies.rb', line 53

def initialize(root)
  @root = root
  @cookies = {}

  init_cookies

end

Instance Method Details

#each(&block) ⇒ Object



25
26
27
28
29
# File 'lib/watobo/http/cookies/cookies.rb', line 25

def each(&block)
  @cookies.each_value do |cookie|
    yield cookie if block_given?
  end
end

#has_parm?(parm_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/watobo/http/cookies/cookies.rb', line 36

def has_parm?(parm_name)
  false
end

#inspectObject



13
14
15
# File 'lib/watobo/http/cookies/cookies.rb', line 13

def inspect
  self.to_a
end

#parameters(&block) ⇒ Object

def



42
43
44
45
46
47
48
49
50
51
# File 'lib/watobo/http/cookies/cookies.rb', line 42

def parameters(&block)
  params = []
  raw_cookies do |cprefs|
    cookie = Watobo::CookieParameter.new(cprefs)
    yield cookie if block_given?
    params << cookie

  end
  params
end

#set(parm) ⇒ Object



31
32
33
34
# File 'lib/watobo/http/cookies/cookies.rb', line 31

def set(parm)
  @cookies[parm.name.to_sym] = parm
  @root.set_header("Cookie", self.to_s)
end

#to_aObject



17
18
19
20
21
22
23
# File 'lib/watobo/http/cookies/cookies.rb', line 17

def to_a
  cookies = []
  raw_cookies do |c|
    cookies << Watobo::Cookie.new(c)
  end
  cookies
end

#to_sObject



5
6
7
8
9
10
11
# File 'lib/watobo/http/cookies/cookies.rb', line 5

def to_s
  s = []
  @cookies.each_value do |v|
    s << "#{v.name}=#{v.value}"
  end
  s.join("; ")
end