class Nephos::Cookies

Params to a hash, where every elements are accessibles via a stringified key so, even if the entry was added with the key :KEY, it will be accessible via a string equivalent to :key.to_s

param["key"] == param[:key]

Every methods present in {Hash} are usable in {Param}.

Public Class Methods

new(hash={}) click to toggle source

@param hash [Hash] hash containing the parameters

# File lib/nephos-server/cookies.rb, line 14
def initialize(hash={})
  raise ArgumentError, "the first argument must be a Hash" unless hash.is_a? Hash
  # TODO: take care of the path
  @hash = Hash[hash.map{|k,v| [k.to_s, {content: v, path: "/"}]}]
end

Public Instance Methods

[](i) click to toggle source
# File lib/nephos-server/cookies.rb, line 25
def [] i
  c = @hash[i.to_s]
  c && c[:content]
end
[]=(i, v, path="/") click to toggle source
# File lib/nephos-server/cookies.rb, line 30
def []= i, v, path="/"
  @hash[i.to_s] = {content: v.to_s, path: path.to_s}
end
method_missing(m, *a) click to toggle source
# File lib/nephos-server/cookies.rb, line 20
def method_missing m, *a
  @hash.send(m, *(a.map(&:to_s)))
  @hash.send(m, *a)
end
path(i) click to toggle source
# File lib/nephos-server/cookies.rb, line 34
def path i
  @hash[i.to_s][:path]
end
set_path(i, v) click to toggle source
# File lib/nephos-server/cookies.rb, line 38
def set_path i, v
  raise InvalidPath, v unless v.is_a? String
  @hash[i.to_s][:path] = URI.encode(v)
end
to_h() click to toggle source
# File lib/nephos-server/cookies.rb, line 43
def to_h
  return @hash
end
Also aliased as: to_hash
to_hash()
Alias for: to_h
to_s() click to toggle source
# File lib/nephos-server/cookies.rb, line 48
def to_s
  return to_h.to_s
end