Class: URL
Overview
The url class handles parsing and updating the url
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
TODO: we need to make it so change events only trigger on changes.
-
#params ⇒ Object
readonly
TODO: we need to make it so change events only trigger on changes.
-
#path ⇒ Object
readonly
TODO: we need to make it so change events only trigger on changes.
-
#port ⇒ Object
readonly
TODO: we need to make it so change events only trigger on changes.
-
#query ⇒ Object
readonly
TODO: we need to make it so change events only trigger on changes.
-
#router ⇒ Object
Returns the value of attribute router.
-
#scheme ⇒ Object
readonly
TODO: we need to make it so change events only trigger on changes.
Instance Method Summary collapse
-
#full_url ⇒ Object
Full url rebuilds the url from it’s constituent parts.
-
#initialize(router = nil) ⇒ URL
constructor
A new instance of URL.
- #parse(url) ⇒ Object
-
#update! ⇒ Object
TODO: ! methods should default to destructive.
Methods included from ReactiveTags
included, #reactive_method_tag
Constructor Details
#initialize(router = nil) ⇒ URL
Returns a new instance of URL.
9 10 11 12 |
# File 'lib/volt/models/url.rb', line 9 def initialize(router=nil) @router = router @params = Params.new({}, 'params') end |
Instance Attribute Details
#host ⇒ Object (readonly)
TODO: we need to make it so change events only trigger on changes
6 7 8 |
# File 'lib/volt/models/url.rb', line 6 def host @host end |
#params ⇒ Object (readonly)
TODO: we need to make it so change events only trigger on changes
6 7 8 |
# File 'lib/volt/models/url.rb', line 6 def params @params end |
#path ⇒ Object (readonly)
TODO: we need to make it so change events only trigger on changes
6 7 8 |
# File 'lib/volt/models/url.rb', line 6 def path @path end |
#port ⇒ Object (readonly)
TODO: we need to make it so change events only trigger on changes
6 7 8 |
# File 'lib/volt/models/url.rb', line 6 def port @port end |
#query ⇒ Object (readonly)
TODO: we need to make it so change events only trigger on changes
6 7 8 |
# File 'lib/volt/models/url.rb', line 6 def query @query end |
#router ⇒ Object
Returns the value of attribute router.
7 8 9 |
# File 'lib/volt/models/url.rb', line 7 def router @router end |
#scheme ⇒ Object (readonly)
TODO: we need to make it so change events only trigger on changes
6 7 8 |
# File 'lib/volt/models/url.rb', line 6 def scheme @scheme end |
Instance Method Details
#full_url ⇒ Object
Full url rebuilds the url from it’s constituent parts
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/volt/models/url.rb', line 33 def full_url if @port host_with_port = "#{@host}:#{@port}" else host_with_port = @host end path, params = @router.url_for_params(@params) new_url = "#{@scheme}://#{host_with_port}#{path || @path}" unless params.empty? new_url += '?' query_parts = [] nested_params_hash(params).each_pair do |key,value| value = value.cur # remove the _ from the front value = `encodeURI(value)` query_parts << "#{key}=#{value}" end new_url += query_parts.join('&') end return new_url end |
#parse(url) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/volt/models/url.rb', line 19 def parse(url) matcher = url.match(/^(https?)[:]\/\/([^\/]+)(.*)$/) @scheme = matcher[1] @host, @port = matcher[2].split(':') @port ||= 80 @path = matcher[3] @path, @fragment = @path.split('#', 2) @path, @query = @path.split('?', 2) assign_query_hash_to_params end |
#update! ⇒ Object
TODO: ! methods should default to destructive
67 68 69 70 71 72 73 |
# File 'lib/volt/models/url.rb', line 67 def update! new_url = full_url() if `(document.location.href != new_url)` `history.pushState(null, null, new_url)` end end |