Class: Avo::Services::URIService

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/services/uri_service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "") ⇒ URIService

Returns a new instance of URIService.



14
15
16
# File 'lib/avo/services/uri_service.rb', line 14

def initialize(path = "")
  @uri = Addressable::URI.parse(path)
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



12
13
14
# File 'lib/avo/services/uri_service.rb', line 12

def uri
  @uri
end

Class Method Details

.parse(path) ⇒ Object



7
8
9
# File 'lib/avo/services/uri_service.rb', line 7

def parse(path)
  new path
end

Instance Method Details

#append_paths(*paths) ⇒ Object Also known as: append_path



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/avo/services/uri_service.rb', line 22

def append_paths(*paths)
  paths = Array.wrap(paths).flatten

  return self if paths.blank?

  # Add the intermediary forward slash
  @uri.path.concat("/") unless @uri.path.ends_with? "/"

  # Add the paths to the URI
  @uri.path = @uri.path.concat(join_paths(paths))

  self
end

#append_query(params) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/avo/services/uri_service.rb', line 37

def append_query(params)
  params = if params.is_a? Hash
    params.map do |key, value|
      "#{key}=#{value}"
    end
  else
    {}
  end

  return self if params.blank?

  # Add the query params to the URI
  @uri.query = [@uri.query, *params].compact.join("&")

  self
end

#callObject



18
19
20
# File 'lib/avo/services/uri_service.rb', line 18

def call
  to_s
end

#to_sObject



54
55
56
# File 'lib/avo/services/uri_service.rb', line 54

def to_s
  @uri.to_s
end