123456789_123456789_123456789_123456789_123456789_

Class: ActionController::AllowBrowser::BrowserBlocker

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_controller/metal/allow_browser.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(request, versions:) ⇒ BrowserBlocker

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 80

def initialize(request, versions:)
  @request, @versions = request, versions
end

Instance Attribute Details

#blocked?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 84

def blocked?
  user_agent_version_reported? && unsupported_browser?
end

#bot?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 105

def bot?
  parsed_user_agent.bot?
end

#request (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 78

attr_reader :request, :versions

#unsupported_browser?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 97

def unsupported_browser?
  version_guarded_browser? && version_below_minimum_required? && !bot?
end

#user_agent_version_reported?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 93

def user_agent_version_reported?
  request.user_agent.present? && parsed_user_agent.version.to_s.present?
end

#version_below_minimum_required?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 109

def version_below_minimum_required?
  if minimum_browser_version_for_browser
    parsed_user_agent.version < UserAgent::Version.new(minimum_browser_version_for_browser.to_s)
  else
    true
  end
end

#version_guarded_browser?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 101

def version_guarded_browser?
  minimum_browser_version_for_browser != nil
end

#versions (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 78

attr_reader :request, :versions

Instance Method Details

#expanded_versions (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 121

def expanded_versions
  @expanded_versions ||= (SETS[versions] || versions).with_indifferent_access
end

#minimum_browser_version_for_browser (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 117

def minimum_browser_version_for_browser
  expanded_versions[normalized_browser_name]
end

#normalized_browser_name (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 125

def normalized_browser_name
  case name = parsed_user_agent.browser.downcase
  when "internet explorer" then "ie"
  else name
  end
end

#parsed_user_agent (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/allow_browser.rb', line 89

def parsed_user_agent
  @parsed_user_agent ||= UserAgent.parse(request.user_agent)
end