Class: Avo::Services::URIService
- Inherits:
-
Object
- Object
- Avo::Services::URIService
- Defined in:
- lib/avo/services/uri_service.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #append_paths(*paths) ⇒ Object (also: #append_path)
- #append_query(params) ⇒ Object
- #call ⇒ Object
-
#initialize(path = "") ⇒ URIService
constructor
A new instance of URIService.
- #to_s ⇒ Object
Constructor Details
#initialize(path = "") ⇒ URIService
Returns a new instance of URIService.
12 13 14 |
# File 'lib/avo/services/uri_service.rb', line 12 def initialize(path = "") @uri = Addressable::URI.parse(path) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/avo/services/uri_service.rb', line 10 def uri @uri end |
Class Method Details
.parse(path) ⇒ Object
5 6 7 |
# File 'lib/avo/services/uri_service.rb', line 5 def parse(path) new path end |
Instance Method Details
#append_paths(*paths) ⇒ Object Also known as: append_path
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/avo/services/uri_service.rb', line 20 def append_paths(*paths) paths = Array.wrap(paths).flatten return self if paths.blank? # Add the intermediary forward slash @uri.path = @uri.path.concat("/") unless @uri.path.ends_with? "/" # Add the paths to the URI @uri.merge!(path: @uri.path.concat(join_paths(paths))) self end |
#append_query(params) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/avo/services/uri_service.rb', line 35 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.merge!(query: [@uri.query, *params].compact.join("&")) self end |
#call ⇒ Object
16 17 18 |
# File 'lib/avo/services/uri_service.rb', line 16 def call to_s end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/avo/services/uri_service.rb', line 52 def to_s @uri.to_s end |