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.
14 15 16 |
# File 'lib/avo/services/uri_service.rb', line 14 def initialize(path = "") @uri = Addressable::URI.parse(path) end |
Instance Attribute Details
#uri ⇒ Object (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 |
#call ⇒ Object
18 19 20 |
# File 'lib/avo/services/uri_service.rb', line 18 def call to_s end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/avo/services/uri_service.rb', line 54 def to_s @uri.to_s end |