Class: ApiBlueprint::Url
- Inherits:
-
Object
- Object
- ApiBlueprint::Url
- Defined in:
- lib/api-blueprint/url.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#custom ⇒ Object
Returns the value of attribute custom.
Instance Method Summary collapse
-
#initialize(base = "", custom = "") ⇒ Url
constructor
A new instance of Url.
- #to_s ⇒ Object
Constructor Details
#initialize(base = "", custom = "") ⇒ Url
Returns a new instance of Url.
5 6 7 8 |
# File 'lib/api-blueprint/url.rb', line 5 def initialize(base = "", custom = "") self.base = base self.custom = custom end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
3 4 5 |
# File 'lib/api-blueprint/url.rb', line 3 def base @base end |
#custom ⇒ Object
Returns the value of attribute custom.
3 4 5 |
# File 'lib/api-blueprint/url.rb', line 3 def custom @custom end |
Instance Method Details
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/api-blueprint/url.rb', line 18 def to_s if base.path.present? && custom.path.present? && !custom.host.present? # Join paths in a permissive way which handles extra slashes gracefully and returns # a string which Addressable can handle when joining with other paths paths = [base.path, custom.path].compact.map { |path| path.gsub(%r{^/*(.*?)/*$}, '\1') }.join("/") Addressable::URI.join(base.site, paths).to_s else base.join(custom).to_s end end |