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.



75
76
77
78
79
80
81
# File 'lib/watobo/http/cookies/cookies.rb', line 75

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

end

Instance Method Details

#each(&block) ⇒ Object



47
48
49
50
51
# File 'lib/watobo/http/cookies/cookies.rb', line 47

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

#has_parm?(parm_name) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/watobo/http/cookies/cookies.rb', line 58

def has_parm?(parm_name)
  false
end

#inspectObject



34
35
36
# File 'lib/watobo/http/cookies/cookies.rb', line 34

def inspect
  self.to_a
end

#parameters(&block) ⇒ Object

def



64
65
66
67
68
69
70
71
72
73
# File 'lib/watobo/http/cookies/cookies.rb', line 64

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



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

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

#to_aObject



38
39
40
41
42
43
44
# File 'lib/watobo/http/cookies/cookies.rb', line 38

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

#to_sObject



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

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