Module: LogicalModel::UrlHelper::ClassMethods
- Defined in:
- lib/logical_model/url_helper.rb
Overview
adds following setters
-
force_ssl
-
set_resource_host
-
set_resource_path
add reader
-
resource_uri
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#resource_path ⇒ Object
Returns the value of attribute resource_path.
-
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
Instance Method Summary collapse
-
#do_with_resource_path(new_path) ⇒ Object
Requests done within the block will go to new path.
-
#force_ssl ⇒ Object
If called in class, will make al request through SSL.
-
#resource_uri(id = nil) ⇒ Object
Will return path to resource.
- #set_resource_host(new_host) ⇒ Object
- #set_resource_path(new_path) ⇒ Object
- #set_resource_url(new_host, new_path) ⇒ Object
-
#ssl_recommended? ⇒ Boolean
Returns true if ssl is recommended.
- #url_protocol_prefix ⇒ String
-
#use_ssl? ⇒ Boolean
Default use_ssl to ssl_recommend?.
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
17 18 19 |
# File 'lib/logical_model/url_helper.rb', line 17 def host @host end |
#resource_path ⇒ Object
Returns the value of attribute resource_path.
17 18 19 |
# File 'lib/logical_model/url_helper.rb', line 17 def resource_path @resource_path end |
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
17 18 19 |
# File 'lib/logical_model/url_helper.rb', line 17 def use_ssl @use_ssl end |
Instance Method Details
#do_with_resource_path(new_path) ⇒ Object
Requests done within the block will go to new path.
84 85 86 87 88 89 |
# File 'lib/logical_model/url_helper.rb', line 84 def do_with_resource_path(new_path) bkp_path = @resource_path @resource_path = new_path yield @resource_path = bkp_path end |
#force_ssl ⇒ Object
If called in class, will make al request through SSL.
34 35 36 |
# File 'lib/logical_model/url_helper.rb', line 34 def force_ssl @use_ssl = true end |
#resource_uri(id = nil) ⇒ Object
Will return path to resource
23 24 25 26 |
# File 'lib/logical_model/url_helper.rb', line 23 def resource_uri(id=nil) sufix = (id.nil?)? "" : "/#{id}" "#{url_protocol_prefix}#{host}#{resource_path}#{sufix}" end |
#set_resource_host(new_host) ⇒ Object
45 46 47 |
# File 'lib/logical_model/url_helper.rb', line 45 def set_resource_host(new_host) @host = new_host end |
#set_resource_path(new_path) ⇒ Object
49 50 51 |
# File 'lib/logical_model/url_helper.rb', line 49 def set_resource_path(new_path) @resource_path = new_path end |
#set_resource_url(new_host, new_path) ⇒ Object
40 41 42 43 |
# File 'lib/logical_model/url_helper.rb', line 40 def set_resource_url(new_host,new_path) @host = new_host @resource_path = new_path end |
#ssl_recommended? ⇒ Boolean
Returns true if ssl is recommended
-
requests to localhost -> false
-
other -> true
71 72 73 |
# File 'lib/logical_model/url_helper.rb', line 71 def ssl_recommended? (@host && !(@host =~ /localhost/)) end |
#url_protocol_prefix ⇒ String
61 62 63 |
# File 'lib/logical_model/url_helper.rb', line 61 def url_protocol_prefix (use_ssl?)? "https://" : "http://" end |
#use_ssl? ⇒ Boolean
Default use_ssl to ssl_recommend?
56 57 58 |
# File 'lib/logical_model/url_helper.rb', line 56 def use_ssl? @use_ssl ||= ssl_recommended? end |