Class: RackCAS::URL

Inherits:
Addressable::URI
  • Object
show all
Defined in:
lib/rack-cas/url.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(uri) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/rack-cas/url.rb', line 5

def self.parse(uri)
  # I know this looks stupid but this seems to be the best way to get
  # Addressable to replace + spaces with %20 spaces. Standardizing on %20
  # should prevent service lookup issues due to encoding differences.
  super.tap do |u|
    u.query_values = u.query_values
  end
end

Instance Method Details

#add_params(params) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rack-cas/url.rb', line 20

def add_params(params)
  self.tap do |u|
    u.query_values = (u.query_values || {}).tap do |qv|
      params.each do |key, value|
        qv[key] = value
      end
    end
  end
end

#append_path(path) ⇒ Object



14
15
16
17
18
# File 'lib/rack-cas/url.rb', line 14

def append_path(path)
  self.tap do |u|
    u.path = (u.path.split('/') + [path]).join('/')
  end
end

#dupObject



48
49
50
# File 'lib/rack-cas/url.rb', line 48

def dup
  RackCAS::URL.new(super.to_hash)
end

#remove_param(param) ⇒ Object



30
31
32
# File 'lib/rack-cas/url.rb', line 30

def remove_param(param)
  remove_params(Array(param))
end

#remove_params(params) ⇒ Object

params can be an array or a hash



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rack-cas/url.rb', line 35

def remove_params(params)
  self.tap do |u|
    u.query_values = (u.query_values || {}).tap do |qv|
      params.each do |key, value|
        qv.delete key
      end
    end
    if u.query_values.empty?
      u.query_values = nil
    end
  end
end