Class: ActionDispatch::HostAuthorization::Permissions
- Inherits:
-
Object
- Object
- ActionDispatch::HostAuthorization::Permissions
- Defined in:
- lib/action_dispatch/middleware/host_authorization.rb
Overview
:nodoc:
Instance Method Summary collapse
- #allows?(host) ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(hosts) ⇒ Permissions
constructor
A new instance of Permissions.
Constructor Details
#initialize(hosts) ⇒ Permissions
Returns a new instance of Permissions.
33 34 35 |
# File 'lib/action_dispatch/middleware/host_authorization.rb', line 33 def initialize(hosts) @hosts = sanitize_hosts(hosts) end |
Instance Method Details
#allows?(host) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/action_dispatch/middleware/host_authorization.rb', line 41 def allows?(host) @hosts.any? do |allowed| if allowed.is_a?(IPAddr) begin allowed === extract_hostname(host) rescue # IPAddr#=== raises an error if you give it a hostname instead of # IP. Treat similar errors as blocked access. false end else allowed === host end end end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/action_dispatch/middleware/host_authorization.rb', line 37 def empty? @hosts.empty? end |