Class: Dommy::Url
- Inherits:
-
Object
- Object
- Dommy::Url
- Defined in:
- lib/dommy/router.rb
Overview
‘URL` constructor — Ruby `URI` wrap. Browser URL API surface: `[:origin]`, `[:pathname]`, `[:search]`, `[:hash]`, `[:href]`. Supports the two-arg form `new URL(raw, base)`.
Instance Method Summary collapse
- #__js_call__(method, _args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #__js_set__(_key, _value) ⇒ Object
-
#initialize(raw, base = nil) ⇒ Url
constructor
A new instance of Url.
Constructor Details
#initialize(raw, base = nil) ⇒ Url
Returns a new instance of Url.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/dommy/router.rb', line 218 def initialize(raw, base = nil) uri = if base && !base.empty? URI.join(base, raw) else URI(raw.to_s) end @origin = origin_of(uri) @pathname = uri.path.to_s == "" ? "/" : uri.path @search = uri.query ? "?#{uri.query}" : "" @hash = uri.fragment ? "##{uri.fragment}" : "" @href = uri.to_s rescue URI::InvalidURIError, ArgumentError @origin = "" @pathname = "" @search = "" @hash = "" @href = raw.to_s end |
Instance Method Details
#__js_call__(method, _args) ⇒ Object
259 260 261 |
# File 'lib/dommy/router.rb', line 259 def __js_call__(method, _args) method == "toString" ? @href : nil end |
#__js_get__(key) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/dommy/router.rb', line 238 def __js_get__(key) case key when "origin" @origin when "pathname" @pathname when "search" @search when "hash" @hash when "href" @href when "toString" @href end end |
#__js_set__(_key, _value) ⇒ Object
255 256 257 |
# File 'lib/dommy/router.rb', line 255 def __js_set__(_key, _value) nil end |